You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by to...@apache.org on 2006/02/05 18:48:04 UTC

svn commit: r375061 - in /db/ojb/trunk: ./ lib/ profile/ src/java/org/apache/ojb/broker/platforms/ src/java/org/apache/ojb/broker/util/dbhandling/ src/schema/

Author: tomdz
Date: Sun Feb  5 09:48:02 2006
New Revision: 375061

URL: http://svn.apache.org/viewcvs?rev=375061&view=rev
Log:
Ported Derby platform to trunk
Updated DdlUtils-using db setup task

Added:
    db/ojb/trunk/profile/derby.profile
    db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDerbyImpl.java
Modified:
    db/ojb/trunk/build.properties
    db/ojb/trunk/build.xml
    db/ojb/trunk/lib/DdlUtils-1.0-dev.jar
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandling.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandlingTask.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DdlUtilslDatabaseHandling.java
    db/ojb/trunk/src/schema/ojbtest-data-new.xml

Modified: db/ojb/trunk/build.properties
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/build.properties?rev=375061&r1=375060&r2=375061&view=diff
==============================================================================
--- db/ojb/trunk/build.properties (original)
+++ db/ojb/trunk/build.properties Sun Feb  5 09:48:02 2006
@@ -21,9 +21,7 @@
 # With the 'profile' property you can choose the RDBMS platform OJB is using
 # implemented profiles:
 #
-profile=hsqldb
-# Use this when running the unit tests with the commons-sql dbhandling:
-#profile=hsqldb-commons-sql
+#profile=hsqldb
 
 # use the mssqldb-JSQLConnect profile for Microsoft SQL Server and
 # you will automatically JSQLConnect driver, from http://www.j-netdirect.com/
@@ -34,6 +32,7 @@
 #profile=mssqldb-ms
 #profile=mysql
 #profile=db2
+profile=derby
 #profile=oracle
 #profile=oracle9i
 #profile=msaccess

Modified: db/ojb/trunk/build.xml
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/build.xml?rev=375061&r1=375060&r2=375061&view=diff
==============================================================================
--- db/ojb/trunk/build.xml (original)
+++ db/ojb/trunk/build.xml Sun Feb  5 09:48:02 2006
@@ -423,11 +423,23 @@
 
         </copy>
 
+        <taskdef name="ddlToDatabase"
+                 classname="org.apache.ddlutils.task.DdlToDatabaseTask">
+            <classpath refid="runtime-classpath"/>
+        </taskdef>
         <taskdef name="dbhandling"
                  classname="org.apache.ojb.broker.util.dbhandling.DatabaseHandlingTask">
             <classpath refid="runtime-classpath"/>
         </taskdef>
 
+        <ddlToDatabase usedelimitedsqlidentifiers="false"
+                       useinternaldtd="true">
+          <database driverclassname="${torque.database.driver}"
+                    url="${torque.database.url}"
+                    username="${torque.database.user}"
+                    password="${torque.database.password}"/> 
+          <createdatabase failonerror="false"/> 
+        </ddlToDatabase> 
         <dbhandling ojbpropertiesfile="${build.test}/ojb/OJB.properties">
             <fileset dir="${build.test}" includes="*schema.xml"/>
             <databaseProperties files="profile/${profile}.profile"/>

Modified: db/ojb/trunk/lib/DdlUtils-1.0-dev.jar
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/lib/DdlUtils-1.0-dev.jar?rev=375061&r1=375060&r2=375061&view=diff
==============================================================================
Binary files - no diff available.

Added: db/ojb/trunk/profile/derby.profile
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/profile/derby.profile?rev=375061&view=auto
==============================================================================
--- db/ojb/trunk/profile/derby.profile (added)
+++ db/ojb/trunk/profile/derby.profile Sun Feb  5 09:48:02 2006
@@ -0,0 +1,157 @@
+#<!--
+#/* Copyright 2002-2004 The Apache Software Foundation
+# *
+# * Licensed under the Apache License, Version 2.0 (the "License");
+# * you may not use this file except in compliance with the License.
+# * You may obtain a copy of the License at
+# *
+# *     http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * Unless required by applicable law or agreed to in writing, software
+# * distributed under the License is distributed on an "AS IS" BASIS,
+# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# * See the License for the specific language governing permissions and
+# * limitations under the License.
+# */
+#-->
+# location of jar that you will be using for testing
+# so that it can be copied into the dist/lib directory.
+
+torque.testDatabaseJar = ${lib.repo}/derby.jar
+torque.idMethod = idbroker
+torque.defaultDatabase = OJB
+
+# -------------------------------------------------------------------
+#
+# T O R Q U E  C O N F I G U R A T I O N  F I L E
+#
+# -------------------------------------------------------------------
+
+# -------------------------------------------------------------------
+#
+#  T A R G E T  D A T A B A S E
+#
+# -------------------------------------------------------------------
+
+torque.database = db2
+
+# -------------------------------------------------------------------
+#
+#  O B J E C T  M O D E L  I N F O R M A T I O N
+#
+# -------------------------------------------------------------------
+# These settings will allow you to customize the way your
+# Peer-based object model is created.
+# -------------------------------------------------------------------
+# addSaveMethod=true adds tracking code to determine how to save objects
+#
+# addGetByNameMethod=true adds methods to get fields by name/position
+#
+# complexObjectModel=true generates an om with collection support
+#
+# addTimeStamp=true puts time stamps in generated files
+#
+# addIntakeRetrievable=implement Intake's Retrievable interface
+# -------------------------------------------------------------------
+
+targetPackage=org.apache.torque.test
+basePrefix=Base
+addSaveMethod=true
+addGetByNameMethod=true
+complexObjectModel=true
+addTimeStamp=true
+addIntakeRetrievable=false
+useManagers=true
+
+# -------------------------------------------------------------------
+#
+#  D A T A B A S E  S E T T I N G S
+#
+# -------------------------------------------------------------------
+# JDBC connection settings. This is used by the JDBCToXML task that
+# will create an XML database schema from JDBC metadata. These
+# settings are also used by the SQL Ant task to initialize your
+# Turbine system with the generated SQL.
+# -------------------------------------------------------------------
+
+dbmsName = Derby
+jdbcLevel = 3.0
+urlProtocol = jdbc
+urlSubprotocol = derby
+#urlDbalias = target/test/derbydb
+urlDbalias = //localhost/OJB
+
+
+#
+# settings for torque 3.1.1
+#
+torque.database.createUrl = ${urlProtocol}:${urlSubprotocol}:${urlDbalias}
+torque.database.buildUrl = ${urlProtocol}:${urlSubprotocol}:${urlDbalias}
+torque.database.url = ${urlProtocol}:${urlSubprotocol}:${urlDbalias}
+torque.database.host = 127.0.0.1
+
+#torque.database.driver = org.apache.derby.jdbc.EmbeddedDriver
+#torque.database.user = app
+#torque.database.password = 
+
+torque.database.driver = org.apache.derby.jdbc.ClientDriver
+torque.database.user = ojb
+torque.database.password = ojb
+
+
+# Tells JDBC task that javaName attribute for the tables and columns
+# should be made same as SQL name.
+sameJavaName=false
+
+# -------------------------------------------------------------------
+#
+#  D O C U M E N T A T I O N   S E T T I N G S
+#
+# -------------------------------------------------------------------
+# These settings will allow you to customize the way your schema
+# documentation is created.
+# Valid formats are: html, anakia (for use with jakarta-site2)
+# -------------------------------------------------------------------
+documentationFormat=html
+
+# -------------------------------------------------------------------
+# You should NOT have to edit anything below here.
+# -------------------------------------------------------------------
+
+# -------------------------------------------------------------------
+#
+#  T E M P L A T E  P A T H
+#
+# -------------------------------------------------------------------
+
+templatePath = ../templates
+
+# -------------------------------------------------------------------
+#
+#  C O N T R O L  T E M P L A T E S
+#
+# -------------------------------------------------------------------
+
+SQLControlTemplate = sql/base/Control.vm
+OMControlTemplate = om/Control.vm
+idTableControlTemplate = sql/id-table/Control.vm
+DataDTDControlTemplate = data/Control.vm
+DataDumpControlTemplate = data/dump/Control.vm
+DataSQLControlTemplate = sql/load/Control.vm
+DocControlTemplate = doc/Control.vm
+
+# -------------------------------------------------------------------
+#
+#  O U T P U T  D I R E C T O R Y
+#
+# -------------------------------------------------------------------
+
+outputDirectory=src
+
+# -------------------------------------------------------------------
+#
+#  S C H E M A  D I R E C T O R Y
+#
+# -------------------------------------------------------------------
+
+schemaDirectory=schema

Added: db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDerbyImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDerbyImpl.java?rev=375061&view=auto
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDerbyImpl.java (added)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDerbyImpl.java Sun Feb  5 09:48:02 2006
@@ -0,0 +1,70 @@
+package org.apache.ojb.broker.platforms;
+
+/* Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * This class defines specific behavior for the Derby platform.
+ */
+public class PlatformDerbyImpl extends PlatformDefaultImpl
+{
+    /**
+     * {@inheritDoc}
+     */
+    public byte getJoinSyntaxType()
+    {
+        return SQL92_NOPAREN_JOIN_SYNTAX;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setObjectForStatement(PreparedStatement ps, int index, Object value, int jdbcType) throws SQLException
+    {
+        if (((jdbcType == Types.CHAR) || (jdbcType == Types.VARCHAR)) &&
+            (value instanceof Character))
+        {
+            // [tomdz]
+            // Currently, Derby doesn't like Character objects in the PreparedStatement
+            // when using PreparedStatement#setObject(index, value, jdbcType) method
+            // (see issue DERBY-773)
+            // So we make a String object out of the Character object and use that instead
+            super.setObjectForStatement(ps, index, value.toString(), jdbcType);
+        }
+        else
+        {
+            super.setObjectForStatement(ps, index, value, jdbcType);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getLastInsertIdentityQuery(String tableName)
+    {
+        // matthias.roth@impart.ch
+        // the function is used by the org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl
+		// this call must be made before commit the insert command, so you
+        // must turn off autocommit by seting the useAutoCommit="2"
+        // or use useAutoCommit="1" or use a connection with autoCommit set false
+        // by default (e.g. in managed environments)
+        // transaction demarcation is mandatory
+        return "values IDENTITY_VAL_LOCAL()";
+    }
+}

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandling.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandling.java?rev=375061&r1=375060&r2=375061&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandling.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandling.java Sun Feb  5 09:48:02 2006
@@ -89,6 +89,13 @@
     public void addSchemaFile(Reader reader) throws IOException, DatabaseHandlingException;
 
     /**
+     * Specifies whether to use delimited identifiers when accessing the database.
+     *
+     * @param useDelimitedIdentifiers <code>true</code> if delimited identifiers shall be used
+     */
+    public void setUseDelimitedIdentifiers(boolean useDelimitedIdentifiers);
+
+    /**
      * Creates the database with all tables as defined in the schema(s).
      * If it already exists, then it will be cleared.
      * 

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandlingTask.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandlingTask.java?rev=375061&r1=375060&r2=375061&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandlingTask.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DatabaseHandlingTask.java Sun Feb  5 09:48:02 2006
@@ -453,6 +453,8 @@
     private ArrayList _actions = new ArrayList();
     /** Database properties */
     private ArrayList _dbProps = new ArrayList();
+    /** Whether to use delimited identifiers. */
+    private boolean _useDelimitedIdentifiers;
     /** The OJB instance */
     private OJB _ojb;
 
@@ -546,6 +548,26 @@
     }
 
     /**
+     * Determines whether to use delimited identifiers when accessing the database.
+     *
+     * @return <code>true</code> if delimited identifiers are used
+     */
+    public boolean getUseDelimitedIdentifiers()
+    {
+        return _useDelimitedIdentifiers;
+    }
+
+    /**
+     * Specifies whether to use delimited identifiers when accessing the database.
+     *
+     * @param useDelimitedIdentifiers <code>true</code> if delimited identifiers shall be used
+     */
+    public void setUseDelimitedIdentifiers(boolean useDelimitedIdentifiers)
+    {
+        _useDelimitedIdentifiers = useDelimitedIdentifiers;
+    }
+
+    /**
      * Creates a new database property object for Ant.
      * 
      * @return The property object
@@ -728,9 +750,6 @@
 
     /**
      * Initializes OJB for our purposes.
-     * 
-     * TODO: This is currently somewhat nasty but will become easier once the
-     *       new OJB configuration scheme is implemented
      */
     private void initOJB() throws BuildException
     {

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DdlUtilslDatabaseHandling.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DdlUtilslDatabaseHandling.java?rev=375061&r1=375060&r2=375061&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DdlUtilslDatabaseHandling.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/util/dbhandling/DdlUtilslDatabaseHandling.java Sun Feb  5 09:48:02 2006
@@ -52,6 +52,8 @@
     private JdbcConnectionDescriptor _jcd;
     /** The model */
     private DescriptorRepository _model;
+    /** Whether to use delimited identifiers. */
+    private boolean _useDelimitedIdentifiers;
     /** The datasource for DdlUtils */
     private BasicDataSource _dataSource;
     /** The platform */
@@ -288,6 +290,14 @@
     }
 
     /**
+     * {@inheritDoc}
+     */
+    public void setUseDelimitedIdentifiers(boolean useDelimitedIdentifiers)
+    {
+        
+    }
+
+    /**
      * Returns the platform instance.
      * 
      * @return The platform instance
@@ -307,6 +317,8 @@
                     }
                 }
                 _platform.setDataSource(getDataSource());
+                _platform.getPlatformInfo().setUseDelimitedIdentifiers(_useDelimitedIdentifiers);
+                _platform.getPlatformInfo().setCommentsSupported(false);
             }
             catch (Exception ex)
             {
@@ -338,7 +350,7 @@
     {
         try
         {
-            getPlatform().alterTables(_schema, true);
+            getPlatform().alterTables(_schema, true, true, true);
         }
         catch (Exception ex)
         {

Modified: db/ojb/trunk/src/schema/ojbtest-data-new.xml
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/schema/ojbtest-data-new.xml?rev=375061&r1=375060&r2=375061&view=diff
==============================================================================
--- db/ojb/trunk/src/schema/ojbtest-data-new.xml (original)
+++ db/ojb/trunk/src/schema/ojbtest-data-new.xml Sun Feb  5 09:48:02 2006
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database.dtd">
 <!--
-#/* Copyright 2002-2004 The Apache Software Foundation
+#/* Copyright 2002-2006 The Apache Software Foundation
 # *
 # * Licensed under the Apache License, Version 2.0 (the "License");
 # * you may not use this file except in compliance with the License.
@@ -147,10 +148,10 @@
     <Role member_id="7" project_id="5" roleName="founder"/>
     <Role member_id="7" project_id="6" roleName="tester"/>
 
-    <Task task_id="1" member_id="2" project_id="1" taskName="Initial Layout"/>
-    <Task task_id="2" member_id="2" project_id="1" taskName="Initial Spec"/>
-    <Task task_id="3" member_id="2" project_id="2" taskName="Project Cleanup"/>
-    <Task task_id="4" member_id="2" project_id="3" taskName="Testing Scripts"/>
+    <Task task_id="1" person_id="2" project_id="1" taskName="Initial Layout"/>
+    <Task task_id="2" person_id="2" project_id="1" taskName="Initial Spec"/>
+    <Task task_id="3" person_id="2" project_id="2" taskName="Project Cleanup"/>
+    <Task task_id="4" person_id="2" project_id="3" taskName="Testing Scripts"/>
 
     <FieldConversionTest_2_ConversionReferrer pk1="1" ref1="50" testId="10"/>
     <FieldConversionTest_2_ConversionReferrer pk1="2" ref1="51" testId="11"/>
@@ -174,14 +175,14 @@
     <News id="2" headline="Ferrai for sale (CARS - BUYERS)"/>
     <News id="3" headline="Brazil World Cup Champion ! (SPORTS)"/>
 
-    <Paper id="10" headline="NONE" issuedate="today" author="NONE"/>
-    <Paper id="11" headline="SALES" issuedate="yesterday" author="SALES MAN"/>
+    <Paper id="10" date="today" author="NONE"/>
+    <Paper id="11" date="yesterday" author="SALES MAN"/>
 
     <Topic id="10" name="Buyers" importance="important"/>
     <Topic id="11" name="Sellers" importance="unimportant"/>
 
-    <TopicExt id="30" name="Buyers_Ext" importance="important" Description="The buyer"/>
-    <TopicExt id="31" name="Sellers_Ext" importance="unimportant" Description="The seller"/>
+    <TopicExt id="30" name="Buyers_Ext" importance="important" description="The buyer"/>
+    <TopicExt id="31" name="Sellers_Ext" importance="unimportant" description="The seller"/>
 
     <Category id="1" name="Cars" description="The cars category"/>
     <Category id="2" name="Sports"/>
@@ -197,6 +198,6 @@
     <CONTENT_QUALIFIER CONTENT_ID="11" QUALIFIER_ID="11"/>
     <CONTENT_QUALIFIER CONTENT_ID="11" QUALIFIER_ID="31"/>
 
-   	<InitializableObject Id="1"/>
-	<InitializableObject Id="2"/>
+   	<InitializableObject id="1"/>
+    <InitializableObject id="2"/>
 </dataset>



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org