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

The following examples show how to use org.litepal.LitePal#deleteAll() . 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: DeleteTest.java    From LitePal with Apache License 2.0 6 votes vote down vote up
@Test
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);
    }
    LitePal.saveAll(students);
    List<Student> list = LitePal.where("name=?", "Dusting").find(Student.class);
    assertTrue(list.size() >= 5);
    LitePal.deleteAll(Student.class, "name=?", "Dusting");
    list = LitePal.where("name=?", "Dusting").find(Student.class);
    assertEquals(0, list.size());
    LitePal.saveAll(students);
    list = LitePal.where("name=?", "Dusting").find(Student.class);
    assertEquals(0, list.size());
    LitePal.markAsDeleted(students);
    LitePal.saveAll(students);
    list = LitePal.where("name=?", "Dusting").find(Student.class);
    assertEquals(5, list.size());
}
 
Example 2
Source File: DeleteTest.java    From LitePal with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteAllRows() {
	createStudentsTeachersWithIdCard();
	int rowsCount = getRowsCount(teacherTable);
	int affectedRows = 0;
	affectedRows = LitePal.deleteAll(Teacher.class);
	assertTrue(rowsCount <= affectedRows);
	rowsCount = getRowsCount(studentTable);
	affectedRows = LitePal.deleteAll(Student.class);
	assertTrue(rowsCount<= affectedRows);
	rowsCount = getRowsCount(DBUtility.getTableNameByClassName(IdCard.class.getName()));
	affectedRows = LitePal.deleteAll(IdCard.class);
	assertTrue(rowsCount<=affectedRows);
	createStudentsTeachersWithAssociations();
	rowsCount = getRowsCount(teacherTable);
	affectedRows = LitePal.deleteAll(Teacher.class);
	assertTrue(rowsCount<=affectedRows);
	rowsCount = getRowsCount(studentTable);
	affectedRows = LitePal.deleteAll(Student.class);
	assertTrue(rowsCount<=affectedRows);
	rowsCount = getRowsCount(DBUtility.getIntermediateTableName(studentTable, teacherTable));
	affectedRows = LitePal.deleteAll(DBUtility.getIntermediateTableName(studentTable, teacherTable));
	assertTrue(rowsCount<=affectedRows);
}
 
Example 3
Source File: AddCountyActivity.java    From DongWeather with Apache License 2.0 6 votes vote down vote up
/**
 * Called when a view has been clicked.
 *
 * @param v The view that was clicked.
 */
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.clear_database_btn:
            LitePal.deleteAll(Province.class);
            LitePal.deleteAll(City.class);
            LitePal.deleteAll(County.class);
            LitePal.deleteAll(SelectedCounty.class);
            break;
        case R.id.back_btn:
            if (currentLevel == LEVEL_COUNTY) {
                queryCity();
            } else if (currentLevel == LEVEL_CITY) {
                backButton.setVisibility(View.GONE);
                queryProvinces();
            }
            break;
        default:
            break;
    }
}
 
Example 4
Source File: DeleteTest.java    From LitePal with Apache License 2.0 6 votes vote down vote up
@Test
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 = LitePal.deleteAll(Student.class, "name = ? and age = ?", "Dusting",
			"10088");
	assertEquals(1, affectedRows);
	assertNull(getStudent(ids[2]));
	affectedRows = LitePal.deleteAll(Student.class, "name = ? and age > ? and age < ?", "Dusting", "10085", "10092");
	assertEquals(4, affectedRows);
}
 
Example 5
Source File: DbHelperImpl.java    From Yuan-SxMusic with Apache License 2.0 6 votes vote down vote up
@Override
public void insertAllAlbumSong(List<AlbumSong.DataBean.ListBean> songList) {
    LitePal.deleteAll(OnlineSong.class);
    for (int i = 0; i < songList.size(); i++) {
        AlbumSong.DataBean.ListBean song = songList.get(i);
        OnlineSong onlineSong = new OnlineSong();
        onlineSong.setId(i + 1);
        onlineSong.setName(song.getSongname());
        onlineSong.setSinger(song.getSinger().get(0).getName());
        onlineSong.setSongId(song.getSongmid());
        onlineSong.setDuration(song.getInterval());
        onlineSong.setPic(Api.ALBUM_PIC + song.getAlbummid()+Api.JPG);
        onlineSong.setUrl(null);
        onlineSong.setLrc(null);
        onlineSong.save();
    }
}
 
Example 6
Source File: DeleteTest.java    From LitePal with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteAllCascadeM2MAssociations() {
	createStudentsTeachersWithAssociations();
	int rowsAffected = LitePal.deleteAll(Teacher.class, "id=?", "" + john.getId());
	assertEquals(2, rowsAffected);
	assertNull(getTeacher(john.getId()));
	assertM2MFalse(studentTable, teacherTable, rose.getId(), john.getId());
	assertM2M(studentTable, teacherTable, rose.getId(), mike.getId());
	assertM2M(studentTable, teacherTable, jude.getId(), mike.getId());
	createStudentsTeachersWithAssociations();
	rowsAffected = LitePal.deleteAll(Teacher.class, "id=?", "" + mike.getId());
	assertEquals(3, rowsAffected);
	assertNull(getTeacher(mike.getId()));
	assertM2MFalse(studentTable, teacherTable, rose.getId(), mike.getId());
	assertM2MFalse(studentTable, teacherTable, jude.getId(), mike.getId());
	assertM2M(studentTable, teacherTable, rose.getId(), john.getId());
}
 
Example 7
Source File: DeleteTest.java    From LitePal with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteAllCascadeM2OAssociationsOnOSide() {
	createClassroomStudentsTeachers();
	int rowsAffected = LitePal.deleteAll(Student.class, "id = ?", String.valueOf(jude.getId()));
	assertEquals(1, rowsAffected);
	assertNull(getStudent(jude.getId()));
	rowsAffected = LitePal.deleteAll(Student.class, "id = ?", String.valueOf(rose.getId()));
	assertEquals(1, rowsAffected);
	assertNull(getStudent(rose.getId()));
	rowsAffected = LitePal.deleteAll(Teacher.class, "id = ?", String.valueOf(john.getId()));
	assertEquals(1, rowsAffected);
	assertNull(getTeacher(john.getId()));
	rowsAffected = LitePal.deleteAll(Teacher.class, "id = ?", String.valueOf(mike.getId()));
	assertEquals(1, rowsAffected);
	assertNull(getTeacher(mike.getId()));
}
 
Example 8
Source File: DeleteTest.java    From LitePal with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteAllCascadeO2OAssociations() {
	createStudentsTeachersWithIdCard();
	int affectedRows = LitePal.deleteAll(Student.class, "id = ?", String.valueOf(jude.getId()));
	assertEquals(2, affectedRows);
	assertNull(getStudent(jude.getId()));
	assertNull(getIdCard(judeCard.getId()));
	affectedRows = LitePal.deleteAll(IdCard.class, "id = ?", roseCard.getId() + "");
	assertEquals(2, affectedRows);
	assertNull(getStudent(rose.getId()));
	assertNull(getIdCard(roseCard.getId()));
	affectedRows = LitePal.deleteAll(Teacher.class, "id = ?", "" + john.getId());
	assertEquals(2, affectedRows);
	assertNull(getTeacher(john.getId()));
	assertNull(getIdCard(johnCard.getId()));
	affectedRows = LitePal.deleteAll(IdCard.class, "id=?", "" + mikeCard.getId());
	assertEquals(1, affectedRows);
	assertNull(getIdCard(mikeCard.getId()));
}
 
Example 9
Source File: MainActivity.java    From PoetryWeather with Apache License 2.0 5 votes vote down vote up
/**
 * 同步list中数据到本地数据库
 */
private void updateDatabases() {
    LitePal.deleteAll(CityDb.class);
    for (CityDb cityDb : cityDbList) {
        Log.d(TAG, "updateDatabases: "+cityDbList.size());
        CityDb updateCityDb = new CityDb();
        updateCityDb.setCityDb_cid(cityDb.getCityDb_cid());
        updateCityDb.setCityDb_cityName(cityDb.getCityDb_cityName());
        updateCityDb.setCityDb_txt(cityDb.getCityDb_txt());
        updateCityDb.setCityDb_temperature(cityDb.getCityDb_temperature());
        updateCityDb.setCityDb_imageId(cityDb.getCityDb_imageId());
        updateCityDb.save();
    }
}
 
Example 10
Source File: DeleteTest.java    From LitePal with Apache License 2.0 5 votes vote down vote up
@Test
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 = LitePal.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 = LitePal.deleteAll(Classroom.class, "name = ?", classroom2.getName());
	assertEquals(2, rows);
	assertNull(getClassroom(classroom2.get_id()));
	assertNull(getStudent(s3.getId()));
}
 
Example 11
Source File: DbHelperImpl.java    From Yuan-SxMusic with Apache License 2.0 5 votes vote down vote up
@Override
public boolean saveSong(List<LocalSong> localSongs) {
    LitePal.deleteAll(LocalSong.class);
    for (LocalSong localSong : localSongs) {
        LocalSong song = new LocalSong();
        song.setName(localSong.getName());
        song.setSinger(localSong.getSinger());
        song.setUrl(localSong.getUrl());
        song.setSongId(localSong.getSongId());
        song.setDuration(localSong.getDuration());
        if(!song.save()) return false;
    }
    return true;
}
 
Example 12
Source File: DeleteTest.java    From LitePal with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteWithGenericData() {
    Classroom classroom = new Classroom();
    classroom.setName("classroom1");
    classroom.getNews().add("news1");
    classroom.getNews().add("news2");
    classroom.getNews().add("news3");
    classroom.save();
    int id = classroom.get_id();
    String tableName = DBUtility.getGenericTableName(Classroom.class.getName(), "news");
    String column = DBUtility.getGenericValueIdColumnName(Classroom.class.getName());
    Cursor c = LitePal.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(id));
    assertEquals(3, c.getCount());
    c.close();
    classroom.delete();
    c = LitePal.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(id));
    assertEquals(0, c.getCount());
    c.close();
    assertFalse(classroom.isSaved());
    classroom.save();
    assertTrue(classroom.isSaved());
    c = LitePal.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(classroom.get_id()));
    assertEquals(3, c.getCount());
    c.close();
    LitePal.deleteAll(Classroom.class, "id = ?", String.valueOf(classroom.get_id()));
    c = LitePal.findBySQL("select * from " + tableName + " where " + column + " = ?", String.valueOf(classroom.get_id()));
    assertEquals(0, c.getCount());
    c.close();
}
 
Example 13
Source File: QueryEagerTest.java    From LitePal with Apache License 2.0 5 votes vote down vote up
public void resetData() {
       LitePal.deleteAll(Student.class);
       LitePal.deleteAll(Classroom.class);
       LitePal.deleteAll(Teacher.class);
       LitePal.deleteAll(IdCard.class);
	setUp();
}
 
Example 14
Source File: DeleteTest.java    From LitePal with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteAllCascadeM2OAssociationsOnMSide() {
	createClassroomStudentsTeachers();
	int rowsAffected = LitePal.deleteAll(Classroom.class, "id = ?", gameRoom.get_id() + "");
	assertEquals(5, rowsAffected);
	assertNull(getClassroom(gameRoom.get_id()));
	assertNull(getStudent(jude.getId()));
	assertNull(getStudent(rose.getId()));
	assertNull(getTeacher(john.getId()));
	assertNull(getTeacher(mike.getId()));
}
 
Example 15
Source File: DownloadService.java    From Yuan-SxMusic with Apache License 2.0 4 votes vote down vote up
private void deleteDb(String songId) {
    LitePal.deleteAll(DownloadInfo.class, "songId=?", songId);//删除已下载歌曲的相关列
}
 
Example 16
Source File: DbHelperImpl.java    From Yuan-WanAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public int deleteOneHistory(String key) {
    return LitePal.deleteAll(History.class,"key=?",key);
}
 
Example 17
Source File: DbHelperImp.java    From WanAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public int deleteAllHistoryRecord() {
   return LitePal.deleteAll(HistoryRecord.class);
}
 
Example 18
Source File: DbHelperImp.java    From WanAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public int deleteOneHistoryRecord(String record) {
    return  LitePal.deleteAll(HistoryRecord.class, "record = ?", record);
}
 
Example 19
Source File: WidgetListviewContentProvider.java    From DongWeather with Apache License 2.0 4 votes vote down vote up
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    // Implement this to handle requests to delete one or more rows.
    LitePal.deleteAll(CountyChanged.class);
    return 0;
}
 
Example 20
Source File: DbHelperImpl.java    From Yuan-WanAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public int deleteAllHistory() {
    return LitePal.deleteAll(History.class);
}