Package org.jooq.impl

Examples of org.jooq.impl.DefaultConnectionProvider


            this.silent = silent;
        }

        void run(Transactional tx) {
            // Initialise some jOOQ objects
            final DefaultConnectionProvider c = new DefaultConnectionProvider(connection);
            final Configuration configuration = new DefaultConfiguration().set(c).set(SQLDialect.H2);

            try {
                // Run the transaction and pass a jOOQ
                // DSLContext object to it
                tx.run(DSL.using(configuration));

                // If we get here, then commit the
                // transaction
                c.commit();
            }
            catch (RuntimeException e) {

                // Any exception will cause a rollback
                c.rollback();
                System.err.println(e.getMessage());

                // Eat exceptions in silent mode.
                if (!silent)
                    throw e;
View Full Code Here


     
    try {
        Class.forName("org.postgresql.Driver");
        c = getConnection("jdbc:postgresql:postgres", "postgres", System.getProperty("pw", "test"));
        DSLContext ctx = DSL.using(new DefaultConfiguration()
            .set(new DefaultConnectionProvider(c))
            .set(SQLDialect.POSTGRES)
            .set(new Settings().withExecuteLogging(false)));
       
        return runnable.run(ctx);
      }
View Full Code Here

            }
        };

        DSL.using(new DefaultConfiguration()
               .set(SQLDialect.H2)
               .set(new DefaultConnectionProvider(connection()))
               .set(new DefaultExecuteListenerProvider(listener))
           )
           .select(AUTHOR.ID)
           .from(AUTHOR)
           .fetch();
View Full Code Here

      jooqProvider.begin();
      didWeStartWork.set(true);
    }

    Transactional transactional = readTransactionMetadata(methodInvocation);
    DefaultConnectionProvider conn = this.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();
View Full Code Here

  public void begin() {
    Preconditions.checkState(null == threadFactory.get(),
        "Work already begun on this thread. Looks like you have called UnitOfWork.begin() twice"
         + " without a balancing call to end() in between.");

    DefaultConnectionProvider conn;
    try {
      logger.debug("Getting JDBC connection");
      conn = new DefaultConnectionProvider(jdbcSource.getConnection());
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
   
    DSLContext jooqFactory;
View Full Code Here

    threadFactory.set(jooqFactory);
  }

  public void end() {
    DSLContext jooqFactory = threadFactory.get();
    DefaultConnectionProvider conn = threadConnection.get();
    // Let's not penalize users for calling end() multiple times.
    if (null == jooqFactory) {
      return;
    }

    try {
      logger.debug("Closing JDBC connection");
      conn.acquire().close();
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
    threadFactory.remove();
    threadConnection.remove();
View Full Code Here

TOP

Related Classes of org.jooq.impl.DefaultConnectionProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.