Java Code Examples for com.activeandroid.ActiveAndroid#endTransaction()

The following examples show how to use com.activeandroid.ActiveAndroid#endTransaction() . 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: MainActivity.java    From multi-column-list-adapter with Apache License 2.0 6 votes vote down vote up
private void loadToastersIntoDatabase() {
    List<ToasterModel> toasterModels = new Select().from(ToasterModel.class).execute();
    if (toasterModels == null || toasterModels.size() == 0) {
        ActiveAndroid.beginTransaction();
        try {
            Toaster[] toasters = ToasterData.getToasters();
            for (Toaster toaster : toasters) {
                ToasterModel toasterModel = new ToasterModel();
                toasterModel.name = toaster.name;
                toasterModel.imageResId = toaster.imageResId;
                toasterModel.save();
            }
            ActiveAndroid.setTransactionSuccessful();
        } finally {
            ActiveAndroid.endTransaction();
        }
    }
}
 
Example 2
Source File: AbsDbAPI.java    From umeng_community_android with MIT License 5 votes vote down vote up
@Override
public final void run() {
    ActiveAndroid.beginTransaction();
    execute();
    ActiveAndroid.setTransactionSuccessful();
    ActiveAndroid.endTransaction();
}
 
Example 3
Source File: InsertTest.java    From AirData with MIT License 5 votes vote down vote up
public void testActiveAndroidBulkInsertWithTransaction() {
    ActiveAndroid.initialize(getContext());
    ActiveAndroid.beginTransaction();
    for (int i = 0; i < 10000; i++) {
        Student2 stu = new Student2();
        stu.setMark((char) (i % 24 + 64));
        stu.setName("name" + i);
        stu.setScore(i);
        stu.save();
    }
    ActiveAndroid.setTransactionSuccessful();
    ActiveAndroid.endTransaction();
}
 
Example 4
Source File: AATest.java    From Storm with Apache License 2.0 5 votes vote down vote up
@Override
protected void insert(List<AAObject> list) {
    ActiveAndroid.beginTransaction();
    try {
        for (AAObject aaObject: list) {
            aaObject.save();
        }
        ActiveAndroid.setTransactionSuccessful();
    } finally {
        ActiveAndroid.endTransaction();
    }
}
 
Example 5
Source File: ActiveAndroidSampleActivity.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ActiveAndroid.beginTransaction();
    try {
        List<Todo> ended = new Select()
                .from(Todo.class)
                .where(Todo.COLUMN_STATUS + "=?",
                        Integer.toString(TodoDaoHelper.STATUS_END))
                .execute();
        for (Todo todo : ended) {
            todo.setStatus(TodoDaoHelper.STATUS_ARCHIVE);
            todo.save();
        }
        ActiveAndroid.setTransactionSuccessful();
    } finally {
        ActiveAndroid.endTransaction();
    }

    // 画面更新
    if (mTodoFragment != null) {
        mTodoFragment.reload();
    }
    if (mHistoryFragment != null) {
        mHistoryFragment.reload();
    }

    return true;
}
 
Example 6
Source File: PerfTestActiveAndroid.java    From android-database-performance with Apache License 2.0 4 votes vote down vote up
private void indexedStringEntityQueriesRun(int count) {
    // create entities
    List<IndexedStringEntity> entities = new ArrayList<>(count);
    String[] fixedRandomStrings = StringGenerator.createFixedRandomStrings(count);
    for (int i = 0; i < count; i++) {
        IndexedStringEntity entity = new IndexedStringEntity();
        entity.indexedString = fixedRandomStrings[i];
        entities.add(entity);
    }
    log("Built entities.");

    // insert entities
    ActiveAndroid.beginTransaction();
    try {
        for (int i = 0; i < count; i++) {
            entities.get(i).save();
        }
        ActiveAndroid.setTransactionSuccessful();
    } finally {
        ActiveAndroid.endTransaction();
    }
    log("Inserted entities.");

    // query for entities by indexed string at random
    int[] randomIndices = StringGenerator.getFixedRandomIndices(getQueryCount(), count - 1);

    startClock();
    for (int i = 0; i < getQueryCount(); i++) {
        int nextIndex = randomIndices[i];
        //noinspection unused
        List<IndexedStringEntity> query = new Select()
                .from(IndexedStringEntity.class)
                .where("INDEXED_STRING = ?", fixedRandomStrings[nextIndex])
                .execute();
        // ActiveAndroid already builds all entities when executing the query, so move on
    }
    stopClock(Benchmark.Type.QUERY_INDEXED);

    // delete all entities
    ActiveAndroid.execSQL("DELETE FROM INDEXED_STRING_ENTITY");
    log("Deleted all entities.");
}
 
Example 7
Source File: PerfTestActiveAndroid.java    From android-database-performance with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("ResultOfMethodCallIgnored")
@Override
protected void doBatchCrudRun(int count) throws Exception {
    final List<SimpleEntityNotNull> list = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        list.add(SimpleEntityNotNullHelper.createEntity());
    }

    startClock();
    ActiveAndroid.beginTransaction();
    try {
        for (int i = 0; i < count; i++) {
            list.get(i).save();
        }
        ActiveAndroid.setTransactionSuccessful();
    } finally {
        ActiveAndroid.endTransaction();
    }
    stopClock(Benchmark.Type.BATCH_CREATE);

    startClock();
    ActiveAndroid.beginTransaction();
    try {
        for (int i = 0; i < count; i++) {
            list.get(i).save();
        }
        ActiveAndroid.setTransactionSuccessful();
    } finally {
        ActiveAndroid.endTransaction();
    }
    stopClock(Benchmark.Type.BATCH_UPDATE);

    startClock();
    List<SimpleEntityNotNull> reloaded = new Select()
            .all()
            .from(SimpleEntityNotNull.class)
            .execute();
    stopClock(Benchmark.Type.BATCH_READ);

    startClock();
    for (int i = 0; i < reloaded.size(); i++) {
        SimpleEntityNotNull entity = reloaded.get(i);
        entity.getId();
        entity.getSimpleBoolean();
        entity.getSimpleByte();
        entity.getSimpleShort();
        entity.getSimpleInt();
        entity.getSimpleLong();
        entity.getSimpleFloat();
        entity.getSimpleDouble();
        entity.getSimpleString();
        entity.getSimpleByteArray();
    }
    stopClock(Benchmark.Type.BATCH_ACCESS);

    startClock();
    deleteAll();
    stopClock(Benchmark.Type.BATCH_DELETE);
}
 
Example 8
Source File: ActiveAndroidActivity.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
private void initSampleData() {
    new Delete().from(Book.class).execute();

    ActiveAndroid.beginTransaction();

    try {
        Book book1 = new Book("Android Cookbook",
                "Ian F. Darwin",
                "O'Reilly Media" ,
                "April 2012");
        book1.save();

        Book book2 = new Book("Android Recipes, 3rd Edition",
                "Dave Smith , Jeff Friesen",
                "Apress",
                "February 2014");
        book2.save();

        Book book3 = new Book("Expert Android",
                "Satya Komatineni, Dave MacLean",
                "Apress",
                "July 2013");
        book3.save();

        Book book4 = new Book("50 Android Hacks",
                "Carlos Sessa",
                "Manning Publications",
                "May 2013");
        book4.save();

        Book book5 = new Book("Learn Java for Android Development, 3rd Edition",
                "Jeff Friesen",
                "Apress",
                "March 2014");
        book5.save();

        Book book6 = new Book("Learning Android, 2nd Edition",
                "Marko Gargenta, Masumi Nakamura",
                "O'Reilly Media, Inc.",
                "January 2014");
        book6.save();
    } finally {
        ActiveAndroid.setTransactionSuccessful();
    }

    ActiveAndroid.endTransaction();
}
 
Example 9
Source File: LoadActivity.java    From AnimeTaste with MIT License 4 votes vote down vote up
@Override
protected Boolean doInBackground(Void... voids) {
    try {
        JSONObject list = mSetupResponse.getJSONObject("data").getJSONObject("list");
        JSONArray animations = list.getJSONArray("anime");
        JSONArray category = list.getJSONArray("category");
        JSONArray advert = null;

        if (list.has("advert"))
            advert = list.getJSONArray("advert");

        JSONArray feature = list.getJSONArray("recommend");
        ArrayList<Animation> Animations = Animation.build(animations);
        ArrayList<Category> Categories = new ArrayList<Category>();
        ArrayList<Advertise> Advertises = new ArrayList<Advertise>();
        ArrayList<Animation> Recommends = new ArrayList<Animation>();
        new Delete().from(Animation.class).where("IsFavorite='0'").execute();
        new Delete().from(Category.class).execute();
        new Delete().from(Advertise.class).execute();
        ActiveAndroid.beginTransaction();


        for (int i = 0; i < Animations.size(); i++) {
            Animations.get(i).save();
        }
        for (int i = 0; i < category.length(); i++) {
            Category cat = Category.build(category.getJSONObject(i));
            Categories.add(cat);
            cat.save();
        }

        if (advert != null) {
            for (int i = 0; i < advert.length(); i++) {
                Advertise ad = Advertise.build(advert.getJSONObject(i));
                Advertises.add(ad);
                ad.save();
            }
        }

        for (int i = 0; i < feature.length(); i++) {
            Recommends.add(Animation.build(feature.getJSONObject(i)));
        }
        mIntent = new Intent(LoadActivity.this,
                StartActivity.class);
        mIntent.putParcelableArrayListExtra("Animations", Animations);
        mIntent.putParcelableArrayListExtra("Categories", Categories);
        mIntent.putParcelableArrayListExtra("Advertises", Advertises);
        mIntent.putParcelableArrayListExtra("Recommends", Recommends);
        mIntent.putExtra("Success", true);
        mResult = true;
    } catch (Exception e) {
        e.printStackTrace();
        mResult = false;
    } finally {
        ActiveAndroid.setTransactionSuccessful();
        ActiveAndroid.endTransaction();
        return mResult;
    }
}