Search in sources :

Example 11 with Classroom

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

the class UpdateUsingSaveMethodTest method init.

private void init() {
    Calendar calendar = Calendar.getInstance();
    c1 = new Classroom();
    c1.setName("Working room");
    c2 = new Classroom();
    c2.setName("Resting room");
    s1 = new Student();
    s1.setName("Parker");
    s1.setAge(18);
    s2 = new Student();
    s2.setName("Peter");
    calendar.clear();
    calendar.set(1990, 9, 16, 0, 0, 0);
    s2.setBirthday(calendar.getTime());
    s2.setAge(19);
    s3 = new Student();
    s3.setName("Miley");
    s3.setAge(16);
    id1 = new IdCard();
    id1.setNumber("999777123");
    id1.setAddress("Zhushan road");
    t1 = new Teacher();
    t1.setTeacherName("Jackson");
    t1.setTeachYears(3);
    t1.setAge(28);
    t2 = new Teacher();
    t2.setTeacherName("Rose");
    t2.setTeachYears(12);
    t2.setAge(34);
}
Also used : Calendar(java.util.Calendar) Classroom(com.litepaltest.model.Classroom) Teacher(com.litepaltest.model.Teacher) IdCard(com.litepaltest.model.IdCard) Student(com.litepaltest.model.Student)

Example 12 with Classroom

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

the class UpdateUsingUpdateMethodTest method init.

private void init() {
    classroom = new Classroom();
    classroom.setName("English room");
    classroom.getNews().add("hello");
    classroom.getNews().add("world");
    classroom.getNumbers().add(123);
    classroom.getNumbers().add(456);
    teacher = new Teacher();
    teacher.setTeacherName("Tony");
    teacher.setTeachYears(3);
    teacher.setAge(23);
    teacher.setSex(false);
    student = new Student();
    student.setName("Jonny");
    student.setAge(13);
    student.setClassroom(classroom);
    student.setBirthday(new Date());
    student.getTeachers().add(teacher);
    teacher.getStudents().add(student);
    student.save();
    teacher.save();
    classroom.save();
}
Also used : Classroom(com.litepaltest.model.Classroom) Teacher(com.litepaltest.model.Teacher) Student(com.litepaltest.model.Student) Date(java.util.Date)

Example 13 with Classroom

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

the class SaveAllTest method testSaveAllGenericData.

public void testSaveAllGenericData() {
    List<Classroom> classroomList = new ArrayList<Classroom>();
    for (int i = 0; i < 50; i++) {
        Classroom classroom = new Classroom();
        classroom.setName("classroom " + i);
        for (int j = 0; j < 20; j++) {
            classroom.getNews().add("news " + i);
        }
        for (int k = 0; k < 13; k++) {
            classroom.getNumbers().add(k);
        }
        classroomList.add(classroom);
    }
    DataSupport.saveAll(classroomList);
    assertEquals(50, classroomList.size());
    for (Classroom classroom : classroomList) {
        assertTrue(classroom.isSaved());
        Classroom c = DataSupport.find(Classroom.class, classroom.get_id());
        assertTrue(c.getName().startsWith("classroom"));
        assertEquals(20, c.getNews().size());
        assertEquals(13, c.getNumbers().size());
    }
}
Also used : ArrayList(java.util.ArrayList) Classroom(com.litepaltest.model.Classroom)

Example 14 with Classroom

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

the class SaveAllTest method testSaveAllWithM2OOnOneSide.

public void testSaveAllWithM2OOnOneSide() {
    Classroom classroom = new Classroom();
    classroom.setName("Music room");
    for (int i = 0; i < 50; i++) {
        Student student = new Student();
        student.setName("Tom");
        student.setAge(new Random().nextInt(20));
        classroom.getStudentCollection().add(student);
    }
    DataSupport.saveAll(classroom.getStudentCollection());
    classroom.save();
    List<Student> list = DataSupport.where(classroomTable + "_id = ?", String.valueOf(classroom.get_id())).find(Student.class);
    assertEquals(50, list.size());
}
Also used : Random(java.util.Random) Classroom(com.litepaltest.model.Classroom) Student(com.litepaltest.model.Student)

Example 15 with Classroom

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

the class SaveAllTest method testSaveAllWithM2OOnManySide.

public void testSaveAllWithM2OOnManySide() {
    Classroom classroom = new Classroom();
    classroom.setName("English room");
    List<Student> studentList = new ArrayList<Student>();
    for (int i = 0; i < 50; i++) {
        Student student = new Student();
        student.setName("Tom");
        student.setAge(new Random().nextInt(20));
        student.setClassroom(classroom);
        studentList.add(student);
    }
    DataSupport.saveAll(studentList);
    classroom.save();
    List<Student> list = DataSupport.where(classroomTable + "_id = ?", String.valueOf(classroom.get_id())).find(Student.class);
    assertEquals(50, list.size());
}
Also used : Random(java.util.Random) Classroom(com.litepaltest.model.Classroom) ArrayList(java.util.ArrayList) Student(com.litepaltest.model.Student)

Aggregations

Classroom (com.litepaltest.model.Classroom)20 Student (com.litepaltest.model.Student)11 Teacher (com.litepaltest.model.Teacher)7 IdCard (com.litepaltest.model.IdCard)4 ArrayList (java.util.ArrayList)3 Calendar (java.util.Calendar)3 Cursor (android.database.Cursor)2 Random (java.util.Random)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Cellphone (com.litepaltest.model.Cellphone)1 Computer (com.litepaltest.model.Computer)1 Headset (com.litepaltest.model.Headset)1 Product (com.litepaltest.model.Product)1 Date (java.util.Date)1 LitePalDB (org.litepal.LitePalDB)1