本文整理匯總了Java中com.orm.SugarRecord類的典型用法代碼示例。如果您正苦於以下問題:Java SugarRecord類的具體用法?Java SugarRecord怎麽用?Java SugarRecord使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SugarRecord類屬於com.orm包,在下文中一共展示了SugarRecord類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateFavourites
import com.orm.SugarRecord; //導入依賴的package包/類
@Override
public void updateFavourites(List<Todo> todos) {
List<Todo> favourites = getFavourites();
List<Todo> toUpdate = new ArrayList<>(favourites.size());
for (Todo favourite : favourites) {
for (Todo todo : todos) {
if (todo.getId().equals(favourite.getId())) {
toUpdate.add(todo);
}
}
}
SugarRecord.saveInTx(toUpdate);
}
示例2: onAdd
import com.orm.SugarRecord; //導入依賴的package包/類
@Override
public Object onAdd(SearchResultsAdapter adapter, Object model) {
SugarRecord playlistItem = null;
if (model instanceof Category) {
playlistItem = new PlaylistCategory(Playlist.active(), (Category) model);
} else if (model instanceof Author) {
playlistItem = new PlaylistAuthor(Playlist.active(), (Author) model);
} else if (model instanceof Quote) {
playlistItem = new PlaylistQuote(Playlist.active(), (Quote) model);
}
if (playlistItem != null) {
playlistItem.save();
addRemovePlaylistItem(playlistItem, true);
}
return playlistItem;
}
示例3: findWithQueryAsIteratorTest
import com.orm.SugarRecord; //導入依賴的package包/類
@Test
public void findWithQueryAsIteratorTest() throws Exception {
for (int i = 1; i <= 100; i++) {
save(new SimpleAnnotatedModel());
}
Iterator<SimpleAnnotatedModel> cursor =
SugarRecord.findWithQueryAsIterator(SimpleAnnotatedModel.class,
"Select * from " +
NamingHelper.toSQLName(SimpleAnnotatedModel.class) +
" where id >= ? ", "50");
for (int i = 50; i <= 100; i++) {
assertTrue(cursor.hasNext());
SimpleAnnotatedModel model = cursor.next();
assertNotNull(model);
assertEquals(new Long(i), model.getId());
}
}
示例4: listAllSameTest
import com.orm.SugarRecord; //導入依賴的package包/類
@Test
public void listAllSameTest() throws Exception {
SimpleAnnotatedModel simple = new SimpleAnnotatedModel();
save(simple);
RelationshipAnnotatedModel nested = new RelationshipAnnotatedModel(simple);
save(nested);
for (int i = 1; i <= 100; i++) {
save(new NestedAnnotatedModel(nested));
}
List<NestedAnnotatedModel> models = SugarRecord.listAll(NestedAnnotatedModel.class);
assertEquals(100, models.size());
for (NestedAnnotatedModel model : models) {
assertEquals(nested.getId(), model.getNested().getId());
assertEquals(simple.getId(), model.getNested().getSimple().getId());
}
}
示例5: listAllDifferentTest
import com.orm.SugarRecord; //導入依賴的package包/類
@Test
public void listAllDifferentTest() throws Exception {
for (int i = 1; i <= 100; i++) {
SimpleExtendedModel simple = new SimpleExtendedModel();
save(simple);
RelationshipExtendedModel nested = new RelationshipExtendedModel(simple);
save(nested);
save(new NestedExtendedModel(nested));
}
List<NestedExtendedModel> models = SugarRecord.listAll(NestedExtendedModel.class);
assertEquals(100, models.size());
for (NestedExtendedModel model : models) {
assertEquals(model.getId(), model.getNested().getId());
assertEquals(model.getId(), model.getNested().getSimple().getId());
}
}
示例6: twoDifferentSaveTest
import com.orm.SugarRecord; //導入依賴的package包/類
@Test
public void twoDifferentSaveTest() throws Exception {
SimpleAnnotatedModel simple = new SimpleAnnotatedModel();
save(simple);
SimpleAnnotatedModel another_simple = new SimpleAnnotatedModel();
save(another_simple);
RelationshipMixedAModel nested = new RelationshipMixedAModel(simple);
save(nested);
RelationshipMixedAModel another_nested = new RelationshipMixedAModel(another_simple);
save(another_nested);
save(new NestedMixedBAModel(nested));
save(new NestedMixedBAModel(another_nested));
assertEquals(2L, SugarRecord.count(SimpleAnnotatedModel.class));
assertEquals(2L, SugarRecord.count(RelationshipMixedAModel.class));
assertEquals(2L, SugarRecord.count(NestedMixedBAModel.class));
}
示例7: listAllSameTest
import com.orm.SugarRecord; //導入依賴的package包/類
@Test
public void listAllSameTest() throws Exception {
SimpleAnnotatedModel simple = new SimpleAnnotatedModel();
save(simple);
RelationshipMixedAModel nested = new RelationshipMixedAModel(simple);
save(nested);
for (int i = 1; i <= 100; i++) {
save(new NestedMixedBAModel(nested));
}
List<NestedMixedBAModel> models = SugarRecord.listAll(NestedMixedBAModel.class);
assertEquals(100, models.size());
for (NestedMixedBAModel model : models) {
assertEquals(nested.getId(), model.getNested().getId());
assertEquals(simple.getId(), model.getNested().getSimple().getId());
}
}
示例8: initGoogleAccount
import com.orm.SugarRecord; //導入依賴的package包/類
private void initGoogleAccount() {
if (!AccountHolder.isAccountNameSaved(this)) {
pickAccount();
return;
}
// circles were already loaded
String ourGoogleId = AccountHolder.getSavedGoogleId(this);
List<Contact> forAdapter = SugarRecord.listAll(Contact.class);
if (forAdapter.isEmpty()) { // nothing to load, didn't select account?
pickAccount();
return;
}
ListIterator<Contact> itr = forAdapter.listIterator();
while (itr.hasNext()) { // remove us from list, also populate contacts map
Contact c = itr.next();
mContacts.put(c.getNativeId(), c);
if (c.getNativeId().equals(ourGoogleId)) {
mCurrentPerson = c;
itr.remove();
}
}
if(mCurrentPerson == null) { // didn't find ourselves, error?
pickAccount();
return;
}
// successfully loaded cicrles and ourselves from cache
mPersonList.setAdapter(new AccountsAdapter(this, forAdapter));
mFloatingMenu.showMenu(true);
mProgress.animate().alpha(0.0f).setDuration(0).start();
supportInvalidateOptionsMenu();
}
示例9: twoSameSaveTest
import com.orm.SugarRecord; //導入依賴的package包/類
@Test
public void twoSameSaveTest() throws Exception {
SimpleExtendedModel simple = new SimpleExtendedModel();
save(simple);
save(new RelationshipExtendedModel(simple));
save(new RelationshipExtendedModel(simple));
assertEquals(1L, SugarRecord.count(SimpleExtendedModel.class));
assertEquals(2L, SugarRecord.count(RelationshipExtendedModel.class));
}
示例10: objectLongAnnotatedTest
import com.orm.SugarRecord; //導入依賴的package包/類
@Test
public void objectLongAnnotatedTest() {
Long objectLong = new Long(25L);
save(new LongFieldAnnotatedModel(objectLong));
LongFieldAnnotatedModel model = SugarRecord.findById(LongFieldAnnotatedModel.class, 1);
assertEquals(objectLong, model.getLong());
}
示例11: objectLongExtendedTest
import com.orm.SugarRecord; //導入依賴的package包/類
@Test
public void objectLongExtendedTest() {
Long objectLong = new Long(25L);
save(new LongFieldExtendedModel(objectLong));
LongFieldExtendedModel model = SugarRecord.findById(LongFieldExtendedModel.class, 1);
assertEquals(objectLong, model.getLong());
}
示例12: deleteAllWhereTest
import com.orm.SugarRecord; //導入依賴的package包/類
@Test
public void deleteAllWhereTest() throws Exception {
for (int i = 1; i <= 100; i++) {
save(new SimpleAnnotatedModel());
}
SugarRecord.deleteAll(SimpleAnnotatedModel.class, "id > ?", new String[]{"1"});
assertEquals(1L, SugarRecord.count(SimpleAnnotatedModel.class));
}
示例13: onBindViewHolder
import com.orm.SugarRecord; //導入依賴的package包/類
@Override
public void onBindViewHolder(ImageMultiSelectViewHolder holder, int position) {
SugarRecord sugarRecord = imageSources.get(position);
if (sugarRecord instanceof UnsplashCategory) {
holder.bindTo((UnsplashCategory) imageSources.get(position));
} else {
holder.bindTo((UserAlbum) imageSources.get(position));
}
}
示例14: addRemovePlaylistItem
import com.orm.SugarRecord; //導入依賴的package包/類
void addRemovePlaylistItem(Object item, boolean add) {
String analyticsLabel;
if (item instanceof PlaylistCategory) {
analyticsLabel = ((PlaylistCategory) item).category.name;
} else if (item instanceof PlaylistAuthor) {
analyticsLabel = ((PlaylistAuthor) item).author.name;
} else if (item instanceof PlaylistQuote) {
String quote = ((PlaylistQuote) item).quote.text;
analyticsLabel = quote.substring(0, Math.min(35, quote.length())) + "...";
} else {
return;
}
if (add) {
playlistAdapter.insertItem(item);
} else {
if (playlistAdapter.getPlaylistItemCount() == 1) {
Toast.makeText(this, "Your playlist may not be empty", Toast.LENGTH_LONG).show();
return;
}
playlistAdapter.removeItem(item);
((SugarRecord) item).delete();
}
// Log it
AnalyticsUtils.trackEvent(AnalyticsUtils.CATEGORY_PLAYLIST,
add ? AnalyticsUtils.ACTION_ADDED : AnalyticsUtils.ACTION_REMOVED,
analyticsLabel);
}
示例15: listAllSameTest
import com.orm.SugarRecord; //導入依賴的package包/類
@Test
public void listAllSameTest() throws Exception {
SimpleExtendedModel simple = new SimpleExtendedModel();
save(simple);
for (int i = 1; i <= 100; i++) {
save(new RelationshipExtendedModel(simple));
}
List<RelationshipExtendedModel> models =
SugarRecord.listAll(RelationshipExtendedModel.class);
assertEquals(100, models.size());
for (RelationshipExtendedModel model : models) {
assertEquals(simple.getId(), model.getSimple().getId());
}
}