• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TransactionManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



TransactionManager类属于com.j256.ormlite.misc包,在下文中一共展示了TransactionManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: softDelete

import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
/**
 * Soft deletes (set deleted to 1) a BusinessObject
 *
 * @param bo the BusinessObject to soft-delete
 *
 * @return Status code if it was successful
 *
 * @throws SQLException
 */
public STATUS_CODE softDelete(final BusinessObjectType bo) throws SQLException
{
	return TransactionManager.callInTransaction(
			this.db.getConnectionSource(),
			new Callable<STATUS_CODE>()
			{
				@Override
				public STATUS_CODE call() throws SQLException
				{
					beforeSoftDelete(bo);
					bo.setDeleted(true);
					if (dao.update(bo) == 1) {
						afterSoftDelete(bo);
						return STATUS_CODE.OK;
					}

					return STATUS_CODE.FAIL;
				}
			}
	);
}
 
开发者ID:IAP12-16B,项目名称:jManagr,代码行数:31,代码来源:AbstractDAL.java


示例17: save

import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
/**
 * Saves a BusinessObject to DB
 *
 * @param bo the BusinessObject to save
 *
 * @return Status code if it was successful
 *
 * @throws SQLException
 */
@Override
public STATUS_CODE save(final BusinessObjectType bo) throws SQLException
{
	return TransactionManager.callInTransaction(
			this.db.getConnectionSource(), new Callable<STATUS_CODE>()
	{
		@Override
		public STATUS_CODE call() throws SQLException
		{
			beforeSave(bo);
			Dao.CreateOrUpdateStatus status = dao.createOrUpdate(bo);
			if (status.isCreated() || status.isUpdated()) {
				afterSave(bo);
				return STATUS_CODE.OK;
			}

			return STATUS_CODE.FAIL;
		}
	}
	);
}
 
开发者ID:IAP12-16B,项目名称:jManagr,代码行数:31,代码来源:AbstractDAL.java


示例18: saveReceive

import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
public void saveReceive(final Receive receive) throws Exception{
        TransactionManager.callInTransaction(LmisSqliteOpenHelper.getInstance(context).getConnectionSource(), new
                Callable<Object>() {
                    @Override
                    public Object call() throws Exception {
                        GenericDao<Receive> receiveDao = new GenericDao<>(Receive.class, context);
                        receiveDao.create(receive);
                        saveReceiveItems(receive.getReceiveItems());

                        if (receive.getAllocation() != null) {
                            Allocation allocation = receive.getAllocation();
                            allocation.setReceived(true);
                            if (!allocation.isDummy()) {
                                allocationService.update(allocation);
                                alertsService.deleteAllocationAlert(allocation);
                            } else {
                                allocationService.createAllocation(allocation);
                                EventBus.getDefault().post(new AllocationCreateEvent(receive.getAllocation()));
                            }
                        }
                        return null;
                    }
                });
}
 
开发者ID:clintonhealthaccess,项目名称:chailmis-android,代码行数:25,代码来源:ReceiveService.java


示例19: useTransactions

import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
/**
 * Example of created a query with a ? argument using the {@link SelectArg} object. You then can set the value of
 * this object at a later time.
 */
private void useTransactions(ConnectionSource connectionSource) throws Exception {
	String name = "trans1";
	final Account account = new Account(name);
	assertEquals(1, accountDao.create(account));

	TransactionManager transactionManager = new TransactionManager(connectionSource);
	try {
		// try something in a transaction
		transactionManager.callInTransaction(new Callable<Void>() {
			@Override
			public Void call() throws Exception {
				// we do the delete
				assertEquals(1, accountDao.delete(account));
				assertNull(accountDao.queryForId(account.getId()));
				// but then (as an example) we throw an exception which rolls back the delete
				throw new Exception("We throw to roll back!!");
			}
		});
		fail("This should have thrown");
	} catch (SQLException e) {
		// expected
	}

	assertNotNull(accountDao.queryForId(account.getId()));
}
 
开发者ID:j256,项目名称:ormlite-jdbc,代码行数:30,代码来源:SimpleMain.java


示例20: testAutoCommitOff

import com.j256.ormlite.misc.TransactionManager; //导入依赖的package包/类
public void testAutoCommitOff() throws Exception {
	final Dao<Foo, Integer> dao = createDao(Foo.class, true);
	final Foo foo = new Foo();
	foo.stuff = "stuffery";
	DatabaseConnection conn = dao.startThreadConnection();
	try {
		dao.setAutoCommit(conn, false);
		TransactionManager.callInTransaction(connectionSource, new Callable<Void>() {
			public Void call() throws Exception {
				assertEquals(1, dao.create(foo));
				return null;
			}
		});
		// close and open the connection
		closeConnectionSource();
		openConnectionSource();
		Foo result = dao.queryForId(foo.id);
		assertNotNull(result);
		assertEquals(foo.stuff, result.stuff);
	} finally {
		dao.endThreadConnection(conn);
	}
}
 
开发者ID:j256,项目名称:ormlite-android-tests,代码行数:24,代码来源:AndroidBaseTransactionManagerTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SaveResult类代码示例发布时间:2022-05-21
下一篇:
Java ResponseInfo类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap