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;
}
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");
}
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");
}
Aggregations