io.requery.sql.EntityDataStore Java Examples

The following examples show how to use io.requery.sql.EntityDataStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveTest.java    From requery with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #2
Source File: BenchmarkTest.java    From requery with Apache License 2.0 6 votes vote down vote up
@Setup
public void setup() {
    EntityModel model = Models.DEFAULT;
    dataSource = (DataSource) DatabaseType.getDataSource(platform);
    data = new EntityDataStore<>(dataSource, model);
    new SchemaModifier(dataSource, model).createTables(TableCreationMode.DROP_CREATE);
    final int count = 10000;
    data.runInTransaction(new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            for (int i = 0; i < count; i++) {
                Person person = FunctionalTest.randomPerson();
                data.insert(person);
            }
            return null;
        }
    });
}
 
Example #3
Source File: AutoValueModelTest.java    From requery with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: StatelessTest.java    From requery with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws SQLException {
    CommonDataSource dataSource = DatabaseType.getDataSource(platform);
    EntityModel model = Models.STATELESS;

    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);
}
 
Example #5
Source File: ReactorTest.java    From requery with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #6
Source File: TimeConversionsTest.java    From requery with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #7
Source File: JPAModelTest.java    From requery with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #8
Source File: UpsertTest.java    From requery with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #9
Source File: JacksonTest.java    From requery with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws SQLException {
    CommonDataSource dataSource = DatabaseType.getDataSource(new SQLite());
    EntityModel model = Models.MODEL3;
    Configuration configuration = new ConfigurationBuilder(dataSource, model)
        .useDefaultLogging()
        .setEntityCache(new WeakEntityCache())
        .setWriteExecutor(Executors.newSingleThreadExecutor())
        .build();

    SchemaModifier tables = new SchemaModifier(configuration);
    tables.createTables(TableCreationMode.DROP_CREATE);
    data = new EntityDataStore<>(configuration);
}
 
Example #10
Source File: PerfTestRequery.java    From android-database-performance with Apache License 2.0 5 votes vote down vote up
private void setupDatabase() {
    DatabaseSource source = new DatabaseSource(getTargetContext(), Models.DEFAULT,
            DATABASE_VERSION);
    Configuration configuration = new ConfigurationBuilder(source,
            Models.DEFAULT).setEntityCache(new EmptyEntityCache()).build();
    database = new EntityDataStore<>(configuration).toBlocking();
}
 
Example #11
Source File: ParameterizedFunctionalTest.java    From requery with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws SQLException {
    CommonDataSource dataSource = DatabaseType.getDataSource(platform);
    EntityModel model = Models.DEFAULT;

    CachingProvider provider = Caching.getCachingProvider();
    CacheManager cacheManager = provider.getCacheManager();
    Configuration configuration = new ConfigurationBuilder(dataSource, model)
        .useDefaultLogging()
        // work around bug reusing prepared statements in xerial sqlite
        .setStatementCacheSize(platform instanceof SQLite ? 0 : 10)
        .setBatchUpdateSize(50)
        .setEntityCache(new EntityCacheBuilder(model)
            .useReferenceCache(true)
            .useSerializableCache(true)
            .useCacheManager(cacheManager)
            .build())
        .build();
    data = new EntityDataStore<>(configuration);
    SchemaModifier tables = new SchemaModifier(configuration);
    try {
        tables.dropTables();
    } catch (Exception e) {
        // expected if 'drop if exists' not supported (so ignore in that case)
        if (!platform.supportsIfExists()) {
            throw e;
        }
    }
    TableCreationMode mode = TableCreationMode.CREATE;
    System.out.println(tables.createTablesString(mode));
    tables.createTables(mode);
}
 
Example #12
Source File: ModuleDatabase.java    From AndroidStarterAlt with Apache License 2.0 5 votes vote down vote up
@Provides
    @Singleton
    public SingleEntityStore<Persistable> provideDataStore(@NonNull final Context poContext) {
//        final DatabaseProvider<SQLiteDatabase> loSource = new DatabaseSource(poContext, Models.DEFAULT, "android_starter_alt.sqlite", 1);
        final DatabaseProvider<SQLiteDatabase> loSource = new SqlCipherDatabaseSource(poContext, Models.DEFAULT, "android_start_alt_requery_sqlcipher.sqlite", "android_starter_alt", 1);
        final Configuration loConfiguration = loSource.getConfiguration();
        final SingleEntityStore<Persistable> loDataStore = RxSupport.toReactiveStore(new EntityDataStore<>(loConfiguration));
        return loDataStore;
    }
 
Example #13
Source File: SqliteFunctionalTest.java    From requery with Apache License 2.0 5 votes vote down vote up
@Override
public void setup() {
    dataSource.setLoggingEnabled(true);
    Context context = InstrumentationRegistry.getContext();
    context.deleteDatabase(dbName);
    data = new EntityDataStore<>(dataSource.getConfiguration());
}
 
Example #14
Source File: PeopleApplication.java    From requery with Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example #15
Source File: PretixDroid.java    From pretixdroid with GNU General Public License v3.0 5 votes vote down vote up
public BlockingEntityStore<Persistable> getData() {
    if (dataStore == null) {
        // override onUpgrade to handle migrating to a new version
        DatabaseSource source = new DatabaseSource(this, Models.DEFAULT, 6);
        Configuration configuration = source.getConfiguration();
        dataStore = new EntityDataStore<Persistable>(configuration);
    }
    return dataStore;
}
 
Example #16
Source File: MockModuleDatabase.java    From AndroidStarterAlt with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@Override
public SingleEntityStore<Persistable> provideDataStore(@NonNull final Context poContext) {
    final DatabaseSource loSource = new DatabaseSource(poContext, Models.DEFAULT, "mock_android_starter_alt.sqlite", 1);
    final Configuration loConfiguration = loSource.getConfiguration();
    final SingleEntityStore<Persistable> loDataStore = RxSupport.toReactiveStore(new EntityDataStore<>(loConfiguration));
    return loDataStore;
}
 
Example #17
Source File: RequeryExecutor.java    From android-orm-benchmark-updated with Apache License 2.0 4 votes vote down vote up
@Override
public long readWholeData() throws SQLException {
    long start = System.nanoTime();

    final EntityDataStore<Persistable> userStore = new EntityDataStore<>(
            mHelper.getConfiguration());

    final List<UserEntity> userEntities = userStore.select(UserEntity.class).get().toList();

    String userLog = "Read " + userEntities.size() + " users in " + (System.nanoTime() - start);

    long messageStart = System.nanoTime();

    final List<MessageEntity> messageEntities = userStore.select(MessageEntity.class).get().toList();

    Log.d(TAG, userLog);
    Log.d(TAG, "Read " + messageEntities.size() + " messages in "
            + (System.nanoTime() - messageStart));

    userStore.close();

    return System.nanoTime() - start;
}
 
Example #18
Source File: RequeryExecutor.java    From android-orm-benchmark-updated with Apache License 2.0 4 votes vote down vote up
@Override
public long writeWholeData() throws SQLException {
    final List<UserEntity> users = new LinkedList<UserEntity>();
    for (int i = 0; i < NUM_USER_INSERTS; i++) {
        UserEntity newUser = new UserEntity();
        newUser.lastName = (Util.getRandomString(10));
        newUser.firstName = (Util.getRandomString(10));

        users.add(newUser);
    }

    final List<MessageEntity> messages = new LinkedList<MessageEntity>();
    for (int i = 0; i < NUM_MESSAGE_INSERTS; i++) {
        MessageEntity newMessage = new MessageEntity();
        newMessage.commandId = (i);
        newMessage.sortedBy = (System.nanoTime());
        newMessage.content = (Util.getRandomString(100));
        newMessage.clientId = (System.currentTimeMillis());
        newMessage
                .senderId = (Math.round(Math.random() * NUM_USER_INSERTS));
        newMessage
                .channelId = (Math.round(Math.random() * NUM_USER_INSERTS));
        newMessage.createdAt = ((int) (System.currentTimeMillis() / 1000L));

        messages.add(newMessage);
    }

    final EntityDataStore<Persistable> userStore = new EntityDataStore<>(mHelper.getConfiguration());

    long start = System.nanoTime();

    userStore.runInTransaction(new Callable<Object>() {
        @Override
        public Object call() throws Exception {
            userStore.insert(users, User.class);

            Log.d(TAG, "Done, wrote " + NUM_USER_INSERTS + " users");

            userStore.insert(messages, Message.class);

            Log.d(TAG, "Done, wrote " + NUM_MESSAGE_INSERTS + " messages");

            return null;
        }
    });

    userStore.close();

    return System.nanoTime() - start;
}