You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

Java Basic Samples

Sample: main construct
String configFile           = "./hibernate.cfg.xml";
SOSHibernateFactory factory = null;
SOSHibernateSession session = null;

try
{
    factory = new SOSHibernateFactory(configFile);
    factory.build();
     
    // session = factory.openSession();     
    // session = factory.getCurrentSession();     
    session = factory.openStatelessSession();
     
    session.beginTransaction();
    ....
    session.commit();
} 
 
catch( Exception e ) 
{
    if ( session != null )
    {
        try
        {
            session.rollback();
        } 
 
		catch( Exception ex ) {}
	} 
    throw e;
}
finally
{
    if ( session != null )
    {
        session.close();
    }
    
    if ( factory != null )
    {
        factory.close();
    }
}
Sample: session.scroll()
...
ScrollableResults sr = null;

try
{
    // Query or NativeQuery
    Query<?> query = session.createQuery("from MY_DBITEM_ENTITY");
    sr = session.scroll(query);             
    while (sr.next()) {                 
        // do something with the current record            
    }
}

catch( Exception e )
{
    throw e;
}

finally
{
    if ( sr != null ){
       sr.close(); 
    }
}             
...
Sample: session.getSQLExecutor().getResultSet(String sql)
...
executor = session.getSQLExecutor();
...    
ResultSet rs = null;

try
{
    rs = executor.getResultSet("select * from MY_TABLE");             
    Map<String, String> record = null;             
    while (!(record = executor.nextAsStringMap(rs)).isEmpty()) { //or ... executor.next(rs) ...               
        // do something with the current record            
    }
}

catch(Exception e)
{
    throw e;
}

finally
{
    executor.close(rs); 
}             
     
...

JavaScript Job Samples

 

 

 

 

 

  • No labels