Thursday, July 21, 2011

How to use JAXB with Spring - Marshalling & Unmarshalling  

Using JAXB with Spring - Marshalling / Unmarshalling XML:

Using JAXB with Spring we can easily Marshall / Unmarshall the XML. Let us see how with an simple example.

Before starting the tutorial here are the definitions for a few technical words:
Spring's Object/XML (In short O/X) Mapping - Is the act of converting an XML document to and from an object.
Marshaller - Responsible for serializing an object (graph) to XML.
Unmarshaller - Deserializes the XML to an object graph.

Getting the JAXB Eclipse plug-in:
1. Download JAXB Eclipse Plug-In (jaxbbuilder.2.0.1581.zip) from
JAXB Eclipse Plug-in

2. Unzip the plug-in and copy the com.viewstreet.java.eclipse.jaxbplugin_0.1.0 folder into your eclipse plug-in folder (../eclipse/plugins). Restart eclipse if already open.

3. You also need to get the following jar files and set in your Eclipse classpath
jaxb-xjc-2.2.jar
jaxb-impl-2.2.jar
jaxb-api-2.2.jar

4. Create new project (Name: xmlBindingProj). Choose “Java XML Binding Project” in the new project creation wizard.



5. Create a XML Schema (.xsd) file customer.xsd: Example


6. Right click on the customer.xsd file on the project explorer and choose “Generate-> JAXB Classes”

7. Give the package name in the following dialog box as "com.mycomp.jaxbexample.order"


You can see the following classes created in the package with JAXB annotations.
ItemDetail.java
ObjectFactory.java
Person.java
Shiporder.java

8. Create the applicationContext.xml file under src directory as given below:


9. Create the following two java files and execute the ShipOrderClient.java
ShipOrderClient.java


JaxbConverter.java

Saturday, July 16, 2011

Multiple columns in Oracle IN clause 

How to use more than one column in Oracle IN clause:

CREATE TABLE t1 (id VARCHAR2(10), version NUMBER(2,1), name VARCHAR2(20));

INSERT INTO t1 VALUES ('1001', 1.1 ,'FIRST ELEMENT');
INSERT INTO t1 VALUES ('1001', 1.2 ,'FIRST ELEMENT');
INSERT INTO t1 VALUES ('1001', 1.3 ,'FIRST ELEMENT');
INSERT INTO t1 VALUES ('1001', 1.4 ,'FIRST ELEMENT');

INSERT INTO t1 VALUES ('1002', 1.1 ,'SECOND ELEMENT');
INSERT INTO t1 VALUES ('1002', 1.2 ,'SECOND ELEMENT');
INSERT INTO t1 VALUES ('1002', 1.3 ,'SECOND ELEMENT');
INSERT INTO t1 VALUES ('1002', 1.4 ,'SECOND ELEMENT');
INSERT INTO t1 VALUES ('1002', 1.5 ,'SECOND ELEMENT');
INSERT INTO t1 VALUES ('1002', 1.6 ,'SECOND ELEMENT');
INSERT INTO t1 VALUES ('1002', 1.7 ,'SECOND ELEMENT');

SELECT id, version, name FROM t1 WHERE (id, version) IN ( (1001,1.1), (1002,1.6) );