se.emilsjolander.sprinkles.Query Java Examples

The following examples show how to use se.emilsjolander.sprinkles.Query. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChooseTagActivity.java    From sprinkles with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.acitivty_choose_tag);

	mNoteId = getIntent().getLongExtra(EXTRA_NOTE_ID, -1);

	Query.many(Tag.class, "select * from Tags").getAsync(
			getLoaderManager(), onTagsLoaded);
	Query.many(NoteTagLink.class,
			"select * from NoteTagLinks where note_id=?", mNoteId).getAsync(
			getLoaderManager(), onLinksLoaded, Note.class, Tag.class);

	mListView = (ListView) findViewById(R.id.list);
	mListView.setEmptyView(findViewById(R.id.empty));
	mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
	mListView.setOnItemClickListener(onListItemClicked);

	mAdapter = new TagsAdapter(this);
	mListView.setAdapter(mAdapter);
}
 
Example #2
Source File: NotesActivity.java    From sprinkles with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	mListView = (ListView) findViewById(R.id.list);

	mAdapter = new NotesAdapter(this);
	mListView.setAdapter(mAdapter);
	mListView.setEmptyView(findViewById(R.id.empty));
	mListView.setOnItemClickListener(onNoteSelected);

	Query.many(Note.class,
               "select Notes.*, " +
                       "(select count(*) from NoteTagLinks where NoteTagLinks.note_id = Notes.id) as tag_count " +
                       "from Notes order by created_at desc"
       )
			.getAsync(getLoaderManager(), onNotesLoaded,
					NoteTagLink.class);

   }
 
Example #3
Source File: AddressBook.java    From AndroidDatabaseLibraryComparison with MIT License 5 votes vote down vote up
@Override
public Collection<SimpleAddressItem> getAddresses() {
    if (addresses == null) {
        addresses = Query.many(SimpleAddressItem.class, "addressBook = ?",
                String.valueOf(id)).get().asList();
    }
    return addresses;
}
 
Example #4
Source File: AddressBook.java    From AndroidDatabaseLibraryComparison with MIT License 5 votes vote down vote up
@Override
public Collection<Contact> getContacts() {
    if (contacts == null) {
        contacts = Query.many(Contact.class, "addressBook = ?",
                String.valueOf(id)).get().asList();
    }
    return contacts;
}
 
Example #5
Source File: SprinklesTest.java    From Storm with Apache License 2.0 5 votes vote down vote up
@Override
protected void deleteAll() {

    // no exceptions are thrown, catch it yourself
    // throws IndexOutOfBoundsException if passed db version is not starts with 0
    // java.lang.IllegalStateException: Couldn't read row 5470, col 5 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.

    final Transaction dt = new Transaction();
    for (SprinklesObject sprinklesObject : Query.all(SprinklesObject.class).get()) {
        sprinklesObject.delete(dt);
    }

    dt.setSuccessful(true);
    dt.finish();
}
 
Example #6
Source File: CreateNoteActivity.java    From sprinkles with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_create_note);
	
	long noteId = getIntent().getLongExtra(EXTRA_NOTE_ID, -1);
	if (noteId < 0) {
		mNote = new Note();
		mNote.save();
	} else {
		mNote = Query.one(Note.class, "select * from Notes where id=?", noteId).get();
	}
	
	final TextView lastUpdatedAt = (TextView) findViewById(R.id.last_updated);
	final EditText noteContent = (EditText) findViewById(R.id.note_content);
	noteContent.setText(mNote.getContent());
	
	if (mNote.exists()) {
		String updatedAtString = new SimpleDateFormat("HH:mm EEEE", Locale.getDefault()).format(mNote.getUpdatedAt());
		lastUpdatedAt.setText(getString(R.string.last_updated, updatedAtString));
	} else {
		lastUpdatedAt.setVisibility(View.GONE);
	}
	
	findViewById(R.id.save).setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			mNote.setContent(noteContent.getText().toString());
			mNote.save();
			finish();
		}
	});
}
 
Example #7
Source File: Utils.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
public static List<Media> loadMedia(boolean sync) {
	boolean empty = true;
	if (!sync) {
		synchronized (cachedMedias) {
			if (cachedMedias.isEmpty()) {
				long start = System.currentTimeMillis();
				cachedMedias.addAll(Query.all(Media.class).get().asList());
				lastCached = System.currentTimeMillis();
				LOG.info(cachedMedias.size() + " load from local database done in " + (System.currentTimeMillis() - start) + " ms");
				empty = cachedMedias.isEmpty();
			} else {
				empty = false;
			}
		}
	}
	if (sync || empty) {
		List<Media> syncMedia = syncMediaDatabase();
		synchronized (cachedMedias) {
			cachedMedias.clear();
			cachedMedias.addAll(syncMedia);
			lastCached = System.currentTimeMillis();
		}
		return syncMedia;
	} else {
		LOG.debug("returning " + (System.currentTimeMillis() - lastCached) + " ms old cachedMedias");
	}
	synchronized (cachedMedias) {
		return new ArrayList<Media>(cachedMedias);
	}
}
 
Example #8
Source File: Contact.java    From AndroidDatabaseLibraryComparison with MIT License 4 votes vote down vote up
@Override
public AddressBook getAddressBookField() {
    return Query.one(AddressBook.class, "id = ?" , addressBook_id).get();
}
 
Example #9
Source File: SprinklesTest.java    From Storm with Apache License 2.0 4 votes vote down vote up
@Override
protected void queryOne(long id) {
    Query.one(SprinklesObject.class, "where id = ?", id).get();
}
 
Example #10
Source File: SprinklesTest.java    From Storm with Apache License 2.0 4 votes vote down vote up
@Override
protected void queryAll() {
    Query.all(SprinklesObject.class).get().asList();
}