protected static SessionFactory getSessionFactory()

in src/main/java/com/google/gcs/sdrs/dao/BaseDao.java [92:130]


  protected static SessionFactory getSessionFactory() {
    if (sessionFactory == null) {
      try {
        // Create registry
        StandardServiceRegistryBuilder registryBuilder =
            new StandardServiceRegistryBuilder().configure();
        registryBuilder.applySetting(
            HIBERNATE_CONNECTION_URL_PROPERTY_KEY, System.getenv(HIBERNATE_CONNECTION_URL_ENV));
        registryBuilder.applySetting(
            HIBERNATE_CONNECTION_USER_PROPERTY_KEY, System.getenv(HIBERNATE_CONNECTION_USER_ENV));
        registryBuilder.applySetting(
            HIBERNATE_CONNECTION_PASSWORD_PROPERTY_KEY,
            System.getenv(HIBERNATE_CONNECTION_PASSWORD_ENV));
        registry = registryBuilder.build();

        // TODO - refactor to remove this hardcoded strategy
        Metadata metadata =
            new MetadataSources(registry)
                .addAnnotatedClass(RetentionRule.class)
                .addAnnotatedClass(RetentionJob.class)
                .addAnnotatedClass(RetentionJobValidation.class)
                .addAnnotatedClass(PooledStsJob.class)
                .addAnnotatedClass(DmRequest.class)
                .addAnnotatedClass(DistributedLock.class)
                .getMetadataBuilder()
                .build();

        // Create SessionFactory
        sessionFactory = metadata.getSessionFactoryBuilder().build();

      } catch (Exception e) {
        e.printStackTrace();
        if (registry != null) {
          StandardServiceRegistryBuilder.destroy(registry);
        }
      }
    }
    return sessionFactory;
  }