Search in sources :

Example 1 with BindSimpleDataSource

use of sqlite.feature.performance.simple.BindSimpleDataSource in project kripton by xcesco.

the class TestPerformanceRuntime method testRunSave.

@Test
public void testRunSave() {
    // delete all
    final BindSimpleDataSource dataSource = BindSimpleDataSource.instance();
    dataSource.execute(new BindSimpleDataSource.Transaction() {

        @Override
        public TransactionResult onExecute(BindSimpleDaoFactory daoFactory) {
            daoFactory.getSimpleAddressDao().deleteAll();
            Collection<SimpleAddressItem> simpleAddressItems = Generator.getKriptonSimpleAddresses(SimpleAddressItem.class, LOOP_COUNT);
            long insertDuration;
            long insertOptimizedDuration;
            // normal INSERT
            {
                log("insert NORMAL start");
                long startTime = System.currentTimeMillis();
                for (SimpleAddressItem simpleAddressItem : simpleAddressItems) {
                    daoFactory.getSimpleAddressDao().insert(simpleAddressItem);
                }
                insertDuration = System.currentTimeMillis() - startTime;
                log("insert duration: %s", insertDuration);
            }
            // end
            daoFactory.getSimpleAddressDao().deleteAll();
            // optimized INSERT
            {
                log("insert OPTIZED start");
                long startTime = System.currentTimeMillis();
                for (SimpleAddressItem simpleAddressItem : simpleAddressItems) {
                    daoFactory.getSimpleAddressDao().insert(simpleAddressItem);
                }
                insertOptimizedDuration = System.currentTimeMillis() - startTime;
                log("insert OPTIMIZED duration: %s", insertOptimizedDuration);
            }
            // end
            return TransactionResult.COMMIT;
        }
    });
}
Also used : SimpleAddressItem(sqlite.feature.performance.simple.SimpleAddressItem) BindSimpleDataSource(sqlite.feature.performance.simple.BindSimpleDataSource) TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) BindSimpleDaoFactory(sqlite.feature.performance.simple.BindSimpleDaoFactory) Collection(java.util.Collection) Test(org.junit.Test) BaseAndroidTest(base.BaseAndroidTest)

Aggregations

BaseAndroidTest (base.BaseAndroidTest)1 TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)1 Collection (java.util.Collection)1 Test (org.junit.Test)1 BindSimpleDaoFactory (sqlite.feature.performance.simple.BindSimpleDaoFactory)1 BindSimpleDataSource (sqlite.feature.performance.simple.BindSimpleDataSource)1 SimpleAddressItem (sqlite.feature.performance.simple.SimpleAddressItem)1