Saturday, June 13, 2009

Oracle Links

More Examples/Snippets

Hibernate JPA Persistence Provider

org.hibernate.ejb.HibernatePersistence

JPA Links

JPA


Example: JPA TopLink JSF

EclipseLink JPA Configuration

Hibernate Dialects


Hibernate Download page

ManyToOne mapping in case of primary key composed of foreign key

For a primary key composed of a foreign key from a ManyToOne in JPA 1.0 you need to map the foreign key field twice. With a basic @Id mapping and with the @ManyToOne, the @ManyToOne should be set read-only (insertable, updatable=false, or use @PrimaryKeyJoinColumn)

Design patterns links

Default eclipse workspace location

$eclipse_installation\configuration\config.ini file

Java Rest Framework Links

Links
http://objectif-naiade.blogspot.com/2007/11/java-rest-framework-jersey.html
http://www.oreillynet.com/onjava/blog/2007/04/restlet_lightweight_rest_frame.html


https://restlet.dev.java.net/


http://www.javaworld.com/javaworld/jw-10-2007/jw-10-resteasy.html


http://twit88.com/blog/2008/09/24/java-open-source-rest-framework/
http://www.restlet.org/about/features


https://cetia4.dev.java.net/


http://marxsoftware.blogspot.com/2009/01/easy-java-based-rest-testing-tools.html


http://www.javaworld.com/community/node/2193

JSF Links

Instantly Deploy Applications in Weblogic

Fast path - Log4j Link

JPA Hibernate Tips

using the old classes12 driver lib results in an issue where OracleDriver.getMajorVersion returns 0, which confuses hibernate.
Upgrading to ojdbc14.jar will fix the issue.

Design patterns

Safe Getters and Setters
-domain objects returning collection objects in getter should check for null
and return EMPTY_COLLECTION instead of null collection
-domain objects returning string objects in getter should check for null and
return empty string instead of null

Assert methods to validate method arguments
-call assert methods to check for null arguments instead of checking objects for null and throwing an IllegalArgumentException

-in graph of objects add getter methods to link child objects to parent objects

Null object Design pattern
-to avoid checking for null across the whole application. centralize the null checks within domain object, service object getters

elements2Attributes.xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">
<xsl:output indent="yes"/>
<xsl:template match="*">
<xsl:copy>
<xsl:for-each select="@*|*[not(* or @*)]">
<xsl:attribute name="{concat(name(.), position())}">
<xsl:value-of select="."/></xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="*[* or @*]|text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

attributes2Elements.xslt

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:copy>
<xsl:if test="@*">
<xsl:for-each select="@*">
<xsl:element name="{substring(name(), 1, string-length(name()) - 1)}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:if>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

javascript

javascript:alert(document.cookie)

echo.xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no" normalization-form="fully-normalized"/>
<xsl:template match="/">
<xsl:apply-templates select="child::node()"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

online utilities

escape unescape html xml

unix bash commands

PS1='\h:\w>'


alias cmd="cat $homedir/.bashrc"
alias log2="tail -100f $file"
alias cdir="cd $dir"
alias u="cd /bea/wl815/user_projects/domains/$domain/admin/upload"
alias cls="clear"
alias c="clear"
alias dir="ls"
alias lsr="ls -ltr"
alias lsm="ls -ltR more"
alias lsa="ls -a "
alias chm="chmod -R 777 * "
alias log="cd log4j && pwd"

displays machine info by ip/name
nslookup

CLASSPATH=jkjkl; export;
echo $CLASSPATH

unix commands links

unix commands

sort filenames in unix in long format, ignore case
ls -l | sort -f -k 9

change to directory a
cda

alias cda="cd a"

tail log
loga
alias loga="tail -100f a"

execute unix commands on windows

oracle

case insensitive search
to retrieve records, search records case insensitive use upper function
select * from User
where upper(name) like 'JOHN%'

select current date/execute function
select sysdate
from dual;

executing a function
select func(x)
from dual;

select number of records in table
select count(*)
from table

executing a procedure which returns a reference cursor

DECLARE
TYPE CurTyp IS REF CURSOR;
cur CurTyp;
BEGIN
DBMS_OUTPUT.ENABLE(1000000); -- enable output
cur := schema.pkg.proc_name(input);
END;

executing a procedure which returns a number

DECLARE
x number;
BEGIN
DBMS_OUTPUT.ENABLE(1000000);
x := schema.pkg.proc_name(input);
END;

executing a procedure which returns a varchar
DECLARE
str varchar(3000);
BEGIN
DBMS_OUTPUT.ENABLE(1000000);
str := schema.pkg.proc_name(input);
END;

printing separator

declare
str varchar(3000);
begin
dbms_output.put_line('------------------');
str := 'Hello';
dbms_output.put_line(str);
end;

string literal is enclosed in single quote
example 'hello'

assignment operator
:=

equality operator
=

not equal to operator
<>

line separator

;

For loop

DECLARE
ii number;
BEGIN
ii := 4;
FOR ii IN -2..20 LOOP
dbms_output.put_line(ii);
END LOOP;
END;

--fetching data from cursors to record

declare
type curtype is ref cursor;
cur curtyp;

type rectype is record
(
col1 number,
col2 varchar(30)
);
rec rectype;

begin
cur := proc(); --execute proc

loop
fetch cur into rec
exit when cur%notfound;

dbms_output.put_line(rec.col1 || ' ' || rec.col2);
end loop

close cur;
end;




jedit find replace regular expression

Find and replace new lines
Find: \n
Replace:

Find start of line
Find: ^

Find one of the following word: test1test2test3
Remember the matches: (test1test2test3)
Replace with the match: $1

Beanshell snippet: _1.equals("value1") ? "val2" : "val3"

ToTitleCase.bsh

public String titleCase(String text) {
String[] strs = text.split("_");
StringBuffer st = new StringBuffer();
for(int ii = 0; ii < line =" textArea.getCaretLine();" text =" textArea.getLineText(line);">

swing-awt-frame

Frame

maximize

frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

Bring to Front
frame.setAlwaysOnTop(true);
frame.setAlwaysOnTop(false);

Request focus

frame.requestFocus();

Sizing,Visibility

frame.pack();
frame.setVisible(true);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

Get Screen size

Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();

java tips

Format number to two digits

System.out.println(new DecimalFormat("00").format(8));
System.out.println(new DecimalFormat("00").format(18));

Invoke just before the appliction shutsdown
static {
//add runtime shutdown hook in a runnable
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
//...
}
});
}

struts tiles reload

<action path="/tiles-admin/reload" type="org.apache.struts.tiles.actions.ReloadDefinitionsAction"> </action> <action path="/tiles-admin/view" type="org.apache.struts.tiles.actions.ViewDefinitionsAction"> </action>

Links


Launch explorer from eclipse - launch.bat

c:
echo %1
cd %1
explorer "%CD%"

weblogic jndi lookup

domain > servers > server
Listen Port: XXX

weblogic.jndi.Environment environment = new weblogic.jndi.Environment();
environment.setInitialContextFactory(weblogic.jndi.Environment.DEFAULT_INITIAL_CONTEXT_FACTORY);
environment.setProviderUrl("t3://domain:XXX");
environment.setSecurityPrincipal("user");
environment.setSecurityCredentials("pwd");
Context initialContext = environment.getInitialContext();
Object ds = initialContext.lookup("YYY");