use of org.datanucleus.NucleusContext in project datanucleus-api-jdo by datanucleus.
the class MetaDataParserTest method testParseMetaDataURLnullhandler.
public void testParseMetaDataURLnullhandler() {
NucleusContext nucCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataParser parser = new MetaDataParser(new JDOMetaDataManager(nucCtx), nucCtx.getPluginManager(), true, true);
try {
parser.parseMetaDataURL(getClass().getResource("/org/datanucleus/api/jdo/metadata/xml/package2.jdo"), null);
fail("expected JPOXException");
} catch (NucleusException ex) {
// expected
}
}
use of org.datanucleus.NucleusContext in project datanucleus-api-jdo by datanucleus.
the class JDOMetaDataHandlerTest method testParseNamespace.
public void testParseNamespace() {
NucleusContext nucCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataParser parser = new MetaDataParser(new JDOMetaDataManager(nucCtx), nucCtx.getPluginManager(), true, true);
MetaData md = parser.parseMetaDataURL(getClass().getResource("/org/datanucleus/api/jdo/metadata/xml/package2.jdo"), "jdo");
assertNotNull(md);
}
use of org.datanucleus.NucleusContext in project datanucleus-api-jdo by datanucleus.
the class PersistenceFileMetaDataHandlerTest method testParseDefaultNamespace.
public void testParseDefaultNamespace() {
NucleusContext nucCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataParser parser = new MetaDataParser(new JDOMetaDataManager(nucCtx), nucCtx.getPluginManager(), true, true);
MetaData md = parser.parseMetaDataURL(getClass().getResource("/org/datanucleus/api/jdo/metadata/xml/persistence1.xml"), "persistence");
assertNotNull(md);
}
use of org.datanucleus.NucleusContext in project datanucleus-api-jdo by datanucleus.
the class JDOReplicationManager method replicate.
/**
* Method to perform the replication for all objects of the specified class names.
* @param classNames Classes to replicate
*/
public void replicate(String... classNames) {
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("012052", pmfSource, pmfTarget, StringUtils.objectArrayToString(classNames)));
}
// Check if classes are detachable
NucleusContext nucleusCtxSource = ((JDOPersistenceManagerFactory) pmfSource).getNucleusContext();
MetaDataManager mmgr = nucleusCtxSource.getMetaDataManager();
ClassLoaderResolver clr = nucleusCtxSource.getClassLoaderResolver(null);
for (int i = 0; i < classNames.length; i++) {
AbstractClassMetaData cmd = mmgr.getMetaDataForClass(classNames[i], clr);
if (!cmd.isDetachable()) {
throw new JDOUserException("Class " + classNames[i] + " is not detachable so cannot replicate");
}
}
Object[] detachedObjects = null;
// Detach from datastore 1
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("012053"));
}
PersistenceManager pm1 = pmfSource.getPersistenceManager();
Transaction tx1 = pm1.currentTransaction();
if (getBooleanProperty("datanucleus.replicateObjectGraph")) {
pm1.getFetchPlan().setGroup(javax.jdo.FetchPlan.ALL);
pm1.getFetchPlan().setMaxFetchDepth(-1);
}
try {
tx1.begin();
clr = ((JDOPersistenceManager) pm1).getExecutionContext().getClassLoaderResolver();
ArrayList objects = new ArrayList();
for (int i = 0; i < classNames.length; i++) {
Class cls = clr.classForName(classNames[i]);
AbstractClassMetaData cmd = mmgr.getMetaDataForClass(cls, clr);
if (!cmd.isEmbeddedOnly()) {
Extent ex = pm1.getExtent(cls);
Iterator iter = ex.iterator();
while (iter.hasNext()) {
objects.add(iter.next());
}
}
}
Collection detachedColl = pm1.detachCopyAll(objects);
detachedObjects = detachedColl.toArray();
tx1.commit();
} finally {
if (tx1.isActive()) {
tx1.rollback();
}
pm1.close();
}
replicateInTarget(detachedObjects);
}
use of org.datanucleus.NucleusContext in project datanucleus-api-jdo by datanucleus.
the class JDOReplicationManager method replicate.
/**
* Method to perform the replication for all objects of the specified types.
* @param types Classes to replicate
*/
public void replicate(Class... types) {
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("012052", pmfSource, pmfTarget, StringUtils.objectArrayToString(types)));
}
// Check if classes are detachable
NucleusContext nucleusCtxSource = ((JDOPersistenceManagerFactory) pmfSource).getNucleusContext();
MetaDataManager mmgr = nucleusCtxSource.getMetaDataManager();
ClassLoaderResolver clr = nucleusCtxSource.getClassLoaderResolver(null);
for (int i = 0; i < types.length; i++) {
AbstractClassMetaData cmd = mmgr.getMetaDataForClass(types[i], clr);
if (!cmd.isDetachable()) {
throw new JDOUserException("Class " + types[i] + " is not detachable so cannot replicate");
}
}
Object[] detachedObjects = null;
// Detach from datastore 1
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("012053"));
}
PersistenceManager pm1 = pmfSource.getPersistenceManager();
Transaction tx1 = pm1.currentTransaction();
if (getBooleanProperty("datanucleus.replicateObjectGraph")) {
pm1.getFetchPlan().setGroup(javax.jdo.FetchPlan.ALL);
pm1.getFetchPlan().setMaxFetchDepth(-1);
}
try {
tx1.begin();
ArrayList objects = new ArrayList();
for (int i = 0; i < types.length; i++) {
AbstractClassMetaData cmd = mmgr.getMetaDataForClass(types[i], clr);
if (!cmd.isEmbeddedOnly()) {
Extent ex = pm1.getExtent(types[i]);
Iterator iter = ex.iterator();
while (iter.hasNext()) {
objects.add(iter.next());
}
}
}
Collection detachedColl = pm1.detachCopyAll(objects);
detachedObjects = detachedColl.toArray();
tx1.commit();
} finally {
if (tx1.isActive()) {
tx1.rollback();
}
pm1.close();
}
replicateInTarget(detachedObjects);
}
Aggregations