当前位置: 首页>>代码示例>>Java>>正文


Java TransactionManager.callInTransaction方法代码示例

本文整理汇总了Java中com.j256.ormlite.misc.TransactionManager.callInTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionManager.callInTransaction方法的具体用法?Java TransactionManager.callInTransaction怎么用?Java TransactionManager.callInTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.j256.ormlite.misc.TransactionManager的用法示例。


在下文中一共展示了TransactionManager.callInTransaction方法的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;
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:WeatherDao.java

示例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();
    }
}
 
开发者ID:saveendhiman,项目名称:XMPPSample_Studio,代码行数:20,代码来源:DatabaseHelper.java

示例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();
    }
}
 
开发者ID:saveendhiman,项目名称:XMPPSample_Studio,代码行数:24,代码来源:DatabaseHelper.java

示例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();
    }
}
 
开发者ID:saveendhiman,项目名称:XMPPSample_Studio,代码行数:21,代码来源:DatabaseHelper.java

示例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;
}
 
开发者ID:lujianzhao,项目名称:AndroidBase,代码行数:25,代码来源:OrmLiteDao.java

示例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);
    }
}
 
开发者ID:zulip,项目名称:zulip-android,代码行数:26,代码来源:Message.java

示例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);
    }
}
 
开发者ID:zulip,项目名称:zulip-android,代码行数:25,代码来源:ZulipApp.java

示例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;
}
 
开发者ID:SIGLUS,项目名称:lmis-moz-mobile,代码行数:23,代码来源:RnrFormRepository.java

示例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);
    }
}
 
开发者ID:SIGLUS,项目名称:lmis-moz-mobile,代码行数:19,代码来源:ProgramRepository.java

示例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();
    }

}
 
开发者ID:SIGLUS,项目名称:lmis-moz-mobile,代码行数:17,代码来源:StockRepository.java

示例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();
    }
}
 
开发者ID:SIGLUS,项目名称:lmis-moz-mobile,代码行数:20,代码来源:StockRepository.java

示例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();
}
 
开发者ID:jawg,项目名称:osm-contributor,代码行数:26,代码来源:OsmSqliteOpenHelper.java

示例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;
}
 
开发者ID:f97one,项目名称:WeightRecorder,代码行数:19,代码来源:WeightHistoryModel.java

示例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;
}
 
开发者ID:f97one,项目名称:WeightRecorder,代码行数:20,代码来源:WeightHistoryModel.java

示例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;
		}
	}
	);
}
 
开发者ID:IAP12-16B,项目名称:jManagr,代码行数:30,代码来源:AbstractDAL.java


注:本文中的com.j256.ormlite.misc.TransactionManager.callInTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。