db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r463778 - in /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sequence: SeqManMultiHsqlTest.java SeqManMultiTest.java
Date Fri, 13 Oct 2006 19:06:01 GMT
Author: arminw
Date: Fri Oct 13 12:06:01 2006
New Revision: 463778

URL: http://svn.apache.org/viewvc?view=rev&rev=463778
Log:
initial check in

Added:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sequence/SeqManMultiHsqlTest.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sequence/SeqManMultiTest.java

Added: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sequence/SeqManMultiHsqlTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sequence/SeqManMultiHsqlTest.java?view=auto&rev=463778
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sequence/SeqManMultiHsqlTest.java
(added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sequence/SeqManMultiHsqlTest.java
Fri Oct 13 12:06:01 2006
@@ -0,0 +1,42 @@
+package org.apache.ojb.broker.sequence;
+
+/* 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.PlatformHsqldbImpl;
+
+/**
+ * Tests the per field sequence manager declaration of HSQL.
+ *
+ * @version $Id: $
+ */
+public class SeqManMultiHsqlTest extends SeqManMultiTest
+{
+    protected Class getSupportedDatabase()
+    {
+        return PlatformHsqldbImpl.class;
+    }
+
+    protected String getTableCreate() throws Exception
+    {
+        return "CREATE TABLE SEQ_MULTI (IDENTITY_ IDENTITY NOT NULL PRIMARY KEY, HILO_ int,"
+
+            " MEMORY_ int, SEQHILO_ int, NEXTVAL_ int, VERSION_ int)";
+    }
+
+    protected String getTableDrop() throws Exception
+    {
+        return "DROP TABLE SEQ_MULTI";
+    }
+}

Added: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sequence/SeqManMultiTest.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sequence/SeqManMultiTest.java?view=auto&rev=463778
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sequence/SeqManMultiTest.java
(added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/sequence/SeqManMultiTest.java
Fri Oct 13 12:06:01 2006
@@ -0,0 +1,390 @@
+package org.apache.ojb.broker.sequence;
+
+/* 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.commons.lang.builder.ToStringBuilder;
+import org.apache.ojb.broker.metadata.MetadataManager;
+import org.apache.ojb.broker.metadata.ClassDescriptor;
+import org.apache.ojb.broker.metadata.FieldDescriptor;
+import org.apache.ojb.broker.metadata.SequenceDescriptor;
+import org.apache.ojb.broker.platforms.Platform;
+import org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl;
+import org.apache.ojb.broker.util.sequence.SequenceManagerInMemoryImpl;
+import org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl;
+import org.apache.ojb.broker.util.sequence.SequenceManagerSeqHiLoImpl;
+import org.apache.ojb.broker.util.sequence.SequenceManagerIdentityImpl;
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.PersistenceBrokerException;
+import org.apache.ojb.broker.PersistenceBrokerFactory;
+import org.apache.ojb.junit.PBTestCase;
+
+/**
+ * Tests the per field sequence manager declaration.
+ *
+ * @version $Id: $
+ */
+abstract public class SeqManMultiTest extends PBTestCase
+{
+    public static void main(String[] args)
+    {
+        String[] arr = {SeqManMultiTest.class.getName()};
+        junit.textui.TestRunner.main(arr);
+    }
+
+    /**
+     * Override this method to implement other databases.
+     * @throws Exception
+     */
+    abstract protected String getTableCreate() throws Exception;
+
+    /**
+     * Override this method to implement other databases.
+     * @throws Exception
+     */
+    abstract protected String getTableDrop() throws Exception;
+
+    /**
+     * Return the name of current database.
+     */
+    abstract protected Class getSupportedDatabase();
+
+    protected Platform platform;
+    String createTable;
+    String dropTable;
+    boolean oldPerField;
+
+    public void setUp() throws Exception
+    {
+        super.setUp();
+
+        MetadataManager mm = MetadataManager.getInstance();
+        SequenceDescriptor sd = mm.connectionRepository().getDescriptor(broker.getPBKey()).getSequenceDescriptor();
+        oldPerField = sd.isPerFieldSequences();
+        sd.setPerFieldSequences(true);
+        broker.close();
+
+        // check usage of correct SequenceManager implementation
+        PersistenceBrokerFactory.releaseAllInstances();
+        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
+
+        sd = mm.connectionRepository().getDescriptor(broker.getPBKey()).getSequenceDescriptor();
+        assertTrue(sd.isPerFieldSequences());
+
+        platform = broker.serviceConnectionManager().getSupportedPlatform();
+        if(platform.getClass().isAssignableFrom(getSupportedDatabase()))
+        {
+            try{executeStatement(getTableDrop());}catch(Exception e){}
+            executeStatement(getTableCreate());
+        }
+        ClassDescriptor cld = null;
+        try
+        {
+            cld = broker.getClassDescriptor(SeqObjectRuntime.class);
+        }
+        catch(PersistenceBrokerException e)
+        {
+        }
+        if(cld == null)
+        {
+            initMetadata();
+        }
+    }
+
+    public void tearDown() throws Exception
+    {
+        broker.getDescriptorRepository().remove(SeqObjectRuntime.class);
+
+        MetadataManager mm = MetadataManager.getInstance();
+        SequenceDescriptor sd = mm.connectionRepository().getDescriptor(broker.getPBKey()).getSequenceDescriptor();
+        sd.setPerFieldSequences(oldPerField);
+        broker.close();
+
+        PersistenceBrokerFactory.releaseAllInstances();
+        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
+
+        super.tearDown();
+    }
+
+    protected void initMetadata()
+    {
+        ClassDescriptor cld = new ClassDescriptor(broker.getDescriptorRepository());
+        cld.setTableName("SEQ_MULTI");
+        cld.setClassOfObject(SeqObjectRuntime.class);
+
+        FieldDescriptor fld_0 = new FieldDescriptor(cld, 0);
+        fld_0.setColumnName("IDENTITY_");
+        fld_0.setPersistentField(SeqObjectRuntime.class, "identity");
+        fld_0.setPrimaryKey(true);
+        fld_0.setAutoIncrement(true);
+        fld_0.setAccess("readonly");
+        fld_0.setSequenceDescriptor(new SequenceDescriptor(SequenceManagerIdentityImpl.class));
+
+        FieldDescriptor fld_1 = new FieldDescriptor(cld, 1);
+        fld_1.setColumnName("HILO_");
+        fld_1.setPersistentField(SeqObjectRuntime.class, "hilo");
+        fld_1.setPrimaryKey(true);
+        fld_1.setAutoIncrement(true);
+        fld_1.setSequenceDescriptor(new SequenceDescriptor(SequenceManagerHighLowImpl.class));
+
+        FieldDescriptor fld_2 = new FieldDescriptor(cld, 2);
+        fld_2.setColumnName("MEMORY_");
+        fld_2.setPersistentField(SeqObjectRuntime.class, "memory");
+        fld_2.setPrimaryKey(true);
+        fld_2.setAutoIncrement(true);
+        fld_2.setSequenceDescriptor(new SequenceDescriptor(SequenceManagerInMemoryImpl.class));
+
+        FieldDescriptor fld_3 = new FieldDescriptor(cld, 3);
+        fld_3.setColumnName("NEXTVAL_");
+        fld_3.setPersistentField(SeqObjectRuntime.class, "nextval");
+        fld_3.setPrimaryKey(true);
+        fld_3.setAutoIncrement(true);
+        fld_3.setSequenceDescriptor(new SequenceDescriptor(SequenceManagerNextValImpl.class));
+
+        FieldDescriptor fld_4 = new FieldDescriptor(cld, 4);
+        fld_4.setColumnName("SEQHILO_");
+        fld_4.setPersistentField(SeqObjectRuntime.class, "seqhilo");
+        fld_4.setPrimaryKey(true);
+        fld_4.setAutoIncrement(true);
+        fld_4.setSequenceDescriptor(new SequenceDescriptor(SequenceManagerSeqHiLoImpl.class));
+
+        FieldDescriptor fld_5 = new FieldDescriptor(cld, 5);
+        fld_5.setColumnName("VERSION_");
+        fld_5.setPersistentField(SeqObjectRuntime.class, "version");
+        fld_5.setPrimaryKey(false);
+        fld_5.setLocking(true);
+
+        cld.addFieldDescriptor(fld_0);
+        cld.addFieldDescriptor(fld_1);
+        cld.addFieldDescriptor(fld_2);
+        cld.addFieldDescriptor(fld_3);
+        cld.addFieldDescriptor(fld_4);
+        cld.addFieldDescriptor(fld_5);
+
+        broker.getDescriptorRepository().put(SeqObjectRuntime.class, cld);
+    }
+
+    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(!platform.getClass().isAssignableFrom(getSupportedDatabase()))
+        {
+            this.ojbSkipTestMessage("Skip " + getSupportedDatabase() + " specific test");
+            return;
+        }
+
+        SeqObjectRuntime so_1 = new SeqObjectRuntime();
+        SeqObjectRuntime so_2 = new SeqObjectRuntime();
+        broker.beginTransaction();
+        broker.store(so_1);
+        broker.store(so_2);
+        broker.commitTransaction();
+
+//        System.out.println("so1: " + so_1);
+//        System.out.println("so2: " + so_2);
+        Identity oid_1 = broker.serviceIdentity().buildIdentity(so_1);
+        Identity oid_2 = broker.serviceIdentity().buildIdentity(so_2);
+        broker.clearCache();
+
+        SeqObjectRuntime result = (SeqObjectRuntime) broker.getObjectByIdentity(oid_1);
+        assertNotNull(result);
+        assertNotNull(result.getHilo());
+        assertNotNull(result.getMemory());
+        assertNotNull(result.getIdentity());
+        assertNotNull(result.getNextval());
+        assertNotNull(result.getSeqhilo());
+        assertNotNull(result.getVersion());
+
+        result = (SeqObjectRuntime) broker.getObjectByIdentity(oid_2);
+        assertNotNull(result);
+        assertNotNull(result.getHilo());
+        assertNotNull(result.getMemory());
+        assertNotNull(result.getIdentity());
+        assertNotNull(result.getNextval());
+        assertNotNull(result.getSeqhilo());
+        assertNotNull(result.getVersion());
+
+        broker.beginTransaction();
+        broker.store(so_1);
+        broker.store(so_2);
+        broker.commitTransaction();
+
+        broker.beginTransaction();
+        broker.delete(so_1);
+        broker.delete(so_2);
+        broker.commitTransaction();
+        result = (SeqObjectRuntime) broker.getObjectByIdentity(oid_1);
+        assertNull(result);
+        result = (SeqObjectRuntime) broker.getObjectByIdentity(oid_2);
+        assertNull(result);
+    }
+
+    public void testInsert_2()
+    {
+        if(!platform.getClass().isAssignableFrom(getSupportedDatabase()))
+        {
+            this.ojbSkipTestMessage("Skip " + getSupportedDatabase() + " specific test");
+            return;
+        }
+
+        SeqObject so_1 = new SeqObject();
+        SeqObject so_2 = new SeqObject();
+        broker.beginTransaction();
+        broker.store(so_1);
+        broker.store(so_2);
+        broker.commitTransaction();
+
+//        System.out.println("so1: " + so_1);
+//        System.out.println("so2: " + so_2);
+        Identity oid_1 = broker.serviceIdentity().buildIdentity(so_1);
+        Identity oid_2 = broker.serviceIdentity().buildIdentity(so_2);
+        broker.clearCache();
+
+        SeqObject result = (SeqObject) broker.getObjectByIdentity(oid_1);
+        assertNotNull(result);
+        assertNotNull(result.getHilo());
+        assertNotNull(result.getMemory());
+        assertNotNull(result.getIdentity());
+        assertNotNull(result.getNextval());
+        assertNotNull(result.getSeqhilo());
+        assertNotNull(result.getVersion());
+
+        result = (SeqObject) broker.getObjectByIdentity(oid_2);
+        assertNotNull(result);
+        assertNotNull(result.getHilo());
+        assertNotNull(result.getMemory());
+        assertNotNull(result.getIdentity());
+        assertNotNull(result.getNextval());
+        assertNotNull(result.getSeqhilo());
+        assertNotNull(result.getVersion());
+
+        broker.beginTransaction();
+        broker.store(so_1);
+        broker.store(so_2);
+        broker.commitTransaction();
+
+        broker.beginTransaction();
+        broker.delete(so_1);
+        broker.delete(so_2);
+        broker.commitTransaction();
+        result = (SeqObject) broker.getObjectByIdentity(oid_1);
+        assertNull(result);
+        result = (SeqObject) broker.getObjectByIdentity(oid_2);
+        assertNull(result);
+    }
+
+    public static class SeqObject extends SeqObjectRuntime
+    {
+    }
+
+    public static class SeqObjectRuntime
+    {
+        private Integer identity;
+        private Integer hilo;
+        private Integer memory;
+        private Integer seqhilo;
+        private Integer nextval;
+        private Integer version;
+
+        public SeqObjectRuntime()
+        {
+        }
+
+        public Integer getHilo()
+        {
+            return hilo;
+        }
+
+        public void setHilo(Integer hilo)
+        {
+            this.hilo = hilo;
+        }
+
+        public Integer getMemory()
+        {
+            return memory;
+        }
+
+        public void setMemory(Integer memory)
+        {
+            this.memory = memory;
+        }
+
+        public Integer getIdentity()
+        {
+            return identity;
+        }
+
+        public void setIdentity(Integer identity)
+        {
+            this.identity = identity;
+        }
+
+        public Integer getNextval()
+        {
+            return nextval;
+        }
+
+        public void setNextval(Integer nextval)
+        {
+            this.nextval = nextval;
+        }
+
+        public Integer getSeqhilo()
+        {
+            return seqhilo;
+        }
+
+        public void setSeqhilo(Integer seqhilo)
+        {
+            this.seqhilo = seqhilo;
+        }
+
+        public Integer getVersion()
+        {
+            return version;
+        }
+
+        public void setVersion(Integer version)
+        {
+            this.version = version;
+        }
+
+        public String toString()
+        {
+            return ToStringBuilder.reflectionToString(this);
+        }
+    }
+}



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


Mime
View raw message