Search in sources :

Example 21 with MapMetaData

use of org.datanucleus.metadata.MapMetaData in project datanucleus-core by datanucleus.

the class DetachFieldManager method processMapContainer.

private Object processMapContainer(int fieldNumber, Object mapContainer, AbstractMemberMetaData mmd, ContainerHandler<Object, MapContainerAdapter<Object>> containerHandler) {
    Object detachedMapContainer;
    // TODO If cascadeDetach is false then don't do this
    MapContainerAdapter<Object> mapAdapter = containerHandler.getAdapter(mapContainer);
    if (copy) {
        detachedMapContainer = containerHandler.newContainer(mmd);
        MapMetaData mapMd = mmd.getMap();
        MapContainerAdapter copyAdapter = containerHandler.getAdapter(detachedMapContainer);
        for (Entry<Object, Object> entry : mapAdapter.entries()) {
            Object key = entry.getKey();
            if (mapMd.keyIsPersistent()) {
                key = processPersistableCopy(key);
            }
            Object value = entry.getValue();
            if (mapMd.valueIsPersistent()) {
                value = processPersistableCopy(value);
            }
            copyAdapter.put(key, value);
        }
        // Get the updated version of the container
        detachedMapContainer = copyAdapter.getContainer();
    } else {
        detachedMapContainer = mapContainer;
        MapMetaData mapMd = mmd.getMap();
        for (Entry<Object, Object> entry : mapAdapter.entries()) {
            Object key = entry.getKey();
            if (mapMd.keyIsPersistent()) {
                processPersistable(key);
            }
            Object value = entry.getValue();
            if (mapMd.valueIsPersistent()) {
                processPersistable(value);
            }
        }
    }
    return detachedMapContainer;
}
Also used : MapContainerAdapter(org.datanucleus.store.types.MapContainerAdapter) MapMetaData(org.datanucleus.metadata.MapMetaData)

Example 22 with MapMetaData

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

the class AnnotationTest method testOneToManyUniMapFK.

/**
 * Test of JPA 1-N unidir Map relation
 */
public void testOneToManyUniMapFK() {
    NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
    ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
    MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
    PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
    metaDataMgr.loadPersistenceUnit(pumd, null);
    // owner side
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("phoneNumbers");
    assertNotNull("Department.phoneNumbers is null!", fmd1);
    assertEquals("Department.phoneNumbers mapped-by is incorrect", fmd1.getMappedBy(), null);
    assertEquals("Department.phoneNumbers relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_MANY_UNI);
    assertEquals("Department.phoneNumbers jointable name is incorrect", fmd1.getTable(), null);
    MapMetaData mmd = fmd1.getMap();
    assertNotNull("Department.phoneNumbers has no Map metadata!", mmd);
    KeyMetaData keymd = fmd1.getKeyMetaData();
    assertNotNull("Department.phoneNumbers has no Key metadata!", keymd);
    assertEquals("Department.phoneNumbers has incorrect key mapped-by", keymd.getMappedBy(), "name");
}
Also used : JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) KeyMetaData(org.datanucleus.metadata.KeyMetaData) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) MapMetaData(org.datanucleus.metadata.MapMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) PersistenceUnitMetaData(org.datanucleus.metadata.PersistenceUnitMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Example 23 with MapMetaData

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

the class XMLTest method testOneToManyUniMapFK.

/**
 * Test of JPA 1-N unidir Map relation.
 */
public void testOneToManyUniMapFK() {
    NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
    ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
    MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
    PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
    metaDataMgr.loadPersistenceUnit(pumd, null);
    // owner side
    ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
    AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("phoneNumbers");
    assertNotNull("Department.phoneNumbers is null!", fmd1);
    assertEquals("Department.phoneNumbers mapped-by is incorrect", fmd1.getMappedBy(), null);
    assertEquals("Department.phoneNumbers relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_MANY_UNI);
    assertEquals("Department.phoneNumbers jointable name is incorrect", fmd1.getTable(), null);
    MapMetaData mmd = fmd1.getMap();
    assertNotNull("Department.phoneNumbers has no Map metadata!", mmd);
    KeyMetaData keymd = fmd1.getKeyMetaData();
    assertNotNull("Department.phoneNumbers has no Key metadata!", keymd);
    assertEquals("Department.phoneNumbers has incorrect key mapped-by", keymd.getMappedBy(), "name");
}
Also used : JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) KeyMetaData(org.datanucleus.metadata.KeyMetaData) NucleusContext(org.datanucleus.NucleusContext) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) JPAMetaDataManager(org.datanucleus.api.jpa.metadata.JPAMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) MapMetaData(org.datanucleus.metadata.MapMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) PersistenceUnitMetaData(org.datanucleus.metadata.PersistenceUnitMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData)

Aggregations

MapMetaData (org.datanucleus.metadata.MapMetaData)23 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)14 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)10 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)9 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)8 SQLTable (org.datanucleus.store.rdbms.sql.SQLTable)8 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)8 MapTable (org.datanucleus.store.rdbms.table.MapTable)8 NucleusException (org.datanucleus.exceptions.NucleusException)7 KeyMetaData (org.datanucleus.metadata.KeyMetaData)7 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)6 ClassMetaData (org.datanucleus.metadata.ClassMetaData)5 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)5 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)5 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)4 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)4 SelectStatement (org.datanucleus.store.rdbms.sql.SelectStatement)4 NucleusContext (org.datanucleus.NucleusContext)3 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)3 MetaDataManager (org.datanucleus.metadata.MetaDataManager)3