Search in sources :

Example 11 with JDOPersistenceManagerFactory

use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.

the class CacheTest method testRelationshipCachingWhenNontransactional.

public void testRelationshipCachingWhenNontransactional() throws Exception {
    try {
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        // Create sample data
        Object acctId = null;
        try {
            tx.begin();
            LoginAccount acct = new LoginAccount("Barney", "Rubble", "brubble", "bambam");
            pm.makePersistent(acct);
            acctId = JDOHelper.getObjectId(acct);
            tx.commit();
        } catch (Exception e) {
            LOG.error(e);
            fail("Exception thrown while creating 1-1 unidirectional relationship data : " + e.getMessage());
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
        // Make sure the object isn't in the cache following persistence
        pmf.getDataStoreCache().evictAll();
        pmf.getDataStoreCache().pinAll(true, LoginAccount.class);
        pmf.getDataStoreCache().pinAll(true, Login.class);
        // Retrieve the record and check the data
        pm = pmf.getPersistenceManager();
        try {
            LOG.info(">> CacheTest fetching LoginAccount(1)");
            LoginAccount acct = (LoginAccount) pm.getObjectById(acctId);
            assertTrue("LoginAccount \"firstName\" is incorrect", acct.getFirstName().equals("Barney"));
            assertTrue("LoginAccount \"lastName\" is incorrect", acct.getLastName().equals("Rubble"));
            LOG.info(">> CacheTest fetching Login(1)");
            // Access the login field to make sure it is read. Should get L2 cached now
            Login login = acct.getLogin();
            assertEquals("Login \"login\" is incorrect", login.getUserName(), "brubble");
            assertEquals("Login \"password\" is incorrect", login.getPassword(), "bambam");
        } catch (Exception e) {
            LOG.error(e);
            fail("Exception thrown while interrogating 1-1 unidirectional relationship data : " + e.getMessage());
        } finally {
            pm.close();
        }
        // login account is in the cache now after the last getObjectById
        LOG.info(">> CacheTest fetching LoginAccount(non-tx)");
        CachedPC cpc = ((JDOPersistenceManagerFactory) pmf).getNucleusContext().getLevel2Cache().get(acctId);
        assertTrue("LoginAccount is not cached", cpc != null);
        assertTrue("LoginAccount \"login\" is not cached", cpc.getFieldValue(2) != null);
        // Retrieve the record and check the data
        pm = pmf.getPersistenceManager();
        try {
            LoginAccount acct = (LoginAccount) pm.getObjectById(acctId);
            String[] loadedFields = NucleusJDOHelper.getLoadedFields(acct, pm);
            LOG.info(">> loadedFields=" + StringUtils.objectArrayToString(loadedFields));
            LOG.info(">> Accessing field login");
            Login login = acct.getLogin();
            LOG.info(">> login=" + login);
        } finally {
            pm.close();
        }
    } finally {
        clean(LoginAccount.class);
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) LoginAccount(org.jpox.samples.one_one.unidir.LoginAccount) CachedPC(org.datanucleus.cache.CachedPC) Login(org.jpox.samples.one_one.unidir.Login) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException)

Example 12 with JDOPersistenceManagerFactory

use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.

the class DN2NamingFactoryTest method testVersionColumnName.

public void testVersionColumnName() {
    JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
    NucleusContext nucCtx = jdoPMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(Trade1.class, clr);
    DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
    factory.setMaximumLength(SchemaComponent.COLUMN, 128);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    assertEquals("Column name for version is incorrect", "version", factory.getColumnName(cmd1, ColumnType.VERSION_COLUMN));
}
Also used : DN2NamingFactory(org.datanucleus.store.schema.naming.DN2NamingFactory) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) MetaDataManager(org.datanucleus.metadata.MetaDataManager) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Example 13 with JDOPersistenceManagerFactory

use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.

the class DN2NamingFactoryTest method testEmbeddedPCColumnNames.

public void testEmbeddedPCColumnNames() {
    JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
    NucleusContext nucCtx = jdoPMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
    factory.setMaximumLength(SchemaComponent.COLUMN, 128);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    AbstractClassMetaData compCmd = mmgr.getMetaDataForClass(Computer.class, clr);
    AbstractMemberMetaData graphicsMmd = compCmd.getMetaDataForMember("graphicsCard");
    AbstractClassMetaData cardCmd = mmgr.getMetaDataForClass(ComputerCard.class, clr);
    AbstractMemberMetaData makerMmd = cardCmd.getMetaDataForMember("makerName");
    List<AbstractMemberMetaData> colMmds = new ArrayList<AbstractMemberMetaData>();
    colMmds.add(graphicsMmd);
    colMmds.add(makerMmd);
    String colName = factory.getColumnName(colMmds, 0);
    // Comes from EmbeddedMetaData override
    assertEquals("graphics_maker", colName);
}
Also used : DN2NamingFactory(org.datanucleus.store.schema.naming.DN2NamingFactory) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) ArrayList(java.util.ArrayList) MetaDataManager(org.datanucleus.metadata.MetaDataManager) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Example 14 with JDOPersistenceManagerFactory

use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.

the class DN2NamingFactoryTest method testTableName.

public void testTableName() {
    JDOPersistenceManagerFactory jdoPMF = (JDOPersistenceManagerFactory) pmf;
    NucleusContext nucCtx = jdoPMF.getNucleusContext();
    ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
    MetaDataManager mmgr = nucCtx.getMetaDataManager();
    AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(BooleanArray.class, clr);
    DN2NamingFactory factory = new DN2NamingFactory(nucCtx);
    factory.setMaximumLength(SchemaComponent.TABLE, 128);
    factory.setNamingCase(NamingCase.LOWER_CASE);
    assertEquals("Table name is incorrect", "booleanarray", factory.getTableName(cmd1));
    factory.setNamingCase(NamingCase.LOWER_CASE_QUOTED);
    assertEquals("Table name is incorrect", "\"booleanarray\"", factory.getTableName(cmd1));
    factory.setNamingCase(NamingCase.UPPER_CASE);
    assertEquals("Table name is incorrect", "BOOLEANARRAY", factory.getTableName(cmd1));
    factory.setNamingCase(NamingCase.UPPER_CASE_QUOTED);
    assertEquals("Table name is incorrect", "\"BOOLEANARRAY\"", factory.getTableName(cmd1));
}
Also used : DN2NamingFactory(org.datanucleus.store.schema.naming.DN2NamingFactory) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) MetaDataManager(org.datanucleus.metadata.MetaDataManager) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Example 15 with JDOPersistenceManagerFactory

use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tests by datanucleus.

the class PgGeometrySpatialHelperTest method setUp.

protected void setUp() throws Exception {
    helper = new SpatialHelper((JDOPersistenceManagerFactory) pmf);
    super.setUp();
}
Also used : SpatialHelper(org.datanucleus.store.types.geospatial.jdo.SpatialHelper) JDOPersistenceManagerFactory(org.datanucleus.api.jdo.JDOPersistenceManagerFactory)

Aggregations

JDOPersistenceManagerFactory (org.datanucleus.api.jdo.JDOPersistenceManagerFactory)39 PersistenceManager (javax.jdo.PersistenceManager)15 PersistenceManagerFactory (javax.jdo.PersistenceManagerFactory)14 Transaction (javax.jdo.Transaction)14 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)14 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)12 NucleusContext (org.datanucleus.NucleusContext)9 Query (javax.jdo.Query)8 MetaDataManager (org.datanucleus.metadata.MetaDataManager)7 DN2NamingFactory (org.datanucleus.store.schema.naming.DN2NamingFactory)7 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)6 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 JDOException (javax.jdo.JDOException)4 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)4 IOException (java.io.IOException)3 Field (java.lang.reflect.Field)3 ArrayList (java.util.ArrayList)3