Search in sources :

Example 96 with ClassLoaderResolver

use of org.datanucleus.ClassLoaderResolver 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 97 with ClassLoaderResolver

use of org.datanucleus.ClassLoaderResolver 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 98 with ClassLoaderResolver

use of org.datanucleus.ClassLoaderResolver 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 99 with ClassLoaderResolver

use of org.datanucleus.ClassLoaderResolver in project tests by datanucleus.

the class BasicTest method testLoadingMetaDataForPackage.

/**
 * Tests the loading of XML metadata specified in package,jdo.
 */
public void testLoadingMetaDataForPackage() {
    MetaDataManager mmgr = new PersistenceNucleusContextImpl("JDO", null).getMetaDataManager();
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    // Validate metadata for DateWidget
    AbstractClassMetaData cmd = mmgr.getMetaDataForClass(DateWidget.class, clr);
    assertNotNull("ClassMetaData is null!", cmd);
    assertEquals("Class name", DateWidget.class.getName(), cmd.getFullClassName());
    assertEquals("Package name", "org.datanucleus.samples.widget", cmd.getPackageName());
    assertEquals("Superclass", Widget.class.getName(), cmd.getPersistableSuperclass());
    assertEquals("Identity type", IdentityType.DATASTORE, cmd.getIdentityType());
    assertNull("Identity class", cmd.getObjectidClass());
    assertNotNull("Inheritance", cmd.getInheritanceMetaData());
    assertEquals("Inheritance strategy", cmd.getInheritanceMetaData().getStrategy().toString(), "new-table");
    String[] sortedFieldNames = new String[] { "dateField", "dateJdbcTimestampField", "sqlDateField", "sqlTimestampField" };
    Assert.assertEquals("Field count", sortedFieldNames.length, cmd.getNoOfManagedMembers());
    for (int i = 0; i < sortedFieldNames.length; ++i) {
        AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtRelativePosition(i);
        String s = sortedFieldNames[i];
        assertEquals(s, fmd.getName());
        assertEquals(s + " persistence modifier", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
        assertEquals(s + " primary key", false, fmd.isPrimaryKey());
        assertEquals(s + " null value handling", NullValue.NONE, fmd.getNullValue());
        assertEquals(s + " default fetch group", true, fmd.isDefaultFetchGroup());
        assertNull(s + " collection metadata", fmd.getContainer());
        assertNull(s + " map metadata", fmd.getContainer());
    }
    // Validate metadata for FloatWidget
    cmd = mmgr.getMetaDataForClass(FloatWidget.class, clr);
    assertNotNull("Metadata", cmd);
    assertEquals("Class name", FloatWidget.class.getName(), cmd.getFullClassName());
    assertEquals("Package name", "org.datanucleus.samples.widget", cmd.getPackageName());
    assertEquals("Superclass", Widget.class.getName(), cmd.getPersistableSuperclass());
    assertEquals("Identity type", IdentityType.DATASTORE, cmd.getIdentityType());
    assertNull("Identity class", cmd.getObjectidClass());
    sortedFieldNames = new String[] { "doubleField", "doubleObjField", "floatField", "floatObjField" };
    NullValue[] nullValueHandlings = new NullValue[] { NullValue.EXCEPTION, NullValue.NONE, NullValue.EXCEPTION, NullValue.NONE };
    assertEquals("Field count", sortedFieldNames.length, cmd.getNoOfManagedMembers());
    for (int i = 0; i < sortedFieldNames.length; ++i) {
        AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtRelativePosition(i);
        String s = sortedFieldNames[i];
        Assert.assertEquals(s, fmd.getName());
        Assert.assertEquals(s + " persistence modifier", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
        Assert.assertEquals(s + " primary key", false, fmd.isPrimaryKey());
        Assert.assertEquals(s + " null value handling", nullValueHandlings[i], fmd.getNullValue());
        Assert.assertEquals(s + " default fetch group", true, fmd.isDefaultFetchGroup());
        Assert.assertNull(s + " collection metadata", fmd.getContainer());
        Assert.assertNull(s + " map metadata", fmd.getContainer());
    }
}
Also used : FloatWidget(org.datanucleus.samples.widget.FloatWidget) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) DateWidget(org.datanucleus.samples.widget.DateWidget) LevelAboveWidget(org.datanucleus.samples.widget.LevelAboveWidget) DateWidget(org.datanucleus.samples.widget.DateWidget) FloatWidget(org.datanucleus.samples.widget.FloatWidget) Widget(org.datanucleus.samples.widget.Widget) PackageClassWidget(org.datanucleus.samples.widget.PackageClassWidget) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) NullValue(org.datanucleus.metadata.NullValue) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Example 100 with ClassLoaderResolver

use of org.datanucleus.ClassLoaderResolver in project tests by datanucleus.

the class JDOQLEvaluatorTest method testFilterCollectionContains.

/**
 * Test of filter with collectionField.contains(element).
 */
public void testFilterCollectionContains() {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        // Create some instances to query over
        List<UserGroup> instances = new ArrayList<>();
        UserGroup grp1 = new UserGroup(101, "First Group");
        UserGroup grp2 = new UserGroup(102, "Second Group");
        UserGroup grp3 = new UserGroup(103, "Third Group");
        GroupMember mem1 = new GroupMember(201, "Donald Duck");
        GroupMember mem2 = new GroupMember(202, "Mickey Mouse");
        GroupMember mem3 = new GroupMember(203, "Minnie Mouse");
        grp1.getMembers().add(mem1);
        grp2.getMembers().add(mem1);
        grp2.getMembers().add(mem2);
        grp3.getMembers().add(mem2);
        grp3.getMembers().add(mem3);
        instances.add(grp1);
        instances.add(grp2);
        instances.add(grp3);
        // Compile the query
        JDOQuery q = (JDOQuery) pm.newQuery(UserGroup.class, "members.contains(el) && el.name == 'Minnie Mouse'");
        q.declareVariables(GroupMember.class.getName() + " el");
        Query query = q.getInternalQuery();
        ClassLoaderResolver clr = query.getExecutionContext().getClassLoaderResolver();
        JavaQueryCompiler compiler = new JDOQLCompiler(query.getExecutionContext().getNucleusContext(), clr, null, query.getCandidateClass(), null, query.getFilter(), query.getParsedImports(), query.getOrdering(), query.getResult(), query.getGrouping(), query.getHaving(), query.getExplicitParametersDeclaration(), query.getExplicitVariablesDeclaration(), null);
        QueryCompilation compilation = compiler.compile(new HashMap(), null);
        // Execute the query
        JavaQueryInMemoryEvaluator eval = new JDOQLInMemoryEvaluator(query, instances, compilation, null, clr);
        List results = (List) eval.execute(true, true, true, true, true);
        assertEquals("Number of result instances was wrong", 1, results.size());
        UserGroup grp = (UserGroup) results.get(0);
        assertEquals("Result instance has wrong name", "Third Group", grp.getName());
        tx.commit();
    } catch (Exception e) {
        LOG.info(">> Unexpected exception thrown during test", e);
        fail("Exception thrown during query execution " + e.getMessage());
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : JDOQLCompiler(org.datanucleus.query.compiler.JDOQLCompiler) GroupMember(org.jpox.samples.one_many.unidir_2.GroupMember) Query(org.datanucleus.store.query.Query) JDOQuery(org.datanucleus.api.jdo.JDOQuery) PersistenceManager(javax.jdo.PersistenceManager) HashMap(java.util.HashMap) JavaQueryInMemoryEvaluator(org.datanucleus.query.inmemory.JavaQueryInMemoryEvaluator) ArrayList(java.util.ArrayList) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) JDOQLInMemoryEvaluator(org.datanucleus.query.inmemory.JDOQLInMemoryEvaluator) JDOQuery(org.datanucleus.api.jdo.JDOQuery) UserGroup(org.jpox.samples.one_many.unidir_2.UserGroup) JavaQueryCompiler(org.datanucleus.query.compiler.JavaQueryCompiler) Transaction(javax.jdo.Transaction) ArrayList(java.util.ArrayList) List(java.util.List) QueryCompilation(org.datanucleus.query.compiler.QueryCompilation)

Aggregations

ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)242 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)94 MetaDataManager (org.datanucleus.metadata.MetaDataManager)72 NucleusContext (org.datanucleus.NucleusContext)68 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)65 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)65 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)56 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)56 ClassMetaData (org.datanucleus.metadata.ClassMetaData)54 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)51 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)44 NucleusException (org.datanucleus.exceptions.NucleusException)42 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)40 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)40 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)39 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)37 ArrayList (java.util.ArrayList)36 ExecutionContext (org.datanucleus.ExecutionContext)32 SelectStatement (org.datanucleus.store.rdbms.sql.SelectStatement)30 HashMap (java.util.HashMap)28