Search in sources :

Example 1 with XMLReaderProvider

use of org.apache.cayenne.configuration.xml.XMLReaderProvider in project cayenne by apache.

the class DataChannelProjectLoaderTest method testLoad.

@Test
public void testLoad() {
    DataChannelProjectLoader loader = new DataChannelProjectLoader();
    Module testModule = binder -> {
        binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
        binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
        binder.bind(DataMapLoader.class).to(XMLDataMapLoader.class);
        binder.bind(DataChannelDescriptorLoader.class).to(XMLDataChannelDescriptorLoader.class);
        binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
        binder.bind(HandlerFactory.class).to(DefaultHandlerFactory.class);
        binder.bind(DataChannelMetaData.class).to(NoopDataChannelMetaData.class);
        binder.bind(XMLReader.class).toProviderInstance(new XMLReaderProvider(false)).withoutScope();
    };
    Injector injector = DIBootstrap.createInjector(testModule);
    injector.injectMembers(loader);
    String testConfigName = "PROJECT1";
    String baseUrl = getClass().getPackage().getName().replace('.', '/');
    URL url = getClass().getClassLoader().getResource(baseUrl + "/cayenne-" + testConfigName + ".xml");
    Resource rootSource = new URLResource(url);
    Project project = loader.loadProject(rootSource);
    assertNotNull(project);
    DataChannelDescriptor rootNode = (DataChannelDescriptor) project.getRootNode();
    assertNotNull(rootNode);
    assertSame(rootSource, rootNode.getConfigurationSource());
    assertNotNull(project.getConfigurationResource());
    assertEquals(project.getConfigurationResource(), rootSource);
}
Also used : Injector(org.apache.cayenne.di.Injector) HandlerFactory(org.apache.cayenne.configuration.xml.HandlerFactory) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) URL(java.net.URL) ConfigurationNameMapper(org.apache.cayenne.configuration.ConfigurationNameMapper) Module(org.apache.cayenne.di.Module) DataChannelDescriptorLoader(org.apache.cayenne.configuration.DataChannelDescriptorLoader) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) XMLReader(org.xml.sax.XMLReader) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) DIBootstrap(org.apache.cayenne.di.DIBootstrap) URLResource(org.apache.cayenne.resource.URLResource) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Test(org.junit.Test) DataChannelMetaData(org.apache.cayenne.configuration.xml.DataChannelMetaData) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) Resource(org.apache.cayenne.resource.Resource) Assert(org.junit.Assert) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) URL(java.net.URL) XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) URLResource(org.apache.cayenne.resource.URLResource) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) XMLReader(org.xml.sax.XMLReader) Test(org.junit.Test)

Example 2 with XMLReaderProvider

use of org.apache.cayenne.configuration.xml.XMLReaderProvider in project cayenne by apache.

the class DataChannelProjectSaverTest method testSaveAs.

@Test
public void testSaveAs() throws Exception {
    FileProjectSaver saver = new FileProjectSaver(Collections.<ProjectExtension>emptyList());
    Module testModule = binder -> {
        binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
        binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
        binder.bind(DataMapLoader.class).to(XMLDataMapLoader.class);
        binder.bind(DataChannelDescriptorLoader.class).to(XMLDataChannelDescriptorLoader.class);
        binder.bind(ProjectLoader.class).to(DataChannelProjectLoader.class);
        binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
        binder.bind(HandlerFactory.class).to(DefaultHandlerFactory.class);
        binder.bind(DataChannelMetaData.class).to(NoopDataChannelMetaData.class);
        binder.bind(XMLReader.class).toProviderInstance(new XMLReaderProvider(false)).withoutScope();
    };
    Injector injector = DIBootstrap.createInjector(testModule);
    injector.injectMembers(saver);
    String testConfigName = "PROJECT2";
    String baseUrl = getClass().getPackage().getName().replace('.', '/');
    URL url = getClass().getClassLoader().getResource(baseUrl + "/cayenne-" + testConfigName + ".xml");
    Resource source = new URLResource(url);
    Project project = injector.getInstance(ProjectLoader.class).loadProject(source);
    File outFile = setupTestDirectory("testSave");
    saver.saveAs(project, new URLResource(outFile.toURI().toURL()));
    File rootFile = new File(outFile, "cayenne-PROJECT2.xml");
    assertTrue(rootFile.exists());
    assertTrue(rootFile.length() > 0);
    File map1File = new File(outFile, "testProjectMap2_1.map.xml");
    assertTrue(map1File.exists());
    assertTrue(map1File.length() > 0);
    File map2File = new File(outFile, "testProjectMap2_2.map.xml");
    assertTrue(map2File.exists());
    assertTrue(map2File.length() > 0);
}
Also used : Injector(org.apache.cayenne.di.Injector) HandlerFactory(org.apache.cayenne.configuration.xml.HandlerFactory) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) Project2Case(org.apache.cayenne.project.unit.Project2Case) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) URL(java.net.URL) ConfigurationNameMapper(org.apache.cayenne.configuration.ConfigurationNameMapper) Module(org.apache.cayenne.di.Module) DataChannelDescriptorLoader(org.apache.cayenne.configuration.DataChannelDescriptorLoader) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) XMLReader(org.xml.sax.XMLReader) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) DIBootstrap(org.apache.cayenne.di.DIBootstrap) ProjectExtension(org.apache.cayenne.project.extension.ProjectExtension) PrintWriter(java.io.PrintWriter) URLResource(org.apache.cayenne.resource.URLResource) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Test(org.junit.Test) DataChannelMetaData(org.apache.cayenne.configuration.xml.DataChannelMetaData) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) File(java.io.File) Resource(org.apache.cayenne.resource.Resource) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) Assert(org.junit.Assert) Collections(java.util.Collections) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) URLResource(org.apache.cayenne.resource.URLResource) Resource(org.apache.cayenne.resource.Resource) URL(java.net.URL) XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) URLResource(org.apache.cayenne.resource.URLResource) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) File(java.io.File) XMLReader(org.xml.sax.XMLReader) Test(org.junit.Test)

Example 3 with XMLReaderProvider

use of org.apache.cayenne.configuration.xml.XMLReaderProvider in project cayenne by apache.

the class ServerCaseModule method configure.

public void configure(Binder binder) {
    // these are the objects injectable in unit tests that subclass from
    // ServerCase. Note that ServerRuntimeProvider creates ServerRuntime
    // instances complete with their own DI injectors, independent from the
    // unit test injector. ServerRuntime injector contents are customized
    // inside ServerRuntimeProvider.
    binder.bindMap(String.class, UnitDbAdapterProvider.TEST_ADAPTERS_MAP).put(FirebirdAdapter.class.getName(), FirebirdUnitDbAdapter.class.getName()).put(OracleAdapter.class.getName(), OracleUnitDbAdapter.class.getName()).put(DerbyAdapter.class.getName(), DerbyUnitDbAdapter.class.getName()).put(Oracle8Adapter.class.getName(), OracleUnitDbAdapter.class.getName()).put(SybaseAdapter.class.getName(), SybaseUnitDbAdapter.class.getName()).put(MySQLAdapter.class.getName(), MySQLUnitDbAdapter.class.getName()).put(PostgresAdapter.class.getName(), PostgresUnitDbAdapter.class.getName()).put(OpenBaseAdapter.class.getName(), OpenBaseUnitDbAdapter.class.getName()).put(SQLServerAdapter.class.getName(), SQLServerUnitDbAdapter.class.getName()).put(DB2Adapter.class.getName(), DB2UnitDbAdapter.class.getName()).put(HSQLDBAdapter.class.getName(), HSQLDBUnitDbAdapter.class.getName()).put(H2Adapter.class.getName(), H2UnitDbAdapter.class.getName()).put(FrontBaseAdapter.class.getName(), FrontBaseUnitDbAdapter.class.getName()).put(IngresAdapter.class.getName(), IngresUnitDbAdapter.class.getName()).put(SQLiteAdapter.class.getName(), SQLiteUnitDbAdapter.class.getName());
    ServerModule.contributeProperties(binder).put(Constants.SERVER_OBJECT_RETAIN_STRATEGY_PROPERTY, "soft");
    // configure extended types
    ServerModule.contributeDefaultTypes(binder).add(new VoidType()).add(new BigDecimalType()).add(new BooleanType()).add(new ByteArrayType(false, true)).add(new ByteType(false)).add(new CharType(false, true)).add(new DateType()).add(new DoubleType()).add(new FloatType()).add(new IntegerType()).add(new LongType()).add(new ShortType(false)).add(new TimeType()).add(new TimestampType()).add(new UtilDateType()).add(new CalendarType<>(GregorianCalendar.class)).add(new CalendarType<>(Calendar.class));
    ServerModule.contributeUserTypes(binder);
    ServerModule.contributeTypeFactories(binder);
    ServerModule.contributeValueObjectTypes(binder).add(BigIntegerValueType.class).add(UUIDValueType.class).add(LocalDateValueType.class).add(LocalTimeValueType.class).add(LocalDateTimeValueType.class).add(CharacterValueType.class);
    binder.bind(ValueObjectTypeRegistry.class).to(DefaultValueObjectTypeRegistry.class);
    binder.bind(SchemaBuilder.class).to(SchemaBuilder.class);
    binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
    binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
    binder.bind(ObjectMapRetainStrategy.class).to(DefaultObjectMapRetainStrategy.class);
    // singleton objects
    binder.bind(UnitTestLifecycleManager.class).toInstance(new ServerCaseLifecycleManager(testScope));
    binder.bind(DataSourceInfo.class).toProvider(ServerCaseDataSourceInfoProvider.class);
    binder.bind(DataSourceFactory.class).to(ServerCaseSharedDataSourceFactory.class);
    binder.bind(DbAdapter.class).toProvider(ServerCaseDbAdapterProvider.class);
    binder.bind(JdbcAdapter.class).toProvider(ServerCaseDbAdapterProvider.class);
    binder.bind(UnitDbAdapter.class).toProvider(UnitDbAdapterProvider.class);
    // this factory is a hack that allows to inject to DbAdapters loaded outside of
    // server runtime... BatchQueryBuilderFactory is hardcoded and whatever is placed
    // in the ServerModule is ignored
    binder.bind(BatchTranslatorFactory.class).toProvider(ServerCaseBatchQueryBuilderFactoryProvider.class);
    binder.bind(DataChannelInterceptor.class).to(ServerCaseDataChannelInterceptor.class);
    binder.bind(SQLTemplateCustomizer.class).toProvider(SQLTemplateCustomizerProvider.class);
    binder.bind(ServerCaseDataSourceFactory.class).to(ServerCaseDataSourceFactory.class);
    binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
    binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
    binder.bind(ResourceLocator.class).to(ClassLoaderResourceLocator.class);
    binder.bind(Key.get(ResourceLocator.class, Constants.SERVER_RESOURCE_LOCATOR)).to(ClassLoaderResourceLocator.class);
    binder.bind(ObjectStoreFactory.class).to(DefaultObjectStoreFactory.class);
    binder.bind(DataMapLoader.class).to(XMLDataMapLoader.class);
    binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
    binder.bind(HandlerFactory.class).to(DefaultHandlerFactory.class);
    binder.bind(DataChannelMetaData.class).to(NoopDataChannelMetaData.class);
    binder.bind(XMLReader.class).toProviderInstance(new XMLReaderProvider(false)).withoutScope();
    // test-scoped objects
    binder.bind(EntityResolver.class).toProvider(ServerCaseEntityResolverProvider.class).in(testScope);
    binder.bind(DataNode.class).toProvider(ServerCaseDataNodeProvider.class).in(testScope);
    binder.bind(ServerCaseProperties.class).to(ServerCaseProperties.class).in(testScope);
    binder.bind(ServerRuntime.class).toProvider(ServerRuntimeProvider.class).in(testScope);
    binder.bind(ObjectContext.class).toProvider(ServerCaseObjectContextProvider.class).withoutScope();
    binder.bind(DataContext.class).toProvider(ServerCaseDataContextProvider.class).withoutScope();
    binder.bind(DBHelper.class).toProvider(FlavoredDBHelperProvider.class).in(testScope);
    binder.bind(DBCleaner.class).toProvider(DBCleanerProvider.class).in(testScope);
}
Also used : SQLServerUnitDbAdapter(org.apache.cayenne.unit.SQLServerUnitDbAdapter) JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) SQLiteUnitDbAdapter(org.apache.cayenne.unit.SQLiteUnitDbAdapter) ByteType(org.apache.cayenne.access.types.ByteType) FloatType(org.apache.cayenne.access.types.FloatType) DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) SQLTemplateCustomizer(org.apache.cayenne.unit.util.SQLTemplateCustomizer) HandlerFactory(org.apache.cayenne.configuration.xml.HandlerFactory) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) DataChannelMetaData(org.apache.cayenne.configuration.xml.DataChannelMetaData) UtilDateType(org.apache.cayenne.access.types.UtilDateType) UtilDateType(org.apache.cayenne.access.types.UtilDateType) DateType(org.apache.cayenne.access.types.DateType) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) ResourceLocator(org.apache.cayenne.resource.ResourceLocator) ClassLoaderResourceLocator(org.apache.cayenne.resource.ClassLoaderResourceLocator) ShortType(org.apache.cayenne.access.types.ShortType) LocalDateValueType(org.apache.cayenne.access.types.LocalDateValueType) ObjectMapRetainStrategy(org.apache.cayenne.access.ObjectMapRetainStrategy) DefaultObjectMapRetainStrategy(org.apache.cayenne.access.DefaultObjectMapRetainStrategy) SQLiteAdapter(org.apache.cayenne.dba.sqlite.SQLiteAdapter) ByteArrayType(org.apache.cayenne.access.types.ByteArrayType) HSQLDBAdapter(org.apache.cayenne.dba.hsqldb.HSQLDBAdapter) PostgresUnitDbAdapter(org.apache.cayenne.unit.PostgresUnitDbAdapter) FirebirdUnitDbAdapter(org.apache.cayenne.unit.FirebirdUnitDbAdapter) CharType(org.apache.cayenne.access.types.CharType) BigDecimalType(org.apache.cayenne.access.types.BigDecimalType) VoidType(org.apache.cayenne.access.types.VoidType) DerbyAdapter(org.apache.cayenne.dba.derby.DerbyAdapter) SQLServerAdapter(org.apache.cayenne.dba.sqlserver.SQLServerAdapter) LongType(org.apache.cayenne.access.types.LongType) DataSourceFactory(org.apache.cayenne.configuration.server.DataSourceFactory) ObjectStoreFactory(org.apache.cayenne.configuration.ObjectStoreFactory) DefaultObjectStoreFactory(org.apache.cayenne.configuration.DefaultObjectStoreFactory) DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) SybaseUnitDbAdapter(org.apache.cayenne.unit.SybaseUnitDbAdapter) ValueObjectTypeRegistry(org.apache.cayenne.access.types.ValueObjectTypeRegistry) DefaultValueObjectTypeRegistry(org.apache.cayenne.access.types.DefaultValueObjectTypeRegistry) FrontBaseUnitDbAdapter(org.apache.cayenne.unit.FrontBaseUnitDbAdapter) BigIntegerValueType(org.apache.cayenne.access.types.BigIntegerValueType) TimeType(org.apache.cayenne.access.types.TimeType) UnitTestLifecycleManager(org.apache.cayenne.unit.di.UnitTestLifecycleManager) FrontBaseUnitDbAdapter(org.apache.cayenne.unit.FrontBaseUnitDbAdapter) UnitDbAdapter(org.apache.cayenne.unit.UnitDbAdapter) SybaseUnitDbAdapter(org.apache.cayenne.unit.SybaseUnitDbAdapter) PostgresUnitDbAdapter(org.apache.cayenne.unit.PostgresUnitDbAdapter) HSQLDBUnitDbAdapter(org.apache.cayenne.unit.HSQLDBUnitDbAdapter) DbAdapter(org.apache.cayenne.dba.DbAdapter) MySQLUnitDbAdapter(org.apache.cayenne.unit.MySQLUnitDbAdapter) IngresUnitDbAdapter(org.apache.cayenne.unit.IngresUnitDbAdapter) SQLiteUnitDbAdapter(org.apache.cayenne.unit.SQLiteUnitDbAdapter) SQLServerUnitDbAdapter(org.apache.cayenne.unit.SQLServerUnitDbAdapter) H2UnitDbAdapter(org.apache.cayenne.unit.H2UnitDbAdapter) FirebirdUnitDbAdapter(org.apache.cayenne.unit.FirebirdUnitDbAdapter) DerbyUnitDbAdapter(org.apache.cayenne.unit.DerbyUnitDbAdapter) OpenBaseUnitDbAdapter(org.apache.cayenne.unit.OpenBaseUnitDbAdapter) OracleUnitDbAdapter(org.apache.cayenne.unit.OracleUnitDbAdapter) DB2UnitDbAdapter(org.apache.cayenne.unit.DB2UnitDbAdapter) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) ConfigurationNameMapper(org.apache.cayenne.configuration.ConfigurationNameMapper) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) DerbyUnitDbAdapter(org.apache.cayenne.unit.DerbyUnitDbAdapter) TimestampType(org.apache.cayenne.access.types.TimestampType) FrontBaseUnitDbAdapter(org.apache.cayenne.unit.FrontBaseUnitDbAdapter) UnitDbAdapter(org.apache.cayenne.unit.UnitDbAdapter) SybaseUnitDbAdapter(org.apache.cayenne.unit.SybaseUnitDbAdapter) PostgresUnitDbAdapter(org.apache.cayenne.unit.PostgresUnitDbAdapter) HSQLDBUnitDbAdapter(org.apache.cayenne.unit.HSQLDBUnitDbAdapter) MySQLUnitDbAdapter(org.apache.cayenne.unit.MySQLUnitDbAdapter) IngresUnitDbAdapter(org.apache.cayenne.unit.IngresUnitDbAdapter) SQLiteUnitDbAdapter(org.apache.cayenne.unit.SQLiteUnitDbAdapter) SQLServerUnitDbAdapter(org.apache.cayenne.unit.SQLServerUnitDbAdapter) H2UnitDbAdapter(org.apache.cayenne.unit.H2UnitDbAdapter) FirebirdUnitDbAdapter(org.apache.cayenne.unit.FirebirdUnitDbAdapter) DerbyUnitDbAdapter(org.apache.cayenne.unit.DerbyUnitDbAdapter) OpenBaseUnitDbAdapter(org.apache.cayenne.unit.OpenBaseUnitDbAdapter) OracleUnitDbAdapter(org.apache.cayenne.unit.OracleUnitDbAdapter) DB2UnitDbAdapter(org.apache.cayenne.unit.DB2UnitDbAdapter) HSQLDBUnitDbAdapter(org.apache.cayenne.unit.HSQLDBUnitDbAdapter) FrontBaseAdapter(org.apache.cayenne.dba.frontbase.FrontBaseAdapter) FirebirdAdapter(org.apache.cayenne.dba.firebird.FirebirdAdapter) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) BooleanType(org.apache.cayenne.access.types.BooleanType) DataChannelInterceptor(org.apache.cayenne.unit.di.DataChannelInterceptor) PostgresAdapter(org.apache.cayenne.dba.postgres.PostgresAdapter) LocalDateTimeValueType(org.apache.cayenne.access.types.LocalDateTimeValueType) IntegerType(org.apache.cayenne.access.types.IntegerType) SybaseAdapter(org.apache.cayenne.dba.sybase.SybaseAdapter) DoubleType(org.apache.cayenne.access.types.DoubleType) BatchTranslatorFactory(org.apache.cayenne.access.translator.batch.BatchTranslatorFactory) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) CalendarType(org.apache.cayenne.access.types.CalendarType)

Example 4 with XMLReaderProvider

use of org.apache.cayenne.configuration.xml.XMLReaderProvider 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));
    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);
    // configure a filter chain with only one TransactionFilter as default
    contributeDomainFilters(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 UtilDateType()).add(new CalendarType<>(GregorianCalendar.class)).add(new CalendarType<>(Calendar.class));
    contributeUserTypes(binder);
    contributeTypeFactories(binder);
    // Custom ValueObjects types contribution
    contributeValueObjectTypes(binder).add(BigIntegerValueType.class).add(UUIDValueType.class).add(LocalDateValueType.class).add(LocalTimeValueType.class).add(LocalDateTimeValueType.class).add(CharacterValueType.class);
    binder.bind(ValueObjectTypeRegistry.class).to(DefaultValueObjectTypeRegistry.class);
    // configure explicit configurations
    ListBuilder<String> locationsListBuilder = contributeProjectLocations(binder);
    binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
    binder.bind(EventManager.class).to(DefaultEventManager.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();
}
Also used : SchemaUpdateStrategyFactory(org.apache.cayenne.access.dbsync.SchemaUpdateStrategyFactory) DefaultSchemaUpdateStrategyFactory(org.apache.cayenne.access.dbsync.DefaultSchemaUpdateStrategyFactory) QueryCache(org.apache.cayenne.cache.QueryCache) EventBridge(org.apache.cayenne.event.EventBridge) ByteType(org.apache.cayenne.access.types.ByteType) FloatType(org.apache.cayenne.access.types.FloatType) DataChannelDescriptorMerger(org.apache.cayenne.configuration.DataChannelDescriptorMerger) DefaultDataChannelDescriptorMerger(org.apache.cayenne.configuration.DefaultDataChannelDescriptorMerger) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) HandlerFactory(org.apache.cayenne.configuration.xml.HandlerFactory) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) DataChannelMetaData(org.apache.cayenne.configuration.xml.DataChannelMetaData) H2Sniffer(org.apache.cayenne.dba.h2.H2Sniffer) UtilDateType(org.apache.cayenne.access.types.UtilDateType) UtilDateType(org.apache.cayenne.access.types.UtilDateType) DateType(org.apache.cayenne.access.types.DateType) FirebirdSniffer(org.apache.cayenne.dba.firebird.FirebirdSniffer) DefaultRuntimeProperties(org.apache.cayenne.configuration.DefaultRuntimeProperties) RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) DataRowStoreFactory(org.apache.cayenne.access.DataRowStoreFactory) DefaultDataRowStoreFactory(org.apache.cayenne.access.DefaultDataRowStoreFactory) ResourceLocator(org.apache.cayenne.resource.ResourceLocator) ClassLoaderResourceLocator(org.apache.cayenne.resource.ClassLoaderResourceLocator) DataDomain(org.apache.cayenne.access.DataDomain) ShortType(org.apache.cayenne.access.types.ShortType) LocalDateValueType(org.apache.cayenne.access.types.LocalDateValueType) ObjectMapRetainStrategy(org.apache.cayenne.access.ObjectMapRetainStrategy) DefaultObjectMapRetainStrategy(org.apache.cayenne.access.DefaultObjectMapRetainStrategy) ByteArrayType(org.apache.cayenne.access.types.ByteArrayType) TransactionManager(org.apache.cayenne.tx.TransactionManager) DefaultTransactionManager(org.apache.cayenne.tx.DefaultTransactionManager) DefaultTransactionFactory(org.apache.cayenne.tx.DefaultTransactionFactory) TransactionFactory(org.apache.cayenne.tx.TransactionFactory) XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) DataChannelDescriptorLoader(org.apache.cayenne.configuration.DataChannelDescriptorLoader) CharType(org.apache.cayenne.access.types.CharType) SybaseSniffer(org.apache.cayenne.dba.sybase.SybaseSniffer) BigDecimalType(org.apache.cayenne.access.types.BigDecimalType) FrontBaseSniffer(org.apache.cayenne.dba.frontbase.FrontBaseSniffer) VoidType(org.apache.cayenne.access.types.VoidType) LongType(org.apache.cayenne.access.types.LongType) ObjectStoreFactory(org.apache.cayenne.configuration.ObjectStoreFactory) DefaultObjectStoreFactory(org.apache.cayenne.configuration.DefaultObjectStoreFactory) PostgresSniffer(org.apache.cayenne.dba.postgres.PostgresSniffer) DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) ValueObjectTypeRegistry(org.apache.cayenne.access.types.ValueObjectTypeRegistry) DefaultValueObjectTypeRegistry(org.apache.cayenne.access.types.DefaultValueObjectTypeRegistry) BigIntegerValueType(org.apache.cayenne.access.types.BigIntegerValueType) TimeType(org.apache.cayenne.access.types.TimeType) SQLiteSniffer(org.apache.cayenne.dba.sqlite.SQLiteSniffer) AshwoodEntitySorter(org.apache.cayenne.ashwood.AshwoodEntitySorter) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) ConfigurationNameMapper(org.apache.cayenne.configuration.ConfigurationNameMapper) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) TimestampType(org.apache.cayenne.access.types.TimestampType) DefaultTemplateContextFactory(org.apache.cayenne.template.DefaultTemplateContextFactory) TemplateContextFactory(org.apache.cayenne.template.TemplateContextFactory) SQLServerSniffer(org.apache.cayenne.dba.sqlserver.SQLServerSniffer) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) EventManager(org.apache.cayenne.event.EventManager) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) BooleanType(org.apache.cayenne.access.types.BooleanType) RowReaderFactory(org.apache.cayenne.access.jdbc.reader.RowReaderFactory) DefaultRowReaderFactory(org.apache.cayenne.access.jdbc.reader.DefaultRowReaderFactory) ObjectContextFactory(org.apache.cayenne.configuration.ObjectContextFactory) LocalDateTimeValueType(org.apache.cayenne.access.types.LocalDateTimeValueType) IntegerType(org.apache.cayenne.access.types.IntegerType) DataChannel(org.apache.cayenne.DataChannel) DoubleType(org.apache.cayenne.access.types.DoubleType) DefaultBatchTranslatorFactory(org.apache.cayenne.access.translator.batch.DefaultBatchTranslatorFactory) BatchTranslatorFactory(org.apache.cayenne.access.translator.batch.BatchTranslatorFactory) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) CayenneSQLTemplateProcessor(org.apache.cayenne.template.CayenneSQLTemplateProcessor) SQLTemplateProcessor(org.apache.cayenne.access.jdbc.SQLTemplateProcessor) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) CalendarType(org.apache.cayenne.access.types.CalendarType) DefaultSelectTranslatorFactory(org.apache.cayenne.access.translator.select.DefaultSelectTranslatorFactory) SelectTranslatorFactory(org.apache.cayenne.access.translator.select.SelectTranslatorFactory)

Example 5 with XMLReaderProvider

use of org.apache.cayenne.configuration.xml.XMLReaderProvider in project cayenne by apache.

the class ManyToManyCandidateEntityTest method setUp.

@Before
public void setUp() throws Exception {
    Module testModule = binder -> {
        binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
        binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
        binder.bind(DataMapLoader.class).to(XMLDataMapLoader.class);
        binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
        binder.bind(HandlerFactory.class).to(DefaultHandlerFactory.class);
        binder.bind(DataChannelMetaData.class).to(NoopDataChannelMetaData.class);
        binder.bind(XMLReader.class).toProviderInstance(new XMLReaderProvider(false)).withoutScope();
    };
    Injector injector = DIBootstrap.createInjector(testModule);
    // create and initialize loader instance to test
    XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
    injector.injectMembers(loader);
    String testConfigName = "relationship-optimisation";
    URL url = getClass().getResource("cayenne-" + testConfigName + ".xml");
    ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url));
    map = tree.getRootNode().getDataMap(testConfigName);
}
Also used : Injector(org.apache.cayenne.di.Injector) ObjEntity(org.apache.cayenne.map.ObjEntity) HandlerFactory(org.apache.cayenne.configuration.xml.HandlerFactory) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) Relationship(org.apache.cayenne.map.Relationship) URL(java.net.URL) ConfigurationNameMapper(org.apache.cayenne.configuration.ConfigurationNameMapper) Module(org.apache.cayenne.di.Module) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) ArrayList(java.util.ArrayList) DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) DefaultObjectNameGenerator(org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator) XMLReader(org.xml.sax.XMLReader) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) ConfigurationTree(org.apache.cayenne.configuration.ConfigurationTree) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) NoStemStemmer(org.apache.cayenne.dbsync.naming.NoStemStemmer) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) DIBootstrap(org.apache.cayenne.di.DIBootstrap) Before(org.junit.Before) URLResource(org.apache.cayenne.resource.URLResource) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Test(org.junit.Test) DataChannelMetaData(org.apache.cayenne.configuration.xml.DataChannelMetaData) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) Assert(org.junit.Assert) DataMap(org.apache.cayenne.map.DataMap) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) URL(java.net.URL) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) URLResource(org.apache.cayenne.resource.URLResource) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) XMLReader(org.xml.sax.XMLReader) Before(org.junit.Before)

Aggregations

ConfigurationNameMapper (org.apache.cayenne.configuration.ConfigurationNameMapper)6 DataMapLoader (org.apache.cayenne.configuration.DataMapLoader)6 DefaultConfigurationNameMapper (org.apache.cayenne.configuration.DefaultConfigurationNameMapper)6 DataChannelMetaData (org.apache.cayenne.configuration.xml.DataChannelMetaData)6 DefaultHandlerFactory (org.apache.cayenne.configuration.xml.DefaultHandlerFactory)6 HandlerFactory (org.apache.cayenne.configuration.xml.HandlerFactory)6 NoopDataChannelMetaData (org.apache.cayenne.configuration.xml.NoopDataChannelMetaData)6 XMLDataMapLoader (org.apache.cayenne.configuration.xml.XMLDataMapLoader)6 XMLReaderProvider (org.apache.cayenne.configuration.xml.XMLReaderProvider)6 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)6 ClassLoaderManager (org.apache.cayenne.di.ClassLoaderManager)6 DefaultAdhocObjectFactory (org.apache.cayenne.di.spi.DefaultAdhocObjectFactory)6 DefaultClassLoaderManager (org.apache.cayenne.di.spi.DefaultClassLoaderManager)6 XMLDataChannelDescriptorLoader (org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader)5 URL (java.net.URL)4 DataChannelDescriptorLoader (org.apache.cayenne.configuration.DataChannelDescriptorLoader)4 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 DefaultObjectMapRetainStrategy (org.apache.cayenne.access.DefaultObjectMapRetainStrategy)2 ObjectMapRetainStrategy (org.apache.cayenne.access.ObjectMapRetainStrategy)2