use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class XMLTest method testSequenceGenerator.
/**
* Test of JPA <sequence-generator>
*/
public void testSequenceGenerator() {
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);
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
PackageMetaData pmd = cmd1.getPackageMetaData();
assertEquals("Number of Sequences registered for Department class is wrong", pmd.getNoOfSequences(), 1);
SequenceMetaData seqmd = pmd.getSequences()[0];
assertEquals("SequenceGenerator has incorrect name", seqmd.getName(), "DepartmentGenerator");
assertEquals("SequenceGenerator has incorrect sequence name", seqmd.getDatastoreSequence(), "DEPT_SEQ");
assertEquals("SequenceGenerator has incorrect initial value", seqmd.getInitialValue(), 1);
assertEquals("SequenceGenerator has incorrect allocation size", seqmd.getAllocationSize(), 50);
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class JPANamingFactoryTest method testJoinTableName.
public void testJoinTableName() {
JPAEntityManagerFactory jpaEMF = (JPAEntityManagerFactory) emf;
NucleusContext nucCtx = jpaEMF.getNucleusContext();
ClassLoaderResolver clr = nucCtx.getClassLoaderResolver(null);
MetaDataManager mmgr = nucCtx.getMetaDataManager();
AbstractClassMetaData cmd1 = mmgr.getMetaDataForClass(UserGroup.class, clr);
NamingFactory factory = new JPANamingFactory(nucCtx);
factory.setNamingCase(NamingCase.LOWER_CASE);
factory.setMaximumLength(SchemaComponent.TABLE, 128);
String name = factory.getTableName(cmd1.getMetaDataForMember("members"));
assertEquals("Join table name is incorrect", "usergroup_groupmember", name);
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class IdentityUtilsTest method testGetValueForMemberInId.
public void testGetValueForMemberInId() throws Exception {
MetaDataManager mmgr = storeMgr.getNucleusContext().getMetaDataManager();
ClassLoaderResolver clr = storeMgr.getNucleusContext().getClassLoaderResolver(null);
// a). composed of two ints
{
org.jpox.samples.identity.application.ComposedIntIDBase.Key key = new org.jpox.samples.identity.application.ComposedIntIDBase.Key();
key.code = 123;
key.composed = 4567;
AbstractClassMetaData cmd = mmgr.getMetaDataForClass(ComposedIntIDBase.class, clr);
int[] pkNums = cmd.getPKMemberPositions();
// Check code
AbstractMemberMetaData pkMmd0 = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkNums[0]);
assertEquals("code", pkMmd0.getName());
Object pkVal0 = IdentityUtils.getValueForMemberInId(key, pkMmd0);
assertEquals(123, pkVal0);
// Check composed
AbstractMemberMetaData pkMmd1 = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkNums[1]);
assertEquals("composed", pkMmd1.getName());
Object pkVal1 = IdentityUtils.getValueForMemberInId(key, pkMmd1);
assertEquals(4567, pkVal1);
}
// b). composed of two Strings
{
org.jpox.samples.identity.application.ComposedStringIDBase.Key key = new org.jpox.samples.identity.application.ComposedStringIDBase.Key();
key.code = "123";
key.composed = "4567";
AbstractClassMetaData cmd = mmgr.getMetaDataForClass(ComposedStringIDBase.class, clr);
int[] pkNums = cmd.getPKMemberPositions();
// Check code
AbstractMemberMetaData pkMmd0 = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkNums[0]);
assertEquals("code", pkMmd0.getName());
Object pkVal0 = IdentityUtils.getValueForMemberInId(key, pkMmd0);
assertEquals("123", pkVal0);
// Check composed
AbstractMemberMetaData pkMmd1 = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkNums[1]);
assertEquals("composed", pkMmd1.getName());
Object pkVal1 = IdentityUtils.getValueForMemberInId(key, pkMmd1);
assertEquals("4567", pkVal1);
}
// b). composed of int+String+Double
{
org.jpox.samples.identity.application.ComposedMixedIDBase.Key key = new org.jpox.samples.identity.application.ComposedMixedIDBase.Key();
key.code = 123;
key.composed = "4567";
key.doubleObjField = 5.0;
AbstractClassMetaData cmd = mmgr.getMetaDataForClass(ComposedMixedIDBase.class, clr);
int[] pkNums = cmd.getPKMemberPositions();
// Check code
AbstractMemberMetaData pkMmd0 = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkNums[0]);
assertEquals("code", pkMmd0.getName());
Object pkVal0 = IdentityUtils.getValueForMemberInId(key, pkMmd0);
assertEquals(123, pkVal0);
// Check composed
AbstractMemberMetaData pkMmd1 = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkNums[1]);
assertEquals("composed", pkMmd1.getName());
Object pkVal1 = IdentityUtils.getValueForMemberInId(key, pkMmd1);
assertEquals("4567", pkVal1);
// Check composed
AbstractMemberMetaData pkMmd2 = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkNums[2]);
assertEquals("doubleObjField", pkMmd2.getName());
Object pkVal2 = IdentityUtils.getValueForMemberInId(key, pkMmd2);
assertEquals(5.0, pkVal2);
}
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class FetchPlanTest method testFetchPlan.
/**
* Test the use of the fetch plan.
*/
public void testFetchPlan() {
FetchPlan fp = getFetchPlan();
PersistenceNucleusContextImpl nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataManager metaMgr = new JDOMetaDataManager(nucleusCtx);
AbstractClassMetaData cmd = metaMgr.getMetaDataForClass(FP2Base.class, new ClassLoaderResolverImpl());
// --------------------------------------
// all fields in DFG
// --------------------------------------
FetchPlanForClass fpc = fp.getFetchPlanForClass(cmd);
int[] fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 11 fields in fetchplan", 11, fieldsInFP.length);
// check if fields are in the FP
BitSet fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// one FG + DFG
// --------------------------------------
fp.addGroup("groupA");
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 11 fields in fetchplan", 11, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// one FG
// --------------------------------------
fp.addGroup("groupA");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 3 fields in fetchplan", 3, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertFalse("piece4 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertFalse("piece7 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertFalse("piece8 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertFalse("piece9 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// two FG
// --------------------------------------
fp.addGroup("groupA");
fp.addGroup("groupC");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 6 fields in fetchplan", 6, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertFalse("piece4 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// three FG
// --------------------------------------
fp.addGroup("groupA");
fp.addGroup("groupB");
fp.addGroup("groupC");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 9 fields in fetchplan", 9, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// four FG
// --------------------------------------
fp.addGroup("groupA");
fp.addGroup("groupB");
fp.addGroup("groupC");
fp.addGroup("groupD");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 12 fields in fetchplan", 12, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertTrue("piece12 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// three FG
// --------------------------------------
fp.removeGroup("groupD");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 9 fields in fetchplan", 9, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// two FG
// --------------------------------------
fp.removeGroup("groupB");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 6 fields in fetchplan", 6, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertFalse("piece4 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// one FG
// --------------------------------------
fp.removeGroup("groupC");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 3 fields in fetchplan", 3, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertFalse("piece4 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertFalse("piece7 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertFalse("piece8 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertFalse("piece9 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// removed all groups, so use DFG = all fields in DFG
// --------------------------------------
fp.removeGroup("groupA");
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 1 fields in fetchplan", 1, fieldsInFP.length);
// check if fields are in the FP
fp.addGroup(FetchPlan.DEFAULT);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 11 fields in fetchplan", 11, fieldsInFP.length);
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// fetch group with nested fetch groups
// --------------------------------------
fp.addGroup("groupAll");
fp.removeGroup("groupA");
fp.removeGroup("groupB");
fp.removeGroup("groupC");
fp.removeGroup("groupD");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 12 fields in fetchplan", 12, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertTrue("piece12 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// test an intersection, first add all groups, and then remove all, except the one with fields in intersection
// --------------------------------------
fp.addGroup("groupA");
fp.addGroup("groupB");
fp.addGroup("groupC");
fp.addGroup("groupD");
fp.addGroup("groupAll");
fp.addGroup("groupIntersection");
fp.removeGroup("groupA");
fp.removeGroup("groupB");
fp.removeGroup("groupC");
fp.removeGroup("groupD");
fp.removeGroup("groupAll");
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 4 fields in fetchplan", 4, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertFalse("piece2 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertFalse("piece3 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertFalse("piece8 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertFalse("piece9 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
// --------------------------------------
// use FetchPlan.ALL
// --------------------------------------
fp.clearGroups();
fp.addGroup(FetchPlan.ALL);
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 13 fields in fetchplan", 13, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertTrue("piece2 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertTrue("piece3 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertTrue("piece4 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertTrue("piece5 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertTrue("piece6 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertTrue("piece7 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertTrue("piece8 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertTrue("piece9 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertTrue("piece10 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertTrue("piece11 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertTrue("piece12 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
assertTrue("piece14 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece14")));
// --------------------------------------
// use FetchPlan.NONE
// --------------------------------------
fp.clearGroups();
fp.addGroup(FetchPlan.NONE);
fp.removeGroup(FetchPlan.DEFAULT);
fpc = fp.getFetchPlanForClass(cmd);
fieldsInFP = fpc.getMemberNumbers();
assertEquals("should have 1 fields in fetchplan", 1, fieldsInFP.length);
// check if fields are in the FP
fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece1 should be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece1")));
assertFalse("piece2 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece2")));
assertFalse("piece3 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece3")));
assertFalse("piece4 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece4")));
assertFalse("piece5 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece5")));
assertFalse("piece6 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece6")));
assertFalse("piece7 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece7")));
assertFalse("piece8 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece8")));
assertFalse("piece9 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece9")));
assertFalse("piece10 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece10")));
assertFalse("piece11 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece11")));
assertFalse("piece12 should not be in the fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
}
use of org.datanucleus.metadata.MetaDataManager in project tests by datanucleus.
the class FetchPlanTest method testNestedFetchPlans.
/**
* Test of nested fetch plans
*/
public void testNestedFetchPlans() throws Exception {
FetchPlan fp = getFetchPlan();
PersistenceNucleusContextImpl nucleusCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataManager metaMgr = new JDOMetaDataManager(nucleusCtx);
AbstractClassMetaData cmd = metaMgr.getMetaDataForClass(FP2Base.class, new ClassLoaderResolverImpl());
fp.addGroup("defaultPlus12");
FetchPlanForClass fpc = fp.getFetchPlanForClass(cmd);
BitSet fieldsInFPBitSet = fpc.getMemberNumbersByBitSet();
assertTrue("piece12 should be in fetchplan", fieldsInFPBitSet.get(cmd.getAbsolutePositionOfMember("piece12")));
}
Aggregations