use of com.winsonchiu.reader.data.database.TransactionInsertOrReplace in project Reader by TheKeeperOfPie.
the class TableLink method storeLink.
public Action1<SQLiteDatabase> storeLink(final Link link) {
return new Action1<SQLiteDatabase>() {
@Override
public void call(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.beginTransaction();
if (link.getComments().getChildren().isEmpty()) {
TransactionInsertOrReplace transaction = getInsertOrReplace(sqLiteDatabase, COLUMN_TITLE, COLUMN_AUTHOR, COLUMN_JSON);
transaction.insertOrReplace(link.getId(), System.currentTimeMillis(), link.getCreatedUtc(), link.getTitle(), link.getAuthor(), link.getJson());
} else {
TransactionInsertOrReplace transaction = getInsertOrReplace(sqLiteDatabase, COLUMN_TITLE, COLUMN_AUTHOR, COLUMN_JSON, COLUMN_COMMENTS);
transaction.insertOrReplace(link.getId(), System.currentTimeMillis(), link.getCreatedUtc(), link.getTitle(), link.getAuthor(), link.getJson(), link.getJsonComments());
}
sqLiteDatabase.setTransactionSuccessful();
sqLiteDatabase.endTransaction();
}
};
}
use of com.winsonchiu.reader.data.database.TransactionInsertOrReplace in project Reader by TheKeeperOfPie.
the class TableSubredditPage method appendPage.
public Action1<SQLiteDatabase> appendPage(final Subreddit subreddit, final List<String> ids, Sort sort, Time time) {
return new Action1<SQLiteDatabase>() {
@Override
public void call(SQLiteDatabase sqLiteDatabase) {
Cursor query = sqLiteDatabase.query(NAME, COLUMNS, _ID + " = ? LIMIT 1", new String[] { subreddit.getUrl() }, null, null, null);
if (query != null) {
if (query.moveToFirst()) {
String json = query.getString(query.getColumnIndex(COLUMN_LINKS));
try {
LinkedHashSet<String> idsCurrent = new LinkedHashSet<>(Arrays.asList(ComponentStatic.getObjectMapper().readValue(json, String[].class)));
idsCurrent.addAll(ids);
ids.clear();
ids.addAll(idsCurrent);
} catch (IOException e) {
e.printStackTrace();
}
}
query.close();
}
sqLiteDatabase.beginTransaction();
try {
String json = ComponentStatic.getObjectMapper().writeValueAsString(ids);
TransactionInsertOrReplace transaction = getInsertOrReplace(sqLiteDatabase, COLUMNS);
transaction.insertOrReplace(subreddit.getUrl(), System.currentTimeMillis(), subreddit.getCreatedUtc(), subreddit.getDisplayName(), json);
sqLiteDatabase.setTransactionSuccessful();
} catch (IOException e) {
e.printStackTrace();
}
sqLiteDatabase.endTransaction();
}
};
}
use of com.winsonchiu.reader.data.database.TransactionInsertOrReplace in project Reader by TheKeeperOfPie.
the class TableSubredditPage method storePage.
public Action1<SQLiteDatabase> storePage(final Subreddit subreddit, final List<String> ids, Sort sort, Time time) {
return new Action1<SQLiteDatabase>() {
@Override
public void call(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.beginTransaction();
try {
String json = ComponentStatic.getObjectMapper().writeValueAsString(ids);
TransactionInsertOrReplace transaction = getInsertOrReplace(sqLiteDatabase, COLUMNS);
transaction.insertOrReplace(subreddit.getUrl(), System.currentTimeMillis(), subreddit.getCreatedUtc(), subreddit.getDisplayName(), json);
sqLiteDatabase.setTransactionSuccessful();
} catch (IOException e) {
e.printStackTrace();
}
sqLiteDatabase.endTransaction();
}
};
}
use of com.winsonchiu.reader.data.database.TransactionInsertOrReplace in project Reader by TheKeeperOfPie.
the class TableLink method storeLinks.
public Action1<SQLiteDatabase> storeLinks(final List<Link> links) {
return new Action1<SQLiteDatabase>() {
@Override
public void call(SQLiteDatabase sqLiteDatabase) {
List<Link> linksWithComments = new ArrayList<>();
for (int index = links.size() - 1; index >= 0; index--) {
if (!links.get(index).getComments().getChildren().isEmpty()) {
linksWithComments.add(links.remove(index));
}
}
TransactionInsertOrReplace transaction = getInsertOrReplace(sqLiteDatabase, COLUMN_TITLE, COLUMN_AUTHOR, COLUMN_JSON);
sqLiteDatabase.beginTransaction();
for (Link link : links) {
transaction.insertOrReplace(link.getId(), System.currentTimeMillis(), link.getCreatedUtc(), link.getTitle(), link.getAuthor(), link.getJson());
}
sqLiteDatabase.setTransactionSuccessful();
sqLiteDatabase.endTransaction();
TransactionInsertOrReplace transactionWithComments = getInsertOrReplace(sqLiteDatabase, COLUMN_TITLE, COLUMN_AUTHOR, COLUMN_JSON, COLUMN_COMMENTS);
sqLiteDatabase.beginTransaction();
for (Link link : linksWithComments) {
transactionWithComments.insertOrReplace(link.getId(), System.currentTimeMillis(), link.getCreatedUtc(), link.getTitle(), link.getAuthor(), link.getJson(), link.getJsonComments());
}
sqLiteDatabase.setTransactionSuccessful();
sqLiteDatabase.endTransaction();
}
};
}
Aggregations