Search in sources :

Example 11 with EntityModel

use of io.requery.meta.EntityModel in project requery by requery.

the class SchemaModifierTest method setup.

@Before
public void setup() throws SQLException {
    CommonDataSource dataSource = DatabaseType.getDataSource(platform);
    EntityModel model = io.requery.test.model.Models.DEFAULT;
    Configuration configuration = new ConfigurationBuilder(dataSource, model).useDefaultLogging().setStatementCacheSize(10).setBatchUpdateSize(50).setWriteExecutor(Executors.newSingleThreadExecutor()).build();
    schemaModifier = new SchemaModifier(configuration);
    try {
        schemaModifier.dropTables();
    } catch (Exception e) {
        // expected if 'drop if exists' not supported (so ignore in that case)
        if (!platform.supportsIfExists()) {
            throw e;
        }
    }
    schemaModifier.createTables(TableCreationMode.CREATE);
}
Also used : ConfigurationBuilder(io.requery.sql.ConfigurationBuilder) Configuration(io.requery.sql.Configuration) EntityModel(io.requery.meta.EntityModel) CommonDataSource(javax.sql.CommonDataSource) SQLException(java.sql.SQLException) SchemaModifier(io.requery.sql.SchemaModifier) Before(org.junit.Before)

Example 12 with EntityModel

use of io.requery.meta.EntityModel in project requery by requery.

the class AutoValueModelTest method setup.

@Before
public void setup() throws SQLException {
    CommonDataSource dataSource = DatabaseType.getDataSource(new SQLite());
    EntityModel model = Models.AUTOVALUE;
    Configuration configuration = new ConfigurationBuilder(dataSource, model).useDefaultLogging().setEntityCache(new EntityCacheBuilder(model).useReferenceCache(true).build()).build();
    data = new EntityDataStore<>(configuration);
    SchemaModifier tables = new SchemaModifier(configuration);
    tables.dropTables();
    TableCreationMode mode = TableCreationMode.CREATE_NOT_EXISTS;
    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) SQLite(io.requery.sql.platform.SQLite) EntityModel(io.requery.meta.EntityModel) EntityCacheBuilder(io.requery.cache.EntityCacheBuilder) CommonDataSource(javax.sql.CommonDataSource) SchemaModifier(io.requery.sql.SchemaModifier) Before(org.junit.Before)

Example 13 with EntityModel

use of io.requery.meta.EntityModel 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 14 with EntityModel

use of io.requery.meta.EntityModel in project requery by requery.

the class UpsertTest method setup.

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

Aggregations

EntityModel (io.requery.meta.EntityModel)14 Configuration (io.requery.sql.Configuration)13 SchemaModifier (io.requery.sql.SchemaModifier)13 ConfigurationBuilder (io.requery.sql.ConfigurationBuilder)12 CommonDataSource (javax.sql.CommonDataSource)12 Before (org.junit.Before)12 EntityCacheBuilder (io.requery.cache.EntityCacheBuilder)6 EntityDataStore (io.requery.sql.EntityDataStore)5 Platform (io.requery.sql.Platform)5 HSQL (io.requery.sql.platform.HSQL)5 CacheManager (javax.cache.CacheManager)5 CachingProvider (javax.cache.spi.CachingProvider)5 EmptyEntityCache (io.requery.cache.EmptyEntityCache)3 TableCreationMode (io.requery.sql.TableCreationMode)3 SQLite (io.requery.sql.platform.SQLite)3 SQLException (java.sql.SQLException)3 TransactionIsolation (io.requery.TransactionIsolation)1 TransactionListener (io.requery.TransactionListener)1 DatabaseSource (io.requery.android.sqlite.DatabaseSource)1 WeakEntityCache (io.requery.cache.WeakEntityCache)1