Comments on Packages
All,
How does comments on packages/function/procedure affect its execution during runtime?
You can even prove that the compiled size is not affected by comments:
create or replace package wr_test_nocomments
as
n integer;
end;
create or replace package body wr_test_nocomments
as
procedure p
is
begin
null;
end p;
end;
create or replace package wr_test_comments
as
procedure p;
-- Comments can appear anywhere in PL/SQL code. The PL/SQL compiler ignores them.
-- Adding comments to your program promotes readability and aids understanding.
-- A single-line comment starts with a double hyphen and extends to the end of the line.
-- A multiline comment starts with a slash and asterisk and ends with an asterisk and a slash.
The code that begins with PROCEDURE or FUNCTION and ends before IS or AS is the subprogram signature.
The declarative, executable, and exception-handling parts comprise the subprogram body.
The syntax of exception-handler is in "About Exceptions and Exception Handlers".
See Also:
Oracle Database PL/SQL Language Reference for more information about subprogram parts
end;
create or replace package body wr_test_comments
as
procedure p
is
begin
null;
-- Comments can appear anywhere in PL/SQL code. The PL/SQL compiler ignores them.
-- Adding comments to your program promotes readability and aids understanding.
-- A single-line comment starts with a double hyphen and extends to the end of the line.
-- A multiline comment starts with a slash and asterisk and ends with an asterisk and a slash.
The code that begins with PROCEDURE or FUNCTION and ends before IS or AS is the subprogram signature.
The declarative, executable, and exception-handling parts comprise the subprogram body.
The syntax of exception-handler is in "About Exceptions and Exception Handlers".
See Also:
Oracle Database PL/SQL Language Reference for more information about subprogram parts
end p;
end;
break on name skip1
select * from user_object_size s
where s.name like 'WR_TEST%'
and s.type like 'PACKAGE%'
order by 1,2;
NAME TYPE SOURCE_SIZE PARSED_SIZE CODE_SIZE ERROR_SIZE
WR_TEST_COMMENTS PACKAGE 800 192 236 0
PACKAGE BODY 876 0 210 0
WR_TEST_NOCOMMENTS PACKAGE 49 194 236 0
PACKAGE BODY 92 0 210 0
Similar Messages
-
Our application is using lots of packages,In all the package body we have added comments Like author,Date of creation,Modification done by date etc,It also comes around 40 to 50 lines.
will this affect the performance of the application.
Pls advice me.
If its not good to wrirte big comments in Packages pls tell me how to maintain this comments.
Rajesh
Edited by: user635019 on Dec 3, 2008 9:23 PM
Edited by: user635019 on Dec 3, 2008 9:42 PMHi,
Writing comments is goog practice in programming.
There is no impact on the comments are added to packages.
The perpormance of the application not dependent on the comments.
Use below comments
--For singe line
/*..Multi line..*/
Ar runtime Oralce ignore comments. -
How to remove comments in packages in oracle
hi gurus,
can any body help me to remove commented code in packages in oracle?
thanks in advance...The obvious suggestion would be to edit the package (or package body) in whatever editor you prefer and recompile. I'm assuming you know that, however, since you managed to create the package in the first place. If that's not what you're looking for, can you explain a bit more what you're asking?
Justin -
Is there way I could extract just the SQL/PL*SQL from some packages without the comments?
Since comments can be embedded within the code, need not start at the beginning of a line, etc. the data dictionary does not distinguish lines of code and lines of comments. You'd have to write the parser that identifies the comments and removes them.
If you're using a code editor that places comments between the signature of the procedure and the AS keyword, and those are the only comments you want to remove, and the editor creates the comments in a predicatble way (i.e. substr(line, 0, 2) = '--'), you can probably do this in PL/SQL reasonably easily. If you want to get every comment or the comments are generated by people and may be formatted differently, you'll want to write an external script to do the parsing.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Package comments and excluded files
I have an ant target to generate javadoc for a whole package structure minus one sub-package and one class, plus a few classes from another package:
<target name="doc">
<mkdir dir="${build}/docs/api"/>
<javadoc destdir="${build}/docs/api/"
use="true"
windowtitle="Public API">
<classpath>
<path refid="3rdparty.jar.path"/>
</classpath>
<fileset dir="${build}">
<include name="com/company/pkg1/**"/>
<exclude name="com/company/pkg1/util/**"/>
<exclude name="com/company/pkg1/server/ServiceMBean.java"/>
<include name="com/company/pkg2/CustomerReport.java"/>
<include name="com/company/pkg2/DeprecatedReport.java"/>
<include name="com/company/pkg2/Report.java"/>
<include name="com/company/pkg2/TagReport.java"/>
</fileset>
</javadoc>
</target>This worked fine until I started including package.html files for package documentation. Running this with package.html in com/company/pkg1 gives the following error:
javadoc: Illegal package name: "C:\abc\def\com\company\pkg1\package.html"
After playing around, I found that if I shift the 3 <include> and <exclude> lines referring to pkg1 out of the <fileset> tag and into a <packageset> tag, then the package comments work. However, then the exclude for the individual java class (ServiceMBean.java) does not work. Likewise, shifting the file exclude back to the fileset tag still does not exclude it.
It seems that I must decide whether to have package comments or the ability to exclude individual files, but not both. Is there any way around this?Well, it is a known issue. And actually, issue is with DBMS_METADATA, not with DATAPUMP, which simply uses DBMS_METADATA:
SQL> create or replace package
2 --comment
3 MyPkg
4 is
5 a number;
6 end;
7 /
Package created.
SQL> select text from user_source where name = 'MYPKG' order by line;
TEXT
package
--comment
MyPkg
is
a number;
end;
6 rows selected.
SQL> select dbms_metadata.get_ddl('PACKAGE','MYPKG') from dual;
DBMS_METADATA.GET_DDL('PACKAGE','MYPKG')
CREATE OR REPLACE PACKAGE "SCOTT"."MYPKG"
is
a number;
end;
SQL> You should put comments after package name:
SQL> create or replace package
2 MyPkg
3 --comment
4 is
5 a number;
6 end;
7 /
Package created.
SQL> select dbms_metadata.get_ddl('PACKAGE','MYPKG') from dual;
DBMS_METADATA.GET_DDL('PACKAGE','MYPKG')
CREATE OR REPLACE PACKAGE "SCOTT"."MYPKG"
--comment
is
a number;
end;
SQL> SY. -
Pacman suggestion: add own comment to a package that survives upgrades
I install and uninstall lots of packages, and once every few months I clear out all unused explicitly installed stuff. The problem is that for quite a number of packages I forget why I installed it. Usually it is because some script of mine needs it, or to try out something, and the package comment isn't descriptive enough. So I wonder if it would be idea to somehow add one's own comment when installing something, so that a 'pacman -Qi packagename' for example would show it. The most obvious solution would be editing a pkgbuilds from the repository, but they get overwritten with the next upgrade. And to recompile using ABS only to add a comment doesn't seem right. Has anyone else thought about this?
Last edited by rwd (2009-11-07 13:54:03)tags! that's a good idea too! so i added some basic tag actions:
#!/bin/bash
pkgnote_db="pkgnote.db"
[ -f "${pkgnote_db}" ] || touch "${pkgnote_db}" || exit 1
view_pkgnote () {
local pkg="$1"
grep "^${pkg}: " "${pkgnote_db}"
kill_pkgnote () {
local pkg="$1"
sed -i "/^${pkg}: /d" "${pkgnote_db}"
edit_pkgnote () {
local pkg="$1" note
echo "comments for package \`${pkg}':"
read note
grep "^${pkg}: " "${pkgnote_db}" &>/dev/null &&
sed -i "s/\(^${pkg}: \).*/\1${note}/" "${pkgnote_db}" ||
echo "${pkg}: ${note}" >> "${pkgnote_db}"
taga_pkgnote () {
local tag="$1" pkgs=($2) pkg
for pkg in "${pkgs[@]}" ; do
grep "^${pkg}: .*\[\[${tag}\]\]" "${pkgnote_db}" &>/dev/null && continue
grep "^${pkg}: " "${pkgnote_db}" &>/dev/null &&
sed -i "s/^${pkg}: .*/& [[${tag}]]/" "${pkgnote_db}" ||
echo "${pkg}: [[${tag}]]" >> "${pkgnote_db}"
done
tagd_pkgnote () {
local tag="$1"
sed -i "/^[^[[]*\[\[${tag}\]\][^[[]*$/d;s/ \[\[${tag}\]\]//" "${pkgnote_db}"
tagl_pkgnote () {
local tag="$1"
echo "packages with tag [[$1]]:"
sed "/\([^:]*\): .*\[\[${tag}\]\].*/!d;s//\1/" "${pkgnote_db}"
until [ -z "$1" ] ; do
case "$1" in
-v|--view) view_pkgnote "$2" ; shift 2 ;;
-e|--edit) edit_pkgnote "$2" ; shift 2 ;;
-d|--delete) kill_pkgnote "$2" ; shift 2 ;;
-t|--tag)
case "$2" in
a|add) taga_pkgnote "$3" "$4" ; shift 4 ;;
d|delete) tagd_pkgnote "$3" ; shift 3 ;;
l|list) tagl_pkgnote "$3" ; shift 3 ;;
*) echo "invalid tag action: $2" ; shift 2 ;;
esac ;;
*) echo "invalid option: $1" ; shift ;;
esac
done
several examples
$ ./pkgnote.sh -e pkg1 -e pkg2
comments for package `pkg1':
this is package 1 [[project 1]]
comments for package `pkg2':
this is package 2
$ ./pkgnote.sh -v pkg1
pkg1: this is package 1 [[project 1]]
$ ./pkgnote.sh -t list 'project 1'
packages with tag [[project 1]]:
pkg1
$ ./pkgnote.sh -t add 'project 1' 'pkg2 pkg3 pkg4'
$ ./pkgnote.sh -t list 'project 1'
packages with tag [[project 1]]:
pkg1
pkg2
pkg3
pkg4
$ ./pkgnote.sh -t add 'project 2' 'pkg3'
$ ./pkgnote.sh -t d 'project 1'
$ ./pkgnote.sh -t list 'project 1'
packages with tag [[project 1]]:
$ ./pkgnote.sh -t list 'project 2'
packages with tag [[project 2]]:
pkg3
note: --edit also overwrites tag(s) of the package
As seen in the example(note 'pkg3'), --tag delete <tag> will not remove the whole packge comment line from db, unless <tag> is the only tag this package has, which should be as expected.
Still, it's a script that can be used with any kind of short comments...
Last edited by lolilolicon (2009-11-07 16:06:26) -
Trying to understand creating and using packages
Hi all,
I do not understand this problem... Package "shared.utilities" is an entire separate package from "alertsystem". When I comment out "package alertsystem", I get C:\Wdt\alertsystem\File_Handling.java:4: package shared.utilities does not exist
import shared.utilities.*;
^
Below is the code
// package alertsystem;
import shared.utilities.*;
import java.io.*;
import java.util.*;
import java.text.*;
class File_Handling
private long time_buff;
private String alertDir;
private String archPath;
private SData buff;
On the other hand, if I do NOT comment out "package alertsystem", no problem. I do not understand why I need to include "package alertsystem". If I am writing a simple module and want to use one of the library in "shared.utilities", do I always need to make sure all my codes come under a package?
Thanks in advance.Hi,
This is funny... if I do this....
package alertsystem;
import shared.utilities.*;
import java.io.*;
import java.util.*;
import java.text.*;
class File_Handling
private long time_buff;
private String alertDir;
without including the path to the jar file, NO PROBLEM during compilation and run (in this case, util.jar, which is actually the shared.utilities package). But, if I do
// package alertsystem;
import shared.utilities.*;
import java.io.*;
import java.util.*;
import java.text.*;
I still get the same error problem...
C:\Wdt\alertsystem\File_Handling.java:4: package shared.utilities does not exist
import shared.utilities.*;
In other words, if I include or I do not include the path of to the jar file and do this...
package alertsystem;
import shared.utilities.*;
import java.io.*;
import java.util.*;
import java.text.*;
Then, No problem with compilation and running. However, if I do not include "package alertsystem", I get compilation problem.
The jar file consists only of *.class files that I have compiled without a single problem. I included "package shared.utilities;" in all the files of the util.jar
Funny isn't it?
Thanks for responding.
Hi,
What's your classpath look like when you compile when
you include the package and when you don't include the
package? Is it when you compile or run the code? -
AS3 Auto Format not recognizing comments
Something is corrupt with my Flash Professional CS5 Actionscript Auto format:
Comments within a block, such as ' // ' or block comments ' /* ... */ ' are tripping up the Auto Formattor, which returns this error: ' Error with autoformat near line: } '.
Comments before package block don't cause an error.
When I remove comments within package block, Auto format works correctly.
How can I fix my Flash CS3 ActionScript editor Auto format?the problem you're seeing is the least of the known problems with auto-formatter. the worst is the auto-formatter change change well-written code to be mal-formed code.
so, while i don't think you can fix your auto formatter, what you can do is copy chunks of code to a new fla or as file and auto-format that chunk.
then check that it's been formatted correctly and nothing essential has been changed. (ie, at least, check for errors.) if everything looks ok, replace the unformatted chunk in your original file with the formatted chunk.
that's the wisest way to use auto-formatter. it's also good to know and use the undo so you can always undo an auto-format botch. -
How to pass a structure in PL/SQL external proc.
This is for educational purpose only. I am trying to implement kernel32.dll and shell32.dll in PL/SQL using external proc. Everything is working fine, except When there is a structure in OUT parameter.
My database version.
SQL> SELECT * FROM v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - ProductionI have set up the listner.ora and tnsnames.ora and written a package called dbms_kernel32sb.
There are 9 program units.
1. CreateFile -- working fine
2. CloseFile -- working fine
3. GetSize -- working fine
4. FindFirstFile -- NOT working, because one OUT parameter has the structure type WIN32_FIND_DATA.
5. GetFileTime -- NOT working, because one OUT parameter has the structure type FILETIME
6. GetDiskFreeSpace -- working fine
7. GetDriveType -- working fine.
8. GetLastError -- working fine
9. ExecuteCommand -- working fine.
Here is the package specification:
CREATE OR REPLACE PACKAGE dbms_kernel32sb AS
Name: dbms_kernel32sb.pks
Author: Saubhik Banerjee
Date: 24th Jan 2011
Version: 1.0
Comment: This package is to implement some functionality from kernel32.dll.
Usng extproc
OPEN_EXISTING_FILE CONSTANT PLS_INTEGER :=3;
FILE_ATTRIBUTE_NORMAL CONSTANT PLS_INTEGER :=128;
DISABLE_FILE_SHARE_MODE CONSTANT PLS_INTEGER :=0;
NO_FILE_SECURITY_ATTRIBUTE CONSTANT PLS_INTEGER :=0;
NO_TEMPLATE_FILE CONSTANT PLS_INTEGER :=0;
GENERIC_FILE_ACCESS CONSTANT PLS_INTEGER :=0;
FILE_SIZE_HIGH CONSTANT PLS_INTEGER :=400000000;
EXECUTE_FILE CONSTANT VARCHAR2(4):='open';
PRINT_FILE CONSTANT VARCHAR2(5):='print';
NO_PARAMATER CONSTANT VARCHAR2(2):=' ';
FUNCTION CreateFile(pi_FileName VARCHAR2 --1, File name
,pi_DesiredAccess BINARY_INTEGER --2, Type of access required (read/write ect)
,pi_ShareMode BINARY_INTEGER --3, share mode
,pi_SecurityAttributes BINARY_INTEGER --4, securoty attribute
,pi_CreationDisposition BINARY_INTEGER --5, open existing, create new etc
,pi_FlagsAndAttributes BINARY_INTEGER --6, File attribute- normal
,pi_TemplateFile BINARY_INTEGER) --Not required.
Return BINARY_INTEGER;
FUNCTION CloseFile (pi_FileHandle BINARY_INTEGER)
Return BINARY_INTEGER;
FUNCTION GetSize (pi_FileHandle BINARY_INTEGER,
pio_FileSizeHigh IN OUT BINARY_INTEGER)
RETURN BINARY_INTEGER;
FUNCTION FindFirstFile ( pi_FileName VARCHAR2
,pio_Win32_Find_data OUT
WIN32_FIND_DATA
RETURN BINARY_INTEGER;
FUNCTION GetFileTime ( pi_FileHandle BINARY_INTEGER
,pio_FileCreationTime IN OUT FILETIME
,pio_LastAccessTime IN OUT FILETIME
,pio_LastWriteTime IN OUT FILETIME
RETURN BINARY_INTEGER;
FUNCTION GetDiskFreeSpace ( pi_RootPathName VARCHAR2
,pio_SectorsPerCluster OUT BINARY_INTEGER
,pio_BytesPerSector OUT BINARY_INTEGER
,pio_NumberOfFreeClusters OUT BINARY_INTEGER
,pio_TotalNumberOfClusters OUT BINARY_INTEGER
RETURN BINARY_INTEGER;
FUNCTION GetDriveType( pi_driveLetter VARCHAR2) RETURN VARCHAR2;
FUNCTION GetLastError RETURN BINARY_INTEGER;
FUNCTION ExecuteCommand ( pi_OperationType VARCHAR2
,pi_FileName VARCHAR2
,pi_Parameters VARCHAR2
,pi_DefaultDirectory VARCHAR2
RETURN VARCHAR2;
END dbms_kernel32sb;
Here is the package body:
CREATE OR REPLACE PACKAGE BODY dbms_kernel32sb AS
/* Name: dbms_kernel32sb.pkb
Author: Saubhik Banerjee
Date: 24th Jan 2011
Version: 1.0
Comment: This package is to implement some functionality from kernel32.dll.
Usng extproc
FUNCTION
CreateFile( pi_FileName VARCHAR2 --1
, pi_DesiredAccess BINARY_INTEGER --2
, pi_ShareMode BINARY_INTEGER --3
, pi_SecurityAttributes BINARY_INTEGER --4
, pi_CreationDisposition BINARY_INTEGER --5
, pi_FlagsAndAttributes BINARY_INTEGER --6
, pi_TemplateFile BINARY_INTEGER) --7
Return BINARY_INTEGER IS EXTERNAL LIBRARY kernel32 Name "CreateFileA"
PARAMETERS( pi_FileName STRING
, pi_DesiredAccess long
, pi_ShareMode long
, pi_SecurityAttributes long
, pi_CreationDisposition long
, pi_FlagsAndAttributes long
, pi_TemplateFile long
, return long);
FUNCTION CloseFile (pi_FileHandle BINARY_INTEGER)
Return BINARY_INTEGER
IS EXTERNAL
LIBRARY kernel32 Name "CloseHandle"
PARAMETERS (pi_FileHandle long, return long);
FUNCTION GetSize (pi_FileHandle BINARY_INTEGER,
pio_FileSizeHigh IN OUT BINARY_INTEGER)
RETURN BINARY_INTEGER
IS EXTERNAL
LIBRARY kernel32 NAME "GetFileSize"
PARAMETERS (pi_FileHandle long, pio_FileSizeHigh long, return long );
FUNCTION GetFileTime ( pi_FileHandle BINARY_INTEGER
,pio_FileCreationTime IN OUT FILETIME
,pio_LastAccessTime IN OUT FILETIME
,pio_LastWriteTime IN OUT FILETIME
RETURN BINARY_INTEGER
IS EXTERNAL
LIBRARY kernel32 NAME "GetFileTime"
WITH CONTEXT
PARAMETERS ( CONTEXT,
pi_FileHandle long
, pio_FileCreationTime OCIColl
, pio_FileCreationTime INDICATOR SHORT
, pio_LastAccessTime OCIColl
, pio_LastAccessTime INDICATOR SHORT
, pio_LastWriteTime OCIColl
, pio_LastWriteTime INDICATOR SHORT
, return long );
FUNCTION FindFirstFile ( pi_FileName VARCHAR2
,pio_Win32_Find_data OUT
WIN32_FIND_DATA
RETURN BINARY_INTEGER
IS EXTERNAL
LIBRARY kernel32 NAME "FindFirstFileA"
--WITH CONTEXT
PARAMETERS
( --CONTEXT,
pi_FileName STRING--, pi_FileName INDICATOR SHORT
, pio_Win32_Find_data BY REFERENCE OCIColl--,pio_Win32_Find_data INDICATOR long
, return long );
FUNCTION GetDiskFreeSpace ( pi_RootPathName VARCHAR2
,pio_SectorsPerCluster OUT BINARY_INTEGER
,pio_BytesPerSector OUT BINARY_INTEGER
,pio_NumberOfFreeClusters OUT BINARY_INTEGER
,pio_TotalNumberOfClusters OUT BINARY_INTEGER
RETURN BINARY_INTEGER
IS EXTERNAL
LIBRARY kernel32 NAME "GetDiskFreeSpaceA"
PARAMETERS ( pi_RootPathName STRING
, pio_SectorsPerCluster BY REFERENCE long
, pio_BytesPerSector BY REFERENCE long
, pio_NumberOfFreeClusters BY REFERENCE long
, pio_TotalNumberOfClusters BY REFERENCE long
, return long );
FUNCTION GetDriveTypeA( pi_driveLetter VARCHAR2) RETURN BINARY_INTEGER
IS EXTERNAL
LIBRARY kernel32 NAME "GetDriveTypeA"
PARAMETERS (pi_driveLetter STRING, RETURN long);
FUNCTION GetDriveType( pi_driveLetter VARCHAR2) RETURN VARCHAR2 IS
BEGIN
CASE GetDriveTypeA(pi_driveLetter)
WHEN 2 THEN RETURN 'Removable';
WHEN 3 THEN RETURN 'Drive Fixed';
WHEN 4 THEN RETURN 'Remote';
WHEN 5 THEN RETURN 'Cd-Rom';
WHEN 6 THEN RETURN 'Ram disk';
ELSE RETURN 'Unrecognized';
END CASE;
END;
FUNCTION GetLastError RETURN BINARY_INTEGER
IS EXTERNAL
LIBRARY kernel32 NAME "GetLastError"
PARAMETERS (return long);
FUNCTION ShellExecute( pi_Hwnd BINARY_INTEGER
,pi_Operation VARCHAR2
,pi_FileName VARCHAR2
,pi_Parameters VARCHAR2
,pi_DefaultDirectory VARCHAR2
,pi_ShowCmd BINARY_INTEGER
) RETURN BINARY_INTEGER
IS EXTERNAL
LIBRARY SHELL32 NAME "ShellExecuteA"
PARAMETERS (pi_Hwnd long,pi_Operation STRING,pi_FileName STRING
,pi_Parameters STRING,pi_DefaultDirectory STRING
,pi_ShowCmd long, return long
FUNCTION ExecuteCommand ( pi_OperationType VARCHAR2
,pi_FileName VARCHAR2
,pi_Parameters VARCHAR2
,pi_DefaultDirectory VARCHAR2
RETURN VARCHAR2 IS
v_return_val BINARY_INTEGER;
BEGIN
v_return_val:= ShellExecute(0,pi_OperationType
,pi_FileName,pi_Parameters
,pi_DefaultDirectory,0
IF v_return_val <=32 THEN
RETURN 'Error!';
ELSE RETURN 'Success!';
END IF;
END;
END dbms_kernel32sb;
Now the working demos:
SQL> SET SERVEROUT ON
SQL> /* Demo I:- How to obtain file size */
SQL> DECLARE
2 v_FileSize BINARY_INTEGER;
3 v_FileSizeHigh PLS_INTEGER;
4 v_FileHandle BINARY_INTEGER;
5 v_filename VARCHAR2(500) :='C:\test2.csv';
6 v_dummy BINARY_INTEGER;
7 BEGIN
8 v_FileSizeHigh := DBMS_KERNEL32SB.FILE_SIZE_HIGH;
9 v_FileHandle:=DBMS_KERNEL32SB.CreateFile(v_filename -- File name
10 ,DBMS_KERNEL32SB.GENERIC_FILE_ACCESS
11 ,DBMS_KERNEL32SB.DISABLE_FILE_SHARE_MODE
12 ,DBMS_KERNEL32SB.NO_FILE_SECURITY_ATTRIBUT
13 ,DBMS_KERNEL32SB.OPEN_EXISTING_FILE
14 ,DBMS_KERNEL32SB.FILE_ATTRIBUTE_NORMAL
15 ,DBMS_KERNEL32SB.NO_TEMPLATE_FILE);
16 v_FileSize := DBMS_KERNEL32SB.Getsize(v_FileHandle, v_FileSizeHigh)
17 DBMS_OUTPUT.put_line('File Size in Bytes: ' ||v_FileSize);
18 v_dummy:=DBMS_KERNEL32SB.CloseFile(v_FileHandle);
19 END;
20 /
File Size in Bytes: 61
PL/SQL procedure successfully completed.
SQL>
SQL> /* Demo II:- How to find free disk space */
SQL> DECLARE
2 v_rootpath VARCHAR2(500) :='C:\';
3 v_dummy BINARY_INTEGER;
4 v_sectorspercluster BINARY_INTEGER;
5 v_bytespersector BINARY_INTEGER;
6 v_numberoffreeclusters BINARY_INTEGER;
7 v_totalnumberofclusters BINARY_INTEGER;
8 v_freespace NUMBER;
9 v_totalspace NUMBER;
10 BEGIN
11 v_dummy:=DBMS_KERNEL32SB.GetDiskFreeSpace(v_rootpath
12 ,v_sectorspercluster
13 ,v_bytespersector
14 ,v_numberoffreeclusters
15 ,v_totalnumberofclusters
16 );
17
18 DBMS_OUTPUT.put_line('Sector pre Cluster: ' ||v_sectorspercluster);
19 DBMS_OUTPUT.put_line('Bytes per sector: ' ||v_bytespersector);
20 DBMS_OUTPUT.put_line('Number Of Free Clusters: ' ||v_numberoffreeclusters);
21 DBMS_OUTPUT.put_line('Total Number Of Clusters: ' ||v_totalnumberofclusters);
22 v_freespace:=v_numberoffreeclusters/1024/1024/1024;
23 v_freespace:=ROUND(v_freespace*v_sectorspercluster*v_bytespersector,3);
24 v_totalspace:=v_totalnumberofclusters/1024/1024/1024;
25 v_totalspace:=ROUND(v_totalspace*v_sectorspercluster*v_bytespersector,3);
26 DBMS_OUTPUT.put_line('Total Space (GB):' ||v_totalspace);
27 DBMS_OUTPUT.put_line('Total number of Free space (GB): '||v_freespace );
28 END;
29 /
Sector pre Cluster: 8
Bytes per sector: 512
Number Of Free Clusters: 739477
Total Number Of Clusters: 9765622
Total Space (GB):37.253
Total number of Free space (GB): 2.821
PL/SQL procedure successfully completed.
SQL>
SQL> /* Demo IV:- How to get drive type*/
SQL> SELECT dbms_kernel32sb.GetDriveType('C:\') FROM dual;
DBMS_KERNEL32SB.GETDRIVETYPE('C:\')
Drive Fixed
SQL> SELECT dbms_kernel32sb.GetDriveType('D:\') FROM dual;
DBMS_KERNEL32SB.GETDRIVETYPE('D:\')
Cd-Rom
SQL> SELECT dbms_kernel32sb.GetDriveType('E:\') FROM dual;
DBMS_KERNEL32SB.GETDRIVETYPE('E:\')
Unrecognized
SQL>
SQL> /* Demo V:- How to execute an Operating System Command*/
SQL> DECLARE
2 v_FileToExecute VARCHAR2(20):='test.bat';
3 v_Parameter VARCHAR2(20):='test1.csv';--dbms_kernel32sb.NO_PARAMATER
4 v_DefaultDirectory VARCHAR2(20):='C:\';
5 v_ReturnValue VARCHAR2(20);
6 BEGIN
7 v_ReturnValue:=dbms_kernel32sb.ExecuteCommand(dbms_kernel32sb.EXECUTE_FILE
8 ,v_FileToExecute
9 ,v_Parameter
10 ,v_DefaultDirectory
11 );
12 DBMS_OUTPUT.put_line('Status: '||v_ReturnValue);
13 END;
14 /
Status: Success!
PL/SQL procedure successfully completed.
SQL> Now the sub programs with structures are NOT getting called successfully.
SQL> /* Demo III:- How to obtain file time */
SQL> DECLARE
2 v_FileHandle BINARY_INTEGER;
3 v_filename VARCHAR2(500) :='C:\test2.csv';
4 v_dummy BINARY_INTEGER;
5 v_filecreationtime FILETIME;
6 v_lastaccesstime FILETIME;
7 v_lastwritetime FILETIME;
8 v_err BINARY_INTEGER;
9 BEGIN
10 v_FileHandle:=DBMS_KERNEL32SB.CreateFile(v_filename -- File name
11 ,DBMS_KERNEL32SB.GENERIC_FILE_ACCESS
12 ,DBMS_KERNEL32SB.DISABLE_FILE_SHARE_MODE
13 ,DBMS_KERNEL32SB.NO_FILE_SECURITY_ATTRIBUTE
14 ,DBMS_KERNEL32SB.OPEN_EXISTING_FILE
15 ,DBMS_KERNEL32SB.FILE_ATTRIBUTE_NORMAL
16 ,DBMS_KERNEL32SB.NO_TEMPLATE_FILE);
17 v_dummy := DBMS_KERNEL32SB.GetFileTime( v_FileHandle
18 ,v_filecreationtime
19 ,v_lastaccesstime
20 ,v_lastwritetime
21 );
22 v_err:=DBMS_KERNEL32SB.GetLastError;
23 DBMS_OUTPUT.put_line('File Size in Bytes: ' ||v_dummy);
24 DBMS_OUTPUT.put_line('Error:'||v_err);
25 v_dummy:=DBMS_KERNEL32SB.CloseFile(v_FileHandle);
26 END;
27 /
File Size in Bytes: 0
Error:203
PL/SQL procedure successfully completed.
SQL> So, I have noticed that, Where ever a STRUCTURE is involved in external routine, there is a problem. I want to know, How to implement functions with STRUCTURE as OUT parameter.
Forgot to mention: This is my FILETIME object which corresponds to FILETIME structure of win32.
CREATE OR REPLACE TYPE FILETIME_rec IS OBJECT
( LowDateTime NUMBER
,HighDateTime NUMBER
CREATE OR REPLACE TYPE FILETIME IS TABLE OF FILETIME_rec;Edited by: Saubhik on Feb 1, 2011 4:15 PMSaubhik wrote:
This is for educational purpose only. I am trying to implement kernel32.dll and shell32.dll in PL/SQL using external proc. Interesting. Familiar with the Wn32 API, but do not run Oracle on Windows and never looked at this aspect of integration.
So, I have noticed that, Where ever a STRUCTURE is involved in external routine, there is a problem. I want to know, How to implement functions with STRUCTURE as OUT parameter.
Forgot to mention: This is my FILETIME object which corresponds to FILETIME structure of win32.The problem is that this passes the parameter by reference and not value. In a vanilla C/C++/Delphi program, you will create a variable of that struct and then pass a long pointer to that variable when making the API call. That pointer will be dereferenced and the memory it points to, populated. This is not a problem as the underlying DLL you call that does this, uses your process's data segment.
Extproc is different. In order to protect the integrity of the database server process, an external call is done by a "proxy" process. It acts as the interface between your PL/SQL code and the actual external call.
In this case, this "proxy" process will be doing the implicit LoadLibrary() call to load kernel32.dll interface - and the DLL will expect to dereference and access this process's memory struct to populate it. This "proxy" process in turn needs to know that despite it calling the interface by reference, it needs to return that parameter to PL/SQL by value - as your PL/SQL code cannot dereference a pointer passed back by that "proxy" process and access its memory to gain access to that struct.
In basic terms - that argument is a 32 bit number containing a pointer. That is what the "proxy" process needs to pass to the interface call. Your code is passing a struct and not a pointer, right?
And that is the basic problem I believe. How to address this.. not sure. You can have your own DLL as interface that does not use pointers but expect arguments to be passed by value. But this will suck as you then need to include a custom DLL to deploy and have PL/SQL call that, instead of simply accessing and calling the native kernel interface.
Doubt that many Win32 programmers with OCI (Oracle Call Interface) frequents this forum. So perhaps this is not the best place to ask. I would be hitting Metalink (support.oracle.com) search function in your sho3s though as there should be support notes dealing with this subject matter. -
Global variable in servlet & DBPooling questions
Hello guys,
I used to develop PHP/ASP, and am new to servlet. I have been searching around for a solution ...
With Php, we can get the reference of a global variable in any classes->functions...
How do I do this with servlet ?
And second..I have developed the DB class as below... I set the datasource to be static, so it initializes only once. Is it a good idea? How would you like to improve this class? any comments?
package shop.database;
import javax.sql.DataSource;
import java.sql.*;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.log4j.Logger;
import shop.admin.exception.GeneralException;
public class DdManager {
static protected Logger logger = Logger.getLogger(DdManager.class);
private String userName = "root";
private String password = "";
private String hostName = "jdbc:mysql://localhost:3306/shop";
private String database="shop";
static private DataSource ds; // set this to be static so all threads share the same job in JVM
private Statement stmt;
private Connection conn;
private ResultSet rs;
private CallableStatement cs;
public DdManager() {}
* setup the data source and return it
public static DataSource getDataSource(
String sDrvName,
String sUserName,
String sPwd,
String connectURI) {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName( sDrvName );
ds.setUsername( sUserName );
ds.setPassword( sPwd );
ds.setUrl( connectURI );
ds.setMaxActive( 15 );
ds.setMaxIdle( 10 );
ds.setMaxWait( 10000 ); // 10 seconds
return ds;
* static init of the class
* this class is will be called only once to initialize the DataSource
static {
try {
Class.forName( "com.mysql.jdbc.Driver" );
ds = getDataSource( "com.mysql.jdbc.Driver",
"root",
"jdbc:mysql://localhost:3306/shop" );
if (ds == null) {
String msg = "Connection Pool error";
logger.error(msg);
throw new GeneralException(msg);
logger.info("DataSource has been initialized");
} catch(Exception exception) {
logger.error(exception.toString());
try {
throw new GeneralException(exception.toString());
} catch (GeneralException e) {
logger.error(e.toString());
* get the connection from the pool (DataSource)
public void openConnection() throws GeneralException {
try {
BasicDataSource bds = (BasicDataSource) ds;
logger.info("NumActive: " + bds.getNumActive() + ", " + "NumIdle: " + bds.getNumIdle());
conn = ds.getConnection();
logger.info("Connection of " + database + " has been established");
} catch(Exception exception) {
logger.error(exception.toString());
throw new GeneralException(exception.toString());
* close the connection will actually return the connection to the pool (Must)
public void closeConnection() throws GeneralException {
initResource();
try {
if (conn != null){
conn.close();
logger.info("Connection of " + database + " has been closed");
} catch(SQLException exception) {
logger.error(exception.toString());
throw new GeneralException(exception.toString());
* prepare the calling stmt
public void prepareProcedure(String callStatement) throws GeneralException {
initResource();
try {
cs = conn.prepareCall(callStatement);
} catch(SQLException exception) {
logger.error(exception.toString());
throw new GeneralException(exception.toString());
* set the pass-in parameter for "String"
public void setParameter(int position, String parameter) throws GeneralException {
try {
cs.setString(position, parameter);
} catch(Exception exception) {
logger.error(exception.toString());
throw new GeneralException(exception.toString());
* set the pass-in parameter for "Integer"
public void setParameter(int position, int parameter) throws GeneralException {
try {
cs.setInt(position, parameter);
} catch(Exception exception) {
logger.error(exception.toString());
throw new GeneralException(exception.toString());
* execute the procedure and return the resultset
public ResultSet execProcedure() throws GeneralException {
try {
rs = cs.executeQuery();
} catch(SQLException exception) {
logger.error(exception.toString());
throw new GeneralException(exception.toString());
return rs;
* close the statment and resultset
private void initResource() throws GeneralException {
try {
if(rs != null) {
rs.close();
if(stmt!= null) {
stmt.close();
logger.info("Statement & Resultset have been free");
} catch(Exception exception) {
logger.error(exception.toString());
throw new GeneralException(exception.toString());
Thanks mates!
myyThanks Saish,
Your response is really appreciated. Sorry about that
as i didnt know there is 'code' formatting button,
and I will look into the Singleton pattern.
As I'm still in the learning stage. Therefore, i
still have a lot of thing do not understand.
... use it in a method signature ...What is "a method signature" ?
A method signature is basically the method's parameters, return value, name and any access or other modifiers. The following is a method signature:
static final public void main(final String[] args)Between the braces of the method body is the implementation (or as I already alluded to, the method body).
Consider using an already-developed connection poolimplementation, such as Jakarta Commons DBCP ...
I'm trying to implement the Jakarta DBCP. Did I go
into the wrong way?
Sorry, did not read the imports. Yes, you are. However, I am confused about what you are trying to implement. You have a static method getDataSource(). You also have a static variable 'ds'. Use one or the other. I would be that there are seemingly random errors cropping up based on whether you remember to call getDataSource() or not.
You do not, generally, want the data source to be static. Multiple threads might use the class. And if there is only a static data source, you will either need to synchronize the methods that use the data source (resulting in a scaling bottleneck) or not synchronize them (which will totally destroy any concept of a logical unit of work or database transaction).
.. A static datasource, as in your class, can onlysafely be used by one thread at a time, potentially
introducing scaling bottlenecks (or race conditions)
in your system ...
So, you mean there is no need for the DataSource to
be static ?
No, in fact, IMO, it should not be. That is why you are pooling. Use instances. The pool will manage the connections and their availabilty for you.
Why are you throwing GeneralException everywhere?Here's a question: can someone using your class (a
caller) realistically be expected to handle a
database exception?
When there is a database error, I just want to stop
the process and redirect the user to an error page. I
will look into the unchecked exceptions. Thanks.
Unchecked exceptions do not need to be declared in a method signature or caught within the method body. Checked exceptions do. As such, an added benefit is that unchecked exceptions de-clutter your code.
In your initResources() method, what happens if theclose() on ResultSet throws an exception
Oh, yes. I'm so stupid.
Now I only have ...
private static DataSource ds; // set this to
be static so all threads share the same obj in JVM
private Connection conn;
private CallableStatement cs;
private void initResource() throws GeneralException
n {
try {
if(cs != null) {
cs.close();
logger.info("CallableStatement has been
as been free");
} catch(Exception exception) {
logger.error(exception.toString());
throw new
throw new GeneralException(exception.toString());
You still have issues.
public void initResources() {
if (rs != null) {
try { rs.close(); } catch (SQLException ignore) { ignore.printStackTrace(); }
if (stmt != null) {
try { stmt.close(); } catch (SQLException ignore) { ignore.printStackTrace(); }
}Normally, this type of method would not be called initResources() but rather closeResources() or freeResources(). It would be called from within the 'finally' block of another method using the CallableStatement or ResultSet.
This is really is problem, would you mind to tell me
how to handle this(close the connection) if the
close() on either CallableStatement or Resultset
throws an exception ?
See above. Simply log the exception (there is usually nothing meaningful you can do if a close() fails, and it is up to you as a developer if this is an error or just a warning). Another option is to 'chain' exceptions. In your own exception, add a method 'addException(Throwable)'. This would add another exception to a List of exceptions. When you print the stack trace, iterate through the chained exceptions to print them all out. One place where I find this useful is rollback() code. If the original SQL statement fails AND the rollback fails, I definitely want to see that rollback() exception as well in my logs.
The DB thing makes me headache. What I actually
wanted is a solution for:
Let say I have a class "HelloAction.class" contains
the code:
public ActionForward XXX() {
DbManager DB = new DBManager();
... do some DB thing here...
SecondClass SC = new SecondClass();
SC.doSomeOtherDbThing();
... do something else...
ThirdClass TC = new ThirdClass();
SC.doMoreOtherDbThing();
}There are some functions in SecondClass.class and
ThirdClass.class that will need database connection.
I consider 'global variable' is because I want these
two classes are able to use the same
connection(DbManager) from the function -
ActionForward XXX().
What is the best way to implement the above situation
(sharing the same connection in different classes &
sub-classes?
I also just realize that the problem of multi-threads
with these two class variables..
private Connection conn;
private CallableStatement cs;Really headache. I really appreciate any comments.
Thanks.
- myyPass the Connection or DataSource to each method or constructor. Call commit() or rollback() from the method that created the transaction.
- Saish -
Can a method return a class ?
hi,
i have a simple question.
can a method return class value ?
in the below script i did'nt understand the commented line.
package com.google.gwt.sample.stockwatcher.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("login")
public interface LoginService extends RemoteService {
public LoginInfo login(String requestUri); //What is this ? is this a sample of what i asked ?
}The answer to your question is yes.
The idea is that an object calls a function of another object (passing in objects to the function as arguments) in which that object returns an object (note the arguments or returned value of the function may alternately be primitive types). Each object typically encapsulates data and provides a rich set of functions to the calling object so that calling object doesn't have to deal with the raw data directly. Therefore, not only does the calling object get the data it wants, but also a rich set of functions that can manipulate that data.
Example:
Book book = new Book();
int characterCount = book.getChapter(3).getParagraph(4).getSentence(12).getWord(8).getCharacterCount();
In the above, each object (Book, Chapter,Paragraph,Sentence,Word) has a rich set of functions it provides to its caller.
Example: the Sentence Object has a collection of word objects (raw data). Functions it provides to Paragraph object are:
Word getWord(int index), Words getWords(), int getWordCount().
If you haven't already done so, I suggest reading a book on Java from cover to cover to pick up such Object Oriented concepts. -
ASDoc, why are features missing in the SDK?
I've been using ASDoc for a project of mine and I've been really trying to extract some of the functionality I see in Adobe's documentation. I've noticed that there is a lot of functionality that is either missing portions to work right, or disabled altogether. Is there a reason the full version of ASDoc is not included in the SDK?
Some of the features I'm most concerned with is local search, being able to search my documentation without using LiveDocs. I noticed there is JavaScript setup to handle a local search, but you can't enable it. I hardcoded it on, but it then references a search.html which is not included in the templates or generated by Saxon or ASDoc, so i'm confused on where this is supposed to come from.
Another big feature i'm curious about is setting a description for the overview.html page. This would be like settings comments for -package but at the Top level. there are a handful of references to overview.html in the templates, but again. Neither Saxon or ASDoc generate this. But if you go to Adobe's site, their overview.html page has the auto-generated footer so their version of ASDoc must generate the file.
Other misc features I've stumbled across were conventions, appendixes, top level, @author, and @review. All which aren't enabled but work in some fashion or another.
If i could just get those two main features enabled somehow it would be SUPER AWESOME. But at the least, why is all this functionality disabled/broken in the latest sdk?
- gabrielHi Gabriel,
Features like local search etc are not available because no one has asked for them so far. Feel free to log an enhancement request at http://bugs.adobe.com/flex.
The other request to set package description via overview.html seems similar to http://bugs.adobe.com/jira/browse/SDK-19755, currently you can do this via Overviews_Base.xml, but when the feature request is implemented you would be able to do it using a config option.
>> Other misc features I've stumbled across were conventions, appendixes, top level, @author, and @review. All which aren't enabled but work in some >> fashion or another.
This is intentional, so we can generate asdoc faster by avoiding extra transformation processing. The current asdoc tool targets the most common use cases. If you feel these are important to you, please log enhancement requests.
Thanks,
Gaurav Jain
Flex SDK Team -
Error during up2date oracle-validated gives segmentation fault
Hi all,
I am trying to run the up2date oracle-validated command for Oracle Enterprise Linux 5 64 bit and it
fails on memory dump errors.
[root@tstdb01]# up2date oracle-validated
Fetching Obsoletes list for channel: el5_x86_64_latest...
Fetching rpm headers...
Segmentation fault
Any ideas how to resolve this?
Edited by: 783904 on Aug 19, 2010 9:09 AM# cat /etc/sysconfig/rhn/up2date
# Automatically generated Red Hat Update Agent config file, do not edit.
# Format: 1.0
enableRollbacks[comment]=Determine if up2date should create rollback rpms
enableRollbacks=0
noSSLServerURL[comment]=Remote server URL without SSL
noSSLServerURL=http://linux-update.oracle.com/XMLRPC
useNoSSLForPackages[comment] =Use the noSSLServerURL for package, package list, and header fetching
useNoSSLForPackages=0
debug[comment]=Whether or not debugging is enabled
debug=0
noReplaceConfig[comment]=When selected, no packages that would change configuration data are automatically installed
noReplaceConfig=1
retrieveOnly[comment]=Retrieve packages only
retrieveOnly=0
keepAfterInstall[comment]=Keep packages on disk after installation
keepAfterInstall=0
systemIdPath[comment]=Location of system id
systemIdPath=/etc/sysconfig/rhn/systemid
serverURL[comment]=Remote server URL
serverURL=https://linux-update.oracle.com/XMLRPC
pkgSkipList[comment]=A list of package names, optionally including wildcards, to skip
pkgSkipList=kernel*;
pkgsToInstallNotUpdate[comment]=A list of provides names or package names of packages to install not update
pkgsToInstallNotUpdate=kernel;kernel-modules;kernel-devel;
adminAddress[comment]=List of e-mail addresses for update agent to communicate with when run in batch mode
adminAddress=root@localhost;
storageDir[comment]=Where to store packages and other data when they are retrieved
storageDir=/var/spool/up2date
fileSkipList[comment]=A list of file names, optionally including wildcards, to skip
fileSkipList=;
removeSkipList[comment]=A list of package names, optionally including wildcards that up2date will not remove
removeSkipList=kernel*;
enableProxy[comment]=Use a HTTP Proxy
enableProxy=0
retrieveSource[comment]=Retrieve source RPM along with binary package
retrieveSource=0
versionOverride[comment]=Override the automatically determined system version
versionOverride=
httpProxy[comment]=HTTP proxy in host:port format, e.g. squid.redhat.com:3128
httpProxy=
useGPG[comment]=Use GPG to verify package integrity
useGPG=1
gpgKeyRing[comment]=The location of the gpg keyring to use for package checking
gpgKeyRing=/etc/sysconfig/rhn/up2date-keyring.gpg
noBootLoader[comment]=To disable modification of the boot loader (lilo, silo, etc)
noBootLoader=0
noReboot[comment]=Disable the reboot actions
noReboot=0
networkRetries[comment]=Number of attempts to make at network connections before giving up
networkRetries=5
updateUp2date[comment]=Allow up2date to update itself when possible
updateUp2date=1
disallowConfChanges[comment]=Config options that can not be overwritten by a config update action
disallowConfChanges=noReboot;sslCACert;useNoSSLForPackages;noSSLServerURL;serverURL;disallowConfChanges;
sslCACert[comment]=The CA cert used to verify the ssl server
sslCACert=/usr/share/rhn/ULN-CA-CERT
[root@tstdb01 up2date]# *up2date --show-channels*el5_x86_64_latest -
PaintComponent method seems not to be called - im stumped
Please find two simple classes:
When debugging why my background image wont display I have discovered that the paintComponent() method of my BackgroundJPanel class never gets invoked. Its part of the heirarchy so im not sure why.. You will notice a few system.out's the only thing my console shows is a "zooob!" comment..
package xrpg.client;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.*;
import javax.swing.ImageIcon;
import javax.swing.JLayeredPane;
import java.awt.Frame;
import java.awt.Color;
import jka.swingx.*;
public class XClient {
* @param args
public static void main(String[] args)
XClient app = new XClient();
public XClient()
//set look and feel
try { UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName()); }
catch (Exception e) { }
// Create the top-level container
JFrame frame = new JFrame("XClient");
frame.setUndecorated(true);
frame.setBackground(Color.black);
// create background panel and add it to frame
BackgroundJPanel bPanel = new BackgroundJPanel("xrpg/client/content/xrpg00002.jpg");
bPanel.setBackground(Color.white);
frame.getContentPane().add(bPanel, java.awt.BorderLayout.CENTER);
//JButton button = new JButton("I'm a Swing button!");
//bPanel.add(button);
//button.setLocation(10,10);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
System.exit(0);
// show & size frame
frame.pack();
frame.setVisible(true);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(dim);
package jka.swingx;
import javax.swing.*;
import java.awt.*;
public class BackgroundJPanel extends JPanel {
private Image img ;
private boolean draw = true;
public BackgroundJPanel(String imageResource)
System.out.println( "zooob!" );
// load & validate image
ClassLoader cl = this.getClass().getClassLoader();
try { img = new ImageIcon(cl.getResource(imageResource)).getImage(); } catch(Exception e){}
if( img == null ) {
System.out.println( "Image is null" );
draw=false;
if( img.getHeight(this) <= 0 || img.getWidth( this ) <= 0 ) {
System.out.println( "Image width or height must be +ve" );
draw=false;
setLayout( new BorderLayout() ) ;
public void drawBackground( Graphics g ) {
System.out.println( "zeeeb!" );
int w = getWidth() ;
int h = getHeight() ;
int iw = img.getWidth( this ) ;
int ih = img.getHeight( this ) ;
for( int i = 0 ; i < w ; i+=iw ) {
for( int j = 0 ; j < h ; j+= ih ) {
g.drawImage( img , i , j , this ) ;
protected void paintComponent(Graphics g) {
System.out.println( "zeeeha!" );
super.paintComponent(g);
if (draw) drawBackground( g ) ;
}why my "original post with two class" example is not calling the paintComponent() A couple of things have conspired to prevent the invocation of the paintComponent() method.
The preferredSize of your panel is (0, 0). Therefore, the size of all the components added to the frame is (0, 0). when the frame is made visible. It also appears than when you reset the size of the frame there is no need to repaint the panel since its size is (0, 0);
Simple solution is to change the order of your code to be:
frame.setSize(dim);
frame.setVisible(true);A couple of notes:
a) to maximize the frame, rather than setting the size manually it is better to use:
frame.setExtendedState (JFrame.MAXIMIZED_BOTH);
b) instead of using a window listener to close the frame it is easier to use:
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); -
SQL Developer 4.0: 'Open Declaration' bugs
There are several issues I have with this function:
1) Sometimes, when used, it would just "hang" the UI, loading the CPU for 50% for a few seconds.
2) It doesn't seem to work for functions/procedures outside packages, you have to use 'Popup describe' instead. Is that intended?
3) I don't know if it's actually related to 'Open Declaration', but Logging Page sometimes throws a pair oracle.dbtools.parser.plsql.DictionaryQuery errors, supposedly around the same time hangs occur I may be wrong on this one, but still thought it's worth reporting:
Error 1:
select null name, -1 LINE, -1 COL, null USAGE,
case when obj.object_type like 'JAVA%' then 'JAVA' else obj.object_type end TYPE,
OWNER, case when obj.object_type like 'JAVA%' then 'JAVA' else obj.object_type end OBJECT_TYPE,
obj.OBJECT_NAME
from sys.dba_objects obj where rownum <= 10 and obj.object_type != 'TABLE PARTITION' and obj.object_type != 'TABLE SUBPARTITION' and obj.object_type != 'JAVA CLASS' and object_name like :object_name and object_type = :object_type
union all
select null name, -1 LINE, -1 COL, null USAGE,
case when obj.object_type like 'JAVA%' then 'JAVA' else obj.object_type end TYPE,
OWNER, case when obj.object_type like 'JAVA%' then 'JAVA' else obj.object_type end OBJECT_TYPE,
obj.OBJECT_NAME
from sys.dba_objects obj where rownum <= 10 and obj.object_type != 'TABLE PARTITION' and obj.object_type != 'TABLE SUBPARTITION' and obj.object_type != 'JAVA CLASS' and object_name like :object_name and object_type = :object_type
union all
select * from (select text name, LINE, instr(upper(text),upper(:text)) COL, null USAGE, TYPE, OWNER, type OBJECT_TYPE, name OBJECT_NAME
from sys.all_source where rownum <= 10
and upper(text) like upper(:text1) and name not like 'BIN$%'
and (instr(text,'--')<=0 or instr(text,'--')>instr(upper(text),upper(:text2)))
and (instr(text,'/*')<=0 or instr(text,'/*')>instr(upper(text),upper(:text3)))
and type like 'PACKAGE%' and name = :name
) where col = 1 or substr(name/*text*/,col-1,1)=' '
order by type, line and owner = :owner
Error 2:
ORA-00907: missing right parenthesis
The 'and owner = :owner' part is obviously misplaced, causing the error.
P.S. A bit off-topic: SQLDev gives me quite a lot of various warnings both on logging page and in console. They don't seem to break anything, but should I report them anyway? And should I create a separate thread for each group of these, if I do?Okay, I've done some testing. It's far from exhaustive, but shows that 'Open Declaration' works differently in worksheet and package pl/sql editor, and that it depends on the case of the procedure/function that is inspected!
I also found out the cause of ORA-00907 message.
The cause of hangs also became somewhat possible to determine.
Sorry I couldn't test it more, but I already wasted about 2 hours on it, because I did it on our test (much slower) database, and each hang lasted about half a minute. I also didn't test inter-package 'Open Declaration' behavior, because I still have work to do. Hopefully what I found will be enough.
Also, another note is that "hangs" didn't burn the CPU while I tested it, unlike on production database.
We don't have HR schema anymore, so I unlocked SCOTT/TIGER forgotten by everyone, which had no functions/packages/whatsoever, only 4 tables.
All tests were done under 'SCOTT' user. Here's the test suite:
Creating the necessary function, procedure and package:
create or replace function z_test_opendecl_f return number as
begin
return 1;
end z_test_opendecl_f;
create or replace procedure z_test_opendecl_proc as
begin
null;
end z_test_opendecl_proc;
create or replace package z_test_opendecl_pack is
function call_z_func return number;
procedure call_z_proc;
end z_test_opendecl_pack;
create or replace package body z_test_opendecl_pack is
procedure call_z_proc is
begin
--call lowercase external proc without schema
--popup describe works
--open declaration throws "PL/SQL unit Z_TEST_OPENDECL_PROC does not exist" message box
--AND (nailed it!) writes ORA-00907 message I mentioned earlier in point (3) to logging page.
Z_TEST_OPENDECL_PROC;
--call lowercase external proc without schema
--same behavior as above
z_test_opendecl_proc;
--call mixed case external proc without schema
--same behavior as above
Z_Test_Opendecl_Proc;
--call lowercase external proc with schema
--popup describe works
--open declaration hangs, then opens procedure
scott.z_test_opendecl_proc;
--call mixed case external proc with schema
--popup describe works
--open declaration hangs, then gives messagebox
scott.Z_Test_Opendecl_Proc;
end call_z_proc;
function call_z_func return number is
vRet number;
begin
--Same behavior as with procedures above
vRet := z_test_opendecl_f;
vRet := scott.z_test_opendecl_f;
--Calling the procedure inside the package
--without schema, uppercase
--popup describe opens spec
--open declaration hangs, then opens spec
CALL_Z_PROC;
--without schema, uppercase
--popup describe opens spec
--open declaration hangs, then opens spec
Z_TEST_OPENDECL_PACK.CALL_Z_PROC;
--with schema, uppercase
--popup describe opens 'SCOTT' user popup
--open declaration hangs, then opens spec
SCOTT.Z_TEST_OPENDECL_PACK.CALL_Z_PROC;
--Inline SQL, 'Open Declaration' behavior:
select Z_TEST_OPENDECL_F --gives a messagebox, whatever the case
into vRet
from dual d
where z_test_opendecl_f = 1 -- messagebox
or scott.z_test_opendecl_f = 1 --opens declaration
or CALL_Z_FUNC = 1 -- scrolls to function declaration
or Z_TEST_OPENDECL_PACK.CALL_Z_FUNC = 1 --hangs, opens declaration
or SCOTT.Z_TEST_OPENDECL_PACK.CALL_Z_FUNC = 1; --does NOTHING
end call_z_func;
end z_test_opendecl_pack;
(Comments inside package body apply to Package Body Editor).
Here are the tests for worksheet:
--Worksheet tests
declare
vRet number;
begin
--NO SCHEMA SPECIFIED
--call the procedure
--both popup describe and open declaration open the procedure page
Z_TEST_OPENDECL_PROC;
--call the procedure - lowercase
--both popup describe and open declaration open the procedure page
z_test_opendecl_proc;
--call the procedure - mixed case
--popup describe opens the page
--open declaration shows "PL/SQL unit Z_Test_Opendecl_Proc does not exist" messagebox
Z_Test_Opendecl_Proc;
--call the function
--both popup describe and open declaration open the function page
vRet := Z_TEST_OPENDECL_F;
--call the function - lowercase
--both popup describe and open declaration open the function page
vRet := z_test_opendecl_f;
--call the function - mixed case
--popup describe opens the page
--open declaration shows "PL/SQL unit Z_TEST_opendecl_f does not exist" messagebox
vRet := Z_TEST_opendecl_f;
-- call the package procedure
-- popup describe opens package spec
-- open declaration hangs, then opens package spec
Z_TEST_OPENDECL_PACK.CALL_Z_PROC;
-- call the package function
-- popup describe opens package spec
-- open declaration hangs, then opens package spec
vRet := Z_TEST_OPENDECL_PACK.CALL_Z_FUNC;
-- call the package function - mixed case
-- popup describe opens package spec
-- open declaration hangs, then shows "PL/SQL unit CALL_z_func does not exist" messagebox
vRet := Z_TEST_OPENDECL_PACK.CALL_z_func;
--inline SQL
--Shows the same behavior
select Z_TEST_OPENDECL_F --works
into vRet
from dual
where Z_TEST_OPENDECL_F = 1 -- works
or Z_TEST_OPENDECL_PACK.CALL_Z_FUNC = 1 -- hangs, but works
or Z_TEST_opendecl_f = 1; -- messagebox
--WITH SCHEMA SPECIFIED
--Usual calls mostly exhibit the same behavior, except all of them hang on "Open Declaration" now
-- call the package function
-- popup describe opens 'SCOTT' user popup (!?)
-- open declaration hangs, then opens package spec
vRet := SCOTT.Z_TEST_OPENDECL_PACK.CALL_Z_FUNC;
--inline SQL
--Shows the same behavior
select SCOTT.Z_TEST_OPENDECL_F --works
into vRet
from dual
where SCOTT.Z_TEST_OPENDECL_F = 1 -- works
or SCOTT.Z_TEST_OPENDECL_PACK.CALL_Z_FUNC = 1 -- hangs, but works
or SCOTT.Z_TEST_opendecl_f = 1; -- messagebox
end;
There was also an error on production DB I wasn't able to reproduce while testing:
while editing package body, calling 'Open Declaration' on function name inside inline SQL did nothing - neither the message box appeared nor declaration was opened, it also doesn't hang.
I can't disclose the names, but it looks like this:
select myFunction(t.id,vLocalVar) into vLocalVar2 from tablename t;
We have a lot of objects on production, maybe it times out or something, I don't know. Autocomplete also doesn't work unless I call it explicitly with ctrl+space.
An assumption regarding the hangs: we have a ton of public synonyms and a lot of java objects; the hangs are probably related to poor java object querying performance discussed in neighboring topic.
Maybe you are looking for
-
I own an iPad 2 and love it, feeding it with new apps on a regular basis. However it does have obvious shortcomings and I'm seriously thinking of buying another tablet that has features which are missing. Keyboard I'll start with the the most common
-
How to save down an .idml file to open as .idd in CS3?
I'm using a G5 (PPC), OS 10.5.8 and CS3 (v 5.0.4) an recently received client files that were created in InDesign 5 and saved as .idml. What are the steps necessary to save them down to InDesign CS3 version, so I can open them and modify? The other p
-
Bootcamp problems mac osx 10.8.3
Hey guys, Yesterday bought the new mac mini 2011! And today I wanted to install windows 8 or 7, it doesn't matter to me that much! So i downloaded two versions of windows, two times an iso files. I thought it was 64 bit, but not sure. So i started bo
-
Need some info about the wifi on the 3gs. Seems mine is acting up from day one. Had the 3g prior to getting the 3gs in june, i use the wifi at home all the time on the iPhone, my router is the eircom netopia. I always used the wifi at home when on my
-
Broadcasting to many users based on Authorisations
Hi, I have one query which is to be broadcasted to several users and again with different parameters Ex: First user should receive only Country A data Second user should receive only Country B data Third user Should receive only COuntry C Data...and