3 Advanced Methods of Accessing DBWS Designtime API
This chapter includes the following sections:
Using DBWSBuilder with Ant
With EclipseLink DBWS, you can invoke the DBWSBuilder
from Apache Ant (http://ant.apache.org/
) to generate the necessary files, compile, and package the application with additional Ant targets.
Example
This example illustrates how to use Ant to generate a deployable web archive. For this example, consider the following file layout:
<example-root>
dbws-builder.xml
(see Example 3-1) build.xml
(see Example 3-2) build.properties
(see Example 3-3)
jlib
eclipselink.jar
eclipselink-dbwsutils.jar
javax.servlet.jar
javax.wsdl.jar
ojdbc6.jar
org.eclipse.persistence.oracleddlparser.jar
stage
All generated artifacts will saved here, most importantly simpletable.war
.
To run the DBWS builder in this example, simply type ant
in the <example-root>
directory. The builder packages the generated artifacts into the web archive (simpletable.war
) in the stage
directory. This .war
file can then be deployed to WebLogic.
Example 3-1 Sample DBWS Builder File (dbws-builder.xml)
<?xml version="1.0" encoding="UTF-8"?> <dbws-builder xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <properties> <property name="projectName">simpletable</property> ... database properties </properties> <table schemaPattern="SCOTT" tableNamePattern="SIMPLETABLE" /> </dbws-builder>
Example 3-2 Sample Build XML File (build.xml)
<?xml version="1.0"?> <project name="simpletable" default="build"> <property file="${basedir}/build.properties"/> <path id="build.path"> <fileset dir="${jlib.dir}" includes="eclipselink.jar eclipselink-dbwsutils.jar org.eclipse.persistence.oracleddlparser.jar javax.wsdl.jar javax.servlet.jar ojdbc6.jar" > </fileset> </path> <target name="build"> <java classname="org.eclipse.persistence.tools.dbws.DBWSBuilder" fork="true" classpathRef="build.path" > <arg line="-builderFile ${dbws.builder.file} -stageDir ${stage.dir} -packageAs ${server.platform} ${ant.project.name}.war"/> </java> </target> </project>
Example 3-3 Sample Build Properties File (build.properties)
custom = true build.sysclasspath=ignore stage.dir=${basedir}/stage jlib.dir=${basedir}/jlib server.platform=wls dbws.builder.file=dbws-builder.xml
Using with javac
Currently not supported. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=386860
Fixed in 2.4.1 and 2.5
Starting with EclipseLink 2.4.1, you can invoke the DBWSBuilder
from javac
to generate the necessary files, compile, and package the application into a web archive that can be deployed to an active WebLogic instance.
The OXM project org.eclipse.persistence.tools.dbws.DBWSBuilderModelProject
parses the builder XML file (dbws-bulider.xml
), producing model objects that represent properties, table and procedure operations. You can also populate the public class org.eclipse.persistence.tools.dbws.DBWSBuilder
programmatically, through property setters (such as setDriver()
and setUrl()
) and the operation setter addOperation(OperationModel operation)
.
Example 3-4 illustrates how to configure DBWSBuilder
.
Example 3-4 Using DBWSBuilder with javac
DBWSBuilder builder = new DBWSBuilder(); // set properties builder.setProjectName("simpleSP"); builder.setLogLevel("fine"); builder.setUsername("SCOTT"); builder.setPassword("TIGER"); builder.setUrl("jdbc:oracle:thin:@localhost:1521:ORCL"); builder.setDriver("oracle.jdbc.OracleDriver"); builder.setPlatformClassname("org.eclipse.persistence.platform.database.oracle.Oracle11Platform"); // set table and procedure operations ProcedureOperationModel procOpModel = new ProcedureOperationModel(); procOpModel.setName("VarcharTest"); procOpModel.setCatalogPattern("TOPLEVEL"); procOpModel.setProcedurePattern("VarcharSP"); procOpModel.setReturnType("xsd:int"); builder.addOperation(procOpModel); TableOperationModel tableOpModel = new TableOperationModel(); tableOpModel.setSchemaPattern("%"); tableOpModel.setTablePattern("SIMPLESP"); // add nested procedure operation procOpModel = new ProcedureOperationModel(); procOpModel.setName("GetAllTest"); procOpModel.setCatalogPattern("TOPLEVEL"); procOpModel.setProcedurePattern("GetAll"); procOpModel.setIsCollection(true); procOpModel.setReturnType("simplespType"); tableOpModel.addOperation(procOpModel); builder.addOperation(tableOpModel); // setup the web service packager XRPackager xrPackager = new JSR109WebServicePackager(); xrPackager.setDBWSBuilder(builder); builder.setPackager(xrPackager); xrPackager.setSessionsFileName(builder.getSessionsFileName()); xrPackager.setStageDir(new File(".")); // generate the web archive builder.start();