Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/DBWS/DBWSBuilder using ANT and javac"

(DBWSBuilder using javac)
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
= DBWSBuilder using ANT =
 
= DBWSBuilder using ANT =
  
This example illustrates how DBWSBuilder can be invoked from ANT generating all of the required aretfacts to the file system and then compiling and packaging with additional ANT targets.
+
This example illustrates how DBWSBuilder can be invoked from ANT generating all of the required artifacts to the file system, compiling them, and finally packaging them in a web archive that can be deployed to an active WebLogic instance.
  
Example file layout:
+
File layout for this example:
  Base directory
+
    <example-root>
 +
    |
 +
    | <span style="font-weight: bold;">build.properties</span>
 +
    |  <span style="font-weight: bold;">build.xml</span>
 +
    |  <span style="font-weight: bold;">dbws-builder.xml</span>
 +
    |
 
     \---jlib
 
     \---jlib
 
     |
 
     |
Line 16: Line 21:
 
     \---stage
 
     \---stage
 
     |
 
     |
 +
    |  (Artifacts will be generated here, most notably <span style="font-weight: bold;">simpletable.war</span>)
 
     |
 
     |
    |<span style="font-weight: bold;">build.properties</span>
 
    |<span style="font-weight: bold;">build.xml</span>
 
    |<span style="font-weight: bold;">dbws-builder.xml</span>
 
  
==== <span style="font-size:5;font-family:monospace,sans-serif;">build.properties</span> ====
+
To run the DBWS builder in this example, simply type <code>ant</code> in the example-root directory.  The builder packages the generated artifacts into the web archive <code>simpletable.war</code>, which is placed the the <code>stage</code> directory.  This <code>.war</code> file can then be deployed to WebLogic.
<source lang="text">
+
custom = true
+
build.sysclasspath=ignore
+
  
stage.dir=${basedir}/stage
+
==== <span style="font-size:5;font-family:monospace,sans-serif;">dbws-builder.xml</span> ====
jlib.dir=${basedir}/jlib
+
Following is the builder XML file used in this example:
server.platform=wls
+
<source lang="xml">
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>
 
</source>
 
</source>
  
 
==== <span style="font-size:5;font-family:monospace,sans-serif;">build.xml</span> ====
 
==== <span style="font-size:5;font-family:monospace,sans-serif;">build.xml</span> ====
 +
Following is the build XML file used for this example:
 
<source lang="xml">
 
<source lang="xml">
 
<?xml version="1.0"?>
 
<?xml version="1.0"?>
Line 63: Line 75:
 
</source>
 
</source>
  
==== <span style="font-size:5;font-family:monospace,sans-serif;">dbws-builder.xml</span> ====
+
==== <span style="font-size:5;font-family:monospace,sans-serif;">build.properties</span> ====
<source lang="xml">
+
Following is the build properties file used for this example:
<?xml version="1.0" encoding="UTF-8"?>
+
<source lang="text">
<dbws-builder xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
custom = true
  <properties>
+
build.sysclasspath=ignore
    <property name="projectName">simpletable</property>
+
    ... database properties
+
  </properties>
+
  
  <table
+
stage.dir=${basedir}/stage
    schemaPattern="SCOTT"
+
jlib.dir=${basedir}/jlib
    tableNamePattern="SIMPLETABLE"
+
server.platform=wls
  />
+
dbws.builder.file=dbws-builder.xml
</dbws-builder>
+
 
</source>
 
</source>
  
 +
= DBWSBuilder using javac =
 +
 +
This example illustrates how <code>DBWSBuilder</code> can be invoked using <code>javac</code> generating all of the required artifacts to the file system, compiling them, and finally packaging them in a web archive that can be deployed to an active WebLogic instance. 
 +
 +
A given builder XML file is parsed by the OXM Project org.eclipse.persistence.tools.dbws.DBWSBuilderModelProject producing model objects that represent <code>properties</code>, <code>table</code> and <code>procedure</code> operations. The public class org.eclipse.persistence.tools.dbws.DBWSBuilder can also be populated programmatically through property setters (i.e. <code>setDriver()</code>, <code>setUrl()</code>, etc.) and the operation setter <code>addOperation(OperationModel operation)</code>.
 +
 +
 +
The following code snippet illustrates how the DBWSBuilder can be configured programmatically.
 +
<source lang="java">
 +
    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();
 +
</source>
  
 
[[Category:EclipseLink/Example/DBWS|ANT Builder]]
 
[[Category:EclipseLink/Example/DBWS|ANT Builder]]

Latest revision as of 11:52, 10 August 2012

DBWSBuilder using ANT

This example illustrates how DBWSBuilder can be invoked from ANT generating all of the required artifacts to the file system, compiling them, and finally packaging them in a web archive that can be deployed to an active WebLogic instance.

File layout for this example:

   <example-root>
   |
   |  build.properties
   |  build.xml
   |  dbws-builder.xml
   | 
   \---jlib
   |
   |   eclipselink.jar
   |   eclipselink-dbwsutils.jar
   |   javax.servlet.jar
   |   javax.wsdl.jar
   |   ojdbc6.jar
   |   org.eclipse.persistence.oracleddlparser.jar
   |
   \---stage
   |
   |   (Artifacts will be generated here, most notably 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, which is placed the the stage directory. This .war file can then be deployed to WebLogic.

dbws-builder.xml

Following is the builder XML file used in this example:

<?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>

build.xml

Following is the build XML file used for this example:

<?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>

build.properties

Following is the build properties file used for this example:

custom = true
build.sysclasspath=ignore
 
stage.dir=${basedir}/stage
jlib.dir=${basedir}/jlib
server.platform=wls
dbws.builder.file=dbws-builder.xml

DBWSBuilder using javac

This example illustrates how DBWSBuilder can be invoked using javac generating all of the required artifacts to the file system, compiling them, and finally packaging them in a web archive that can be deployed to an active WebLogic instance.

A given builder XML file is parsed by the OXM Project org.eclipse.persistence.tools.dbws.DBWSBuilderModelProject producing model objects that represent properties, table and procedure operations. The public class org.eclipse.persistence.tools.dbws.DBWSBuilder can also be populated programmatically through property setters (i.e. setDriver(), setUrl(), etc.) and the operation setter addOperation(OperationModel operation).


The following code snippet illustrates how the DBWSBuilder can be configured programmatically.

    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();

Back to the top