Search in sources :

Example 96 with ClassMetaData

use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.

the class AnnotationTest method testExtensions.

/**
 * Test for use of @Extension and @Extensions
 */
public void testExtensions() {
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Manager.class.getName(), clr);
    String prefix = cmd1.getFullClassName() + " : ";
    // Test class level @Extension
    Map<String, String> extmds1 = cmd1.getExtensions();
    assertNotNull(prefix + "extension info is null!", extmds1);
    assertTrue(prefix + "extension info has incorrect number of extensions", extmds1.size() == 1);
    assertTrue("extension not present", extmds1.containsKey("someExtensionProp"));
    assertEquals("extension value is incorrect", "My Value", extmds1.get("someExtensionProp"));
    // Test field level @Extensions
    AbstractMemberMetaData fmd = cmd1.getMetaDataForMember("departments");
    assertNotNull(prefix + "doesnt have required field", fmd);
    Map<String, String> extmds2 = fmd.getExtensions();
    assertNotNull(prefix + "extension info is null!", extmds2);
    assertEquals(prefix + "extension info has incorrect number of extensions", 2, extmds2.size());
    assertTrue("extension not present", extmds2.containsKey("prop1"));
    assertTrue("extension not present", extmds2.containsKey("prop2"));
    assertEquals("extension value is incorrect", "val1", extmds2.get("prop1"));
    assertEquals("extension value is incorrect", "val2", extmds2.get("prop2"));
}
Also used : AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 97 with ClassMetaData

use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.

the class AnnotationPlusXMLOverrideTest method testPersistent.

/**
 * Test enabling persistence on a field erroneously annotated as @NotPersistent.
 */
public void testPersistent() {
    // Person
    ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    String prefix = cmd.getFullClassName() + " : ";
    // "mood" - annotated "@NotPersistent", overidden in "package.jdo"
    AbstractMemberMetaData fmd = cmd.getMetaDataForMember("mood");
    assertNotNull(prefix + "doesnt have required field", fmd);
    assertEquals(prefix + "field should be persistent", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
}
Also used : AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 98 with ClassMetaData

use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.

the class AnnotationPlusXMLOverrideTest method testPersistenceCapable.

/* Quick fix tests (artificial) ----------------------------------------- */
/**
 * Test enabling forgotten @PersistenceCapable(detachable="true") annotation
 * parameter on a class in "package.jdo", and correcting the table-name set
 * in "package.jdo" in vendor specific "package.orm".
 * .
 */
public void testPersistenceCapable() {
    // Person
    ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    String prefix = cmd.getFullClassName() + " : ";
    assertEquals(prefix + "table is wrong", "T_Person", cmd.getTable());
    assertTrue(prefix + "detachable is wrong", cmd.isDetachable());
}
Also used : ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 99 with ClassMetaData

use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.

the class AnnotationPlusXMLOverrideTest method testColumn.

/**
 * Check explicit vendor specific column information in "package.orm",
 * overriding the standard settings in "package.jdo".
 */
public void testColumn() {
    // Person
    ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    String prefix = cmd.getFullClassName() + " : ";
    // "dateOfBirth" - JDBC type is TIMESTAMP in "package.jdo"
    AbstractMemberMetaData fmd = cmd.getMetaDataForMember("dateOfBirth");
    ColumnMetaData[] colmds = fmd.getColumnMetaData();
    assertEquals("column identifier incorrect", "DATE_OF_BIRTH", colmds[0].getName());
    assertEquals("column JDBC type incorrect", JdbcType.DATE, colmds[0].getJdbcType());
    // package.orm (additional)
    Map<String, String> extmds = fmd.getExtensions();
    assertNotNull(prefix + "extension info is null!", extmds);
    assertEquals(prefix + "incorrect number of extensions", 1, extmds.size());
    assertTrue("Extension not present", extmds.containsKey("insert-function"));
    assertEquals("Extension value is incorrect", "CURRENT_TIMESTAMP", extmds.get("insert-function"));
    // package.orm (overriding)
    // "emailAddress" - package.jdo VARCHAR(128), package.orm CHAR(100)
    fmd = cmd.getMetaDataForMember("emailAddress");
    colmds = fmd.getColumnMetaData();
    assertEquals(prefix + "column identifier incorrect", "EMAIL_ADDRESS", colmds[0].getName());
    assertEquals(prefix + "column length incorrect", new Integer(100), colmds[0].getLength());
    assertEquals(prefix + "column JDBC type incorrect", JdbcType.CHAR, colmds[0].getJdbcType());
}
Also used : ColumnMetaData(org.datanucleus.metadata.ColumnMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 100 with ClassMetaData

use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.

the class AnnotationPlusXMLOverrideTest method testQuery.

/**
 * A named query using annotation @Query would/should use 'language="JDOQL"',
 * so it's up to the JDO implementation to translate it to applicable SQL
 * - even if it's vendor specific.
 * <p/>
 * Test named query (language="SQL"): proprietary vendor SQL in "package.orm"
 * overriding ANSI-SQL in "package.jdo".
 */
public void testQuery() {
    // Person
    ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    String prefix = cmd.getFullClassName() + " : ";
    QueryMetaData[] qmds = cmd.getQueries();
    assertNotNull(prefix + "query info is incorrect", qmds);
    assertEquals(prefix + "query name incorrect", "NumberOfPeople", qmds[0].getName());
    assertEquals(prefix + "query language incorrect", "SQL", qmds[0].getLanguage());
    assertFalse(prefix + "query unmodifiable incorrect", qmds[0].isUnmodifiable());
    assertTrue(prefix + "query unique incorrect", qmds[0].isUnique());
    assertEquals(prefix + "query string incorrect", "SELECT COUNT(ALL) AS THESIZE FROM PERSON", qmds[0].getQuery());
}
Also used : QueryMetaData(org.datanucleus.metadata.QueryMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Aggregations

ClassMetaData (org.datanucleus.metadata.ClassMetaData)109 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)55 MetaDataManager (org.datanucleus.metadata.MetaDataManager)55 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)53 NucleusContext (org.datanucleus.NucleusContext)52 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)51 JPAMetaDataManager (org.datanucleus.api.jpa.metadata.JPAMetaDataManager)51 PersistenceUnitMetaData (org.datanucleus.metadata.PersistenceUnitMetaData)38 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)18 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)14 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)14 ElementMetaData (org.datanucleus.metadata.ElementMetaData)14 JoinMetaData (org.datanucleus.metadata.JoinMetaData)14 PackageMetaData (org.datanucleus.metadata.PackageMetaData)14 Label (org.datanucleus.enhancer.asm.Label)6 FileMetaData (org.datanucleus.metadata.FileMetaData)6 InterfaceMetaData (org.datanucleus.metadata.InterfaceMetaData)6 PropertyMetaData (org.datanucleus.metadata.PropertyMetaData)6 KeyMetaData (org.datanucleus.metadata.KeyMetaData)5 MapMetaData (org.datanucleus.metadata.MapMetaData)5