use of org.apache.cayenne.DataChannel in project cayenne by apache.
the class CommitLogFilter method onSync.
@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff beforeDiff, int syncType, DataChannelFilterChain filterChain) {
// process commits only; skip rollback
if (syncType != DataChannel.FLUSH_CASCADE_SYNC && syncType != DataChannel.FLUSH_NOCASCADE_SYNC) {
return filterChain.onSync(originatingContext, beforeDiff, syncType);
}
// don't collect changes if there are no listeners
if (listeners.isEmpty()) {
return filterChain.onSync(originatingContext, beforeDiff, syncType);
}
MutableChangeMap changes = new MutableChangeMap();
// passing DataDomain, not ObjectContext to speed things up
// and avoid capturing changed state when fetching snapshots
DataChannel channel = originatingContext.getChannel();
beforeCommit(changes, channel, beforeDiff);
GraphDiff afterDiff = filterChain.onSync(originatingContext, beforeDiff, syncType);
afterCommit(changes, channel, beforeDiff, afterDiff);
notifyListeners(originatingContext, changes);
return afterDiff;
}
use of org.apache.cayenne.DataChannel in project cayenne by apache.
the class ServerModule method configure.
public void configure(Binder binder) {
// configure global stack properties
contributeProperties(binder).put(Constants.SERVER_MAX_ID_QUALIFIER_SIZE_PROPERTY, String.valueOf(DEFAULT_MAX_ID_QUALIFIER_SIZE));
contributeProperties(binder).put(Constants.SERVER_CONTEXTS_SYNC_PROPERTY, String.valueOf(false));
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
// configure known DbAdapter detectors in reverse order of popularity.
// Users can add their own to install custom adapters automatically
contributeAdapterDetectors(binder).add(FirebirdSniffer.class).add(OpenBaseSniffer.class).add(FrontBaseSniffer.class).add(IngresSniffer.class).add(SQLiteSniffer.class).add(DB2Sniffer.class).add(H2Sniffer.class).add(HSQLDBSniffer.class).add(SybaseSniffer.class).add(DerbySniffer.class).add(SQLServerSniffer.class).add(OracleSniffer.class).add(PostgresSniffer.class).add(MySQLSniffer.class).add(MariaDBSniffer.class);
// installing Pk for adapters
binder.bind(PkGeneratorFactoryProvider.class).to(PkGeneratorFactoryProvider.class);
binder.bind(PkGenerator.class).to(JdbcPkGenerator.class);
// set PkGenerators for current Adapters
contributePkGenerators(binder).put(DB2Adapter.class.getName(), DB2PkGenerator.class).put(DerbyAdapter.class.getName(), DerbyPkGenerator.class).put(FrontBaseAdapter.class.getName(), FrontBasePkGenerator.class).put(H2Adapter.class.getName(), H2PkGenerator.class).put(IngresAdapter.class.getName(), IngresPkGenerator.class).put(MySQLAdapter.class.getName(), MySQLPkGenerator.class).put(OpenBaseAdapter.class.getName(), OpenBasePkGenerator.class).put(OracleAdapter.class.getName(), OraclePkGenerator.class).put(Oracle8Adapter.class.getName(), OraclePkGenerator.class).put(PostgresAdapter.class.getName(), PostgresPkGenerator.class).put(SQLServerAdapter.class.getName(), SybasePkGenerator.class).put(SybaseAdapter.class.getName(), SybasePkGenerator.class);
// configure a filter chain with only one TransactionFilter as default
contributeDomainFilters(binder);
contributeDomainQueryFilters(binder);
contributeDomainSyncFilters(binder).add(TransactionFilter.class);
// init listener list
contributeDomainListeners(binder);
// configure extended types
contributeDefaultTypes(binder).add(new VoidType()).add(new BigDecimalType()).add(new BooleanType()).add(new ByteType(false)).add(new CharType(false, true)).add(new DoubleType()).add(new FloatType()).add(new IntegerType()).add(new LongType()).add(new ShortType(false)).add(new ByteArrayType(false, true)).add(new DateType()).add(new TimeType()).add(new TimestampType()).add(new DurationType()).add(new UtilDateType()).add(new CalendarType<>(GregorianCalendar.class)).add(new CalendarType<>(Calendar.class)).add(GeoJsonType.class).add(WktType.class);
contributeUserTypes(binder);
contributeTypeFactories(binder).add(new InternalUnsupportedTypeFactory());
// Custom ValueObjects types contribution
contributeValueObjectTypes(binder).add(BigIntegerValueType.class).add(BigDecimalValueType.class).add(UUIDValueType.class).add(LocalDateValueType.class).add(LocalTimeValueType.class).add(LocalDateTimeValueType.class).add(PeriodValueType.class).add(CharacterValueType.class);
binder.bind(ValueObjectTypeRegistry.class).to(DefaultValueObjectTypeRegistry.class);
binder.bind(ValueComparisonStrategyFactory.class).to(DefaultValueComparisonStrategyFactory.class);
// configure explicit configurations
contributeProjectLocations(binder);
binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
binder.bind(EventManager.class).toProvider(EventManagerProvider.class);
binder.bind(QueryCache.class).toProvider(MapQueryCacheProvider.class);
binder.bind(EventBridge.class).toProvider(NoopEventBridgeProvider.class);
binder.bind(DataRowStoreFactory.class).to(DefaultDataRowStoreFactory.class);
// a service to provide the main stack DataDomain
binder.bind(DataDomain.class).toProvider(DataDomainProvider.class);
binder.bind(DataNodeFactory.class).to(DefaultDataNodeFactory.class);
// will return DataDomain for request for a DataChannel
binder.bind(DataChannel.class).toProvider(DomainDataChannelProvider.class);
binder.bind(ObjectContextFactory.class).to(DataContextFactory.class);
binder.bind(TransactionFactory.class).to(DefaultTransactionFactory.class);
// a service to load project XML descriptors
binder.bind(DataChannelDescriptorLoader.class).to(XMLDataChannelDescriptorLoader.class);
binder.bind(DataChannelDescriptorMerger.class).to(DefaultDataChannelDescriptorMerger.class);
// a service to load DataMap XML descriptors
binder.bind(DataMapLoader.class).to(XMLDataMapLoader.class);
// a locator of resources, such as XML descriptors
binder.bind(ResourceLocator.class).to(ClassLoaderResourceLocator.class);
binder.bind(Key.get(ResourceLocator.class, Constants.SERVER_RESOURCE_LOCATOR)).to(ClassLoaderResourceLocator.class);
// a global properties object
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
// a service to load DataSourceFactories. DelegatingDataSourceFactory
// will attempt to find the actual worker factory dynamically on each
// call depending on DataNodeDescriptor data and the environment
binder.bind(DataSourceFactory.class).to(DelegatingDataSourceFactory.class);
binder.bind(SchemaUpdateStrategyFactory.class).to(DefaultSchemaUpdateStrategyFactory.class);
// a default DBAdapterFactory used to load custom and automatic DbAdapters
binder.bind(DbAdapterFactory.class).to(DefaultDbAdapterFactory.class);
// binding AshwoodEntitySorter without scope, as this is a stateful object and is
// configured by the owning domain
binder.bind(EntitySorter.class).to(AshwoodEntitySorter.class).withoutScope();
binder.bind(BatchTranslatorFactory.class).to(DefaultBatchTranslatorFactory.class);
binder.bind(SelectTranslatorFactory.class).to(DefaultSelectTranslatorFactory.class);
// a default ObjectMapRetainStrategy used to create objects map for
// ObjectStore
binder.bind(ObjectMapRetainStrategy.class).to(DefaultObjectMapRetainStrategy.class);
// a default ObjectStoreFactory used to create ObjectStores for contexts
binder.bind(ObjectStoreFactory.class).to(DefaultObjectStoreFactory.class);
binder.bind(TransactionManager.class).to(DefaultTransactionManager.class);
binder.bind(RowReaderFactory.class).to(DefaultRowReaderFactory.class);
binder.bind(SQLTemplateProcessor.class).to(CayenneSQLTemplateProcessor.class);
binder.bind(TemplateContextFactory.class).to(DefaultTemplateContextFactory.class);
binder.bind(HandlerFactory.class).to(DefaultHandlerFactory.class);
binder.bind(DataChannelMetaData.class).to(NoopDataChannelMetaData.class);
binder.bind(XMLReader.class).toProviderInstance(new XMLReaderProvider(false)).withoutScope();
binder.bind(DataDomainFlushActionFactory.class).to(DefaultDataDomainFlushActionFactory.class);
binder.bind(DbRowOpSorter.class).to(DefaultDbRowOpSorter.class);
}
use of org.apache.cayenne.DataChannel in project cayenne by apache.
the class ServerRuntimeTest method testGetObjectContext_CustomModule.
@Test
public void testGetObjectContext_CustomModule() {
final ObjectContext context = new DataContext();
final ObjectContextFactory factory = new ObjectContextFactory() {
public ObjectContext createContext(DataChannel parent) {
return context;
}
public ObjectContext createContext() {
return context;
}
};
Module module = binder -> binder.bind(ObjectContextFactory.class).toInstance(factory);
ServerRuntime runtime = new ServerRuntime(Collections.singleton(module));
assertSame(context, runtime.newContext());
assertSame(context, runtime.newContext());
}
use of org.apache.cayenne.DataChannel in project cayenne by apache.
the class HttpRemoteService method createServerSession.
/**
* Creates a new ServerSession based on a shared DataChannel. Returned ServerSession
* is stored in HttpSession for future reuse.
*
* @param name shared session name used to lookup a shared DataChannel.
*/
@Override
protected ServerSession createServerSession(String name) {
if (name == null) {
throw new IllegalArgumentException("Name is null for shared session.");
}
HttpSession httpSession = getSession(true);
DataChannel channel;
synchronized (sharedChannels) {
channel = getSharedChannel(name);
if (channel == null) {
channel = createChannel();
saveSharedChannel(name, channel);
logger.debug("Starting a new shared channel: " + name);
} else {
logger.debug("Joining existing shared channel: " + name);
}
}
RemoteSession remoteSession = createRemoteSession(httpSession.getId(), name, true);
ServerSession serverSession = new ServerSession(remoteSession, channel);
httpSession.setAttribute(SESSION_ATTRIBUTE, serverSession);
return serverSession;
}
use of org.apache.cayenne.DataChannel in project cayenne by apache.
the class HttpRemoteService method createServerSession.
/**
* Creates a new ServerSession with a dedicated DataChannel. Returned ServerSession is
* stored in HttpSession for future reuse.
*/
@Override
protected ServerSession createServerSession() {
HttpSession httpSession = getSession(true);
DataChannel channel = createChannel();
RemoteSession remoteSession = createRemoteSession(httpSession.getId(), null, false);
ServerSession serverSession = new ServerSession(remoteSession, channel);
httpSession.setAttribute(SESSION_ATTRIBUTE, serverSession);
return serverSession;
}
Aggregations