Title: Re:metadata changes

Hi,
        i have written a test for my problem. im pasting it here. dont know what im doing wrong :( .. just look at suite() method . im using db2, i have to make id field autoincrement sometimes, so i change the metadata, its changed but not sql statement. is there any method to clear stmnt cache if there is one?

thanks,
Shibin

Application.java
-----------------------
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.ojb.broker.PBKey;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.PersistenceBrokerFactory;
import org.apache.ojb.broker.metadata.ClassDescriptor;
import org.apache.ojb.broker.metadata.DescriptorRepository;
import org.apache.ojb.broker.metadata.FieldDescriptor;
import org.apache.ojb.broker.metadata.MetadataManager;
import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;


class Model {
        private Integer id;
        private String str;
        /**
         * Returns the id.
         * @return Integer
         */
        public Integer getId() {
                return id;
        }

        /**
         * Returns the str.
         * @return String
         */
        public String getStr() {
                return str;
        }

        /**
         * Sets the id.
         * @param id The id to set
         */
        public void setId(Integer id) {
                this.id = id;
        }

        /**
         * Sets the str.
         * @param str The str to set
         */
        public void setStr(String str) {
                this.str = str;
        }

}

public class Application extends TestCase {
        private PersistenceBroker broker = null;
        private MetadataManager mm = null;
        private Model model = null;
       
        /**
         * Constructor for Application.
         */
        public Application() {
                super();
        }

        /**
         * Constructor for Application.
         * @param arg0
         */
        public Application(String arg0) {
                super(arg0);
        }

        public static Test suite() {
                TestSuite suite = new TestSuite();
                /*
                 * DOESNT WORK
                suite.addTest(new Application("testInsert")); //INSERT INTO DB2ADMIN.TEST (STR) VALUES ('quake')
                suite.addTest(new Application("testCustomizedInsert"));//INSERT INTO DB2ADMIN.TEST (STR) VALUES ('quake')

                 */
       
                //WORKS!!
                suite.addTest(new Application("testCustomizedInsert"));//INSERT INTO DB2ADMIN.TEST (ID,STR) VALUES ('56','quake')

                suite.addTest(new Application("testInsert"));//INSERT INTO DB2ADMIN.TEST (STR) VALUES ('quake')
               
                return suite;
        }
               
       
        public void setUp() {  
                mm = MetadataManager.getInstance();
                mm.setEnablePerThreadChanges(true);    
                model = new Model();
                model.setStr("quake");
        }
        public void getBroker() {
                PBKey pbKey = new PBKey("test");
                broker = PersistenceBrokerFactory.createPersistenceBroker(pbKey);
        }
        public void closeBroker() {
                broker.close();
        }
        public void log(String str) {
                System.out.println(str);
        }
        public void setupRepository () {
                mm = MetadataManager.getInstance();
                DescriptorRepository dr = mm.copyOfGlobalRepository();
                ClassDescriptor cd = dr.getDescriptorFor(Model.class);
                FieldDescriptor fd = cd.getFieldDescriptorByName("id");
                fd.setAutoIncrement(false);
                fd.setAccess("readwrite");
                dr.setClassDescriptor(cd);
                mm.setDescriptor(dr);
        }
        public void restoreRepository () {
                mm = MetadataManager.getInstance();
                DescriptorRepository dr = mm.copyOfGlobalRepository();
                ClassDescriptor cd = dr.getDescriptorFor(Model.class);
                FieldDescriptor fd = cd.getFieldDescriptorByName("id");
                fd.setAutoIncrement(true);
                fd.setAccess("readonly");
                dr.setClassDescriptor(cd);
                mm.setDescriptor(dr);
        }      

        public void testInsert() {
                getBroker();
                broker.store(model,ObjectModificationDefaultImpl.INSERT);
                closeBroker();
        }
        public void testCustomizedInsert() {
                model.setId(Integer.valueOf("56"));
                setupRepository();           
                getBroker();
                broker.store(model,ObjectModificationDefaultImpl.INSERT);
                closeBroker();
                restoreRepository();

        }
}

repository.xml
---------------------
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE descriptor-repository PUBLIC
       "-//Apache Software Foundation//DTD OJB Repository//EN"
       "repository.dtd">



<descriptor-repository version="1.0" isolation-level="read-uncommitted">
        <jdbc-connection-descriptor jcd-alias="test" default-connection="true" platform="Db2" jdbc-level="2.0" driver="com.p6spy.engine.spy.P6SpyDriver" protocol="jdbc" subprotocol="db2" dbalias="dog" username="db2admin" password="db2admin" eager-release="false" batch-mode="false" useAutoCommit="0" ignoreAutoCommitExceptions="false">

                <sequence-manager className="SequenceManagerDb2Impl"></sequence-manager>
        </jdbc-connection-descriptor>

        <class-descriptor class="Model" schema="DB2ADMIN" table="TEST">
                <field-descriptor id="0" name="id" column="ID" jdbc-type="INTEGER" primarykey="true" autoincrement="true" access="readonly" />

                <field-descriptor id="2" name="str" column="STR" jdbc-type="VARCHAR" />
        </class-descriptor>
</descriptor-repository>

table
-------
CREATE TABLE  TEST (
       ID                INTEGER NOT NULL GENERATED BY DEFAULT
                                AS IDENTITY(
                                        START WITH 1,
                                        INCREMENT BY 1,
                                        NO CACHE ),
       STR          VARCHAR(50) );
ALTER TABLE TEST
       ADD CONSTRAINT PK_TEST PRIMARY KEY (ID);

This e-mail and any files transmitted with it are for the sole use of the intended 
recipient(s) and may contain confidential and privileged information.
If you are not the intended recipient, please contact the sender by reply e-mail and 
destroy all copies of the original message. 
Any unauthorised review, use, disclosure, dissemination, forwarding, printing or 
copying of this email or any action taken in reliance on this e-mail is strictly 
prohibited and may be unlawful.

                Visit us at http://www.cognizant.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to