Search in sources :

Example 6 with CommonDataSource

use of javax.sql.CommonDataSource in project requery by requery.

the class TimeConversionsTest method setup.

@Before
public void setup() throws SQLException {
    Platform platform = new HSQL();
    CommonDataSource dataSource = DatabaseType.getDataSource(platform);
    EntityModel model = Models.MODEL2;
    Configuration configuration = new ConfigurationBuilder(dataSource, model).useDefaultLogging().setEntityCache(new EmptyEntityCache()).setWriteExecutor(Executors.newSingleThreadExecutor()).build();
    SchemaModifier tables = new SchemaModifier(configuration);
    tables.createTables(TableCreationMode.DROP_CREATE);
    data = new EntityDataStore<>(configuration);
}
Also used : ConfigurationBuilder(io.requery.sql.ConfigurationBuilder) Platform(io.requery.sql.Platform) Configuration(io.requery.sql.Configuration) EmptyEntityCache(io.requery.cache.EmptyEntityCache) HSQL(io.requery.sql.platform.HSQL) EntityModel(io.requery.meta.EntityModel) CommonDataSource(javax.sql.CommonDataSource) SchemaModifier(io.requery.sql.SchemaModifier) Before(org.junit.Before)

Example 7 with CommonDataSource

use of javax.sql.CommonDataSource in project requery by requery.

the class JPAModelTest method setup.

@Before
public void setup() throws SQLException {
    CommonDataSource dataSource = DatabaseType.getDataSource(new H2());
    EntityModel model = Models.JPA;
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    Configuration configuration = new ConfigurationBuilder(dataSource, model).useDefaultLogging().setEntityCache(new EntityCacheBuilder(model).useReferenceCache(true).useSerializableCache(true).useCacheManager(cacheManager).build()).build();
    data = new EntityDataStore<>(configuration);
    SchemaModifier tables = new SchemaModifier(configuration);
    tables.dropTables();
    TableCreationMode mode = TableCreationMode.CREATE;
    System.out.println(tables.createTablesString(mode));
    tables.createTables(mode);
}
Also used : ConfigurationBuilder(io.requery.sql.ConfigurationBuilder) Configuration(io.requery.sql.Configuration) TableCreationMode(io.requery.sql.TableCreationMode) EntityModel(io.requery.meta.EntityModel) CacheManager(javax.cache.CacheManager) H2(io.requery.sql.platform.H2) EntityCacheBuilder(io.requery.cache.EntityCacheBuilder) CommonDataSource(javax.sql.CommonDataSource) CachingProvider(javax.cache.spi.CachingProvider) SchemaModifier(io.requery.sql.SchemaModifier) Before(org.junit.Before)

Example 8 with CommonDataSource

use of javax.sql.CommonDataSource in project hazelcast by hazelcast.

the class WriteJdbcP method metaSupplier.

/**
 * Use {@link SinkProcessors#writeJdbcP}.
 */
public static <T> ProcessorMetaSupplier metaSupplier(@Nullable String jdbcUrl, @Nonnull String updateQuery, @Nonnull SupplierEx<? extends CommonDataSource> dataSourceSupplier, @Nonnull BiConsumerEx<? super PreparedStatement, ? super T> bindFn, boolean exactlyOnce, int batchLimit) {
    checkSerializable(dataSourceSupplier, "newConnectionFn");
    checkSerializable(bindFn, "bindFn");
    checkPositive(batchLimit, "batchLimit");
    return ProcessorMetaSupplier.preferLocalParallelismOne(ConnectorPermission.jdbc(jdbcUrl, ACTION_WRITE), new ProcessorSupplier() {

        private transient CommonDataSource dataSource;

        @Override
        public void init(@Nonnull Context context) {
            dataSource = dataSourceSupplier.get();
        }

        @Nonnull
        @Override
        public Collection<? extends Processor> get(int count) {
            return IntStream.range(0, count).mapToObj(i -> new WriteJdbcP<>(updateQuery, dataSource, bindFn, exactlyOnce, batchLimit)).collect(Collectors.toList());
        }

        @Override
        public List<Permission> permissions() {
            return singletonList(ConnectorPermission.jdbc(jdbcUrl, ACTION_WRITE));
        }
    });
}
Also used : Processor(com.hazelcast.jet.core.Processor) Nonnull(javax.annotation.Nonnull) Collection(java.util.Collection) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) CommonDataSource(javax.sql.CommonDataSource)

Example 9 with CommonDataSource

use of javax.sql.CommonDataSource in project tomee by apache.

the class PoolDataSourceCreator method poolManagedWithRecovery.

@Override
public DataSource poolManagedWithRecovery(final String name, final XAResourceWrapper xaResourceWrapper, final String driver, final Properties properties) {
    final TransactionManager transactionManager = new TransactionManagerWrapper(OpenEJB.getTransactionManager(), name, xaResourceWrapper);
    final CommonDataSource ds = pool(name, driver, properties);
    if (ds instanceof XADataSource) {
        return new ManagedXADataSource(ds, transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
    }
    return new ManagedDataSource(DataSource.class.cast(ds), transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
}
Also used : XADataSource(javax.sql.XADataSource) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource) TransactionManager(javax.transaction.TransactionManager) TransactionManagerWrapper(org.apache.openejb.resource.TransactionManagerWrapper) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) CommonDataSource(javax.sql.CommonDataSource) ManagedDataSource(org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource) ManagedDataSource(org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource) XADataSource(javax.sql.XADataSource) CommonDataSource(javax.sql.CommonDataSource) DataSource(javax.sql.DataSource) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource)

Example 10 with CommonDataSource

use of javax.sql.CommonDataSource in project tomee by apache.

the class JTADataSourceWrapperFactory method create.

public CommonDataSource create() {
    final TransactionManager transactionManager = OpenEJB.getTransactionManager();
    CommonDataSource cds = findDelegate();
    if (cds instanceof XADataSource) {
        cds = new ManagedXADataSource(cds, transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
    } else {
        cds = new ManagedDataSource(DataSource.class.cast(cds), transactionManager, SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class));
    }
    if (logSql) {
        cds = DataSourceFactory.makeItLogging(cds, logPackages);
    }
    return cds;
}
Also used : XADataSource(javax.sql.XADataSource) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource) TransactionManager(javax.transaction.TransactionManager) ManagedXADataSource(org.apache.openejb.resource.jdbc.managed.xa.ManagedXADataSource) CommonDataSource(javax.sql.CommonDataSource) ManagedDataSource(org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource)

Aggregations

CommonDataSource (javax.sql.CommonDataSource)23 EntityModel (io.requery.meta.EntityModel)12 Configuration (io.requery.sql.Configuration)12 ConfigurationBuilder (io.requery.sql.ConfigurationBuilder)12 SchemaModifier (io.requery.sql.SchemaModifier)12 Before (org.junit.Before)12 EntityCacheBuilder (io.requery.cache.EntityCacheBuilder)6 Platform (io.requery.sql.Platform)5 HSQL (io.requery.sql.platform.HSQL)5 CacheManager (javax.cache.CacheManager)5 CachingProvider (javax.cache.spi.CachingProvider)5 EntityDataStore (io.requery.sql.EntityDataStore)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 DataSource (javax.sql.DataSource)4 XADataSource (javax.sql.XADataSource)4 EmptyEntityCache (io.requery.cache.EmptyEntityCache)3 TableCreationMode (io.requery.sql.TableCreationMode)3 SQLite (io.requery.sql.platform.SQLite)3 SQLException (java.sql.SQLException)3 Flushable (java.io.Flushable)2