db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker/sequence NativeIdentifierTest.java
Date Mon, 02 Aug 2004 19:12:05 GMT
brj         2004/08/02 12:12:05

  Modified:    src/test/org/apache/ojb/broker/sequence Tag: OJB_1_0_RELEASE
                        NativeIdentifierTest.java
  Log:
  added referential integrity
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.10.2.3  +80 -26    db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java
  
  Index: NativeIdentifierTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/NativeIdentifierTest.java,v
  retrieving revision 1.10.2.2
  retrieving revision 1.10.2.3
  diff -u -r1.10.2.2 -r1.10.2.3
  --- NativeIdentifierTest.java	29 Jul 2004 07:24:50 -0000	1.10.2.2
  +++ NativeIdentifierTest.java	2 Aug 2004 19:12:04 -0000	1.10.2.3
  @@ -2,8 +2,8 @@
   
   import java.io.Serializable;
   import java.sql.Connection;
  -import java.sql.Statement;
   import java.sql.SQLException;
  +import java.sql.Statement;
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Iterator;
  @@ -27,7 +27,6 @@
   import org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl;
   import org.apache.ojb.junit.PBTestCase;
   import org.apache.ojb.odmg.OJB;
  -import org.apache.ojb.odmg.TransactionExt;
   import org.odmg.Database;
   import org.odmg.Implementation;
   import org.odmg.Transaction;
  @@ -50,16 +49,30 @@
       private static final String CREATE_HSQL =
               "CREATE TABLE NATIVE_MAIN_OBJECT(NATIVE_ID IDENTITY NOT NULL PRIMARY KEY,"
+
               " REF_ID int(11),NAME VARCHAR(250))";
  +
       private static final String INSERT_DUMMY = "INSERT INTO NATIVE_MAIN_OBJECT (NAME) VALUES
('Dummy_1')";
   
  +    private static final String ADD_CONSTRAINT =
  +        "ALTER TABLE NATIVE_MAIN_OBJECT" +
  +        " ADD CONSTRAINT MAIN_REF_FK" +
  +        " FOREIGN KEY (REF_ID) REFERENCES NATIVE_REFERENCE_OBJECT (NATIVE_ID)";
  +    private static final String DROP_CONSTRAINT_HSQL =
  +        "ALTER TABLE NATIVE_MAIN_OBJECT" +
  +        " DROP CONSTRAINT MAIN_REF_FK";
  +    private static final String DROP_CONSTRAINT_MYSQL =
  +        "ALTER TABLE NATIVE_MAIN_OBJECT" +
  +        " DROP FOREIGN KEY";
  +
   
       // Statements for NATIVE_REF_TEST table
       private static final String CREATE_REF_MYSQL =
               "CREATE TABLE NATIVE_REFERENCE_OBJECT (NATIVE_ID int(11) NOT NULL PRIMARY KEY
auto_increment," +
  -            " NAME VARCHAR(250), FK_ID BIGINT, REF_ID int(11), SINGLE_REF_FK BIGINT)";
  +            " NAME VARCHAR(250), FK_ID BIGINT, REF_ID int(11), SINGLE_REF_FK BIGINT" +

  +    		" , FOREIGN KEY (FK_ID) REFERENCES NATIVE_MAIN_OBJECT (NATIVE_ID) )";
       private static final String CREATE_REF_HSQL =
               "CREATE TABLE NATIVE_REFERENCE_OBJECT (NATIVE_ID IDENTITY NOT NULL PRIMARY
KEY," +
  -            " NAME VARCHAR(250), FK_ID BIGINT, REF_ID int(11), SINGLE_REF_FK BIGINT)";
  +            " NAME VARCHAR(250), FK_ID int(11), REF_ID int(11), SINGLE_REF_FK BIGINT" +
  +            " , FOREIGN KEY (FK_ID) REFERENCES NATIVE_MAIN_OBJECT (NATIVE_ID) )";
       private static final String DROP_REF = "DROP TABLE NATIVE_REFERENCE_OBJECT";
       private static final String INSERT_DUMMY_REF = "INSERT INTO NATIVE_REFERENCE_OBJECT
(NAME) VALUES ('Dummy_2')";
   
  @@ -100,7 +113,14 @@
               stmt = con.createStatement();
               try
               {
  -                stmt.execute(DROP);
  +                if(platform instanceof PlatformMySQLImpl)
  +                {
  +                    stmt.execute(DROP_CONSTRAINT_MYSQL);
  +                }
  +                else if(platform instanceof PlatformHsqldbImpl)
  +                {
  +                    stmt.execute(DROP_CONSTRAINT_HSQL);
  +                }
               }
               catch (SQLException e)
               {
  @@ -116,6 +136,16 @@
               {
               }
               stmt.close();
  +
  +            stmt = con.createStatement();
  +            try
  +            {
  +                stmt.execute(DROP);
  +            }
  +            catch (SQLException e)
  +            {
  +            }
  +            stmt.close();
           }
           finally
           {
  @@ -126,30 +156,38 @@
           try
           {
               con = broker.serviceConnectionManager().getConnection();
  -            stmt = con.createStatement();
               if(platform instanceof PlatformMySQLImpl)
               {
  +                stmt = con.createStatement();
                   stmt.execute(CREATE_MYSQL);
  +                stmt.close();
               }
               if(platform instanceof PlatformHsqldbImpl)
               {
  +                stmt = con.createStatement();
                   stmt.execute(CREATE_HSQL);
  +                stmt.close();
               }
  -            stmt.close();
   
               stmt = con.createStatement();
               stmt.execute(INSERT_DUMMY);
               stmt.close();
   
  -            stmt = con.createStatement();
               if(platform instanceof PlatformMySQLImpl)
               {
  +                stmt = con.createStatement();
                   stmt.execute(CREATE_REF_MYSQL);
  +                stmt.close();
               }
               if(platform instanceof PlatformHsqldbImpl)
               {
  +                stmt = con.createStatement();
                   stmt.execute(CREATE_REF_HSQL);
  +                stmt.close();
               }
  +
  +            stmt = con.createStatement();
  +            stmt.execute(ADD_CONSTRAINT);
               stmt.close();
   
               stmt = con.createStatement();
  @@ -161,6 +199,10 @@
               oldSequenceManager = sd.getSequenceManagerClass();
               sd.setSequenceManagerClass(SequenceManagerNativeImpl.class);
           }
  +        catch (SQLException ex)
  +        {
  +            ex.printStackTrace();
  +        }
           finally
           {
               if (broker != null) broker.close();
  @@ -183,19 +225,35 @@
           PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
           try
           {
  -//            con = pb.serviceConnectionManager().getConnection();
  -//            stmt = con.createStatement();
  -//            stmt.execute(DROP);
  -//            stmt.close();
  -//
  -//            stmt = con.createStatement();
  -//            stmt.execute(DROP_REF);
  -//            stmt.close();
  +            con = pb.serviceConnectionManager().getConnection();
  +
  +            stmt = con.createStatement();
  +            if(platform instanceof PlatformMySQLImpl)
  +            {
  +                stmt.execute(DROP_CONSTRAINT_MYSQL);
  +            }
  +            else if(platform instanceof PlatformHsqldbImpl)
  +            {
  +                stmt.execute(DROP_CONSTRAINT_HSQL);
  +            }
  +            stmt.close();
  +
  +            stmt = con.createStatement();
  +            stmt.execute(DROP_REF);
  +            stmt.close();
  +
  +            stmt = con.createStatement();
  +            stmt.execute(DROP);
  +            stmt.close();
   
               SequenceDescriptor sd = MetadataManager.getInstance().connectionRepository().
                       getDescriptor(pb.getPBKey()).getSequenceDescriptor();
               sd.setSequenceManagerClass(oldSequenceManager);
           }
  +        catch (SQLException ex)
  +        {
  +            ex.printStackTrace();
  +        }
           finally
           {
               if (pb != null) pb.close();
  @@ -554,15 +612,11 @@
   
           Transaction tx = odmg.newTransaction();
           tx.begin();
  -//        // workaround
  -//        PersistenceBroker pb = ((TransactionExt) tx).getBroker();
  -//        if(!pb.isInTransaction())pb.beginTransaction();
  -//        pb.store(s_ref_1);
  -//        pb.store(s_ref_2);
  -//        pb.store(s_ref_3);
  -//        pb.store(s_ref_4);
  -//        // workaround end
  -        //db.makePersistent(ref_1);
  +        db.makePersistent(s_ref_1);
  +        db.makePersistent(s_ref_2);
  +        db.makePersistent(s_ref_3);
  +        db.makePersistent(s_ref_4);
  +
           db.makePersistent(obj_1);
           db.makePersistent(obj_2);
           tx.commit();
  
  
  

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