Package org.hibernate

Examples of org.hibernate.StatelessSession


            query.executeUpdate();
        }
    }

    protected StatelessSession getSQLSession(DataMigratorConfiguration config) {
        StatelessSession session = ((org.hibernate.Session) config.getEntityManager().getDelegate())
            .getSessionFactory().openStatelessSession();

        prepareSQLSession(session, config);

        return session;
View Full Code Here


        this.config = config;
    }

    public void migrate() {
        org.hibernate.Query nativeQuery;
        StatelessSession session = getSQLSession(config);

        if (config.isRun1HAggregateDataMigration()) {
            session.getTransaction().begin();
            nativeQuery = session.createSQLQuery(MigrationQuery.DELETE_1H_DATA.toString());
            nativeQuery.executeUpdate();
            session.getTransaction().commit();
            log.info("- RHQ_MEASUREMENT_DATA_NUM_1H - Cleaned -");
        }

        if (config.isRun6HAggregateDataMigration()) {
            session.getTransaction().begin();
            nativeQuery = session.createSQLQuery(MigrationQuery.DELETE_6H_DATA.toString());
            nativeQuery.executeUpdate();
            session.getTransaction().commit();
            log.info("- RHQ_MEASUREMENT_DATA_NUM_6H - Cleaned -");
        }

        if (config.isRun1DAggregateDataMigration()) {
            session.getTransaction().begin();
            nativeQuery = session.createSQLQuery(MigrationQuery.DELETE_1D_DATA.toString());
            nativeQuery.executeUpdate();
            session.getTransaction().commit();
            log.info("- RHQ_MEASUREMENT_DATA_NUM_1D - Cleaned -");
        }

        if (config.isRunRawDataMigration()) {
            for (String table : getRawDataTables()) {
                session.getTransaction().begin();
                String deleteAllData = String.format(MigrationQuery.DELETE_RAW_ALL_DATA.toString(), table);
                nativeQuery = session.createSQLQuery(deleteAllData);
                nativeQuery.executeUpdate();
                session.getTransaction().commit();
                log.info("- " + table + " - Cleaned -");
            }
        }

        closeSQLSession(session);
View Full Code Here

            deleteTableData();
        }
    }

    private long getRowCount(String countQuery) {
        StatelessSession session = getSQLSession(config);

        org.hibernate.Query query = session.createSQLQuery(countQuery);
        query.setReadOnly(true);
        query.setTimeout(DataMigrator.SQL_TIMEOUT);
        long count = Long.parseLong(query.uniqueResult().toString());

        closeSQLSession(session);
View Full Code Here

    private void deleteTableData() throws Exception {
        int failureCount = 0;
        while (failureCount < MAX_NUMBER_OF_FAILURES) {
            try {
                StatelessSession session = getSQLSession(config);
                session.getTransaction().begin();
                org.hibernate.Query nativeQuery = session.createSQLQuery(this.deleteQuery);
                nativeQuery.executeUpdate();
                session.getTransaction().commit();
                closeSQLSession(session);
                log.info("- " + migrationTable.toString() + " - Cleaned -");
            } catch (Exception e) {
                log.error("Failed to delete " + migrationTable.toString()
                    + " data. Attempting to delete data one more time...");
View Full Code Here

        org.hibernate.Session mockHibernateSession = mock(org.hibernate.Session.class);
        when(mockEntityManager.getDelegate()).thenReturn(mockHibernateSession);
        SessionFactory mockSessionFactory = mock(SessionFactory.class);
        when(mockHibernateSession.getSessionFactory()).thenReturn(mockSessionFactory);
        StatelessSession mockStatelessSession = mock(StatelessSession.class);
        when(mockSessionFactory.openStatelessSession()).thenReturn(mockStatelessSession);

        org.hibernate.SQLQuery mockQuery = mock(org.hibernate.SQLQuery.class);
        when(mockStatelessSession.createSQLQuery(any(String.class))).thenReturn(mockQuery);

        when(mockQuery.uniqueResult()).thenReturn("1000");

        ScrollableDataSource mockDataSource = mock(ScrollableDataSource.class);
        PowerMockito.whenNew(ScrollableDataSource.class)
View Full Code Here

        org.hibernate.Session mockHibernateSession = mock(org.hibernate.Session.class);
        when(mockEntityManager.getDelegate()).thenReturn(mockHibernateSession);
        SessionFactory mockSessionFactory = mock(SessionFactory.class);
        when(mockHibernateSession.getSessionFactory()).thenReturn(mockSessionFactory);
        StatelessSession mockStatelessSession = mock(StatelessSession.class);
        when(mockSessionFactory.openStatelessSession()).thenReturn(mockStatelessSession);

        org.hibernate.SQLQuery mockQuery = mock(org.hibernate.SQLQuery.class);
        when(mockStatelessSession.createSQLQuery(any(String.class))).thenReturn(mockQuery);

        when(mockQuery.uniqueResult()).thenReturn("1000");

        ScrollableDataSource mockDataSource = mock(ScrollableDataSource.class);
        PowerMockito.whenNew(ScrollableDataSource.class).withArguments(eq(mockEntityManager), eq(databaseType), any())
View Full Code Here

        org.hibernate.Session mockHibernateSession = mock(org.hibernate.Session.class);
        when(mockEntityManager.getDelegate()).thenReturn(mockHibernateSession);
        SessionFactory mockSessionFactory = mock(SessionFactory.class);
        when(mockHibernateSession.getSessionFactory()).thenReturn(mockSessionFactory);
        StatelessSession mockStatelessSession = mock(StatelessSession.class);
        when(mockSessionFactory.openStatelessSession()).thenReturn(mockStatelessSession);

        org.hibernate.SQLQuery mockQuery = mock(org.hibernate.SQLQuery.class);
        when(mockStatelessSession.createSQLQuery(any(String.class))).thenReturn(mockQuery);

        when(mockQuery.uniqueResult()).thenReturn("1000");

        ScrollableDataSource mockDataSource = mock(ScrollableDataSource.class);
        PowerMockito.whenNew(ScrollableDataSource.class)
View Full Code Here

        org.hibernate.Session mockHibernateSession = mock(org.hibernate.Session.class);
        when(mockEntityManager.getDelegate()).thenReturn(mockHibernateSession);
        SessionFactory mockSessionFactory = mock(SessionFactory.class);
        when(mockHibernateSession.getSessionFactory()).thenReturn(mockSessionFactory);
        StatelessSession mockStatelessSession = mock(StatelessSession.class);
        when(mockSessionFactory.openStatelessSession()).thenReturn(mockStatelessSession);

        org.hibernate.SQLQuery mockQuery = mock(org.hibernate.SQLQuery.class);
        when(mockStatelessSession.createSQLQuery(any(String.class))).thenReturn(mockQuery);

        when(mockQuery.uniqueResult()).thenReturn("1000");

        ScrollableDataSource mockDataSource = mock(ScrollableDataSource.class);
        PowerMockito.whenNew(ScrollableDataSource.class).withArguments(eq(mockEntityManager), eq(databaseType), any())
View Full Code Here

  public static Test suite() {
    return new FunctionalTestClassTestSuite( StatelessSessionTest.class );
  }

  public void testCreateUpdateReadDelete() {
    StatelessSession ss = getSessions().openStatelessSession();
    Transaction tx = ss.beginTransaction();
    Document doc = new Document("blah blah blah", "Blahs");
    ss.insert(doc);
    assertNotNull( doc.getName() );
    Date initVersion = doc.getLastModified();
    assertNotNull( initVersion );
    tx.commit();
   
    tx = ss.beginTransaction();
    doc.setText("blah blah blah .... blah");
    ss.update(doc);
    assertNotNull( doc.getLastModified() );
    assertNotSame( doc.getLastModified(), initVersion );
    tx.commit();
   
    tx = ss.beginTransaction();
    doc.setText("blah blah blah .... blah blay");
    ss.update(doc);
    tx.commit();
   
    Document doc2 = (Document) ss.get(Document.class.getName(), "Blahs");
    assertEquals("Blahs", doc2.getName());
    assertEquals(doc.getText(), doc2.getText());
       
    doc2 = (Document) ss.createQuery("from Document where text is not null").uniqueResult();
    assertEquals("Blahs", doc2.getName());
    assertEquals(doc.getText(), doc2.getText());
   
    ScrollableResults sr = ss.createQuery("from Document where text is not null")
      .scroll(ScrollMode.FORWARD_ONLY);
    sr.next();
    doc2 = (Document) sr.get(0);
    sr.close();
    assertEquals("Blahs", doc2.getName());
    assertEquals(doc.getText(), doc2.getText());
       
    doc2 = (Document) ss.createSQLQuery("select * from Document")
      .addEntity(Document.class)
      .uniqueResult();
    assertEquals("Blahs", doc2.getName());
    assertEquals(doc.getText(), doc2.getText());
       
    doc2 = (Document) ss.createCriteria(Document.class).uniqueResult();
    assertEquals("Blahs", doc2.getName());
    assertEquals(doc.getText(), doc2.getText());
   
    sr = ss.createCriteria(Document.class).scroll(ScrollMode.FORWARD_ONLY);
    sr.next();
    doc2 = (Document) sr.get(0);
    sr.close();
    assertEquals("Blahs", doc2.getName());
    assertEquals(doc.getText(), doc2.getText());

    tx = ss.beginTransaction();
    ss.delete(doc);
    tx.commit();
    ss.close();

  }
View Full Code Here

    ss.close();

  }

  public void testHqlBulk() {
    StatelessSession ss = getSessions().openStatelessSession();
    Transaction tx = ss.beginTransaction();
    Document doc = new Document("blah blah blah", "Blahs");
    ss.insert(doc);
    Paper paper = new Paper();
    paper.setColor( "White" );
    ss.insert(paper);
    tx.commit();

    tx = ss.beginTransaction();
    int count = ss.createQuery( "update Document set name = :newName where name = :oldName" )
        .setString( "newName", "Foos" )
        .setString( "oldName", "Blahs" )
        .executeUpdate();
    assertEquals( "hql-update on stateless session", 1, count );
    count = ss.createQuery( "update Paper set color = :newColor" )
        .setString( "newColor", "Goldenrod" )
        .executeUpdate();
    assertEquals( "hql-update on stateless session", 1, count );
    tx.commit();

    tx = ss.beginTransaction();
    count = ss.createQuery( "delete Document" ).executeUpdate();
    assertEquals( "hql-delete on stateless session", 1, count );
    count = ss.createQuery( "delete Paper" ).executeUpdate();
    assertEquals( "hql-delete on stateless session", 1, count );
    tx.commit();
    ss.close();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.StatelessSession

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.