com.google.inject.persist.UnitOfWork Java Examples
The following examples show how to use
com.google.inject.persist.UnitOfWork.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OrientModule.java From guice-persist-orient with MIT License | 6 votes |
@Override protected void configurePersistence() { poolsMultibinder = Multibinder.newSetBinder(binder(), PoolManager.class); final OrientDBFactory info = new OrientDBFactory( uri, user, password, autoCreateLocalDb, config, serverUser, serverPassword, remoteType); bind(OrientDBFactory.class).toInstance(info); bind(TxConfig.class).annotatedWith(Names.named("orient.txconfig")) .toInstance(txConfig == null ? new TxConfig() : txConfig); configureCustomTypes(); bind(CustomTypesInstaller.class); // extension points bind(TransactionManager.class); // SchemeInitializer.class // DataInitializer.class bind(PersistService.class).to(DatabaseManager.class); bind(OrientDB.class).toProvider(DatabaseManager.class); bind(UnitOfWork.class).to(TransactionManager.class); configurePools(); configureInterceptor(); bindRetryInterceptor(); }
Example #2
Source File: JooqPersistModule.java From guice-persist-jooq with Apache License 2.0 | 5 votes |
@Override protected void configurePersistence() { bind(JooqPersistService.class).in(Singleton.class); bind(PersistService.class).to(JooqPersistService.class); bind(UnitOfWork.class).to(JooqPersistService.class); bind(DSLContext.class).toProvider(JooqPersistService.class); transactionInterceptor = new JdbcLocalTxnInterceptor(getProvider(JooqPersistService.class), getProvider(UnitOfWork.class)); requestInjection(transactionInterceptor); }
Example #3
Source File: JdbcLocalTxnInterceptor.java From guice-persist-jooq with Apache License 2.0 | 4 votes |
@Inject public JdbcLocalTxnInterceptor(Provider<JooqPersistService> jooqPersistServiceProvider, Provider<UnitOfWork> unitOfWorkProvider) { this.jooqPersistServiceProvider = jooqPersistServiceProvider; this.unitOfWorkProvider = unitOfWorkProvider; }
Example #4
Source File: JdbcLocalTxnInterceptor.java From guice-persist-jooq with Apache License 2.0 | 4 votes |
public Object invoke(final MethodInvocation methodInvocation) throws Throwable { UnitOfWork unitOfWork = unitOfWorkProvider.get(); JooqPersistService jooqProvider = jooqPersistServiceProvider.get(); // Should we start a unit of work? if (!jooqProvider.isWorking()) { unitOfWork.begin(); didWeStartWork.set(true); } Transactional transactional = readTransactionMetadata(methodInvocation); DefaultConnectionProvider conn = jooqProvider.getConnectionWrapper(); // Allow 'joining' of transactions if there is an enclosing @Transactional method. if (!conn.getAutoCommit()) { return methodInvocation.proceed(); } logger.debug("Disabling JDBC auto commit for this thread"); conn.setAutoCommit(false); Object result; try { result = methodInvocation.proceed(); } catch (Exception e) { //commit transaction only if rollback didn't occur if (rollbackIfNecessary(transactional, e, conn)) { logger.debug("Committing JDBC transaction"); conn.commit(); } logger.debug("Enabling auto commit for this thread"); conn.setAutoCommit(true); //propagate whatever exception is thrown anyway throw e; } finally { // Close the em if necessary (guarded so this code doesn't run unless catch fired). if (null != didWeStartWork.get() && conn.getAutoCommit()) { didWeStartWork.remove(); unitOfWork.end(); } } // everything was normal so commit the txn (do not move into try block above as it // interferes with the advised method's throwing semantics) try { logger.debug("Committing JDBC transaction"); conn.commit(); logger.debug("Enabling auto commit for this thread"); conn.setAutoCommit(true); } finally { //close the em if necessary if (null != didWeStartWork.get()) { didWeStartWork.remove(); unitOfWork.end(); } } //or return result return result; }