当前位置: 首页>>代码示例>>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;未经允许,请勿转载。