use of org.apache.cayenne.access.DataDomain in project cayenne by apache.
the class OsgiDataDomainProvider method get.
@Override
public DataDomain get() throws ConfigurationException {
// here goes the class loading hack, temporarily setting application
// bundle ClassLoader to be a thread ClassLoader for runtime to start.
Thread thread = Thread.currentThread();
ClassLoader activeCl = thread.getContextClassLoader();
try {
// using fake package name... as long as it is not
// org.apache.cayenne, this do the right trick
thread.setContextClassLoader(classLoaderManager.getClassLoader("com/"));
DataDomain domain = super.get();
EntityResolver entityResolver = domain.getEntityResolver();
for (ObjEntity e : entityResolver.getObjEntities()) {
// it is not enough to just call 'getObjectClass()' on
// ClassDescriptor - there's an optimization that prevents full
// descriptor resolving... so calling some other method...
entityResolver.getClassDescriptor(e.getName()).getProperty("__dummy__");
entityResolver.getCallbackRegistry();
}
// this triggers callbacks initialization using thread class loader
entityResolver.getCallbackRegistry();
return domain;
} finally {
thread.setContextClassLoader(activeCl);
}
}
use of org.apache.cayenne.access.DataDomain in project cayenne by apache.
the class ROPHessianServlet_ConfigModule method configure.
public void configure(Binder binder) {
DataDomain domain = new DataDomain("x");
binder.bind(DataChannel.class).toInstance(domain);
binder.bind(DataDomain.class).toInstance(domain);
binder.bind(RemoteService.class).to(MockRemoteService.class);
}
use of org.apache.cayenne.access.DataDomain in project cayenne by apache.
the class SchemaBuilder method rebuildSchema.
/**
* Completely rebuilds test schema.
*/
// TODO - this method changes the internal state of the object ... refactor
public void rebuildSchema() {
// generate schema combining all DataMaps that require schema support.
// Schema generation is done like that instead of per DataMap on demand
// to avoid conflicts when dropping and generating PK objects.
DataMap[] maps = new DataMap[MAPS_REQUIRING_SCHEMA_SETUP.length];
for (int i = 0; i < maps.length; i++) {
URL mapURL = getClass().getClassLoader().getResource(MAPS_REQUIRING_SCHEMA_SETUP[i]);
maps[i] = loader.load(new URLResource(mapURL));
}
this.domain = new DataDomain("temp");
domain.setEventManager(new DefaultEventManager(2));
domain.setEntitySorter(new AshwoodEntitySorter());
domain.setQueryCache(new MapQueryCache(50));
try {
for (DataMap map : maps) {
initNode(map);
}
if ("true".equalsIgnoreCase(System.getProperty(SKIP_SCHEMA_KEY))) {
logger.info("skipping schema generation... ");
} else {
dropSchema();
dropPKSupport();
createSchema();
createPKSupport();
}
} catch (Exception e) {
throw new RuntimeException("Error rebuilding schema", e);
}
}
use of org.apache.cayenne.access.DataDomain in project cayenne by apache.
the class ServerCaseDataDomainProvider method createAndInitDataDomain.
@Override
protected DataDomain createAndInitDataDomain() throws Exception {
DataDomain domain = super.createAndInitDataDomain();
DataNode node = null;
for (DataMap dataMap : domain.getDataMaps()) {
// add nodes and DataSources dynamically...
DataNodeDescriptor descriptor = new DataNodeDescriptor(dataMap.getName());
node = dataNodeFactory.createDataNode(descriptor);
node.addDataMap(dataMap);
// tweak procedures for testing...
for (Procedure proc : dataMap.getProcedures()) {
unitDbAdapter.tweakProcedure(proc);
}
// customizations from SimpleAccessStackAdapter that are not yet
// ported...
// those can be done better now
// node
// .getAdapter()
// .getExtendedTypes()
// .registerType(new StringET1ExtendedType());
//
domain.addNode(node);
}
if (domain.getDataMaps().size() == 1) {
domain.setDefaultNode(node);
}
return domain;
}
use of org.apache.cayenne.access.DataDomain in project cayenne by apache.
the class CAY_743Test method testLoad2MapsWithCrossMapInheritance.
@Test
public void testLoad2MapsWithCrossMapInheritance() throws Exception {
Injector injector = DIBootstrap.createInjector(new ServerModule() {
@Override
public void configure(Binder binder) {
super.configure(binder);
ServerModule.contributeProjectLocations(binder).add("cay743/cayenne-domain.xml");
}
});
try {
DataDomain domain = injector.getInstance(DataDomain.class);
assertEquals(2, domain.getDataMaps().size());
DataMap m1 = domain.getDataMap("map1");
DataMap m2 = domain.getDataMap("map2");
ObjEntity oe11 = m1.getObjEntity("Entity11");
ObjEntity oe12 = m1.getObjEntity("Entity12");
ObjEntity oe21 = m2.getObjEntity("Entity21");
ObjEntity oe22 = m2.getObjEntity("Entity22");
// this causes StackOverflow per CAY-743
ObjEntity oe21Super = oe21.getSuperEntity();
ObjEntity oe12Super = oe12.getSuperEntity();
assertSame(oe12Super, oe22);
assertSame(oe21Super, oe11);
} finally {
injector.shutdown();
}
}
Aggregations