當前位置: 首頁>>代碼示例>>Java>>正文


Java DataSupport.saveAll方法代碼示例

本文整理匯總了Java中org.litepal.crud.DataSupport.saveAll方法的典型用法代碼示例。如果您正苦於以下問題:Java DataSupport.saveAll方法的具體用法?Java DataSupport.saveAll怎麽用?Java DataSupport.saveAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.litepal.crud.DataSupport的用法示例。


在下文中一共展示了DataSupport.saveAll方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSaveAllWithM2OOnOneSide

import org.litepal.crud.DataSupport; //導入方法依賴的package包/類
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());

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:SaveAllTest.java

示例2: testSaveAllWithM2OOnManySide

import org.litepal.crud.DataSupport; //導入方法依賴的package包/類
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());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:SaveAllTest.java

示例3: testMarkAsDeleted

import org.litepal.crud.DataSupport; //導入方法依賴的package包/類
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());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:DeleteTest.java

示例4: saveFriends

import org.litepal.crud.DataSupport; //導入方法依賴的package包/類
public synchronized void saveFriends(List<UserRelationshipResponse.ResultEntity> list) {
    List<Friend> friends = new ArrayList<>();
    for (UserRelationshipResponse.ResultEntity entity : list) {
        if (entity.getStatus() == 20) {//已經是好友
            Friend friend = new Friend(
                    entity.getUser().getId(),
                    entity.getUser().getNickname(),
                    entity.getUser().getPortraitUri(),
                    TextUtils.isEmpty(entity.getDisplayName()) ? entity.getUser().getNickname() : entity.getDisplayName(),
                    null, null, null, null,
                    PinyinUtils.getPinyin(entity.getUser().getNickname()),
                    PinyinUtils.getPinyin(TextUtils.isEmpty(entity.getDisplayName()) ? entity.getUser().getNickname() : entity.getDisplayName())
            );
            if (TextUtils.isEmpty(friend.getPortraitUri())) {
                friend.setPortraitUri(getPortrait(friend));
            }
            friends.add(friend);
        }
    }
    if (friends != null && friends.size() > 0)
        DataSupport.saveAll(friends);
}
 
開發者ID:starryxp,項目名稱:LQRWeChat-master,代碼行數:23,代碼來源:DBManager.java

示例5: testSaveAll

import org.litepal.crud.DataSupport; //導入方法依賴的package包/類
public void testSaveAll() {
	List<Cellphone> cellList = new ArrayList<Cellphone>();
	for (int i = 0; i < 50; i++) {
		Cellphone cellPhone = new Cellphone();
		cellPhone.setBrand("Samsung unique");
		cellPhone.setPrice(Math.random());
           cellPhone.setSerial(UUID.randomUUID().toString());
		cellList.add(cellPhone);
	}
	DataSupport.saveAll(cellList);
	for (Cellphone cell : cellList) {
		assertTrue(cell.isSaved());
	}
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:15,代碼來源:SaveAllTest.java

示例6: readTimeTableFile

import org.litepal.crud.DataSupport; //導入方法依賴的package包/類
/**
 *  讀json格式時間表文件並寫到數據庫
 */
private void readTimeTableFile(Context context,String filename) {
    String timetableStr = FileUtils.getStrFromAssets(context,filename);
    List<Schedule> timetableList = new Gson().fromJson(timetableStr, new TypeToken<List<Schedule>>() {}.getType());
    if(timetableList == null || timetableList.size() == 0){
        return;
    }
    DataSupport.deleteAll(Schedule.class,"dayInWeek = ?","7");
    DataSupport.saveAll(timetableList);
    initViewByDb();
}
 
開發者ID:WeGdufe,項目名稱:MovingGdufe-Android,代碼行數:14,代碼來源:HomeFragment.java

示例7: saveGroups

import org.litepal.crud.DataSupport; //導入方法依賴的package包/類
public synchronized void saveGroups(List<GetGroupResponse.ResultEntity> list) {
    if (list != null && list.size() > 0) {
        mGroupsList = new ArrayList<>();
        for (GetGroupResponse.ResultEntity groups : list) {
            String portrait = groups.getGroup().getPortraitUri();
            if (TextUtils.isEmpty(portrait)) {
                portrait = RongGenerate.generateDefaultAvatar(groups.getGroup().getName(), groups.getGroup().getId());
            }
            mGroupsList.add(new Groups(groups.getGroup().getId(), groups.getGroup().getName(), portrait, String.valueOf(groups.getRole())));
        }
    }
    if (mGroupsList.size() > 0)
        DataSupport.saveAll(mGroupsList);
}
 
開發者ID:starryxp,項目名稱:LQRWeChat-master,代碼行數:15,代碼來源:DBManager.java

示例8: onCreateView

import org.litepal.crud.DataSupport; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_notify_cmt, container, false);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.fragment_notify_cmt_recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mRecyclerView.setAdapter(new NotifyCmtAdapter(new ArrayList<CmtNotifyItem>()));
    mRecyclerView.addItemDecoration(new SpaceItemDecoration(5));
    mSwipeRefreshLayout = (SwipeRefreshLayout)view.findViewById(R.id.fragment_notify_cmt_swipe_refresh_layout);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.colorPrimary));

    List<CmtNotifyItem> cmtNotifyItemsFromDatabase = DataSupport.findAll(CmtNotifyItem.class);
    if(cmtNotifyItemsFromDatabase==null){
        Log.i(TAG, "onCreateView: cmtNotifyItemsFromDatabase==null");
        getData();
    }
    else{
        Log.i(TAG, "onCreateView: load cmt from database");
        NotifyCmtAdapter adapter = new NotifyCmtAdapter(cmtNotifyItemsFromDatabase);
        mRecyclerView.setAdapter(adapter);

    }

    

    mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case MSG_GET_NOTIFY_LIST:
                    Gson gson = new Gson();
                    List<CmtNotifyItem> cmtNotifyItems = gson.fromJson(mJson, new TypeToken<List<CmtNotifyItem>>(){}.getType());
                    DataSupport.deleteAll(CmtNotifyItem.class);
                    DataSupport.saveAll(cmtNotifyItems);
                    mRecyclerView.setAdapter(new NotifyCmtAdapter(cmtNotifyItems));
                    mSwipeRefreshLayout.setRefreshing(false);
                    break;
                default:
                    break;
            }
        }
    };
    return view;
}
 
開發者ID:shawnsky,項目名稱:RantApp,代碼行數:46,代碼來源:NotifyCmtFragment.java

示例9: onCreateView

import org.litepal.crud.DataSupport; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_notify_star, container, false);
    mRecyclerView = (RecyclerView) view.findViewById(R.id.fragment_notify_star_recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mRecyclerView.setAdapter(new NotifyStarAdapter(new ArrayList<StarNotifyItem>()));
    mRecyclerView.addItemDecoration(new SpaceItemDecoration(5));

    mSwipeRefreshLayout = (SwipeRefreshLayout)view.findViewById(R.id.fragment_notify_star_swipe_refresh_layout);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.colorPrimary));


    List<StarNotifyItem> starNotifyItemsFromDatabase = DataSupport.findAll(StarNotifyItem.class);
    if(starNotifyItemsFromDatabase==null){
        Log.i(TAG, "onCreateView: starNotifyItemsFromDatabase==null");
        getData();
    }
    else{
        Log.i(TAG, "onCreateView: load star from database");
        NotifyStarAdapter adapter = new NotifyStarAdapter(starNotifyItemsFromDatabase);
        mRecyclerView.setAdapter(adapter);
    }

    mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case MSG_GET_NOTIFY_LIST:
                    Gson gson = new Gson();
                    List<StarNotifyItem> starNotifyItems = gson.fromJson(mJson, new TypeToken<List<StarNotifyItem>>(){}.getType());
                    DataSupport.deleteAll(StarNotifyItem.class);
                    DataSupport.saveAll(starNotifyItems);
                    mRecyclerView.setAdapter(new NotifyStarAdapter(starNotifyItems));
                    mSwipeRefreshLayout.setRefreshing(false);
                    break;
                default:
                    break;
            }
        }
    };
    return view;
}
 
開發者ID:shawnsky,項目名稱:RantApp,代碼行數:45,代碼來源:NotifyStarFragment.java


注:本文中的org.litepal.crud.DataSupport.saveAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。