Safe Casting Collections using utility methods
Hi,
I am wondering, are there any utility methods that help extract the elements form one collection<?> to Collection<Box>??
for example, I may have a method signiture that takes List<Box> as a parameter called doYourJob.
and I have a List of List< ? extends Object> someList.
ofcourse I cant use this object for that method:
List<? extends Object> someList;
doYourJob(someList);//wrong
public void doYourJob(List<Box>list){
}what I need to do is to make a utility method that extracts a spisific type from the collection and puts them in another collection:
public List<Box> extract (List<?>list){
ArrayList<Object>newList=new ArrayList<Object>();
for(Object o:list){
if(o instanceof Box)newList.add((Box)o);
return newList;
}my question is: are there in the jave API utility methods to change the generic type of a collection by changing the collection as whole.
Maybe I can send the type that I want as Box.class and it returns that list.
Sorry if the question is repetitive!
I wish his was something that was easier to do in
Java because I think more people would use that
approach if it weren't so verbose.
Maybe I'm confused here, but I don't think of coding
up an interface as being an especially verbose or
arduous exercise...? But then I'm not too sure what
you're comparing it with.It's not writing the interface that's the problem. It's writing the code to wrap the existing classes in your wrappers or whatever implementation you come up with. Doing it once is no big deal but if you are using it as a fairly common approach in your code (as I do) it can become pretty messy. What really bothers me is that it takes a lot of fluff code. I've been looking at other languages esp. Scala on this and they have very concise composition syntax. I'm not ready to go with Scala but I think if the language steered people more towards composition and 'recasting' objects through interfaces, people would do more of it.
I'm working with one now that's all about return
codes and simulating in-out parameters (I said it
once and I'll say it again: Joel Spolsky is an
idiot.)
Hmm. I read Joel On Software, and from a business
perspective he seems pretty clued in. I've never
encountered any of his code, nor read anything much
of a purely technical-diatribe nature from him. But
I'm still alittle surprised.Not sure if you've read this:
http://www.joelonsoftware.com/items/2003/10/13.html
I'm exaggerating, of course. I don't really think he's an idiot but I think the above is super-extra-double-plus stupid. I really can't fathom why he thinks return codes are superior. I can only think he doesn't really get how exceptions work.
There's also this ironically named URL:
http://www.joelonsoftware.com/articles/Wrong.html
Similar Messages
-
How to use utility methods to implement synchronization ?
Hi,
We know that Vector is synchronized , but as it causes performance loss . So how can I use the utility methods of Collections to implement synchonization.
Please help me.
Thanx in advance.http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#synchronizedCollection(java.util.Collection)
See also
http://java.sun.com/j2se/1.5.0/docs/guide/collections/index.html
http://java.sun.com/j2se/1.5.0/docs/guide/collections/overview.html
http://java.sun.com/docs/books/tutorial/collections/index.html
http://java.sun.com/docs/books/tutorial/collections/implementations/wrapper.html -
Class cast exception using Finder method
Hello. I'm new to J2EE. I have set up one entity bean but am having trouble
with my current one.
Basically, I have two finder methods:
public ShareHistory findByPrimaryKey(Integer historyId)
throws FinderException, RemoteException;
public Collection findByShare(String shareId)
throws FinderException, RemoteException; findByPrimaryKey works fine, but findByShare causes a class cast exception in java.lang.String.
The stack trace in the server logs shows that it is my ejbActivate method in my entity bean causing the problem:
public void ejbActivate() {
//String numberString = (String) context.getPrimaryKey();
//historyId = new Integer(numberString);
historyId = (Integer) context.getPrimaryKey();
}The stack trace from my client shows that the class cast exception occurs
in the client at the System.out.println("shareid" + ": " + sh.getShareId());
line:
Collection c = sharesHistoryHome.findByShare("DCAN");
Iterator i = c.iterator();
while (i.hasNext()) {
ShareHistory sh = (ShareHistory) i.next();
System.out.println("shareid" + ": " + sh.getShareId());
System.out.println("value" + ": " + sh.getValue());
System.out.println("time" + ": " + sh.getTime());
System.out.println("date" + ": " + sh.getDate());
}//whileAs you can see I tried casting to a string in ejbactivate, but that simply causes an Integer class cast exception during findByprimaryKey instead. How do I allow both Integer and String objects to be used?
Also I am a bit confused as to why the String passed to findByShare(String) is being used in context.getPrimaryKey() in the first place (if that is actually what's happening).Oops my FindByShare method was returning a collection of shareId's (strings) instead of a collection of Integer primary keys, which would explain the class cast exception.
-
I can't burn a dvd using any method, idvd tells me that my super drive is missing, dvd studio pro quits when i click burn and disk utility keeps spitting the disk out when I click burn and enter the disk??? how do i repair my superdrive for imac, or how do I do whatever I need to do to get it working: I have already tried using a lens cleaning cd and also restored my nvram or something i forget what it was called but i restarted my computer holding down command+optoion+p+r and still nothing???
Free solutions are the best, although if I have to pay I will, I would prefer to not have to buy an external burner if possible and already know that is an option so please don't give me that answer... thank you for any help you can giveUnless your iMac is still covered by AppleCare, get an external DVD burner.
You can get perfectly good ones from Amazon for less than $40. -
Getting error while using TRIM method in collections
Hi Experts,
While using TRIM method I am getting below error. Am I doing any mistake here ?
DB : Oracle 11g
SQL> declare
2
3 type emp_tab is table of employees%rowtype index by binary_integer;
4 l_emp_tab emp_tab;
5
6 begin
7
8 select * bulk collect into l_emp_tab from employees;
9 l_emp_tab.trim(5);
10 dbms_output.put_line(l_emp_tab.count);
11
12 end;
13 /
l_emp_tab.trim(5);
ERROR at line 9:
ORA-06550: line 9, column 2:
PLS-00306: wrong number or types of arguments in call to 'TRIM'
ORA-06550: line 9, column 2:
PL/SQL: Statement ignored
Thanks in advance for all your help.
Cheers,
SuriGerard, and to Unkonwn epxpert ;-)
Thanks for the reply. I am aware about extend method. But not sure about TRIM. Once again thanks for your help.
Cheers,
Suri -
Unexpected "numeric or value error" when using CAST COLLECT
I am having trouble with string aggregation using CAST / COLLECT and the to_string function described on various sites around the net including AskTom and http://www.oracle-developer.net/display.php?id=306.
I am getting "numeric or value error: character string buffer too small" but cannot see which limit I am exceeding.
I have put together a simple test case to highlight this problem which I have pasted below.
The error does not seem to be coming from the to_string function itself (else I expect we would see "TO_STRING raised an exception" in the returned error message).
Any thoughts much appreciated,
Thanks, Andy
SQL*Plus: Release 10.1.0.4.2 - Production on Tue Jun 15 09:56:53 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> CREATE TYPE table_of_varchar2 AS TABLE OF VARCHAR2(32000);
2 /
Type created.
SQL> CREATE OR REPLACE FUNCTION to_string (
2 nt_in IN table_of_varchar2
3 , delimiter_in IN VARCHAR2 DEFAULT ',')
4 RETURN VARCHAR2
5 IS
6 l_idx PLS_INTEGER;
7 l_str VARCHAR2(32767);
8 l_dlm VARCHAR2(10);
9
10 BEGIN
11
12 l_idx := nt_in.FIRST;
13 WHILE l_idx IS NOT NULL LOOP
14 l_str := l_str || l_dlm || nt_in(l_idx);
15 l_dlm := delimiter_in;
16 l_idx := nt_in.NEXT(l_idx);
17 END LOOP;
18
19 RETURN l_str;
20 EXCEPTION
21 WHEN OTHERS THEN
22 raise_application_error(-20000
23 , 'TO_STRING raised an exception. '||
24 'The reported error was: '||sqlerrm);
25 END to_string;
26 /
Function created.
SQL> DECLARE
2 l_longstring varchar2(32000);
3 BEGIN
4 SELECT to_string(CAST( COLLECT( substr(object_name,1,1) ) AS table_of_varchar2 ) )
5 INTO l_longstring
6 FROM all_objects
7 WHERE rownum < 2001;
8
9 EXCEPTION
10 WHEN OTHERS THEN
11 raise_application_error(-20001
12 , 'The anonymous block raised an exception: '||
13 sqlerrm||'. '||DBMS_UTILITY.format_error_backtrace);
14 END;
15 /
PL/SQL procedure successfully completed.
SQL> DECLARE
2 l_longstring varchar2(32000);
3 BEGIN
4 SELECT to_string(CAST( COLLECT( substr(object_name,1,1) ) AS table_of_varchar2 ) )
5 INTO l_longstring
6 FROM all_objects
7 WHERE rownum < 2002;
8
9 EXCEPTION
10 WHEN OTHERS THEN
11 raise_application_error(-20001
12 , 'The anonymous block raised an exception: '||
13 sqlerrm||'. '||DBMS_UTILITY.format_error_backtrace);
14 END;
15 /
DECLARE
ERROR at line 1:
ORA-20001: The anonymous block raised an exception: ORA-06502: PL/SQL: numeric
or value error: character string buffer too small
ORA-06512: at line 1. ORA-06512: at line 1
ORA-06512: at line 4
ORA-06512: at line 11Aha, of course.
I was aware of the 4000 character SQL VARCHAR2 limit but didn't think it would apply here since we are calling a PLSQL function and trying to assign the value it returns into a PLSQL varchar2(32000) variable. BUT... we are of course doing this via a SELECT statement and hence via SQL. Therefore the SQL 4000 limit applies.
With this in mind, I changed the RETURN type of the to_string function to be CLOB. This solved the problem.
Thank you,
Andy -
Using CAST/COLLECT with a function
I have a select statement that gathers comments into a report by user ID and Project Name.
This works really well until I get to a point where the total comments exceeds 4000 characters, then I get a "character string buffer too small".
Is there another way to gather the comments and report on them in APEX?
Here is the Select Statement:
/** START SELECT
SELECT
PROJECT_NAME, USER_ID, COLLECT_FUNC(CAST(COLLECT (USER_NOTES) AS VARCHAR2_T)) as COMMENTS
FROM
TBL_PROJECT
where PROJ_DATE >= to_date('5/1/2011','MM/DD/YYYY') and PROJ_DATE <= to_date('6/30/2011','MM/DD/YYYY')
PROJECT_NAME, USER_ID
order by USER_ID;
/** END SELECT
Where the VARCHAR2_T is:
CREATE OR REPLACE TYPE "VARCHAR2_T" as table of varchar2(4000)
and the function that collects the comments is:
/*** START CODE
create or replace function collect_func (t in varchar2_t)
return varchar2
as
ret varchar(4000) := '';
i number;
begin
i := t.first;
while i is not null loop
if ret is not null then
ret := ret || ' -- <BR> ';
end if;
ret := ret || t(i);
i := t.next(i);
end loop;
return ret;
end;
/*** END CODESleepDeprivedInSeattle wrote:
I created a workspace at http://apex.oracle.com
The user name is: TEST_USER
Password is: myPassword1!You need to tell us the workspace name as well.
If you go to the SQL Workshop, SQL Commands window and try to execute:
SELECT
PROJECT_NAME, USER_ID, COLLECT_FUNC(CAST(COLLECT (COMMENTS_FLD) AS VARCHAR2_T)) as COMMENTS
FROM
TBL_PROJECT
group by PROJECT_NAME, USER_ID
order by USER_ID;
It will work for 10 row. But if you select 1000 rows, it fails because one of the projects has more than 4000 characters in the COMMENTS_FLD field. I expanded the VARCHAR to 6000 and it still fails.The VARCHAR2maximum size of <tt>VARCHAR2</tt> value that can be returned in Oracle SQL is 4000 bytes.
To return more than 4000 bytes, modify <tt>collect_func</tt> to return a CLOB, or use a different string aggregation technique. I normally (ab)use XMLDB for this as it:
<li>allows for either VARCHAR2 or CLOB output
<li>doesn't require any additional objects or privileges
<li>produces clean and properly structured XHTML without a lot of tedious and unreadable concatenations (my colleagues point out that it introduces a lot of tedious and unreadable XMLDB stuff instead)
SQL> select
2 d.deptno
3 , d.dname
4 , xmlserialize(
5 content
6 xmlelement(
7 "ul"
8 , xmlagg(
9 xmlelement("li", e.ename)
10 order by e.ename
11 )
12 )
13 as clob
14 indent size=2
15 ) employees
16 from
17 dept d
18 join emp e on d.deptno = e.deptno
19 group by
20 d.deptno
21 , d.dname
22 order by
23 d.deptno
24* , d.dname
SQL> /
DEPTNO DNAME EMPLOYEES
10 ACCOUNTING <ul>
<li>CLARK</li>
<li>KING</li>
<li>MILLER</li>
</ul>
20 RESEARCH <ul>
<li>ADAMS</li>
<li>JONES</li>
<li>SCOTT</li>
<li>SMITH</li>
</ul>
30 SALES <ul>
<li>ALLEN</li>
<li>BLAKE</li>
<li>JAMES</li>
<li>MARTIN</li>
<li>TURNER</li>
<li>WARD</li>
</ul>
40 OPERATIONS <ul>
<li>FORD</li>
</ul>Note that there is a 32K limit on the total size of a report row in APEX, including all data and mark-up. -
How to encrypt a big folder without using disk utility method ?
How to encrypt big folder
suck as 100 GB
without using disk utility method ??Click the partioned disk > Hit Erase Tab >
Under "Format" Select "MAC OS Extended Journaled, Encrypted
Click "Erase"
Set Password ..
Done -
Is it safe to collect credit card information from donors using a fillable emailable form?
I work for a nonprofit and would like to create a fillable pledge form that we would email to current donors. Our pledge form (which is currently sent and recieved by mail) gives them the opportunity to say how much they'd like to donate and exactly how it should be done (check, credit card, installments, payroll deduction etc). I know how to create the form and how to put an email / print button on the form. What I can't seem to find on any threads is an answer regarding how safe the collected information that is EMAILED back to us would be. Would we be putting our donors at risk by collecting that kind of data via email? If so is there a way to make it safe - and that doesn't make it complicated for our less tech-savvy friends? Would there be any safety difference between creating the form using LiveCycle vs using the pdf form wizard?
Any advice would be much appreciated.As you are using email as the vehichle for delivery the question isn't how safe is the form ...it is how safe is the email system that is being used.
The form itself will be a PDF so by virtue of that anyone can open it (unless you employ an encryption strategy but that woudl be a nuisance to your clients). You coudl employ a password to open the PDF but again that is a nuisance for your clients. So secure email might be the easiest way.
Normally this is done by posting the form to a web server using https protocols (secure and encypted) and not through email.
Paul -
Casting & abstract class & final method
what is casting abstract class & final method in ABAP Objects give some scenario where actually use these.
Hi Sri,
I'm not sure we can be any more clear.
An Abstract class can not be instantiated. It can only be used as the superclass for it's subclasses. In other words it <b>can only be inherited</b>.
A Final class cannot be the superclass for a subclass. In other words <b>it cannot be inherited.</b>
I recommend the book <a href="http://www.sappress.com/product.cfm?account=&product=H1934">ABAP Objects: ABAP Programming in SAP NetWeaver</a>
Cheers
Graham -
Error in parallel exp-imp using ftp method
Hi,
We are doing migration of ERP system running on redhat linux 6 and sybase 15.7 .
Trying to do parallel export import using ftp method.
Here when we start the export monitor, it gives the below error.
Required system resources are missing or not available:
Structure of subdirectories in local export directory '/export/TRS_Mock_Export/ABAP' and FTP export directory '/usr/sap/TRQ/DVEBMGS00/TRS_Mock_Export/ABAP' on '<ip>' server is different.
But the structure is entirely same.
Even we have moved the export directory which got created after sapinst was run (before starting migmon) to the target server.
Below is a content of export monitor file .
export_monitor_cmd.properties
ftpCopy
dbType=SYB
exportDirs=/export/TRS_Mock_Export/ABAP
installDir=/media/sapinst_logs/Mock_Exp_Imp/sapinst_instdir/BS2010/ERP605/LM/COPY/SYB/EXP/CENTRAL/AS-ABAP/EXP/log_17_Apr_2015_05_03_53
ddlFile=/export/TRS_Mock_Export/ABAP/DB/DDLSYB_LRG.TPL
r3loadExe=/usr/sap/TRS/DVEBMGS00/exe/R3load
tskFiles=yes
dataCodepage=4103
jobNum=8
monitorTimeout=30
loadArgs=-stop_on_error
ftpHost=ip
ftpUser=user
ftpPassword=pw
ftpExportDirs=/usr/sap/TRQ/DVEBMGS00/TRS_Mock_Export/ABAP
ftpExchangeDir=/media/sbx_exchange_dir
ftpJobNum=3
trace=all
Please suggest.
Regards,
Amit Jana.Thanks for the steps Siddhesh.
ftp is working.
in the properties file for ftp user earlier gave a different user.
Now gave sidadm and this error is resolved.
Now facing a different issue.
In the properties file we gave 'server' in the beginning . This is only starting R3load processes but ftp transfer does not start.
Then gave 'ftp' below 'server' but got the below error.
Check below the file contents and error :
export_monitor_cmd.properties
server
ftp
dbType=SYB
exportDirs=/export/TRS_Mock_Export/ABAP
installDir=/media/sapinst_logs/Mock_Exp_Imp/sapinst_instdir/BS2010/ERP605/LM/COPY/SYB/EXP/CENTRAL/AS-ABAP/EXP/log_17_Apr_2015_05_03_53
ddlFile=/export/TRS_Mock_Export/ABAP/DB/DDLSYB_LRG.TPL
r3loadExe=/usr/sap/TRS/DVEBMGS00/exe/R3load
tskFiles=yes
dataCodepage=4103
jobNum=8
monitorTimeout=30
loadArgs=-stop_on_error
ftpHost=ip
ftpUser=user
ftpPassword=pw
ftpExportDirs=/usr/sap/TRQ/DVEBMGS00/TRS_Mock_Export/ABAP
ftpExchangeDir=/media/sbx_exchange_dir
ftpJobNum=3
trace=all
=======================================
TRACE: 2015-04-20 06:14:57 sun.net.ftp.impl.FtpClient readServerResponse
Server [/192.168.51.12:21] --> 230 Login successful.
ERROR: 2015-04-20 06:14:57 com.sap.inst.migmon.exp.ExportStandardTask run
Fatal exception during execution of the Export Monitor.
java.io.IOException: illegal filename for a PUT
at sun.net.www.protocol.ftp.FtpURLConnection.getOutputStream(FtpURLConnection.java:528)
at com.sap.inst.lib.ftp.FtpService.put(FtpService.java:160)
at com.sap.inst.migmon.exp.ExportExchangeTask.removeExportStatistics(ExportExchangeTask.java:277)
at com.sap.inst.migmon.exp.ExportStandardTask.doRun(ExportStandardTask.java:92)
at com.sap.inst.migmon.MigrationTask.run(MigrationTask.java:431)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:791)
INFO: 2015-04-20 06:14:57
Export Monitor is stopped. -
How to use protected method in jsp code
Could anyone tell me how to use protected method in jsp code ...
I declare a Calendar class , and I want to use the isTimeSet method ,
But if I write the code as follows ..
========================================================
<%
Calendar create_date = Calendar.getInstance();
if (create_date.isTimeSet) System.out.println("true");
%>
============================================================
when I run this jsp , it appears the error wirtten "isTimeSet has protected access in java.util.Calendar"The only way to access a protected variable is to subclass.
MyCalendar extends Calendar
but I doubt you need to do this. If you only want to tell if a Calendar object has a time associated with it, try using
cal.isSet( Calendar.HOUR ); -
Class extends JComponent how to use custom methods?
I have a class Block which extends JPanel
code is hereprivate class Block extends JLabel{
boolean top;
Block(int a,Color c){
setSize(40 + a*10,20);
setBorder(BorderFactory.createMatteBorder(40+a*10,0,0,0,c));
void setTop(boolean b){
this.top = b;
boolean getTop(){
return top;
}I need to use getTop() method of certain block in class implementing MouseMotionListener
I used getComponent() method like this
e.getComponent().getTop()but it didn't work and gave
HanoiTowers.java:59: cannot find symbol
symbol : method getTop()
location: class java.awt.Component
if(e.getComponent().getTop()){}
error
Is there some other way to do this?Antti_ wrote:
I have a class Block which extends JPanelahem, I believe that it extends JLabel.
Is there some other way to do this?You could cast I suppose:
Component c = e.getComponent();
if (c instanceof Block)
System.out.println(((Block)c).getTop());
} -
Managing statistics for object collections used as table types in SQL
Hi All,
Is there a way to manage statistics for collections used as table types in SQL.
Below is my test case
Oracle Version :
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL> Original Query :
SELECT
9999,
tbl_typ.FILE_ID,
tf.FILE_NM ,
tf.MIME_TYPE ,
dbms_lob.getlength(tfd.FILE_DATA)
FROM
TG_FILE tf,
TG_FILE_DATA tfd,
SELECT
FROM
TABLE
SELECT
CAST(TABLE_ESC_ATTACH(OBJ_ESC_ATTACH( 9999, 99991, 'file1.png', NULL, NULL, NULL),
OBJ_ESC_ATTACH( 9999, 99992, 'file2.png', NULL, NULL, NULL)) AS TABLE_ESC_ATTACH)
FROM
dual
) tbl_typ
WHERE
tf.FILE_ID = tfd.FILE_ID
AND tf.FILE_ID = tbl_typ.FILE_ID
AND tfd.FILE_ID = tbl_typ.FILE_ID;
Elapsed: 00:00:02.90
Execution Plan
Plan hash value: 3970072279
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 194 | 4567 (2)| 00:00:55 |
|* 1 | HASH JOIN | | 1 | 194 | 4567 (2)| 00:00:55 |
|* 2 | HASH JOIN | | 8168 | 287K| 695 (3)| 00:00:09 |
| 3 | VIEW | | 8168 | 103K| 29 (0)| 00:00:01 |
| 4 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | 8168 | 16336 | 29 (0)| 00:00:01 |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 6 | TABLE ACCESS FULL | TG_FILE | 565K| 12M| 659 (2)| 00:00:08 |
| 7 | TABLE ACCESS FULL | TG_FILE_DATA | 852K| 128M| 3863 (1)| 00:00:47 |
Predicate Information (identified by operation id):
1 - access("TF"."FILE_ID"="TFD"."FILE_ID" AND "TFD"."FILE_ID"="TBL_TYP"."FILE_ID")
2 - access("TF"."FILE_ID"="TBL_TYP"."FILE_ID")
Statistics
7 recursive calls
0 db block gets
16783 consistent gets
16779 physical reads
0 redo size
916 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed Indexes are present in both the tables ( TG_FILE, TG_FILE_DATA ) on column FILE_ID.
select
index_name,blevel,leaf_blocks,DISTINCT_KEYS,clustering_factor,num_rows,sample_size
from
all_indexes
where table_name in ('TG_FILE','TG_FILE_DATA');
INDEX_NAME BLEVEL LEAF_BLOCKS DISTINCT_KEYS CLUSTERING_FACTOR NUM_ROWS SAMPLE_SIZE
TG_FILE_PK 2 2160 552842 21401 552842 285428
TG_FILE_DATA_PK 2 3544 852297 61437 852297 852297 Ideally the view should have used NESTED LOOP, to use the indexes since the no. of rows coming from object collection is only 2.
But it is taking default as 8168, leading to HASH join between the tables..leading to FULL TABLE access.
So my question is, is there any way by which I can change the statistics while using collections in SQL ?
I can use hints to use indexes but planning to avoid it as of now. Currently the time shown in explain plan is not accurate
Modified query with hints :
SELECT
/*+ index(tf TG_FILE_PK ) index(tfd TG_FILE_DATA_PK) */
9999,
tbl_typ.FILE_ID,
tf.FILE_NM ,
tf.MIME_TYPE ,
dbms_lob.getlength(tfd.FILE_DATA)
FROM
TG_FILE tf,
TG_FILE_DATA tfd,
SELECT
FROM
TABLE
SELECT
CAST(TABLE_ESC_ATTACH(OBJ_ESC_ATTACH( 9999, 99991, 'file1.png', NULL, NULL, NULL),
OBJ_ESC_ATTACH( 9999, 99992, 'file2.png', NULL, NULL, NULL)) AS TABLE_ESC_ATTACH)
FROM
dual
tbl_typ
WHERE
tf.FILE_ID = tfd.FILE_ID
AND tf.FILE_ID = tbl_typ.FILE_ID
AND tfd.FILE_ID = tbl_typ.FILE_ID;
Elapsed: 00:00:00.01
Execution Plan
Plan hash value: 1670128954
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 194 | 29978 (1)| 00:06:00 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 1 | 194 | 29978 (1)| 00:06:00 |
| 3 | NESTED LOOPS | | 8168 | 1363K| 16379 (1)| 00:03:17 |
| 4 | VIEW | | 8168 | 103K| 29 (0)| 00:00:01 |
| 5 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | 8168 | 16336 | 29 (0)| 00:00:01 |
| 6 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
| 7 | TABLE ACCESS BY INDEX ROWID | TG_FILE_DATA | 1 | 158 | 2 (0)| 00:00:01 |
|* 8 | INDEX UNIQUE SCAN | TG_FILE_DATA_PK | 1 | | 1 (0)| 00:00:01 |
|* 9 | INDEX UNIQUE SCAN | TG_FILE_PK | 1 | | 1 (0)| 00:00:01 |
| 10 | TABLE ACCESS BY INDEX ROWID | TG_FILE | 1 | 23 | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
8 - access("TFD"."FILE_ID"="TBL_TYP"."FILE_ID")
9 - access("TF"."FILE_ID"="TBL_TYP"."FILE_ID")
filter("TF"."FILE_ID"="TFD"."FILE_ID")
Statistics
0 recursive calls
0 db block gets
16 consistent gets
8 physical reads
0 redo size
916 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
2 rows processed
Thanks,
BThanks Tubby,
While searching I had found out that we can use CARDINALITY hint to set statistics for TABLE funtion.
But I preferred not to say, as it is currently undocumented hint. I now think I should have mentioned it while posting for the first time
http://www.oracle-developer.net/display.php?id=427
If we go across the document, it has mentioned in total 3 hints to set statistics :
1) CARDINALITY (Undocumented)
2) OPT_ESTIMATE ( Undocumented )
3) DYNAMIC_SAMPLING ( Documented )
4) Extensible Optimiser
Tried it out with different hints and it is working as expected.
i.e. cardinality and opt_estimate are taking the default set value
But using dynamic_sampling hint provides the most correct estimate of the rows ( which is 2 in this particular case )
With CARDINALITY hint
SELECT
/*+ cardinality( e, 5) */*
FROM
TABLE
SELECT
CAST(TABLE_ESC_ATTACH(OBJ_ESC_ATTACH( 9999, 99991, 'file1.png', NULL, NULL, NULL),
OBJ_ESC_ATTACH( 9999, 99992, 'file2.png', NULL, NULL, NULL)) AS TABLE_ESC_ATTACH)
FROM
dual
) e ;
Elapsed: 00:00:00.00
Execution Plan
Plan hash value: 1467416936
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5 | 10 | 29 (0)| 00:00:01 |
| 1 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | 5 | 10 | 29 (0)| 00:00:01 |
| 2 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
With OPT_ESTIMATE hint
SELECT
/*+ opt_estimate(table, e, scale_rows=0.0006) */*
FROM
TABLE
SELECT
CAST(TABLE_ESC_ATTACH(OBJ_ESC_ATTACH( 9999, 99991, 'file1.png', NULL, NULL, NULL),
OBJ_ESC_ATTACH( 9999, 99992, 'file2.png', NULL, NULL, NULL)) AS TABLE_ESC_ATTACH)
FROM
dual
) e ;
Execution Plan
Plan hash value: 4043204977
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 5 | 485 | 29 (0)| 00:00:01 |
| 1 | VIEW | | 5 | 485 | 29 (0)| 00:00:01 |
| 2 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | 5 | 10 | 29 (0)| 00:00:01 |
| 3 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
With DYNAMIC_SAMPLING hint
SELECT
/*+ dynamic_sampling( e, 5) */*
FROM
TABLE
SELECT
CAST(TABLE_ESC_ATTACH(OBJ_ESC_ATTACH( 9999, 99991, 'file1.png', NULL, NULL, NULL),
OBJ_ESC_ATTACH( 9999, 99992, 'file2.png', NULL, NULL, NULL)) AS TABLE_ESC_ATTACH)
FROM
dual
) e ;
Elapsed: 00:00:00.00
Execution Plan
Plan hash value: 1467416936
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 2 | 4 | 11 (0)| 00:00:01 |
| 1 | COLLECTION ITERATOR CONSTRUCTOR FETCH| | 2 | 4 | 11 (0)| 00:00:01 |
| 2 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
Note
- dynamic sampling used for this statement (level=2)I will be testing the last option "Extensible Optimizer" and put my findings here .
I hope oracle in future releases, improve the statistics gathering for collections which can be used in DML and not just use the default block size.
By the way, are you aware why it uses the default block size ? Is it because it is the smallest granular unit which oracle provides ?
Regards,
B -
How to use addPasswordToPasswordHistory method
Hi
Can some one please tell me how to use the method addPasswordToPasswordHistory from the class WSUser.I have a requirement to add user password to password history whenever user changes his password through my custom password change workflow.Custom workflow changes the password in idm but it will not add the previous password to the password history.
It will be helpfull if you paste the code to use this method
Regards
Karthik PHi Amar
Thanks for the reply
I tried setting the password through setPassword method but its giving an exception ==>java.lang.NoSuchMethodException: java.lang.String.setPassword(com..waveset.util.EncrypteData)
Then I decrypted the password but no luck getting ==>java.lang.NoSuchMethodException: java.lang.String.setPassword() exception.
Am i missing something here.do i need to pass the encrypted password in byte array format? if yes how to do that.
Here encrypted password is coming from a form.
regards
karthik p
.
Maybe you are looking for
-
Releasing a Transport Request ends with error code 0012.
Hi, We have a Development system and a Production System (both running on separate windows machine) but they are not connected in STMS. We perform transporting of Requests at o.s level and NOT through STMS. We are facing this new problem - We are try
-
How can I boot to USB device if no USB boot option in BIOS
I just purchased a Toshiba NB305-N410BL but am concerned as to how I would image the 250GB HDD if I can not boot from an external cdrom drive. I tried to backup to shared network folder but none show up on list. Only boot options in BIOS are HDD, F
-
Status in incident is NULL when it is created from SC
HI All, We are experiencing an issue with service catalog. interface connector: Open a new incident when we order an item from catalog, interaction is being created along with the related incident. But when i open the related incident, format still r
-
Limit number of pages in the report
Hi I am tasked to create a report to display only 10 pages maximum. Please advise the way to do this. 1. I have suppressed all the sections with formula: PageNumber >10 This leaves a blank page at the end, which does not go even when i place Not OnLa
-
How do I retrive date field using Xpath
How do I retrive data,which is in date format in XML file using XPath query. If this is not possible, Is there any other alternative? Bye