[prev in list] [next in list] [prev in thread] [next in thread]
List: ojb-dev
Subject: svn commit: r431738 - in
From: arminw () apache ! org
Date: 2006-08-15 23:40:42
Message-ID: 20060815234043.AE03D1A981A () eris ! apache ! org
[Download RAW message or body]
Author: arminw
Date: Tue Aug 15 16:40:42 2006
New Revision: 431738
URL: http://svn.apache.org/viewvc?rev=431738&view=rev
Log:
add test: persistence via stored procedures
Added:
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/StoredProcedureMaxDBTest.java
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/StoredProcedureTest.java
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java?rev=431738&r1=431737&r2=431738&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java \
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/AllTests.java Tue \
Aug 15 16:40:42 2006 @@ -126,6 +126,7 @@
suite.addTestSuite(UnwrapHelperTest.class);
suite.addTestSuite(LOBTest.class);
suite.addTestSuite(JdbcJavaObjectTest.class);
+ suite.addTestSuite(StoredProcedureMaxDBTest.class);
// BRJ: ensure shutdown of hsqldb
suite.addTestSuite(HsqldbShutdown.class);
Added: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/StoredProcedureMaxDBTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/StoredProcedureMaxDBTest.java?rev=431738&view=auto
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/StoredProcedureMaxDBTest.java \
(added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/StoredProcedureMaxDBTest.java \
Tue Aug 15 16:40:42 2006 @@ -0,0 +1,71 @@
+package org.apache.ojb.broker;
+
+/* 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.
+ * 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 org.apache.ojb.broker.platforms.PlatformMaxDBImpl;
+import org.apache.ojb.broker.platforms.PlatformSapdbImpl;
+
+/**
+ * This class
+ *
+ * @version $Id: $
+ */
+public class StoredProcedureMaxDBTest extends StoredProcedureTest
+{
+ public static void main(String[] args)
+ {
+ String[] arr = {StoredProcedureMaxDBTest.class.getName()};
+ junit.textui.TestRunner.main(arr);
+ }
+
+ public StoredProcedureMaxDBTest(String name)
+ {
+ super(name);
+ }
+
+ protected void initDBDependend() throws Exception
+ {
+ databaseName = "SapDB/MaxDB";
+ String schemaName = \
broker.serviceConnectionManager().getConnectionDescriptor().getUserName() + "."; +
+ createTable = "CREATE TABLE SP_CUSTOMER(ID_ SERIAL PRIMARY KEY, NAME \
VARCHAR(150))"; + deleteTable = "DROP TABLE SP_CUSTOMER CASCADE";
+
+ insertProcedure =
+ "CREATE DBPROC SP_CUSTOMER_INSERT (IN NAME VARCHAR(150), OUT \
CUSTOMER_ID FIXED(10)) " + + "AS SET CUSTOMER_ID = 0;" +
+ "INSERT INTO " + schemaName + "SP_CUSTOMER (NAME) VALUES \
(:NAME);" + + "BEGIN " +
+ "SET CUSTOMER_ID=SP_CUSTOMER.CURRVAL;" +
+ "END;";
+ updateProcedure = "CREATE DBPROC SP_CUSTOMER_UPDATE" +
+ " (IN ID_ FIXED(10), IN NAME VARCHAR(150)) AS " +
+ "UPDATE " + schemaName + "SP_CUSTOMER SET NAME=:NAME WHERE \
ID_=:ID_;"; + deleteProcedure = "CREATE DBPROC SP_CUSTOMER_DELETE" +
+ " (IN ID_ FIXED(10)) AS " +
+ "DELETE FROM " + schemaName + "SP_CUSTOMER WHERE ID_=:ID_;";
+
+ dropInsertProcedure = "DROP DBPROC SP_CUSTOMER_INSERT";
+ dropUpdateProcedure = "DROP DBPROC SP_CUSTOMER_UPDATE";
+ dropDeleteProcedure = "DROP DBPROC SP_CUSTOMER_DELETE";
+ }
+
+ protected boolean isSupportedDatabase()
+ {
+ return broker.serviceConnectionManager().getSupportedPlatform() instanceof \
PlatformSapdbImpl + || \
broker.serviceConnectionManager().getSupportedPlatform() instanceof \
PlatformMaxDBImpl; + }
+}
Added: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/StoredProcedureTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/StoredProcedureTest.java?rev=431738&view=auto
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/StoredProcedureTest.java \
(added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/StoredProcedureTest.java \
Tue Aug 15 16:40:42 2006 @@ -0,0 +1,280 @@
+package org.apache.ojb.broker;
+
+/* 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.
+ * 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.Connection;
+import java.sql.Statement;
+
+import org.apache.ojb.junit.PBTestCase;
+
+/**
+ * Abstract base class to test OJB insert, update, delete operations
+ * via stored procedures. Extend this class to implement database specific
+ * tests.
+ *
+ * @version $Id: $
+ */
+abstract public class StoredProcedureTest extends PBTestCase
+{
+ protected String databaseName;
+
+ protected String createTable;
+ protected String deleteTable;
+
+
+ protected String insertProcedure;
+ protected String updateProcedure;
+ protected String deleteProcedure;
+
+
+ protected String dropInsertProcedure;
+ protected String dropUpdateProcedure;
+ protected String dropDeleteProcedure;
+
+ public StoredProcedureTest(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ if(isSupportedDatabase())
+ {
+ initDBDependend();
+ try{executeStatement(dropInsertProcedure);}catch(Exception e){}
+ try{executeStatement(dropDeleteProcedure);}catch(Exception e){}
+ try{executeStatement(dropUpdateProcedure);}catch(Exception e){}
+ try{executeStatement(deleteTable);}catch(Exception e){}
+ executeStatement(createTable);
+ executeStatement(insertProcedure);
+ executeStatement(updateProcedure);
+ executeStatement(deleteProcedure);
+ }
+ }
+
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ /**
+ * Override this method to implement other databases.
+ * @throws Exception
+ */
+ abstract protected void initDBDependend() throws Exception;
+
+ /**
+ * Override this check for each database dependend implementation.
+ * @return Return <em>true</em> if the
+ */
+ abstract protected boolean isSupportedDatabase();
+
+ protected void executeStatement(String statement) throws Exception
+ {
+ try
+ {
+ broker.beginTransaction();
+ Connection con = broker.serviceConnectionManager().getConnection();
+ Statement stmt = con.createStatement();
+ stmt.execute(statement);
+ stmt.close();
+ broker.commitTransaction();
+ }
+ catch(Exception e)
+ {
+ if(broker != null) broker.abortTransaction();
+ throw e;
+ }
+ }
+
+ public void testInsert()
+ {
+ if(!isSupportedDatabase())
+ {
+ this.ojbSkipTestMessage("Skip " + databaseName + " specific test");
+ return;
+ }
+
+ Customer c1 = createCustomer();
+ c1.setName("testInsert_1");
+ Customer c2 = createCustomer();
+ c2.setName("testInsert_2");
+ broker.beginTransaction();
+ try
+ {
+ broker.store(c1);
+ broker.store(c2);
+ broker.commitTransaction();
+ }
+ catch(PersistenceBrokerException e)
+ {
+ if(broker != null) broker.abortTransaction();
+ throw e;
+ }
+ assertNotNull(c1.getId());
+ assertNotNull(c2.getId());
+// System.out.println("ID: " + c1.getId());
+// System.out.println("ID: " + c2.getId());
+ }
+
+ public void testUpdate()
+ {
+ if(!isSupportedDatabase())
+ {
+ this.ojbSkipTestMessage("Skip " + databaseName + " specific test");
+ return;
+ }
+
+ Customer c1 = createCustomer();
+ c1.setName("testUpdate_1");
+ Customer c2 = createCustomer();
+ c2.setName("testUpdate_2");
+ broker.beginTransaction();
+ try
+ {
+ broker.store(c1);
+ broker.store(c2);
+ broker.commitTransaction();
+ }
+ catch(PersistenceBrokerException e)
+ {
+ if(broker != null) broker.abortTransaction();
+ throw e;
+ }
+ assertNotNull(c1.getId());
+ assertNotNull(c2.getId());
+
+ c1.setName("update_1");
+ broker.beginTransaction();
+ try
+ {
+ broker.store(c1);
+ broker.store(c2);
+ broker.commitTransaction();
+ }
+ catch(PersistenceBrokerException e)
+ {
+ if(broker != null) broker.abortTransaction();
+ throw e;
+ }
+
+ broker.clearCache();
+
+ Identity oid_1 = broker.serviceIdentity().buildIdentity(Customer.class, \
c1.getId()); + Identity oid_2 = \
broker.serviceIdentity().buildIdentity(Customer.class, c2.getId()); +
+ Customer r1 = (Customer) broker.getObjectByIdentity(oid_1);
+ Customer r2 = (Customer) broker.getObjectByIdentity(oid_2);
+
+ assertNotNull(r1);
+ assertNotNull(r2);
+ assertEquals("update_1", r1.getName());
+ assertEquals("testUpdate_2", r2.getName());
+ }
+
+ public void testDelete()
+ {
+ if(!isSupportedDatabase())
+ {
+ this.ojbSkipTestMessage("Skip " + databaseName + " specific test");
+ return;
+ }
+
+ Customer c1 = createCustomer();
+ c1.setName("testDelete_1");
+ Customer c2 = createCustomer();
+ c2.setName("testDelete_2");
+ broker.beginTransaction();
+ try
+ {
+ broker.store(c1);
+ broker.store(c2);
+ broker.commitTransaction();
+ }
+ catch(PersistenceBrokerException e)
+ {
+ if(broker != null) broker.abortTransaction();
+ throw e;
+ }
+ assertNotNull(c1.getId());
+ assertNotNull(c2.getId());
+
+ broker.clearCache();
+
+ Identity oid_1 = broker.serviceIdentity().buildIdentity(Customer.class, \
c1.getId()); + Identity oid_2 = \
broker.serviceIdentity().buildIdentity(Customer.class, c2.getId()); +
+ Customer r1 = (Customer) broker.getObjectByIdentity(oid_1);
+ Customer r2 = (Customer) broker.getObjectByIdentity(oid_2);
+
+ assertNotNull(r1);
+ assertNotNull(r2);
+ assertEquals("testDelete_1", r1.getName());
+ assertEquals("testDelete_2", r2.getName());
+
+ broker.beginTransaction();
+ try
+ {
+ broker.delete(c1);
+ broker.delete(c2);
+ broker.commitTransaction();
+ }
+ catch(PersistenceBrokerException e)
+ {
+ if(broker != null) broker.abortTransaction();
+ throw e;
+ }
+
+ r1 = (Customer) broker.getObjectByIdentity(oid_1);
+ r2 = (Customer) broker.getObjectByIdentity(oid_2);
+
+ assertNull(r1);
+ assertNull(r2);
+ }
+
+ protected StoredProcedureTest.Customer createCustomer()
+ {
+ return new StoredProcedureTest.Customer();
+ }
+
+ public static class Customer
+ {
+ private Integer id;
+ private String name;
+
+ public Integer getId()
+ {
+ return id;
+ }
+
+ public void setId(Integer id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+ }
+}
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml?rev=431738&r1=431737&r2=431738&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml \
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/repository_junit.xml Tue \
Aug 15 16:40:42 2006 @@ -3261,4 +3261,38 @@
jdbc-type="JAVA_OBJECT"
/>
</class-descriptor>
+
+
+ <class-descriptor
+ class="org.apache.ojb.broker.StoredProcedureTest$Customer"
+ table="SP_CUSTOMER"
+ >
+ <field-descriptor
+ name="id"
+ column="ID_"
+ jdbc-type="INTEGER"
+ primarykey="true"
+ autoincrement="false"
+ />
+
+ <field-descriptor
+ name="name"
+ column="NAME"
+ jdbc-type="VARCHAR"
+ />
+
+ <insert-procedure name="SP_CUSTOMER_INSERT">
+ <runtime-argument field-ref="name"/>
+ <runtime-argument field-ref="id" return="true"/>
+ </insert-procedure>
+
+ <update-procedure name="SP_CUSTOMER_UPDATE">
+ <runtime-argument field-ref="id"/>
+ <runtime-argument field-ref="name"/>
+ </update-procedure>
+
+ <delete-procedure name="SP_CUSTOMER_DELETE">
+ <runtime-argument field-ref="id"/>
+ </delete-procedure>
+ </class-descriptor>
<!-- Mapping of classes used in junit tests and tutorials ends here -->
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic