本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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);
}
示例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());
}
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}