本文整理了Java中com.zulip.android.ZulipApp.getDao()
方法的一些代码示例,展示了ZulipApp.getDao()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZulipApp.getDao()
方法的具体详情如下:
包路径:com.zulip.android.ZulipApp
类名称:ZulipApp
方法名:getDao
暂无
代码示例来源:origin: zulip/zulip-android
public <C, T> RuntimeExceptionDao<C, T> getDao(Class<C> cls) {
return getDao(cls, false);
}
代码示例来源:origin: zulip/zulip-android
public static Person getById(ZulipApp app, int id) {
RuntimeExceptionDao<Person, Object> dao = app.getDao(Person.class);
return dao.queryForId(id);
}
代码示例来源:origin: zulip/zulip-android
@Override
public Cursor call() throws Exception {
String query = "SELECT s.id as _id, s.name, s.color"
+ " FROM streams as s LEFT JOIN messages as m ON s.id=m.stream ";
String selectArg = null;
if (!etSearchStream.getText().toString().equals("") && !etSearchStream.getText().toString().isEmpty()) {
//append where clause
selectArg = etSearchStream.getText().toString() + '%';
query += " WHERE s.name LIKE ? " + " and s." + Stream.SUBSCRIBED_FIELD + " = " + "1 ";
//set visibility of this image false
ivSearchStreamCancel.setVisibility(View.VISIBLE);
} else {
//set visibility of this image false
query += " WHERE s." + Stream.SUBSCRIBED_FIELD + " = " + "1 ";
ivSearchStreamCancel.setVisibility(View.GONE);
}
//append group by
query += " group by s.name order by s.name COLLATE NOCASE";
if (selectArg != null) {
return ((AndroidDatabaseResults) app.getDao(Stream.class).queryRaw(query, selectArg).closeableIterator().getRawResults()).getRawCursor();
} else {
return ((AndroidDatabaseResults) app.getDao(Stream.class).queryRaw(query).closeableIterator().getRawResults()).getRawCursor();
}
}
};
代码示例来源:origin: zulip/zulip-android
public static Stream getByName(ZulipApp app, String name) {
Stream stream = null;
try {
RuntimeExceptionDao<Stream, Object> streams = app.getDao(Stream.class);
stream = streams.queryBuilder().where()
.eq(Stream.NAME_FIELD, new SelectArg(name)).queryForFirst();
if (stream == null) {
Log.w("Stream.getByName",
"We received a stream message for a stream we don't have data for. Fake it until you make it.");
stream = new Stream(name);
app.getDao(Stream.class).createIfNotExists(stream);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return stream;
}
代码示例来源:origin: zulip/zulip-android
@Override
public Cursor getChildrenCursor(Cursor groupCursor) {
List<String[]> results = new ArrayList<>();
try {
results = ZulipApp.get().getDao(Message.class).queryRaw("SELECT DISTINCT subject FROM messages " +
"JOIN streams ON streams.id=messages.stream " +
"WHERE streams.id=" + groupCursor.getInt(0) + " and streams." + Stream.SUBSCRIBED_FIELD + " = " + "1 group by subject").getResults();
} catch (SQLException e) {
ZLog.logException(e);
}
MatrixCursor matrixCursor = new MatrixCursor(new String[]{"subject", "_id"});
for (String[] result : results) {
try {
matrixCursor.addRow(new String[]{result[0], String.valueOf(groupCursor.getInt(0))});
} catch (Exception e) {
ZLog.logException(e);
}
}
return matrixCursor;
}
}
代码示例来源:origin: zulip/zulip-android
public static List<Person> getAllPeople(ZulipApp app) throws SQLException {
RuntimeExceptionDao<Person, Object> dao = app.getDao(Person.class);
return dao.queryBuilder().where().eq(Person.ISBOT_FIELD, false).query();
}
代码示例来源:origin: zulip/zulip-android
public void processStreams(List<EventsBranch> events) {
for (EventsBranch event : events) {
StreamWrapper streamEvent = (StreamWrapper) event;
if (streamEvent.getOperation().equalsIgnoreCase(StreamWrapper.OP_OCCUPY)) {
Dao<Stream, Integer> streamDao = app.getDao(Stream.class);
List<Stream> streams = streamEvent.getStreams();
for (Stream stream : streams) {
try {
// use default color for not subscribed streams
stream.setDefaultColor();
streamDao.createIfNotExists(stream);
} catch (SQLException e) {
ZLog.logException(e);
}
}
} else {
// TODO: handle other operations of stream event
Log.d("AsyncEvents", "unhandled operation for stream type event");
return;
}
}
}
代码示例来源:origin: zulip/zulip-android
private Cursor makePeopleNameCursor(CharSequence name) throws SQLException {
if (name == null) {
name = "";
}
return ((AndroidDatabaseResults) app
.getDao(Person.class)
.queryRaw(
"SELECT rowid _id, * FROM people WHERE "
+ Person.ISBOT_FIELD + " = 0 AND "
+ Person.ISACTIVE_FIELD + " = 1 AND "
+ Person.NAME_FIELD
+ " LIKE ? ESCAPE '\\' ORDER BY "
+ Person.NAME_FIELD + " COLLATE NOCASE",
DatabaseHelper.likeEscape(name.toString()) + "%")
.closeableIterator().getRawResults()).getRawCursor();
}
代码示例来源:origin: zulip/zulip-android
/**
* Returns a cursor for the combinedAdapter used to suggest Emoji when ':' is typed in the {@link #messageEt}
*
* @param emoji A string to search in the existing database
*/
private Cursor makeEmojiCursor(CharSequence emoji)
throws SQLException {
if (emoji == null) {
emoji = "";
}
return ((AndroidDatabaseResults) app
.getDao(Emoji.class)
.queryRaw("SELECT rowid _id,name FROM emoji WHERE name LIKE '%" + emoji + "%'")
.closeableIterator().getRawResults()).getRawCursor();
}
代码示例来源:origin: zulip/zulip-android
@Override
public void onDataSetChanged() {
Log.i("ZULIP_WIDGET", "onDataSetChanged() = Data reloaded");
QueryBuilder<Message, Object> queryBuilder = ZulipApp.get().getDao(Message.class).queryBuilder();
String filter;
filter = setupWhere();
if (!filter.equals("")) {
queryBuilder.where().raw(filter);
}
try {
messageList = queryBuilder.query();
} catch (SQLException e) {
ZLog.logException(e);
}
}
代码示例来源:origin: zulip/zulip-android
/**
* Creates a cursor to get the streams saved in the database
*
* @param streamName Filter out streams name containing this string
*/
private Cursor makeStreamCursor(CharSequence streamName)
throws SQLException {
if (streamName == null) {
streamName = "";
}
return ((AndroidDatabaseResults) app
.getDao(Stream.class)
.queryRaw(
"SELECT rowid _id, * FROM streams WHERE "
+ Stream.SUBSCRIBED_FIELD + " = 1 AND "
+ Stream.NAME_FIELD
+ " LIKE ? ESCAPE '\\' ORDER BY "
+ Stream.NAME_FIELD + " COLLATE NOCASE",
DatabaseHelper.likeEscape(streamName.toString()) + "%")
.closeableIterator().getRawResults()).getRawCursor();
}
代码示例来源:origin: zulip/zulip-android
public Void call() throws Exception {
for (int i = 1; i <= 300; i++) {
sampleMessage(app, i);
}
for (int i = 501; i <= 800; i++) {
sampleMessage(app, i);
}
app.getDao(MessageRange.class).create(new MessageRange(1, 300));
app.getDao(MessageRange.class).create(
new MessageRange(501, 800));
return null;
}
});
代码示例来源:origin: zulip/zulip-android
/**
* Fills the Emoji Table with the existing emoticons saved in the assets folder.
*/
private void setupEmoji() {
try {
final RuntimeExceptionDao<Emoji, Object> dao = getDao(Emoji.class);
if (dao.queryForAll().size() != 0) return;
final String emojis[] = getAssets().list("emoji");
TransactionManager.callInTransaction(getDatabaseHelper()
.getConnectionSource(),
new Callable<Void>() {
public Void call() throws Exception {
for (String newEmoji : emojis) {
//currently emojis are in png format
newEmoji = newEmoji.replace(".png", "");
dao.create(new Emoji(newEmoji));
}
return null;
}
});
} catch (SQLException | IOException e) {
ZLog.logException(e);
}
}
代码示例来源:origin: zulip/zulip-android
/**
* Checks stream name is valid or not
*
* @param app ZulipApp
* @param streamName Checks this stream name is valid or not
* @return null if stream does not exist else cursor
*/
public static Stream streamCheckBeforeMessageSend(ZulipApp app, CharSequence streamName) {
if (streamName == null) {
return null;
}
try {
return app.getDao(Stream.class)
.queryBuilder().where()
.eq(Stream.NAME_FIELD, new SelectArg(Stream.NAME_FIELD, streamName)).queryForFirst();
} catch (SQLException e) {
ZLog.logException(e);
}
return null;
}
代码示例来源:origin: zulip/zulip-android
public static void updateNewMessagesRange(ZulipApp app, int maxId) {
synchronized (app.updateRangeLock) {
RuntimeExceptionDao<MessageRange, Integer> rangeDao = app
.getDao(MessageRange.class);
MessageRange currentRange = MessageRange.getRangeContaining(
app.getMaxMessageId(), rangeDao);
if (currentRange == null) {
currentRange = new MessageRange(app.getMaxMessageId(),
app.getMaxMessageId());
}
if (currentRange.high <= maxId) {
currentRange.high = maxId;
rangeDao.createOrUpdate(currentRange);
}
}
app.setMaxMessageId(maxId);
}
代码示例来源:origin: zulip/zulip-android
private void checkRanges(String rangestr) throws SQLException {
List<MessageRange> ranges = app.getDao(MessageRange.class)
.queryBuilder().orderBy("low", true).query();
String s = "";
for (MessageRange rng : ranges) {
s += "(" + rng.low + "," + rng.high + ")";
}
assertEquals(rangestr, s);
}
代码示例来源:origin: zulip/zulip-android
private void selectPointer() {
if (filter != null) {
Where<Message, Object> filteredWhere;
try {
filteredWhere = filter.modWhere(app.getDao(Message.class)
.queryBuilder().where());
filteredWhere.and().le(Message.ID_FIELD, app.getPointer());
QueryBuilder<Message, Object> closestQuery = app.getDao(
Message.class).queryBuilder();
closestQuery.orderBy(Message.TIMESTAMP_FIELD, false).setWhere(
filteredWhere);
Message closestMessage = closestQuery.queryForFirst();
// use anchor message id if message was narrowed
if (anchorId != -1) {
selectMessage(getMessageById(anchorId));
} else {
recyclerView.scrollToPosition(adapter.getItemIndex(closestMessage));
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
} else {
int anc = app.getPointer();
selectMessage(getMessageById(anc));
}
}
代码示例来源:origin: zulip/zulip-android
public Void call() throws Exception {
RuntimeExceptionDao<Message, Object> messageDao = app.getDao(Message.class);
for (Message m : messages) {
Person person = Person.getOrUpdate(app, m.getSenderEmail(), m.getSenderFullName(), m.getAvatarUrl(), m.getSenderId());
m.setSender(person);
Stream stream = null;
if (m.getType() == MessageType.STREAM_MESSAGE) {
stream = Stream.getByName(app, m.getRecipients());
}
m.setStream(stream);
messageDao.createOrUpdate(m);
}
return null;
}
});
代码示例来源:origin: zulip/zulip-android
/**
* Returns old form of edited message.
*
* @return {@link Message} message
*/
public Message getMessage(int messageId) {
try {
Dao<Message, Integer> messageDao = ZulipApp.get().getDao(Message.class);
Message message = messageDao.queryBuilder().where().eq(Message.ID_FIELD, messageId).queryForFirst();
if (message != null) {
if (this.formattedContent != null) {
message.setFormattedContent(this.formattedContent);
message.setHasBeenEdited(true);
}
if (containsSubject()) {
message.setSubject(this.subject);
}
return message;
}
} catch (SQLException e) {
ZLog.logException(e);
}
return null;
}
代码示例来源:origin: zulip/zulip-android
/**
* Run this before each test to set up the activity.
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void prepTests() {
setApplication(app);
this.startActivity(new Intent(getInstrumentation().getTargetContext(),
ZulipActivity.class), null, null);
this.getInstrumentation().waitForIdleSync();
app.setContext(getInstrumentation().getTargetContext());
// Need to setEmail twice to reinitialise the database after destroying
// it.
app.setEmail(TESTUSER_EXAMPLE_COM);
app.deleteDatabase(app.getDatabaseHelper().getDatabaseName());
app.setEmail(TESTUSER_EXAMPLE_COM);
messageDao = app.getDao(Message.class);
}
内容来源于网络,如有侵权,请联系作者删除!