Examples of SessionFactory


Examples of org.hibernate.SessionFactory

  protected String standardTransactionName;
  protected String connectionName;

  public Object construct(WireContext wireContext) {
    // get the hibernate-session-factory
    SessionFactory sessionFactory = null;
    if (factoryName!=null) {
      sessionFactory = (SessionFactory) wireContext.get(factoryName);
    } else {
      Environment environment = wireContext.getEnvironment();
      if (environment!=null) {
        sessionFactory = environment.get(SessionFactory.class);
      } else {
        sessionFactory = wireContext.get(SessionFactory.class);
      }
    }
    if (sessionFactory==null) {
      throw new WireException("couldn't find hibernate-session-factory "+(factoryName!=null ? "'"+factoryName+"'" : "by type ")+"to open a hibernate-session");
    }

    // open the hibernate-session
    Session session = null;
    if (connectionName!=null) {
      Connection connection = (Connection) wireContext.get(connectionName);
      log.finest("creating hibernate session with connection "+connection);
      session = sessionFactory.openSession(connection);

    } else {
      log.finest("creating hibernate session");
      session = sessionFactory.openSession();
    }

    return session;
  }
View Full Code Here

Examples of org.hibernate.SessionFactory

  public boolean matches(String name, Object value) {
    boolean matches = false;
   
    Environment environment = Environment.getCurrent();
    if (environment!=null) {
      SessionFactory sessionFactory = (SessionFactory) environment.get("hibernate.session.factory");
      if (sessionFactory!=null) {
        ClassMetadata classMetadata = sessionFactory.getClassMetadata(value.getClass());
        matches = ( (classMetadata!=null)
                    && (classMetadata.getIdentifierType().getClass()==StringType.class)
                   );
      }
    } else {
View Full Code Here

Examples of org.hibernate.SessionFactory

  public boolean matches(String name, Object value) {
    boolean matches = false;
   
    Environment environment = Environment.getCurrent();
    if (environment!=null) {
      SessionFactory sessionFactory = (SessionFactory) environment.get("hibernate.session.factory");
      if (sessionFactory!=null) {
        ClassMetadata classMetadata = sessionFactory.getClassMetadata(value.getClass());
        matches =  ( (classMetadata!=null)
                     && (classMetadata.getIdentifierType().getClass()==LongType.class)
                   );
      }
    } else {
View Full Code Here

Examples of org.hibernate.SessionFactory

public class JNDIReferenceTest extends OgmTestCase {

  @Test
  public void testGetReferenceImplementation() throws Exception {
    final Session session = openSession();
    SessionFactory factory = session.getSessionFactory();

    assertThat( factory.getClass() ).isEqualTo( OgmSessionFactoryImpl.class );

    Reference reference = factory.getReference();
    assertThat( reference.getClassName() ).isEqualTo( OgmSessionFactoryImpl.class.getName() );
    assertThat( reference.getFactoryClassName() ).isEqualTo( OgmSessionFactoryObjectFactory.class.getName() );
    assertThat( reference.get( 0 ) ).isNotNull();
    assertThat( reference.getFactoryClassLocation() ).isNull();

    OgmSessionFactoryObjectFactory objFactory = new OgmSessionFactoryObjectFactory();
    SessionFactory factoryFromRegistry = (SessionFactory) objFactory.getObjectInstance( reference, null, null, null );
    assertThat( factoryFromRegistry.getClass() ).isEqualTo( OgmSessionFactoryImpl.class );
    assertThat( factoryFromRegistry.getReference() ).isEqualTo( factory.getReference() );

    session.close();
  }
View Full Code Here

Examples of org.hibernate.SessionFactory

  @Test
  public void testWrappedFromEntityManagerAPI() throws Exception {
    final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone", TestHelper.getEnvironmentProperties() );
    assertThat( HibernateEntityManagerFactory.class.isAssignableFrom( emf.getClass() ) ).isTrue();
    SessionFactory factory = ( (HibernateEntityManagerFactory) emf ).getSessionFactory();
    assertThat( factory.getClass() ).isEqualTo( OgmSessionFactoryImpl.class );

    Session s = factory.openSession();
    assertThat( s.getClass() ).isEqualTo( OgmSessionImpl.class );
    assertThat( s.getSessionFactory().getClass() ).isEqualTo( OgmSessionFactoryImpl.class );
    s.close();

    EntityManager em = emf.createEntityManager();
View Full Code Here

Examples of org.hibernate.SessionFactory

  }

  @Test
  public void testJNDIReference() throws Exception {
    final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "jpajtastandalone", TestHelper.getEnvironmentProperties() );
    SessionFactory factory = ( (HibernateEntityManagerFactory) emf ).getSessionFactory();
    Reference reference = factory.getReference();
    assertThat( reference.getClassName() ).isEqualTo( OgmSessionFactoryImpl.class.getName() );
    assertThat( reference.getFactoryClassName() ).isEqualTo( OgmSessionFactoryObjectFactory.class.getName() );
    assertThat( reference.get( 0 ) ).isNotNull();
    assertThat( reference.getFactoryClassLocation() ).isNull();

    OgmSessionFactoryObjectFactory objFactory = new OgmSessionFactoryObjectFactory();
    SessionFactory factoryFromRegistry = (SessionFactory) objFactory.getObjectInstance( reference, null, null, null );
    assertThat( factoryFromRegistry.getClass() ).isEqualTo( OgmSessionFactoryImpl.class );
    assertThat( factoryFromRegistry.getReference() ).isEqualTo( factory.getReference() );

    emf.close();
  }
View Full Code Here

Examples of org.hibernate.SessionFactory

    ProcessDefinitionFactoryBean definition = new ProcessDefinitionFactoryBean();
    definition.setDefinitionLocation(definitionLocation);
    definition.afterPropertiesSet();

    MockControl sfCtrl = MockControl.createControl(SessionFactory.class);
    SessionFactory sf = (SessionFactory) sfCtrl.getMock();

    MockControl sCtrl = MockControl.createNiceControl(Session.class);
    Session session = (Session) sCtrl.getMock();

    MockControl queryCtrl = MockControl.createNiceControl(Query.class);
    Query query = (Query) queryCtrl.getMock();

    session.getNamedQuery("");
    sCtrl.setMatcher(MockControl.ALWAYS_MATCHER);
    sCtrl.setReturnValue(query);

    sfCtrl.expectAndReturn(sf.openSession(), session);
    sfCtrl.replay();
    sCtrl.replay();
    queryCtrl.replay();

    configuration.setProcessDefinitions(new ProcessDefinition[] { (ProcessDefinition) definition.getObject() });
View Full Code Here

Examples of org.hibernate.SessionFactory

    Upsert, Delete
  }

  public void performDBAction(Object objToSave, DBActionCriteria criteria) {

    SessionFactory sessionFactory = null;
    Session session = null;

    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();
     
      performDBAction(objToSave, criteria, session);

    } catch (Exception a_th) {
      throw new RuntimeException(a_th);
View Full Code Here

Examples of org.hibernate.SessionFactory

    performDBAction(baseRight, DBActionCriteria.Delete);
  }
 
  public RightsGroup getRightGroup(String groupName) {
    validateNullEntries(groupName);
    SessionFactory sessionFactory = null;
    Session session = null;
    RightsGroup group = null;
    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();
      Criteria c = session.createCriteria(RightsGroup.class);
      c.add(Restrictions.eq("groupName", groupName));
      List<RightsGroup> lstRights = c.list();
      if(lstRights != null && lstRights.size() > 0) {
        group = lstRights.get(0);
View Full Code Here

Examples of org.hibernate.SessionFactory

    }
    return group;
  }
 
  public RightsGroup getRightGroup(long groupID) {
    SessionFactory sessionFactory = null;
    Session session = null;
    RightsGroup group = null;
    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();
      Criteria c = session.createCriteria(RightsGroup.class);
      c.add(Restrictions.idEq(groupID));
      List<RightsGroup> lstRights = c.list();
      if(lstRights != null && lstRights.size() > 0) {
        group = lstRights.get(0);
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.