Search in sources :

Example 31 with Student

use of com.litepaltest.model.Student in project LitePal by LitePalFramework.

the class DeleteTest method testMarkAsDeleted.

public void testMarkAsDeleted() {
    List<Student> students = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        Student s = new Student();
        s.setName("Dusting");
        s.setAge(i + 10);
        students.add(s);
    }
    DataSupport.saveAll(students);
    List<Student> list = DataSupport.where("name=?", "Dusting").find(Student.class);
    assertTrue(list.size() >= 5);
    DataSupport.deleteAll(Student.class, "name=?", "Dusting");
    list = DataSupport.where("name=?", "Dusting").find(Student.class);
    assertEquals(0, list.size());
    DataSupport.saveAll(students);
    list = DataSupport.where("name=?", "Dusting").find(Student.class);
    assertEquals(0, list.size());
    DataSupport.markAsDeleted(students);
    DataSupport.saveAll(students);
    list = DataSupport.where("name=?", "Dusting").find(Student.class);
    assertEquals(5, list.size());
}
Also used : ArrayList(java.util.ArrayList) Student(com.litepaltest.model.Student)

Example 32 with Student

use of com.litepaltest.model.Student in project LitePal by LitePalFramework.

the class DeleteTest method testDeleteWithNoParameter.

public void testDeleteWithNoParameter() {
    initJude();
    jude.save();
    int rowsAffected = jude.delete();
    assertEquals(1, rowsAffected);
    Student s = getStudent(jude.getId());
    assertNull(s);
}
Also used : Student(com.litepaltest.model.Student)

Example 33 with Student

use of com.litepaltest.model.Student in project LitePal by LitePalFramework.

the class DeleteTest method initRose.

private void initRose() {
    rose = new Student();
    rose.setName("Rose");
    rose.setAge(15);
    roseCard = new IdCard();
    roseCard.setAddress("Rose Street");
    roseCard.setNumber("123457");
    roseCard.setStudent(rose);
}
Also used : IdCard(com.litepaltest.model.IdCard) Student(com.litepaltest.model.Student)

Example 34 with Student

use of com.litepaltest.model.Student in project LitePal by LitePalFramework.

the class DeleteTest method testDeleteAll.

public void testDeleteAll() {
    Student s;
    int[] ids = new int[5];
    for (int i = 0; i < 5; i++) {
        s = new Student();
        s.setName("Dusting");
        s.setAge(i + 10086);
        s.save();
        ids[i] = s.getId();
    }
    int affectedRows = DataSupport.deleteAll(Student.class, "name = ? and age = ?", "Dusting", "10088");
    assertEquals(1, affectedRows);
    assertNull(getStudent(ids[2]));
    affectedRows = DataSupport.deleteAll(Student.class, "name = ? and age > ? and age < ?", "Dusting", "10085", "10092");
    assertEquals(4, affectedRows);
}
Also used : Student(com.litepaltest.model.Student)

Aggregations

Student (com.litepaltest.model.Student)34 Classroom (com.litepaltest.model.Classroom)11 Teacher (com.litepaltest.model.Teacher)11 IdCard (com.litepaltest.model.IdCard)8 ArrayList (java.util.ArrayList)5 Cursor (android.database.Cursor)4 Calendar (java.util.Calendar)4 Random (java.util.Random)4 Date (java.util.Date)2 ContentValues (android.content.ContentValues)1 SQLiteException (android.database.sqlite.SQLiteException)1 Cellphone (com.litepaltest.model.Cellphone)1 DataSupportException (org.litepal.exceptions.DataSupportException)1