Search in sources :

Example 1 with EntityDataStore

use of io.requery.sql.EntityDataStore in project requery by requery.

the class PeopleApplication method getData.

/**
     * @return {@link EntityDataStore} single instance for the application.
     * <p/>
     * Note if you're using Dagger you can make this part of your application level module returning
     * {@code @Provides @Singleton}.
     */
ReactiveEntityStore<Persistable> getData() {
    if (dataStore == null) {
        // override onUpgrade to handle migrating to a new version
        DatabaseSource source = new DatabaseSource(this, Models.DEFAULT, 1);
        if (BuildConfig.DEBUG) {
            // use this in development mode to drop and recreate the tables on every upgrade
            source.setTableCreationMode(TableCreationMode.DROP_CREATE);
        }
        Configuration configuration = source.getConfiguration();
        dataStore = ReactiveSupport.toReactiveStore(new EntityDataStore<Persistable>(configuration));
    }
    return dataStore;
}
Also used : DatabaseSource(io.requery.android.sqlite.DatabaseSource) Configuration(io.requery.sql.Configuration) EntityDataStore(io.requery.sql.EntityDataStore)

Example 2 with EntityDataStore

use of io.requery.sql.EntityDataStore in project requery by requery.

the class RxTest method setup.

@Before
public void setup() throws SQLException {
    Platform platform = new HSQL();
    CommonDataSource dataSource = DatabaseType.getDataSource(platform);
    EntityModel model = io.requery.test.model.Models.DEFAULT;
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    Configuration configuration = new ConfigurationBuilder(dataSource, model).useDefaultLogging().setWriteExecutor(Executors.newSingleThreadExecutor()).setEntityCache(new EntityCacheBuilder(model).useReferenceCache(true).useSerializableCache(true).useCacheManager(cacheManager).build()).build();
    SchemaModifier tables = new SchemaModifier(configuration);
    tables.createTables(TableCreationMode.DROP_CREATE);
    data = RxSupport.toReactiveStore(new EntityDataStore<Persistable>(configuration));
}
Also used : ConfigurationBuilder(io.requery.sql.ConfigurationBuilder) Platform(io.requery.sql.Platform) Configuration(io.requery.sql.Configuration) HSQL(io.requery.sql.platform.HSQL) EntityDataStore(io.requery.sql.EntityDataStore) EntityModel(io.requery.meta.EntityModel) CacheManager(javax.cache.CacheManager) EntityCacheBuilder(io.requery.cache.EntityCacheBuilder) CommonDataSource(javax.sql.CommonDataSource) CachingProvider(javax.cache.spi.CachingProvider) SchemaModifier(io.requery.sql.SchemaModifier) Before(org.junit.Before)

Example 3 with EntityDataStore

use of io.requery.sql.EntityDataStore in project requery by requery.

the class ReactorTest method setup.

@Before
public void setup() throws SQLException {
    Platform platform = new HSQL();
    CommonDataSource dataSource = DatabaseType.getDataSource(platform);
    EntityModel model = io.requery.test.model.Models.DEFAULT;
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    Configuration configuration = new ConfigurationBuilder(dataSource, model).useDefaultLogging().setWriteExecutor(Executors.newSingleThreadExecutor()).setEntityCache(new EntityCacheBuilder(model).useReferenceCache(true).useSerializableCache(true).useCacheManager(cacheManager).build()).build();
    SchemaModifier tables = new SchemaModifier(configuration);
    tables.createTables(TableCreationMode.DROP_CREATE);
    data = new ReactorEntityStore<>(new EntityDataStore<Persistable>(configuration));
}
Also used : ConfigurationBuilder(io.requery.sql.ConfigurationBuilder) Platform(io.requery.sql.Platform) Configuration(io.requery.sql.Configuration) HSQL(io.requery.sql.platform.HSQL) EntityDataStore(io.requery.sql.EntityDataStore) EntityModel(io.requery.meta.EntityModel) CacheManager(javax.cache.CacheManager) EntityCacheBuilder(io.requery.cache.EntityCacheBuilder) CommonDataSource(javax.sql.CommonDataSource) CachingProvider(javax.cache.spi.CachingProvider) SchemaModifier(io.requery.sql.SchemaModifier) Before(org.junit.Before)

Example 4 with EntityDataStore

use of io.requery.sql.EntityDataStore in project requery by requery.

the class CompletableEntityStoreTest method setup.

@Before
public void setup() throws SQLException {
    Platform platform = new HSQL();
    CommonDataSource dataSource = DatabaseType.getDataSource(platform);
    EntityModel model = io.requery.test.model.Models.DEFAULT;
    final TransactionListener transactionListener = new TransactionListener() {

        @Override
        public void beforeBegin(TransactionIsolation isolation) {
        }

        @Override
        public void afterBegin(TransactionIsolation isolation) {
            transactionState = TransactionState.BEGIN;
        }

        @Override
        public void beforeCommit(Set<Type<?>> types) {
        }

        @Override
        public void afterCommit(Set<Type<?>> types) {
            transactionState = TransactionState.COMMIT;
        }

        @Override
        public void beforeRollback(Set<Type<?>> types) {
        }

        @Override
        public void afterRollback(Set<Type<?>> types) {
            transactionState = TransactionState.ROLLBACK;
        }
    };
    Configuration configuration = new ConfigurationBuilder(dataSource, model).useDefaultLogging().setStatementCacheSize(10).setBatchUpdateSize(50).setWriteExecutor(Executors.newSingleThreadExecutor()).addTransactionListenerFactory(new Supplier<TransactionListener>() {

        @Override
        public TransactionListener get() {
            return transactionListener;
        }
    }).build();
    data = new CompletableEntityStore<>(new EntityDataStore<Persistable>(configuration));
    SchemaModifier tables = new SchemaModifier(configuration);
    tables.createTables(TableCreationMode.DROP_CREATE);
}
Also used : TransactionListener(io.requery.TransactionListener) ConfigurationBuilder(io.requery.sql.ConfigurationBuilder) HashSet(java.util.HashSet) Set(java.util.Set) Platform(io.requery.sql.Platform) Configuration(io.requery.sql.Configuration) HSQL(io.requery.sql.platform.HSQL) TransactionIsolation(io.requery.TransactionIsolation) EntityModel(io.requery.meta.EntityModel) CommonDataSource(javax.sql.CommonDataSource) SchemaModifier(io.requery.sql.SchemaModifier) EntityDataStore(io.requery.sql.EntityDataStore) Supplier(io.requery.util.function.Supplier) Before(org.junit.Before)

Example 5 with EntityDataStore

use of io.requery.sql.EntityDataStore in project requery by requery.

the class ReactiveTest method setup.

@Before
public void setup() throws SQLException {
    Platform platform = new HSQL();
    CommonDataSource dataSource = DatabaseType.getDataSource(platform);
    EntityModel model = io.requery.test.model.Models.DEFAULT;
    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    Configuration configuration = new ConfigurationBuilder(dataSource, model).useDefaultLogging().setWriteExecutor(Executors.newSingleThreadExecutor()).setEntityCache(new EntityCacheBuilder(model).useReferenceCache(true).useSerializableCache(true).useCacheManager(cacheManager).build()).build();
    SchemaModifier tables = new SchemaModifier(configuration);
    tables.createTables(TableCreationMode.DROP_CREATE);
    data = ReactiveSupport.toReactiveStore(new EntityDataStore<Persistable>(configuration));
}
Also used : ConfigurationBuilder(io.requery.sql.ConfigurationBuilder) Platform(io.requery.sql.Platform) Configuration(io.requery.sql.Configuration) HSQL(io.requery.sql.platform.HSQL) EntityDataStore(io.requery.sql.EntityDataStore) EntityModel(io.requery.meta.EntityModel) CacheManager(javax.cache.CacheManager) EntityCacheBuilder(io.requery.cache.EntityCacheBuilder) CommonDataSource(javax.sql.CommonDataSource) CachingProvider(javax.cache.spi.CachingProvider) SchemaModifier(io.requery.sql.SchemaModifier) Before(org.junit.Before)

Aggregations

Configuration (io.requery.sql.Configuration)5 EntityDataStore (io.requery.sql.EntityDataStore)5 EntityModel (io.requery.meta.EntityModel)4 ConfigurationBuilder (io.requery.sql.ConfigurationBuilder)4 Platform (io.requery.sql.Platform)4 SchemaModifier (io.requery.sql.SchemaModifier)4 HSQL (io.requery.sql.platform.HSQL)4 CommonDataSource (javax.sql.CommonDataSource)4 Before (org.junit.Before)4 EntityCacheBuilder (io.requery.cache.EntityCacheBuilder)3 CacheManager (javax.cache.CacheManager)3 CachingProvider (javax.cache.spi.CachingProvider)3 TransactionIsolation (io.requery.TransactionIsolation)1 TransactionListener (io.requery.TransactionListener)1 DatabaseSource (io.requery.android.sqlite.DatabaseSource)1 Supplier (io.requery.util.function.Supplier)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1