本文整理汇总了Java中com.j256.ormlite.misc.TransactionManager类的典型用法代码示例。如果您正苦于以下问题:Java TransactionManager类的具体用法?Java TransactionManager怎么用?Java TransactionManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransactionManager类属于com.j256.ormlite.misc包,在下文中一共展示了TransactionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryAllSaveCity
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
/**
* 查询数据库中的所有已添加的城市
*
* @return 结果集中只包括城市信息,天气数据不在其中
* @throws SQLException
*/
public List<Weather> queryAllSaveCity() throws SQLException {
return TransactionManager.callInTransaction(WeatherDatabaseHelper.getInstance(context).getConnectionSource(), () -> {
List<Weather> weatherList = weatherDaoOperation.queryForAll();
for (Weather weather : weatherList) {
String cityId = weather.getCityId();
weather.setAirQualityLive(apiDaoOperation.queryForId(cityId));
weather.setWeatherForecasts(forecastDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
weather.setLifeIndexes(lifeIndexesDaoOperation.queryForEq(WeatherForecast.CITY_ID_FIELD_NAME, cityId));
weather.setWeatherLive(realTimeDaoOperation.queryForId(cityId));
}
return weatherList;
});
}
示例2: updateContact
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
public void updateContact(final ContactItem contact) {
try {
TransactionManager.callInTransaction(getConnectionSource(),
new Callable<Void>() {
public Void call() throws Exception {
List<ContactItem> contacts = DatabaseHelper.this
.getDao(ContactItem.class).queryForEq(
"username", contact.username);
if (contacts != null)
DatabaseHelper.this.getDao(ContactItem.class)
.createOrUpdate(contact);
return null;
}
});
return;
} catch (SQLException localSQLException) {
localSQLException.printStackTrace();
}
}
示例3: updateContactStatus
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
public void updateContactStatus(final String jid, final String status,
final int mood) {
try {
TransactionManager.callInTransaction(getConnectionSource(),
new Callable<Void>() {
public Void call() throws Exception {
UpdateBuilder<ContactItem, ?> builder = getDao(
ContactItem.class).updateBuilder();
builder.updateColumnValue("status", status);
builder.updateColumnValue("mood", mood);
builder.where().eq("username",
JidCreate.bareFrom(jid));
getDao(ContactItem.class).update(builder.prepare());
return (Void) null;
}
});
return;
} catch (SQLException localSQLException) {
localSQLException.printStackTrace();
}
}
示例4: updateContacts
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
public void updateContacts(final Collection<ContactItem> contactList) {
if (contactList == null || contactList.size() == 0)
return;
try {
TransactionManager.callInTransaction(getConnectionSource(),
new Callable<Void>() {
public Void call() throws Exception {
Dao<ContactItem, ?> localDao = DatabaseHelper.this
.getDao(ContactItem.class);
for (ContactItem contact : contactList) {
localDao.createOrUpdate(contact);
}
return null;
}
});
return;
} catch (SQLException localSQLException) {
localSQLException.printStackTrace();
}
}
示例5: doBatchInTransaction
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
/**
* 数据批量处理
*
* @param list 要处理的数据集合
* @param batchType 操作类型
* @return
*/
private boolean doBatchInTransaction(final List<T> list, final int batchType) {
boolean doBatch = false;
ConnectionSource connectionSource = ormLiteDao.getConnectionSource();
TransactionManager transactionManager = new TransactionManager(connectionSource);
Callable<Boolean> callable = new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return doBatch(list, batchType);
}
};
try {
doBatch = transactionManager.callInTransaction(callable);
} catch (SQLException e) {
LogUtils.e(e);
}
return doBatch;
}
示例6: createMessages
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
public static void createMessages(final ZulipApp app,
final List<Message> messages) {
try {
TransactionManager.callInTransaction(app.getDatabaseHelper()
.getConnectionSource(), new Callable<Void>() {
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;
}
});
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例7: setupEmoji
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
/**
* 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);
}
}
示例8: createInitRnrForm
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
private RnRForm createInitRnrForm(final RnRForm rnrForm) throws LMISException {
try {
TransactionManager.callInTransaction(LmisSqliteOpenHelper.getInstance(context).getConnectionSource(), new Callable<Object>() {
@Override
public Object call() throws Exception {
create(rnrForm);
List<StockCard> stockCards = stockRepository.getStockCardsBeforePeriodEnd(rnrForm);
rnrFormItemRepository.batchCreateOrUpdate(generateRnrFormItems(rnrForm, stockCards));
regimenItemRepository.batchCreateOrUpdate(generateRegimeItems(rnrForm));
baseInfoItemRepository.batchCreateOrUpdate(generateBaseInfoItems(rnrForm));
genericDao.refresh(rnrForm);
return null;
}
});
} catch (SQLException e) {
throw new LMISException(e);
}
assignCategoryForRnrItems(rnrForm);
return rnrForm;
}
示例9: createOrUpdateProgramWithProduct
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
public void createOrUpdateProgramWithProduct(final List<Program> programs) throws LMISException {
try {
TransactionManager.callInTransaction(LmisSqliteOpenHelper.getInstance(context).getConnectionSource(), new Callable<Object>() {
@Override
public Object call() throws Exception {
for (Program program : programs) {
createOrUpdate(program);
for (Product product : program.getProducts()) {
productRepository.createOrUpdate(product);
}
}
return null;
}
});
} catch (SQLException e) {
throw new LMISException(e);
}
}
示例10: addStockMovementAndUpdateStockCard
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
public void addStockMovementAndUpdateStockCard(final StockMovementItem stockMovementItem) {
try {
TransactionManager.callInTransaction(LmisSqliteOpenHelper.getInstance(context).getConnectionSource(), new Callable<Object>() {
@Override
public Object call() throws Exception {
StockCard stockcard = stockMovementItem.getStockCard();
createOrUpdate(stockcard);
stockMovementRepository.batchCreateStockMovementItemAndLotItems(stockMovementItem);
return null;
}
});
} catch (SQLException e) {
new LMISException(e).reportToFabric();
}
}
示例11: batchCreateSyncDownStockCardsAndMovements
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
public void batchCreateSyncDownStockCardsAndMovements(final List<StockCard> stockCards) {
try {
TransactionManager.callInTransaction(LmisSqliteOpenHelper.getInstance(context).getConnectionSource(), new Callable<Object>() {
@Override
public Object call() throws Exception {
for (StockCard stockCard : stockCards) {
if (stockCard.getId() <= 0) {
saveStockCardAndBatchUpdateMovements(stockCard);
} else {
stockMovementRepository.batchCreateOrUpdateStockMovementsAndLotMovements(stockCard.getStockMovementItemsWrapper());
}
}
return null;
}
});
} catch (SQLException e) {
new LMISException(e).reportToFabric();
}
}
示例12: executeSqlScript
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
/**
* Execute a script in a SQLiteDatabase.
*
* @param context Context of the application.
* @param connectionSource ConnectionSource.
* @param database SQLiteDatabase where the script must be executed.
* @param sqlScriptFilename Name of the script to execute.
* @throws IOException
* @throws SQLException
*/
private static void executeSqlScript(final Context context, final ConnectionSource connectionSource, final SQLiteDatabase database, final String sqlScriptFilename) throws IOException, SQLException {
final BufferedReader reader = new BufferedReader(new InputStreamReader(context.getAssets().open(sqlScriptFilename)));
TransactionManager.callInTransaction(connectionSource, (new Callable<Void>() {
@Override
public Void call() throws Exception {
String line;
while ((line = reader.readLine()) != null) {
Timber.i("executing sql : %s", line);
database.execSQL(line);
}
return null;
}
}));
reader.close();
}
示例13: saveHist
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
public int saveHist(final WeightHistory savedEntity) {
int ret = 0;
try {
ret = TransactionManager.callInTransaction(mDao.getConnectionSource(), new Callable<Integer>() {
@Override
public Integer call() throws Exception {
Dao.CreateOrUpdateStatus status = mDao.createOrUpdate(savedEntity);
return status.getNumLinesChanged();
}
});
} catch (SQLException e) {
e.printStackTrace();
}
return ret;
}
示例14: erase
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
public boolean erase(final WeightHistory historyEntity) {
boolean ret = false;
try {
ret = TransactionManager.callInTransaction(mDao.getConnectionSource(), new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
int affected = mDao.delete(historyEntity);
return affected > 0 ? true : false;
}
});
} catch (SQLException e) {
e.printStackTrace();
}
return ret;
}
示例15: delete
import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
/**
* Deletes a BusinessObject
*
* @param bo the BusinessObject to delete
*
* @return Status code if it was successful
*
* @throws SQLException
*/
@Override
public STATUS_CODE delete(final BusinessObjectType bo) throws SQLException
{
return TransactionManager.callInTransaction(
this.db.getConnectionSource(), new Callable<STATUS_CODE>()
{
@Override
public STATUS_CODE call() throws SQLException
{
beforeDelete(bo);
if (dao.delete(bo) == 1) {
afterDelete(bo);
return STATUS_CODE.OK;
}
return STATUS_CODE.FAIL;
}
}
);
}