Package org.hibernate

Examples of org.hibernate.Session.doWork()


    s.close();

    assertEquals( "rollback() should not index", 3, getDocumentNumber() );

    s = getSessionFactory().openSession();
    s.doWork( new Work() {
      @Override
      public void execute(Connection connection) throws SQLException {
        connection.setAutoCommit( true ); // www.hibernate.org/403.html
      }
    } );
View Full Code Here


   * @throws SQLException in case the insert fails.
   */
  private TShirt createObjectWithSQL() throws SQLException {
    Session s = openSession();
    s.getTransaction().begin();
    s.doWork( new Work() {
      @Override
      public void execute(Connection connection) throws SQLException {
        final Statement statement = connection.createStatement();
        statement.executeUpdate(
            "insert into TShirt_Master(id, logo, size_, length_) values( 1, 'JBoss balls', 'large', 23.2)"
View Full Code Here

      for ( long iterationIndex = 0; iterationIndex < iterationCount; iterationIndex++ ) {
        final long idOffset = initialOffset + ( iterationIndex * batchSize );
        final long idCount = initialOffset + ( iterationIndex * batchSize ) + batchSize - 1;

        Transaction tx = s.beginTransaction();
        s.doWork( new Work() {
          @Override
          public void execute(Connection connection) throws SQLException {
            PreparedStatement ps = connection.prepareStatement( sql );
            for ( long id = idOffset; id < idCount; id++ ) {
              batchCallback.initStatement( ps, id );
View Full Code Here

  }

  private Session getSessionWithAutoCommit() {
    Session s;
    s = openSession();
    s.doWork( new Work() {
      @Override
      public void execute(Connection connection) throws SQLException {
        connection.setAutoCommit( true );
      }
    } );
View Full Code Here

  @Test
  public void testObjectNotFound() throws Exception {
    Session session = openSession();
    Transaction tx = session.beginTransaction();

    session.doWork(
        new Work() {
          @Override
          public void execute(Connection connection) throws SQLException {
            Statement statement = connection.createStatement();
            statement.executeUpdate( "DELETE FROM Author where name = 'Charles Dickens'" );
View Full Code Here


    @Override
    public void run(EntityManager entityManager, Consumer<Connection> work) {
        Session session = entityManager.unwrap(Session.class);
        session.doWork(connection -> work.accept(connection));
    }


    @Override
    public <R> R exec(EntityManager entityManager, Function<Connection, R> work) {
View Full Code Here

  public void doWork(Work work) {
    // Flush the EntityManager to make sure we have all entities available
    this.em.flush();
   
    Session session = this.em.unwrap(Session.class);
    session.doWork(work);
  }
 
  /**
   * Executes some DB work that require a DataSource instance.
   * <p>
 
View Full Code Here

    }
   
    conf.getProperties().put("hibernate.dialect", this.emf.getProperties().get("hibernate.dialect"));
   
    Session session = (Session)em.getDelegate();
    session.doWork(new Work() {
      @Override
      public void execute(Connection connection) throws SQLException {
        SchemaExport export = new SchemaExport(conf, connection);
        export.create(true, true);
      }
View Full Code Here

   * the transaction (if any) of the EntityManager.
   * @param work Work callback interface
   */
  public static void doWork(EntityManager em, Work work) {
    Session session = em.unwrap(Session.class);
    session.doWork(work);
  }
 
  /**
   * Executes some DB work using a raw JDBC connection.
   * <p>
 
View Full Code Here

  }

  public void testGeneralUsage() throws Throwable {
    Session session = openSession();
    session.beginTransaction();
    session.doWork(
        new Work() {
          public void execute(Connection connection) throws SQLException {
            // in this current form, users must handle try/catches themselves for proper resource release
            Statement statement = null;
            try {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.