Java Code Examples for org.hibernate.SessionFactory

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project capedwarf-green, under directory /server-jee/src/main/java/org/jboss/capedwarf/server/jee/persistence/.

Source file: HibernateStatelessAdapterFactory.java

  25 
vote

protected StatelessAdapter doCreateStatelessAdapter(EntityManager em){
  Object delegate=em.getDelegate();
  if (delegate instanceof Session == false)   throw new IllegalArgumentException("Can only handle Hibernate Session: " + delegate);
  Session session=(Session)delegate;
  SessionFactory factory=session.getSessionFactory();
  return new HibernateStatelessAdapter(factory.openStatelessSession());
}
 

Example 2

From project core_5, under directory /exo.core.component.database/src/main/java/org/exoplatform/services/database/impl/.

Source file: HibernateServiceImpl.java

  22 
vote

/** 
 * @return the SessionFactory
 */
public SessionFactory getSessionFactory(){
  if (sessionFactory_ == null) {
    sessionFactory_=SecurityHelper.doPrivilegedAction(new PrivilegedAction<SessionFactory>(){
      public SessionFactory run(){
        SessionFactory factory=conf_.buildSessionFactory();
        return factory;
      }
    }
);
  }
  return sessionFactory_;
}
 

Example 3

From project faces, under directory /Proyectos/02-richfaces-solution/src/test/java/accounts/internal/dao/.

Source file: HibernateAccountRepositoryTest.java

  22 
vote

@Override protected void setUp() throws Exception {
  SessionFactory sessionFactory=createTestSessionFactory();
  accountRepository=new HibernateAccountRepository(sessionFactory);
  transactionManager=new HibernateTransactionManager(sessionFactory);
  transactionStatus=transactionManager.getTransaction(new DefaultTransactionDefinition());
}
 

Example 4

From project hibernate-ogm, under directory /hibernate-ogm-core/src/test/java/org/hibernate/ogm/test/hibernatecore/.

Source file: HibernateCoreAPIWrappingTest.java

  22 
vote

@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(OgmSessionFactory.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(OgmSessionFactory.class);
  assertThat(factoryFromRegistry.getReference()).isEqualTo(factory.getReference());
  emf.close();
}
 

Example 5

From project hibernate-tools, under directory /src/testsupport/.

Source file: HibernateTestAuto.java

  22 
vote

public static void main(String[] args){
  Configuration cfg=new Configuration();
  cfg.configure("/hibernate.cfg.xml");
  SessionFactory factory=cfg.buildSessionFactory();
  Session session=factory.openSession();
  Map allClassMetadata=factory.getAllClassMetadata();
  Iterator iterator=allClassMetadata.values().iterator();
  while (iterator.hasNext()) {
    ClassMetadata element=(ClassMetadata)iterator.next();
    List list=session.createQuery("from " + element.getMappedClass().getName()).list();
    System.out.println(list);
  }
}
 

Example 6

From project jdonframework, under directory /JdonAccessory/src/com/jdon/persistence/hibernate/.

Source file: HibernateCRUDTemplate.java

  22 
vote

public HibernateCRUDTemplate(ConfFactory hibernateConfFactory){
  this.dataSource=hibernateConfFactory.getDataSource();
  SessionFactory sessionFactory=hibernateConfFactory.getSessionFactory();
  this.sessionProvider=new ThreadLocalSessionProvider(sessionFactory);
  this.hibernateTemplate=new HibernateTemplate(sessionProvider);
}
 

Example 7

From project riot, under directory /common/src/org/riotfamily/common/hibernate/.

Source file: ActiveRecordUtils.java

  22 
vote

/** 
 * Returns the identifier of the given ActiveRecord. The id is obtained using the Hibernate meta-data API.
 * @see ClassMetadata#getIdentifier(Object,EntityMode)
 */
public static Serializable getId(ActiveRecord record){
  SessionFactory sessionFactory=ActiveRecord.getSessionFactory();
  if (sessionFactory == null) {
    return "N/A";
  }
  return sessionFactory.getClassMetadata(getClass(record)).getIdentifier(record,EntityMode.POJO);
}
 

Example 8

From project rsql-hibernate, under directory /src/test/java/cz/jirutka/rsql/hibernate/.

Source file: AbstractCriterionBuilderTest.java

  22 
vote

@Test public void testIsPropertyName(){
  SessionFactory sf=SessionFactoryInitializer.getSessionFactory();
  ClassMetadata classMetadata=sf.getClassMetadata(Course.class);
  assertTrue(instance.isPropertyName("code",classMetadata));
  assertTrue(instance.isPropertyName("department",classMetadata));
  assertFalse(instance.isPropertyName("foo",classMetadata));
}
 

Example 9

From project serengeti-ws, under directory /server/serengeti/src/main/java/com/vmware/bdd/dal/.

Source file: DAL.java

  22 
vote

private static SessionFactory buildSessionFactory(){
  try {
    SessionFactory _ssn=new org.hibernate.cfg.Configuration().configure().buildSessionFactory();
    checkIsolationLevel(_ssn.getCurrentSession());
    return _ssn;
  }
 catch (  Throwable ex) {
    throw new ExceptionInInitializerError(ex);
  }
}
 

Example 10

From project tawus, under directory /tawus-hibernate/src/main/java/com/googlecode/tawus/hibernate/internal/services/.

Source file: SessionFactorySourceImpl.java

  22 
vote

private void setupSessionFactory(final SessionFactoryConfiguration configuration){
  final Configuration hibernateConfig=new Configuration();
  final List<Class<?>> entities=loadEntityClasses(configuration);
  for (  final Class<?> entityClass : entities) {
    hibernateConfig.addAnnotatedClass(entityClass);
    entityMap.put(entityClass,configuration.getFactoryId());
  }
  configuration.configure(hibernateConfig);
  final SessionFactory sf=hibernateConfig.buildSessionFactory();
  if (configuration.getFactoryId() != null) {
    factoryMap.put(configuration.getFactoryId(),sf);
  }
}
 

Example 11

From project azure4j-blog-samples, under directory /SQLAzure/SqlAzureHibernate/src/com/persistent/azure/.

Source file: HibernateAccess.java

  21 
vote

/** 
 * main method
 * @param args
 */
public static void main(String[] args){
  SessionFactory sessionFactory=buildSessionFactory();
  Session session;
  session=sessionFactory.openSession();
  session.beginTransaction();
  try {
    @SuppressWarnings("unchecked") List<Employee> employeeList=session.createQuery("from Employee").list();
    Employee employee=null;
    for (int index=0; index < employeeList.size(); index++) {
      employee=employeeList.get(index);
      System.out.println(employee.getName());
    }
  }
 catch (  Exception e) {
  }
 finally {
    session.close();
  }
}
 

Example 12

From project jboss-jpa, under directory /deployers/src/test/java/org/jboss/jpa/deployers/test/jbjpa6/.

Source file: PersistenceUnitJNDIBindingsTestCase.java

  21 
vote

@Test public void testSF() throws Exception {
  InitialContext ctx=new InitialContext();
  SessionFactory sf=null;
  try {
    sf=(SessionFactory)ctx.lookup(SF_PATH);
  }
 catch (  Exception e) {
    fail("SessionFactory binding failed");
  }
  try {
    sf.isClosed();
  }
 catch (  Exception e) {
    fail("SessionFactory test invocation failed");
  }
}
 

Example 13

From project joda-time-hibernate, under directory /src/test/java/org/joda/time/contrib/hibernate/.

Source file: HibernateTestCase.java

  21 
vote

protected SessionFactory getSessionFactory(){
  if (this.factory == null) {
    cfg=new Configuration();
    setupConfiguration(cfg);
    cfg.setProperty("hibernate.connection.driver_class","org.hsqldb.jdbcDriver");
    cfg.setProperty("hibernate.connection.url","jdbc:hsqldb:mem:hbmtest" + getClass().getName());
    cfg.setProperty("hibernate.dialect",HSQLDialect.class.getName());
    cfg.setProperty("hibernate.show_sql","true");
    SessionFactory factory=cfg.buildSessionFactory();
    SchemaUpdate update=new SchemaUpdate(cfg);
    update.execute(true,true);
    this.factory=factory;
  }
  return factory;
}
 

Example 14

From project onebusaway-gtfs-modules, under directory /onebusaway-gtfs-hibernate/src/test/java/org/onebusaway/gtfs/examples/.

Source file: GtfsHibernateReaderExampleMain.java

  21 
vote

private static HibernateGtfsFactory createHibernateGtfsFactory(String resource){
  Configuration config=new Configuration();
  if (resource.startsWith(KEY_CLASSPATH)) {
    resource=resource.substring(KEY_CLASSPATH.length());
    config=config.configure(resource);
  }
 else   if (resource.startsWith(KEY_FILE)) {
    resource=resource.substring(KEY_FILE.length());
    config=config.configure(new File(resource));
  }
 else {
    config=config.configure(new File(resource));
  }
  SessionFactory sessionFactory=config.buildSessionFactory();
  return new HibernateGtfsFactory(sessionFactory);
}
 

Example 15

From project persistence_1, under directory /impl/src/main/java/org/jboss/seam/persistence/hibernate/.

Source file: HibernateManagedSessionBeanLifecycle.java

  21 
vote

/** 
 * creates the proxy
 */
public Session create(Bean<Session> bean,CreationalContext<Session> arg0){
  try {
    SessionFactory sf=getSessionFactory();
    Session session=sf.openSession();
    session=(Session)persistenceProvider.proxyDelegate(session);
    HibernateManagedSessionProxyHandler handler=new HibernateManagedSessionProxyHandler(session,manager,bean.getQualifiers(),persistenceProvider,manager);
    Session proxy=(Session)proxyConstructor.newInstance(handler);
    try {
      ((ManagedPersistenceContext)proxy).changeFlushMode(getPersistenceContexts().getFlushMode());
    }
 catch (    ContextNotActiveException e) {
    }
    manager.fireEvent(new SeamManagedHibernateSessionCreated(proxy),qualifiers);
    return proxy;
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 16

From project portal, under directory /portal-core/src/test/java/org/devproof/portal/core/module/common/repository/.

Source file: FinderDispatcherGenericRepositoryImplTest.java

  21 
vote

@Before @SuppressWarnings("unchecked") public void setUp() throws Exception {
  SessionFactory sessionFactory=createMock(SessionFactory.class);
  Session session=createMock(Session.class);
  crudRepository=createMock(CrudRepository.class);
  impl=new FinderDispatcherGenericRepositoryImpl<TestEntity,Integer>(){
    private static final long serialVersionUID=1L;
    @Override protected CrudRepository<TestEntity,Integer> createGenericHibernateDao(){
      return crudRepository;
    }
  }
;
  impl.setDaoInterface(TestRepository.class);
  impl.setEntityClass(TestEntity.class);
  impl.setSessionFactory(sessionFactory);
  testDao=(TestRepository)impl.getObject();
  expect(session.getSessionFactory()).andReturn(sessionFactory);
  expect(sessionFactory.openSession()).andReturn(session);
  SessionHolder sessionHolder=new SessionHolder(session);
  TransactionSynchronizationManager.bindResource(sessionFactory,sessionHolder);
  expect(session.isOpen()).andReturn(false);
  expect(session.getSessionFactory()).andReturn(sessionFactory);
}
 

Example 17

From project qcadoo, under directory /qcadoo-model/src/main/java/com/qcadoo/model/internal/sessionfactory/.

Source file: DynamicSessionFactory.java

  21 
vote

private SessionFactory getSessionFactory(final boolean allowCreation){
  SessionFactory result=sessionFactory;
  if (result == null) {
synchronized (this) {
      result=sessionFactory;
      if (result == null) {
        if (!allowCreation) {
          throw new IllegalStateException("DynamicSessionFactory is not ready to use");
        }
        try {
          result=sessionFactory=sessionFactoryBean.getObject();
        }
 catch (        Exception e) {
          throw new IllegalStateException(e.getMessage(),e);
        }
      }
    }
  }
  return result;
}
 

Example 18

From project Utah-Tools-Decision-Support, under directory /core/edu.utah.cdmcc.decisionsupport.objects.core/src/core/hibernate/.

Source file: HibernateUtil.java

  21 
vote

public static SessionFactory getSessionFactory(){
  log.debug("Getting normal session factory");
  SessionFactory sf=null;
  String sfName=configuration.getProperty(Environment.SESSION_FACTORY_NAME);
  if (sfName != null) {
    try {
      sf=(SessionFactory)new InitialContext().lookup(sfName);
    }
 catch (    NamingException ex) {
      throw new RuntimeException(ex);
    }
  }
 else {
    sf=sessionFactory;
  }
  if (sf == null)   throw new IllegalStateException("SessionFactory not available.");
  return sf;
}
 

Example 19

From project zanata, under directory /zanata-war/src/test/java/org/zanata/.

Source file: ZanataDbunitJpaTest.java

  21 
vote

private void clearCache(){
  Session session=getSession();
  SessionFactory sessionFactory=session.getSessionFactory();
  Map classMetadata=sessionFactory.getAllClassMetadata();
  for (  Object obj : classMetadata.values()) {
    EntityPersister p=(EntityPersister)obj;
    if (p.hasCache()) {
      sessionFactory.evictEntity(p.getEntityName());
    }
  }
  Map collMetadata=sessionFactory.getAllCollectionMetadata();
  for (  Object obj : collMetadata.values()) {
    AbstractCollectionPersister p=(AbstractCollectionPersister)obj;
    if (p.hasCache()) {
      sessionFactory.evictCollection(p.getRole());
    }
  }
}
 

Example 20

From project alphaportal_dev, under directory /sys-src/alphaportal/core/src/main/java/alpha/portal/dao/hibernate/.

Source file: PayloadDaoHibernate.java

  19 
vote

/** 
 * Internal function to load the highest sequenceNumber from the AlphaCard table.
 * @param sessionFactory the session factory
 * @param column the column
 * @return 0 if no record is found
 */
private Long getLastValue(final SessionFactory sessionFactory,final String column){
  Session session;
  boolean sessionOwn=false;
  try {
    session=sessionFactory.getCurrentSession();
  }
 catch (  final Exception e) {
    session=sessionFactory.openSession();
    sessionOwn=true;
  }
  final Query q=session.createSQLQuery("select max(" + column + ") from payload");
  final List<Object> list=q.list();
  BigInteger value=(BigInteger)list.get(0);
  if (value == null) {
    value=new BigInteger("0");
  }
  if (sessionOwn) {
    session.close();
  }
  return value.longValue();
}
 

Example 21

From project brix-cms, under directory /brix-rmiserver/src/main/java/org/brixcms/rmiserver/boot/.

Source file: Bootstrapper.java

  19 
vote

public Bootstrapper(DataSource datasource,PlatformTransactionManager transactionManager,Configuration configuration,SessionFactory sessionFactory,UserService userService,String workspaceManagerLogin,String workspaceManagerPassword){
  this.datasource=datasource;
  this.configuration=configuration;
  this.sessionFactory=sessionFactory;
  this.transactionManager=transactionManager;
  this.userService=userService;
  this.workspaceManagerLogin=workspaceManagerLogin;
  this.workspaceManagerPassword=workspaceManagerPassword;
}
 

Example 22

From project egov-data, under directory /egov-data-hibernate/src/main/java/egov/data/hibernate/repository/support/.

Source file: HibernateEntityInformationSupport.java

  19 
vote

public static <T>HibernateEntityInformation<T,?> getMetadata(Class<T> domainClass,SessionFactory sessionFactory){
  Assert.notNull(domainClass);
  Assert.notNull(sessionFactory);
  ClassMetadata metadata=sessionFactory.getClassMetadata(domainClass);
  if (Persistable.class.isAssignableFrom(domainClass)) {
    return new HibernatePersistableEntityInformation(domainClass,metadata);
  }
 else {
    return new HibernateMetamodelEntityInformation(domainClass,metadata);
  }
}
 

Example 23

From project ehour, under directory /eHour-persistence/src/main/java/net/rrm/ehour/persistence/appconfig/.

Source file: HibernateConfiguration.java

  19 
vote

@Bean(name="sessionFactory") public SessionFactory getSessionFactory() throws Exception {
  Properties configProperties=EhourHomeUtil.loadDatabaseProperties(databaseName);
  LOGGER.info("Using database type: " + databaseName);
  AnnotationSessionFactoryBean factoryBean=new AnnotationSessionFactoryBean();
  factoryBean.setDataSource(dataSource);
  List<Resource> resources=getMappingResources(configProperties);
  factoryBean.setMappingLocations(resources.toArray(new Resource[resources.size()]));
  factoryBean.setAnnotatedClasses(DomainObjects.DOMAIN_OBJECTS);
  Properties hibernateProperties=new Properties();
  hibernateProperties.put("hibernate.dialect",configProperties.get("hibernate.dialect"));
  hibernateProperties.put("show_sql","false");
  hibernateProperties.put("use_outer_join","true");
  hibernateProperties.put("hibernate.cache.region.factory_class","net.sf.ehcache.hibernate.EhCacheRegionFactory");
  hibernateProperties.put("hibernate.cache.use_second_level_cache","true");
  hibernateProperties.put("net.sf.ehcache.configurationResourceName","ehcache.xml");
  hibernateProperties.put("hibernate.cache.use_query_cache","true");
  hibernateProperties.put("hibernate.hbm2ddl.auto",configProperties.get("hibernate.hbm2ddl.auto"));
  factoryBean.setHibernateProperties(hibernateProperties);
  factoryBean.afterPropertiesSet();
  return factoryBean.getObject();
}
 

Example 24

From project jagger, under directory /chassis/core/src/main/java/com/griddynamics/jagger/monitoring/.

Source file: MonitorProcess.java

  19 
vote

MonitorProcess(String sessionId,NodeId agentId,NodeContext nodeContext,Coordinator coordinator,ExecutorService executor,long pollingInterval,long profilerPollingInterval,MonitoringProcessor monitoringProcessor,String taskId,LogWriter logWriter,SessionFactory sessionFactory,long ttl){
  this.sessionId=sessionId;
  this.agentId=agentId;
  this.nodeContext=nodeContext;
  this.coordinator=coordinator;
  this.executor=executor;
  this.pollingInterval=pollingInterval;
  this.monitoringProcessor=monitoringProcessor;
  this.taskId=taskId;
  this.logWriter=logWriter;
  this.profilerPollingInterval=profilerPollingInterval;
  this.setSessionFactory(sessionFactory);
  this.ttl=ttl;
}
 

Example 25

From project java-maven-tests, under directory /src/hiber-demo/src/main/java/com/truward/hiberdemo/services/.

Source file: HibernateAccessor.java

  19 
vote

private static SessionFactory buildSessionFactory(){
  try {
    return new Configuration().configure().buildSessionFactory();
  }
 catch (  Exception e) {
    log.error(e);
    throw new ExceptionInInitializerError(e);
  }
}
 

Example 26

From project jBilling, under directory /src/java/com/sapienter/jbilling/server/util/db/.

Source file: HibernateIdGenerator.java

  19 
vote

/** 
 * Constructs a new ID generator for the given segment. If the segment does not exist in the sequence table, it will be created with the newly generated id values starting from zero. *
 * @param segmentValue jbilling sequence name (value of the 'name' column)
 */
public HibernateIdGenerator(String segmentValue){
  Properties configuration=new Properties();
  configuration.setProperty(TableGenerator.TABLE_PARAM,"jbilling_seqs");
  configuration.setProperty(TableGenerator.SEGMENT_COLUMN_PARAM,"name");
  configuration.setProperty(TableGenerator.SEGMENT_VALUE_PARAM,segmentValue);
  configuration.setProperty(TableGenerator.VALUE_COLUMN_PARAM,"next_id");
  configuration.setProperty(TableGenerator.INCREMENT_PARAM,"100");
  sessionFactory=((SessionFactory)Context.getBean(Context.Name.HIBERNATE_SESSION));
  generator=IdentifierGeneratorFactory.create("org.hibernate.id.enhanced.TableGenerator",new IntegerType(),configuration,((SessionFactoryImpl)sessionFactory).getDialect());
}
 

Example 27

From project jDcHub, under directory /jdchub-core/src/main/java/ru/sincore/db/.

Source file: HibernateUtils.java

  19 
vote

private static SessionFactory buildSessionFactory(){
  try {
    configuration=new Configuration().configure(new File(ConfigurationManager.getInstance().getHubConfigDir() + "/hibernate.cfg.xml"));
    return configuration.buildSessionFactory();
  }
 catch (  Throwable ex) {
    log.error("Initial SessionFactory creation failed.",ex);
    throw new ExceptionInInitializerError(ex);
  }
}
 

Example 28

From project jeppetto, under directory /jeppetto-dao-hibernate/src/main/java/org/iternine/jeppetto/dao/hibernate/.

Source file: HibernateQueryModelDAO.java

  19 
vote

protected HibernateQueryModelDAO(Class<T> persistentClass,Map<String,Object> daoProperties,AccessControlContextProvider accessControlContextProvider){
  this.persistentClass=persistentClass;
  this.sessionFactory=(SessionFactory)daoProperties.get("sessionFactory");
  this.accessControlHelper=(AccessControlHelper)daoProperties.get("accessControlHelper");
  this.accessControlContextProvider=accessControlContextProvider;
  if (accessControlHelper != null) {
    accessControlHelper.registerDAO(persistentClass,this);
  }
}
 

Example 29

From project logback-audit, under directory /audit-server/src/main/java/ch/qos/logback/audit/persistent/.

Source file: Persistor.java

  19 
vote

/** 
 * Create or re-obtain our single Hibernate SessionFactory.
 * @return An instantiated SessionFactory, always the same (the createdinstance is cached in this class).
 * @throws HibernateException
 */
private static SessionFactory getSessionFactory() throws HibernateException {
  if (sessionFactory == null) {
synchronized (SessionFactory.class) {
      if (sessionFactory == null) {
        sessionFactory=createSessionFactory();
      }
    }
  }
  return sessionFactory;
}
 

Example 30

From project picketlink-idm, under directory /picketlink-idm-hibernate/src/test/java/org/picketlink/idm/impl/store/hibernate/.

Source file: HibernateIdentityStoreTestCase.java

  19 
vote

public void setUp() throws Exception {
  super.start();
  setIdentityConfig("store-test-config.xml");
  commonTest=new CommonIdentityStoreTest(this);
  IdentityConfigurationMetaData configurationMD=JAXB2IdentityConfiguration.createConfigurationMetaData(getIdentityConfig());
  IdentityConfigurationContextRegistry identityConfiguration=(IdentityConfigurationContextRegistry)new IdentityConfigurationImpl().configure(configurationMD);
  IdentityStoreConfigurationMetaData storeMD=null;
  for (  IdentityStoreConfigurationMetaData metaData : configurationMD.getIdentityStores()) {
    if (metaData.getId().equals("HibernateTestStore")) {
      storeMD=metaData;
      break;
    }
  }
  IdentityStoreConfigurationContext context=new IdentityStoreConfigurationContextImpl(configurationMD,identityConfiguration,storeMD);
  store=new HibernateIdentityStoreImpl("HibernateTestStore"){
    @Override protected Session getHibernateSession(    IdentityStoreInvocationContext ctx){
      return getHibernateSupport().getSessionFactory().getCurrentSession();
    }
    @Override protected SessionFactory bootstrapHibernateSessionFactory(    IdentityStoreConfigurationContext configurationContext) throws IdentityException {
      return getHibernateSupport().getSessionFactory();
    }
  }
;
  store.bootstrap(context);
  ctx=new IdentityStoreInvocationContext(){
    public IdentityStoreSession getIdentityStoreSession(){
      return null;
    }
    public String getRealmId(){
      return "testRealm";
    }
    public String getSessionId(){
      return "";
    }
  }
;
}
 

Example 31

From project picketlink-idm_1, under directory /picketlink-idm-testsuite/src/test/java/org/picketlink/idm/impl/store/hibernate/.

Source file: HibernateIdentityStoreTestCase.java

  19 
vote

public void setUp() throws Exception {
  super.start();
  setIdentityConfig("store-test-config.xml");
  commonTest=new CommonIdentityStoreTest(this);
  IdentityConfigurationMetaData configurationMD=JAXB2IdentityConfiguration.createConfigurationMetaData(getIdentityConfig());
  IdentityConfigurationContextRegistry identityConfiguration=(IdentityConfigurationContextRegistry)new IdentityConfigurationImpl().configure(configurationMD);
  IdentityStoreConfigurationMetaData storeMD=null;
  for (  IdentityStoreConfigurationMetaData metaData : configurationMD.getIdentityStores()) {
    if (metaData.getId().equals("HibernateTestStore")) {
      storeMD=metaData;
      break;
    }
  }
  IdentityStoreConfigurationContext context=new IdentityStoreConfigurationContextImpl(configurationMD,identityConfiguration,storeMD);
  store=new HibernateIdentityStoreImpl("HibernateTestStore"){
    @Override protected Session getHibernateSession(    IdentityStoreInvocationContext ctx){
      return getHibernateSupport().getSessionFactory().getCurrentSession();
    }
    @Override protected SessionFactory bootstrapHibernateSessionFactory(    IdentityStoreConfigurationContext configurationContext) throws IdentityException {
      return getHibernateSupport().getSessionFactory();
    }
  }
;
  store.bootstrap(context);
  ctx=new IdentityStoreInvocationContext(){
    public IdentityStoreSession getIdentityStoreSession(){
      return null;
    }
    public String getRealmId(){
      return "testRealm";
    }
    public String getSessionId(){
      return "";
    }
  }
;
}
 

Example 32

From project projectsonar, under directory /src/edu/kit/ipd/sonar/server/.

Source file: HibernateUtil.java

  19 
vote

/** 
 * Returns the Hibernate session factory.
 * @return hibernate session factory
 */
static SessionFactory getSessionFactory(){
  if (sessionFactory == null) {
    rebuildSessionFactory(configuration);
  }
  return sessionFactory;
}
 

Example 33

From project SeavusJB3, under directory /src/java/com/sapienter/jbilling/server/util/db/.

Source file: HibernateIdGenerator.java

  19 
vote

/** 
 * Constructs a new ID generator for the given segment. If the segment does not exist in the sequence table, it will be created with the newly generated id values starting from zero. *
 * @param segmentValue jbilling sequence name (value of the 'name' column)
 */
public HibernateIdGenerator(String segmentValue){
  Properties configuration=new Properties();
  configuration.setProperty(TableGenerator.TABLE_PARAM,"jbilling_seqs");
  configuration.setProperty(TableGenerator.SEGMENT_COLUMN_PARAM,"name");
  configuration.setProperty(TableGenerator.SEGMENT_VALUE_PARAM,segmentValue);
  configuration.setProperty(TableGenerator.VALUE_COLUMN_PARAM,"next_id");
  configuration.setProperty(TableGenerator.INCREMENT_PARAM,"100");
  sessionFactory=((SessionFactory)Context.getBean(Context.Name.HIBERNATE_SESSION));
  generator=IdentifierGeneratorFactory.create("org.hibernate.id.enhanced.TableGenerator",new IntegerType(),configuration,((SessionFactoryImpl)sessionFactory).getDialect());
}
 

Example 34

From project spliffy, under directory /spliffy-core/src/main/java/org/spliffy/server/db/store/.

Source file: LocalVolumeInstanceType.java

  19 
vote

private void initInitialDirs(List<File> initialDirs,SessionFactory sessionFactory){
  Session session=sessionFactory.openSession();
  Transaction tx=session.beginTransaction();
  for (  File f : initialDirs) {
    VolumeInstance vi=VolumeInstance.find(session,f.getAbsolutePath(),getTypeId());
    if (vi == null) {
      vi=new VolumeInstance();
      vi.setCapacity(10000000l);
      vi.setCost(10);
      vi.setInstanceType(id);
      vi.setLocation(f.getAbsolutePath());
      vi.setOnline(true);
      session.save(vi);
    }
  }
  tx.commit();
}
 

Example 35

From project spring-flex, under directory /spring-flex-core/src/main/java/org/springframework/flex/core/io/.

Source file: HibernateConfigProcessor.java

  19 
vote

/** 
 * {@inheritDoc}
 */
@Override public void afterPropertiesSet() throws Exception {
  if (!this.hibernateConfigured) {
    if (BeanFactoryUtils.beanNamesForTypeIncludingAncestors(getBeanFactory(),SessionFactory.class).length > 0) {
      for (      SessionFactory sessionFactory : BeanFactoryUtils.beansOfTypeIncludingAncestors(beanFactory,SessionFactory.class).values()) {
        extractHibernateMetadata(sessionFactory);
      }
    }
  }
  super.afterPropertiesSet();
}
 

Example 36

From project spring-framework-issues, under directory /SPR-8853/src/main/java/org/springframework/issues/.

Source file: AppConfigWithComponentScan.java

  19 
vote

@Bean public SessionFactory sessionFactory() throws Exception {
  AnnotationSessionFactoryBean bean=new AnnotationSessionFactoryBean();
  bean.setDataSource(dataSource());
  bean.setPackagesToScan(new String[]{"org.springframework.issues"});
  bean.setHibernateProperties(hibernateProps());
  bean.afterPropertiesSet();
  return bean.getObject();
}
 

Example 37

From project spring-webflow, under directory /spring-webflow/src/test/java/org/springframework/webflow/persistence/.

Source file: HibernateFlowExecutionListenerTests.java

  19 
vote

private SessionFactory getSessionFactory(DataSource dataSource) throws Exception {
  LocalSessionFactoryBean factory=new LocalSessionFactoryBean();
  factory.setDataSource(dataSource);
  factory.setMappingLocations(new Resource[]{new ClassPathResource("org/springframework/webflow/persistence/TestBean.hbm.xml"),new ClassPathResource("org/springframework/webflow/persistence/TestAddress.hbm.xml")});
  factory.afterPropertiesSet();
  return factory.getObject();
}
 

Example 38

From project webframe, under directory /wf-core/src/main/java/org/webframe/core/hibernate/.

Source file: WFSessionFactoryBean.java

  19 
vote

protected SessionFactory buildSessionFactory() throws Exception {
  if ("false".equals(PropertyConfigurerUtils.getString(HIBERNATE_LOAD))) {
    return new NullSessionFactory();
  }
  if (hasWFDataSource()) {
    WFDataSource bds=(WFDataSource)this.getDataSource();
    String databaseType=bds.getDatabaseType().getValue();
    LobHandler lobHandler=getLobHandlers().get(databaseType);
    if (lobHandler == null) {
      lobHandler=getLobHandlers().get(defaultLobHandlerString);
    }
    super.setLobHandler(lobHandler);
    if (bds.getDialect() != null) {
      this.getHibernateProperties().put(HIBERNATE_DIALECT,bds.getDialect());
    }
  }
  return super.buildSessionFactory();
}
 

Example 39

From project zen-project, under directory /zen-search/src/main/java/com/nominanuda/hibernate/.

Source file: HibernateConfiguration.java

  19 
vote

public SessionFactory getSessionFactory(){
  if (sessionFactory == null) {
    Configuration cfg=getConfiguration();
    sessionFactory=cfg.buildSessionFactory();
  }
  return sessionFactory;
}