Package org.hibernate

Examples of org.hibernate.SessionFactory


    }
   
    private String getTablename(HasBlob<?> hasBlob) {
        String tablename = entitiesTablenames.get(hasBlob.getClass());
        if (tablename == null) {
            SessionFactory sf = GrailsIntegration.getCurrentSessionFactory();
            ClassMetadata classMetadata = sf.getClassMetadata(hasBlob.getClass());
            if (classMetadata instanceof SingleTableEntityPersister) {
                SingleTableEntityPersister step = (SingleTableEntityPersister) classMetadata;
                tablename = step.getTableName();
                entitiesTablenames.put(hasBlob.getClass(), tablename);
            }
View Full Code Here


        // Fetch and pre-process the Hibernate mapping descriptors.
        loadHibernateDescriptors(hbmConfig);

        // Initialize the Hibernate session factory.
        ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(hbmConfig.getProperties()).buildServiceRegistry();
        SessionFactory factory = hbmConfig.buildSessionFactory(serviceRegistry);
        hibernateSessionFactoryProvider.setSessionFactory(factory);

        // Synchronize the database schema.
        if (databaseAutoSynchronizer != null) {
            databaseAutoSynchronizer.synchronize(this);
View Full Code Here

    assertNotNull(Invocation.getInvocation(invocations, "rollback", 0));
  }
 
  public void testUserSuppliedSession() throws Exception {
    DbPersistenceServiceFactory persistenceServiceFactory = new DbPersistenceServiceFactory();
    SessionFactory sessionFactory = persistenceServiceFactory.getSessionFactory();
    DbPersistenceService persistenceService = (DbPersistenceService) persistenceServiceFactory.openService();
   
    Session session = sessionFactory.openSession();
    persistenceService.setSession(session);
   
    persistenceService.getSession();
    assertNull(persistenceService.transaction);
    persistenceService.close();
View Full Code Here

  public void testUserSuppliedSessionWithRollback() throws Exception {
    DataSource dataSource = Jdbc.createRecordedDataSource();
    Connection connection = dataSource.getConnection();

    DbPersistenceServiceFactory persistenceServiceFactory = new DbPersistenceServiceFactory();
    SessionFactory sessionFactory = persistenceServiceFactory.getSessionFactory();
    DbPersistenceService persistenceService = (DbPersistenceService) persistenceServiceFactory.openService();
   
    Session session = sessionFactory.openSession(connection);
    persistenceService.setSession(session);
    persistenceService.setRollbackOnly();
   
    persistenceService.getSession();
    assertNull(persistenceService.transaction);
View Full Code Here

   
    return configuration;
  }

  public static SessionFactory buildSessionFactory(Configuration configuration) {
    SessionFactory sessionFactory = null;
    // create the hibernate session factory
    log.debug("building hibernate session factory");
    sessionFactory = configuration.buildSessionFactory();
    return sessionFactory;
  }
View Full Code Here

  public boolean matches(Class valueClass) {
    boolean matches = false;
    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
    if (jbpmContext!=null) {
      SessionFactory sessionFactory = jbpmContext.getSessionFactory();
      ClassMetadata classMetadata = sessionFactory.getClassMetadata(valueClass);
      matches = ( (classMetadata!=null)
                  && (classMetadata.getIdentifierType().getClass()==StringType.class)
                 );
    } else {
      log.debug("no current context so valueClass cannot be stored as a string-id-ref to a hibernate object");
View Full Code Here

  public boolean matches(Class valueClass) {
    boolean matches = false;
    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
    if (jbpmContext!=null) {
      SessionFactory sessionFactory = jbpmContext.getSessionFactory();
      ClassMetadata classMetadata = sessionFactory.getClassMetadata(valueClass);
      matches =  ( (classMetadata!=null)
                   && (classMetadata.getIdentifierType().getClass()==LongType.class)
                 );
    } else {
      log.debug("no current context so valueClass cannot be stored as a long-id-ref to a hibernate object");
View Full Code Here

    Configuration configuration = createConfiguration(cfgXmlResource, propertiesResource);
    return createSessionFactory(configuration, isConfigLookupEnabled);
  }

  public static SessionFactory createSessionFactory(Configuration configuration, boolean isConfigLookupEnabled) {
    SessionFactory sessionFactory = configuration.buildSessionFactory();
    if (isConfigLookupEnabled) {
      configurations.put(sessionFactory, configuration);
    }
    return sessionFactory;
  }
View Full Code Here

  }

  public void testDefaults() {
    DbPersistenceServiceFactory persistenceServiceFactory = new DbPersistenceServiceFactory();
    assertNull(persistenceServiceFactory.sessionFactory);
    SessionFactory sessionFactory = persistenceServiceFactory.getSessionFactory();
    assertNotNull(sessionFactory);
    assertSame(sessionFactory, persistenceServiceFactory.sessionFactory);
    assertNotNull(persistenceServiceFactory.sessionFactory.getClassMetadata(Token.class));
  }
View Full Code Here

    assertEquals(dataSource, persistenceServiceFactory.getDataSource());
    assertNotNull(persistenceServiceFactory.dataSource);
  }

  public void testJndiSessionFactory() throws Exception {
    SessionFactory sessionFactory = createSimplestSessionFactory();
    Jndi.putInJndi("java:/hibernate/testSessionFactory", sessionFactory);

    DbPersistenceServiceFactory persistenceServiceFactory = new DbPersistenceServiceFactory();
    persistenceServiceFactory.sessionFactoryJndiName = "java:/hibernate/testSessionFactory";
    assertNull(persistenceServiceFactory.sessionFactory);
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.