Search in sources :

Example 6 with Student

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

the class DeleteTest method testDeleteById.

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

Example 7 with Student

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

the class DeleteTest method testDeleteNoSavedModelWithNoParameter.

public void testDeleteNoSavedModelWithNoParameter() {
    Student tony = new Student();
    tony.setName("Tony");
    tony.setAge(23);
    int rowsAffected = tony.delete();
    assertEquals(0, rowsAffected);
}
Also used : Student(com.litepaltest.model.Student)

Example 8 with Student

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

the class DeleteTest method testDeleteAllCascadeWithConditions.

public void testDeleteAllCascadeWithConditions() {
    Classroom classroom = new Classroom();
    classroom.setName("1" + System.currentTimeMillis());
    classroom.save();
    Classroom classroom2 = new Classroom();
    classroom2.setName("2" + System.currentTimeMillis());
    classroom2.save();
    Student s1 = new Student();
    s1.setClassroom(classroom);
    s1.save();
    Student s2 = new Student();
    s2.setClassroom(classroom);
    s2.save();
    Student s3 = new Student();
    s3.setClassroom(classroom2);
    s3.save();
    int rows = DataSupport.deleteAll(Classroom.class, "name = ?", classroom.getName());
    assertEquals(3, rows);
    assertNull(getClassroom(classroom.get_id()));
    assertNull(getStudent(s1.getId()));
    assertNull(getStudent(s2.getId()));
    assertNotNull(getClassroom(classroom2.get_id()));
    assertNotNull(getStudent(s3.getId()));
    rows = DataSupport.deleteAll(Classroom.class, "name = ?", classroom2.getName());
    assertEquals(2, rows);
    assertNull(getClassroom(classroom2.get_id()));
    assertNull(getStudent(s3.getId()));
}
Also used : Classroom(com.litepaltest.model.Classroom) Student(com.litepaltest.model.Student)

Example 9 with Student

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

the class DeleteTest method initJude.

private void initJude() {
    jude = new Student();
    jude.setName("Jude");
    jude.setAge(13);
    judeCard = new IdCard();
    judeCard.setAddress("Jude Street");
    judeCard.setNumber("123456");
    jude.setIdcard(judeCard);
    judeCard.setStudent(jude);
}
Also used : IdCard(com.litepaltest.model.IdCard) Student(com.litepaltest.model.Student)

Example 10 with Student

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

the class LitePalTestCase method getStudents.

protected List<Student> getStudents(int[] ids) {
    List<Student> students = new ArrayList<Student>();
    Cursor cursor = Connector.getDatabase().query(getTableName(Student.class), null, getWhere(ids), null, null, null, null);
    if (cursor.moveToFirst()) {
        Student s = new Student();
        String name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
        int age = cursor.getInt(cursor.getColumnIndexOrThrow("age"));
        s.setName(name);
        s.setAge(age);
        students.add(s);
    }
    cursor.close();
    return students;
}
Also used : ArrayList(java.util.ArrayList) Student(com.litepaltest.model.Student) Cursor(android.database.Cursor)

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