当前位置: 首页>>代码示例>>Java>>正文


Java DataSupport.find方法代码示例

本文整理汇总了Java中org.litepal.crud.DataSupport.find方法的典型用法代码示例。如果您正苦于以下问题:Java DataSupport.find方法的具体用法?Java DataSupport.find怎么用?Java DataSupport.find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.litepal.crud.DataSupport的用法示例。


在下文中一共展示了DataSupport.find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeItem

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void removeItem(int position) {
    IOItem ioItem = mIOItemList.get(position);
    Sum sum = DataSupport.find(Sum.class, 1);  // 1 代表sum;
    Sum month;
    int type = ioItem.getType();
    sum.setTotal(sum.getTotal()-ioItem.getMoney() * type);
    sum.save();
    // 判断收支类型
    if (type < 0) month = DataSupport.find(Sum.class, 2);     // 2 代表cost
    else month = DataSupport.find(Sum.class, 3);              // 3 代表earn
    month.setTotal(month.getTotal()-ioItem.getMoney());
    month.save();
    DataSupport.delete(IOItem.class, mIOItemList.get(position).getId());

    mIOItemList.remove(position);
    notifyItemRemoved(position);
}
 
开发者ID:yuukidach,项目名称:Ucount,代码行数:18,代码来源:IOItemAdapter.java

示例2: onCreate

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_intake);
    ButterKnife.bind(this);
    //setSupportActionBar(toolbar);
    intakeID = getIntent().getLongExtra("intakeID",-1);
    intakeMoment  = DataSupport.find(IntakeMoment.class,intakeID);
    medicine = DataSupport.find(Medicine.class,intakeMoment.getMedicineId());

    RequestOptions requestOptions = new RequestOptions();
    requestOptions.placeholder(R.drawable.pill_placeholder);
    requestOptions.error(R.drawable.pill_placeholder);
    requestOptions.centerCrop();
    String image_path= medicine.getImage();

    Glide.with(this).setDefaultRequestOptions(requestOptions).load(image_path).into(imageView);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(medicine.getName());
    imageView.setBackgroundColor(getResources().getColor(R.color.grey));

    time_text.setText(String.format("%02d:%02d", intakeMoment.getStartDate().getHours(),intakeMoment.getStartDate().getMinutes()));
    seekBar.setProgress(intakeMoment.getQuantity());
}
 
开发者ID:jcolladosp,项目名称:ePills,代码行数:27,代码来源:EditIntakeActivity.java

示例3: testSaveWithBlob

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testSaveWithBlob() {
    byte[] b = new byte[10];
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte)i;
    }
    Product product = new Product();
    product.setBrand("Android");
    product.setPrice(2899.69);
    product.setPic(b);
    assertTrue(product.saveFast());
    Product p = DataSupport.find(Product.class, product.getId());
    byte[] pic = p.getPic();
    assertEquals(b.length, pic.length);
    for (int i = 0; i < b.length; i++) {
        assertEquals(i, pic[i]);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:SaveTest.java

示例4: testSaveInheritModels

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testSaveInheritModels() {
    WeChatMessage weChatMessage = new WeChatMessage();
    weChatMessage.setFriend("Tom");
    weChatMessage.setContent("Hello nice to meet you");
    weChatMessage.setTitle("Greeting message");
    weChatMessage.setType(1);
    assertTrue(weChatMessage.save());
    assertTrue(weChatMessage.getId() > 0);
    WeChatMessage message1 = DataSupport.find(WeChatMessage.class, weChatMessage.getId());
    assertEquals("Tom", message1.getFriend());
    assertEquals("Hello nice to meet you", message1.getContent());
    assertNull(message1.getTitle());
    assertEquals(1, message1.getType());

    WeiboMessage weiboMessage = new WeiboMessage();
    weiboMessage.setType(2);
    weiboMessage.setTitle("Following message");
    weiboMessage.setContent("Something big happens");
    weiboMessage.setFollower("Jimmy");
    weiboMessage.setNumber(123456);
    assertTrue(weiboMessage.saveFast());
    assertTrue(weiboMessage.getId() > 0);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:SaveTest.java

示例5: onClick

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
@Override
public void onClick(View view) {
    switch (view.getId()) {
        // 按住加号按钮以后,切换到AddItemActivity
        case R.id.add_button:
            Intent intent = new Intent(MainActivity.this, AddItemActivity.class);
            startActivity(intent);
            break;
        case R.id.show_money_button:
            if (showBtn.getText() == "显示余额") {
                sum = DataSupport.find(Sum.class, sum.SUM);
                String sumString = decimalFormat.format( sum.getTotal() );
                showBtn.setText(sumString);
            } else showBtn.setText("显示余额");
            break;
        default:
            break;
    }
}
 
开发者ID:yuukidach,项目名称:Ucount,代码行数:20,代码来源:MainActivity.java

示例6: testFind

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testFind() {
	short isbn = 30013;
	Book book = new Book();
	book.setArea(10.5f);
	book.setBookName("Android First Line");
	book.setIsbn(isbn);
	book.setLevel('A');
	book.setPages(450);
	book.setPrice(49.99);
	book.setPublished(false);
	book.save();
	Book b = DataSupport.find(Book.class, book.getId());
	assertEquals(book.getId(), b.getId());
	assertEquals(10.5f, b.getArea());
	assertEquals("Android First Line", b.getBookName());
	assertEquals(isbn, b.getIsbn());
	assertEquals('A', b.getLevel());
	assertTrue(450 == b.getPages());
	assertEquals(49.99, b.getPrice());
	assertFalse(b.isPublished());
	assertTrue(b.isSaved());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:QueryBasicTest.java

示例7: testUpdateBlobWithStaticUpdate

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testUpdateBlobWithStaticUpdate() {
    byte[] b = new byte[10];
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte)i;
    }
    Product product = new Product();
    product.setBrand("Android");
    product.setPrice(2899.69);
    product.setPic(b);
    assertTrue(product.saveFast());
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte) (b.length - i);
    }
    ContentValues values = new ContentValues();
    values.put("pic", b);
    int rows = DataSupport.update(Product.class, values, product.getId());
    assertEquals(1, rows);
    Product p = DataSupport.find(Product.class, product.getId());
    byte[] pic = p.getPic();
    assertEquals(b.length, pic.length);
    for (int i = 0; i < b.length; i++) {
        byte a = (byte) (b.length - i);
        assertEquals(a, pic[i]);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:UpdateUsingUpdateMethodTest.java

示例8: testUpdateBlobWithInstanceUpdate

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testUpdateBlobWithInstanceUpdate() {
    byte[] b = new byte[10];
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte)i;
    }
    Product product = new Product();
    product.setBrand("Android");
    product.setPrice(2899.69);
    product.setPic(b);
    assertTrue(product.saveFast());
    for (int i = 0; i < b.length; i++) {
        b[i] = (byte) (b.length - i);
    }
    Product pro = new Product();
    pro.setPic(b);
    int rows = pro.update(product.getId());
    assertEquals(1, rows);
    Product p = DataSupport.find(Product.class, product.getId());
    byte[] pic = p.getPic();
    assertEquals(b.length, pic.length);
    for (int i = 0; i < b.length; i++) {
        byte a = (byte) (b.length - i);
        assertEquals(a, pic[i]);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:UpdateUsingUpdateMethodTest.java

示例9: testUpdateToDefaultValueWithInstanceUpdate

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testUpdateToDefaultValueWithInstanceUpdate() {
	Student s = new Student();
	s.setToDefault("age");
	s.setToDefault("name");
	s.setToDefault("birthday");
	int affectedStudent = s.update(student.getId());
	assertEquals(1, affectedStudent);
	Student newStudent = DataSupport.find(Student.class, student.getId());
	assertNull(newStudent.getBirthday());
	assertEquals(null, newStudent.getName());
	assertEquals(0, newStudent.getAge());
	Teacher t = new Teacher();
	t.setAge(45);
	t.setTeachYears(5);
	t.setTeacherName("John");
	t.setToDefault("teacherName");
	t.setToDefault("age");
	int affectedTeacher = t.update(teacher.getId());
	assertEquals(1, affectedTeacher);
	Teacher newTeacher = getTeacher(teacher.getId());
	assertEquals(22, newTeacher.getAge());
	assertEquals("", newTeacher.getTeacherName());
	assertEquals(5, newTeacher.getTeachYears());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:UpdateUsingUpdateMethodTest.java

示例10: testUpdateGenericData

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testUpdateGenericData() {
    Classroom c = new Classroom();
    c.setName("Math room");
    c.getNews().add("news");
    c.getNews().add("paper");
    c.update(classroom.get_id());
    Classroom result = DataSupport.find(Classroom.class, classroom.get_id());
    assertEquals("Math room", result.getName());
    StringBuilder builder = new StringBuilder();
    for (String s : result.getNews()) {
        builder.append(s);
    }
    assertEquals("newspaper", builder.toString());
    assertEquals(2, result.getNumbers().size());
    Classroom c2 = new Classroom();
    c2.setToDefault("numbers");
    c2.update(classroom.get_id());
    result = DataSupport.find(Classroom.class, classroom.get_id());
    assertEquals("Math room", result.getName());
    assertEquals(2, result.getNews().size());
    assertEquals(0, result.getNumbers().size());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:UpdateUsingUpdateMethodTest.java

示例11: testUpdateGenericData

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testUpdateGenericData() {
    Classroom classroom = new Classroom();
    classroom.setName("Classroom origin");
    classroom.getNews().add("n");
    classroom.getNews().add("e");
    classroom.getNews().add("w");
    classroom.getNumbers().add(1);
    classroom.getNumbers().add(2);
    classroom.getNumbers().add(3);
    classroom.save();
    classroom.setName("Classroom update");
    classroom.getNews().add("s");
    classroom.getNumbers().clear();
    classroom.save();
    Classroom c = DataSupport.find(Classroom.class, classroom.get_id());
    assertEquals("Classroom update", c.getName());
    assertEquals(4, classroom.getNews().size());
    assertEquals(0, classroom.getNumbers().size());
    StringBuilder builder = new StringBuilder();
    for (String s : classroom.getNews()) {
        builder.append(s);
    }
    assertEquals("news", builder.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:UpdateUsingSaveMethodTest.java

示例12: getNoteInfo

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
private void getNoteInfo() {
    int noteId = getIntent().getIntExtra("note_id", -1);
    if (noteId == -1) {
        String noteTitle = getIntent().getStringExtra("note_title");
        int noteType = getIntent().getIntExtra("note_type", -1);
        note = new Note();
        note.setTitle(noteTitle);
        note.setSecret(noteType == Constant.TYPE_SECRET_NOTE ? true : false);
        note.setCreateTime(System.currentTimeMillis());
        note.setUpdateTime(System.currentTimeMillis());
        note.save();
        isEdit = true;
        initLocationClient();
    } else {
        note = DataSupport.find(Note.class, noteId);
    }
}
 
开发者ID:StableChen,项目名称:easynote,代码行数:18,代码来源:NoteDetailActivity.java

示例13: testUpdateM2OAssociationsOnMSide

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testUpdateM2OAssociationsOnMSide() {
	init();
	s1.setClassroom(c1);
	s2.setClassroom(c1);
	assertTrue(c1.save());
	assertTrue(c2.save());
	assertTrue(s1.save());
	assertTrue(s2.save());
	s1.setClassroom(c2);
	s2.setClassroom(c2);
	Calendar calendar = Calendar.getInstance();
	calendar.clear();
	calendar.set(1989, 7, 7, 0, 0, 0);
	s2.setBirthday(calendar.getTime());
	assertTrue(s1.save());
	assertTrue(s2.save());
	assertEquals(c2.get_id(), getForeignKeyValue(studentTable, classroomTable, s1.getId()));
	assertEquals(c2.get_id(), getForeignKeyValue(studentTable, classroomTable, s2.getId()));
	Student student2 = DataSupport.find(Student.class, s2.getId());
	calendar.clear();
	calendar.set(1989, 7, 7, 0, 0, 0);
	assertEquals(calendar.getTimeInMillis(), student2.getBirthday().getTime());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:UpdateUsingSaveMethodTest.java

示例14: calculateMonthlyMoney

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void calculateMonthlyMoney(int type, IOItem ioItem) {
    Sum sum = new Sum();
    Sum tmpSum = new Sum();
    String sumDate = formatSum.format(new Date());
    int id = (int)((double)type / 2 + 2.5);

    // 保证一定现有2号id,避免出现当月支出不更新的bug
    if (!tmpSum.isThereASum(tmpSum.MONTHLY_COST))
        tmpSum.saveSum(tmpSum, tmpSum.MONTHLY_COST, 0.0, 1, sumDate);

    if (sum.isThereASum(id)) {
        sum = DataSupport.find(Sum.class, id);
        if (sum.getDate().equals(ioItem.getTimeStamp().substring(0, 8))) {
            sum.calculateMoney(id, ioItem.getMoney(), type*type);
        } else {
            sum.saveSum(sum, id, ioItem.getMoney(), type*type, sumDate);
        }
    } else {
        sum.saveSum(sum, id, ioItem.getMoney(), type*type, sumDate);
    }
}
 
开发者ID:yuukidach,项目名称:Ucount,代码行数:22,代码来源:AddItemActivity.java

示例15: testSaveInheritModelsWithAssociations

import org.litepal.crud.DataSupport; //导入方法依赖的package包/类
public void testSaveInheritModelsWithAssociations() {
    Cellphone cellphone = new Cellphone();
    cellphone.setBrand("iPhone 7");
    cellphone.setInStock('N');
    cellphone.setPrice(6999.99);
    cellphone.setSerial(UUID.randomUUID().toString());
    cellphone.setMac("ff:3d:4a:99:76");
    cellphone.save();

    WeChatMessage weChatMessage = new WeChatMessage();
    weChatMessage.setFriend("Tom");
    weChatMessage.setContent("Hello nice to meet you");
    weChatMessage.setTitle("Greeting message");
    weChatMessage.setType(1);
    assertTrue(weChatMessage.save());
    assertTrue(weChatMessage.getId() > 0);
    WeChatMessage message1 = DataSupport.find(WeChatMessage.class, weChatMessage.getId());
    assertEquals("Tom", message1.getFriend());
    assertEquals("Hello nice to meet you", message1.getContent());
    assertNull(message1.getTitle());
    assertEquals(1, message1.getType());

    WeiboMessage weiboMessage = new WeiboMessage();
    weiboMessage.setType(2);
    weiboMessage.setTitle("Following message");
    weiboMessage.setContent("Something big happens");
    weiboMessage.setFollower("Jimmy");
    weiboMessage.setNumber(123456);
    weiboMessage.setCellphone(cellphone);
    assertTrue(weiboMessage.save());
    assertTrue(weiboMessage.getId() > 0);
    WeiboMessage message2 = DataSupport.find(WeiboMessage.class, weiboMessage.getId(), true);
    Cellphone result = message2.getCellphone();
    assertEquals(cellphone.getId(), result.getId());
    assertEquals(cellphone.getBrand(), result.getBrand());
    assertEquals(cellphone.getInStock(), result.getInStock());
    assertEquals(cellphone.getPrice(), result.getPrice());
    assertEquals(cellphone.getSerial(), result.getSerial());
    assertEquals(cellphone.getMac(), result.getMac());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:41,代码来源:SaveTest.java


注:本文中的org.litepal.crud.DataSupport.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。