Package org.hibernate

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


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

  @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

  }

  @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

    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

    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

    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

    }
    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

    }
    return group;
  }
 
  public BaseRight getBaseRight(long baseRightID) {
    SessionFactory sessionFactory = null;
    Session session = null;
    BaseRight baseRight = null;
    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();
      Criteria c = session.createCriteria(BaseRight.class);
      c.add(Restrictions.idEq(baseRightID));
      List<BaseRight> lstRights = c.list();
      if(lstRights != null && lstRights.size() > 0) {
        baseRight = lstRights.get(0);
View Full Code Here

    validateNullEntries(assignGroup);
    performDBAction(assignGroup, DBActionCriteria.Upsert);
  }
 
  public List<AssignedRightsGroup> getAllAssociatedGroups(IPermisibleResource resource, RightsGroup group) {
    SessionFactory sessionFactory = null;
    Session session = null;
    try {
      sessionFactory = HibernateSessionFactory.getInstance();
      session = sessionFactory.openSession();
      Criteria c = session.createCriteria(AssignedRightsGroup.class);
      if(resource != null) {
        c.add(Restrictions.eq("resourceTypeID", resource.getResourceTypeID()))
      }
     
View Full Code Here

TOP

Related Classes of org.hibernate.SessionFactory

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.