Java Code Examples for org.litepal.LitePal#update()

The following examples show how to use org.litepal.LitePal#update() . 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: TransactionTest.java    From LitePal with Apache License 2.0 6 votes vote down vote up
@Test
public void testTransactionForUpdate() {
    Teacher teacher = new Teacher();
    teacher.setTeacherName("Tony");
    teacher.setTeachYears(3);
    teacher.setAge(23);
    teacher.setSex(false);
    Assert.assertTrue(teacher.save());
    LitePal.beginTransaction();
    ContentValues values = new ContentValues();
    values.put("TeachYears", 13);
    int rows = LitePal.update(Teacher.class, values, teacher.getId());
    Assert.assertEquals(1, rows);
    Teacher teacherFromDb = LitePal.find(Teacher.class, teacher.getId());
    Assert.assertEquals(13, teacherFromDb.getTeachYears());
    // not set transaction successful
    LitePal.endTransaction();
    teacherFromDb = LitePal.find(Teacher.class, teacher.getId());
    Assert.assertEquals(3, teacherFromDb.getTeachYears());
}
 
Example 2
Source File: UpdateUsingUpdateMethodTest.java    From LitePal with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateWithStaticUpdate() {
	ContentValues values = new ContentValues();
	values.put("TEACHERNAME", "Toy");
	int rowsAffected = LitePal.update(Teacher.class, values, teacher.getId());
	assertEquals(1, rowsAffected);
	assertEquals("Toy", getTeacher(teacher.getId()).getTeacherName());
	values.clear();
	values.put("aGe", 15);
	rowsAffected = LitePal.update(Student.class, values, student.getId());
	assertEquals(1, rowsAffected);
	assertEquals(15, getStudent(student.getId()).getAge());
}
 
Example 3
Source File: UpdateUsingUpdateMethodTest.java    From LitePal with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateWithStaticUpdateButWrongClass() {
	ContentValues values = new ContentValues();
	values.put("TEACHERNAME", "Toy");
	try {
           LitePal.update(Object.class, values, teacher.getId());
	} catch (SQLiteException e) {
	}
}
 
Example 4
Source File: UpdateUsingUpdateMethodTest.java    From LitePal with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateWithStaticUpdateButWrongColumn() {
	ContentValues values = new ContentValues();
	values.put("TEACHERYEARS", 13);
	try {
           LitePal.update(Teacher.class, values, teacher.getId());
		fail("no such column: TEACHERYEARS");
	} catch (SQLiteException e) {
	}
}
 
Example 5
Source File: UpdateUsingUpdateMethodTest.java    From LitePal with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateWithStaticUpdateButNotExistsRecord() {
	ContentValues values = new ContentValues();
	values.put("TEACHERNAME", "Toy");
	int rowsAffected = LitePal.update(Teacher.class, values, 998909);
	assertEquals(0, rowsAffected);
}