Java 类org.hibernate.cfg.ImprovedNamingStrategy 实例源码

项目:spring4-understanding    文件:LocalSessionFactoryBeanTests.java   
@Test
@SuppressWarnings("serial")
public void testLocalSessionFactoryBeanWithNamingStrategy() throws Exception {
    LocalSessionFactoryBean sfb = new LocalSessionFactoryBean() {
        @Override
        protected Configuration newConfiguration() {
            return new Configuration() {
                @Override
                public Configuration setNamingStrategy(NamingStrategy namingStrategy) {
                    throw new IllegalArgumentException(namingStrategy.toString());
                }
            };
        }
    };
    sfb.setMappingResources(new String[0]);
    sfb.setDataSource(new DriverManagerDataSource());
    sfb.setNamingStrategy(ImprovedNamingStrategy.INSTANCE);
    try {
        sfb.afterPropertiesSet();
        fail("Should have thrown IllegalArgumentException");
    }
    catch (IllegalArgumentException ex) {
        // expected
        assertTrue("Correct exception", ex.getMessage().equals(ImprovedNamingStrategy.INSTANCE.toString()));
    }
}
项目:class-guard    文件:LocalSessionFactoryBeanTests.java   
@Test
@SuppressWarnings("serial")
public void testLocalSessionFactoryBeanWithNamingStrategy() throws Exception {
    LocalSessionFactoryBean sfb = new LocalSessionFactoryBean() {
        @Override
        protected Configuration newConfiguration() {
            return new Configuration() {
                @Override
                public Configuration setNamingStrategy(NamingStrategy namingStrategy) {
                    throw new IllegalArgumentException(namingStrategy.toString());
                }
            };
        }
    };
    sfb.setMappingResources(new String[0]);
    sfb.setDataSource(new DriverManagerDataSource());
    sfb.setNamingStrategy(ImprovedNamingStrategy.INSTANCE);
    try {
        sfb.afterPropertiesSet();
        fail("Should have thrown IllegalArgumentException");
    }
    catch (IllegalArgumentException ex) {
        // expected
        assertTrue("Correct exception", ex.getMessage().equals(ImprovedNamingStrategy.INSTANCE.toString()));
    }
}
项目:NickNack    文件:H2DatabaseConfiguration.java   
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws Exception {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();

    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPackagesToScan("com.github.kmbulebu.nicknack.server.model");
    entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);


    Properties jpaProperties = new Properties();

    jpaProperties.put(PROPERTY_NAME_HIBERNATE_DIALECT, org.hibernate.dialect.H2Dialect.class.getName());
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_FORMAT_SQL, "true");
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY, ImprovedNamingStrategy.class.getName());
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL, "false");
    jpaProperties.put(PROPERTY_NAME_HIBERNATE_HBM2DDL_AUTO, "update");

    entityManagerFactoryBean.setJpaProperties(jpaProperties);

    return entityManagerFactoryBean;
}
项目:openhds-server    文件:Ejb3SchemaExport.java   
public static void main(String[] args) {
    Ejb3Configuration ejb3Cfg = new Ejb3Configuration();

    // set propeties (these were set based on the persistence.xml file)
    Properties props = new Properties();
    props.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
    ejb3Cfg.addProperties(props);

    ejb3Cfg.setNamingStrategy(ImprovedNamingStrategy.INSTANCE);

    // add annotated classes
    ejb3Cfg.addAnnotatedClass(EndUser.class);
    ejb3Cfg.addAnnotatedClass(Individual.class);
    ejb3Cfg.addAnnotatedClass(Location.class);
    ejb3Cfg.addAnnotatedClass(SocialGroup.class);
    ejb3Cfg.addAnnotatedClass(Visit.class);

    Configuration cfg = ejb3Cfg.getHibernateConfiguration();

    SchemaExport se = new SchemaExport(cfg).setOutputFile(RESOURCES_PATH + "specialstudy-schema-ddl.sql");
    se.execute(false, false, false, true);
}
项目:windup-rulesets    文件:HibernateUtil.java   
public static SessionFactory buildSessionFactoryFromAnnotations()
{
    try
    {
        sessionFactory = new AnnotationConfiguration()
                    .setNamingStrategy(ImprovedNamingStrategy.INSTANCE)
                    .configure("/hib.cfg.xml")
                    .buildSessionFactory();
        return sessionFactory;
    }
    catch (Throwable ex)
    {
        throw new ExceptionInInitializerError(ex);
    }
}
项目:base-framework    文件:CreateDataBaseTableByHibernateConfigFile.java   
public static void main(String[] args) {
    Configuration configuration = new Configuration().configure().setNamingStrategy(new ImprovedNamingStrategy());
    EnversSchemaGenerator generator = new EnversSchemaGenerator(configuration);
    SchemaExport export = generator.export();

    export.setFormat(false);
    export.setOutputFile("src/test/resources/data/h2/create-table-new.sql");
    export.create(true, false);
}
项目:base-framework    文件:CreateTestInitializeDataBaseSqlFile.java   
public static void main(String[] args) {

    Configuration configuration = new Configuration().configure().setNamingStrategy(new ImprovedNamingStrategy());
    EnversSchemaGenerator generator = new EnversSchemaGenerator(configuration);
    SchemaExport export = generator.export();

    export.setFormat(false);
    export.setOutputFile("src/test/resources/h2schma.sql");
    export.create(true, false);
}
项目:hibernate-examples    文件:OracleNamingStrategyTest.java   
@Test
public void improvedNaming_ClassToTableName() {
    ImprovedNamingStrategy namingStrategy = new ImprovedNamingStrategy();

    for (int i = 0; i < classNames.length; i++) {
        String tableName = namingStrategy.classToTableName(classNames[i]);
        assertThat(tableName).isEqualTo(tableNames[i]);
    }
}
项目:hibernate-examples    文件:OracleNamingStrategyTest.java   
@Test
public void improvedNaming_PropertyToColumnName() {
    ImprovedNamingStrategy namingStrategy = new ImprovedNamingStrategy();

    for (int i = 0; i < propertyNames.length; i++) {
        final String columnName = namingStrategy.propertyToColumnName(propertyNames[i]);
        assertThat(columnName).isEqualTo(columnNames[i]);
    }
}
项目:debop4j    文件:OracleNamingStrategyTest.java   
@Test
public void improvedNaming_ClassToTableName() {
    ImprovedNamingStrategy improvedNamingStrategy = new ImprovedNamingStrategy();

    for (int i = 0; i < classNames.length; i++) {
        Assert.assertEquals(tableNames[i],
                            improvedNamingStrategy.classToTableName(classNames[i]));
    }
}
项目:debop4j    文件:OracleNamingStrategyTest.java   
@Test
public void improvedNaming_PropertyToColumnName() {
    ImprovedNamingStrategy improvedNamingStrategy = new ImprovedNamingStrategy();

    for (int i = 0; i < propertyNames.length; i++) {
        Assert.assertEquals(columnNames[i],
                            improvedNamingStrategy.propertyToColumnName(propertyNames[i]));
    }
}
项目:statement-generator    文件:ResultSetStatementTest.java   
@Test
public void testSuccessGetResultSetStatementImprovedNamingStrategyJava() {
    interpretedClass = InterpretedClassFactory.getInterpretedClass(ExampleModel.class);
    resultSetStatement = new ResultSetStatement(interpretedClass, new ImprovedNamingStrategy());
    assertEquals(Results.resultSetStringImprovedNamingStrategy, resultSetStatement.getStatement());
}
项目:statement-generator    文件:ResultSetStatementTest.java   
@Test
public void testSuccessGetResultSetStatementImprovedNamingStrategyClass() {
    interpretedClass = InterpretedClassFactory.getInterpretedClass(ExampleModel.class);
    resultSetStatement = new ResultSetStatement(interpretedClass, new ImprovedNamingStrategy());
    assertEquals(Results.resultSetStringImprovedNamingStrategy, resultSetStatement.getStatement());
}
项目:statement-generator    文件:UpdateSQLStatementTest.java   
@Test
public void testSuccessGetStatementImprovedNamingStrategyJava() {
    interpretedClass = InterpretedClassFactory.getInterpretedClass(ExampleModel.class);
    statement = new UpdateSQLStatement(interpretedClass, new ImprovedNamingStrategy());
    assertEquals(Results.updateSQLStatementStringImprovedNamingStrategy, statement.getStatement());
}
项目:statement-generator    文件:UpdateSQLStatementTest.java   
@Test
public void testSuccessGetStatementImprovedNamingStrategyClass() {
    interpretedClass = InterpretedClassFactory.getInterpretedClass(getJavaClass());
    statement = new UpdateSQLStatement(interpretedClass, new ImprovedNamingStrategy());
    assertEquals(Results.updateSQLStatementStringImprovedNamingStrategy, statement.getStatement());
}
项目:statement-generator    文件:InsertSQLStatementTest.java   
@Test
public void testSuccessGetStatementImprovedNamingStrategyJava() {
    interpretedClass = InterpretedClassFactory.getInterpretedClass(ExampleModel.class);
    statement = new InsertSQLStatement(interpretedClass, new ImprovedNamingStrategy());
    assertEquals(Results.insertSQLStatementStringImprovedNamingStrategy, statement.getStatement());
}
项目:statement-generator    文件:InsertSQLStatementTest.java   
@Test
public void testSuccessGetStatementImprovedNamingStrategyClass() {
    interpretedClass = InterpretedClassFactory.getInterpretedClass(getJavaClass());
    statement = new InsertSQLStatement(interpretedClass, new ImprovedNamingStrategy());
    assertEquals(Results.insertSQLStatementStringImprovedNamingStrategy, statement.getStatement());
}
项目:statement-generator    文件:SelectSQLStatementTest.java   
@Test
public void testSuccessGetStatementImprovedNamingStrategyJava() {
    interpretedClass = InterpretedClassFactory.getInterpretedClass(ExampleModel.class);
    statement = new SelectSQLStatement(interpretedClass, new ImprovedNamingStrategy());
    assertEquals(Results.selectSQLStatementStringImprovedNamingStrategy, statement.getStatement());
}
项目:statement-generator    文件:SelectSQLStatementTest.java   
@Test
public void testSuccessGetStatementImprovedNamingStrategyClass() {
    interpretedClass = InterpretedClassFactory.getInterpretedClass(getJavaClass());
    statement = new SelectSQLStatement(interpretedClass, new ImprovedNamingStrategy());
    assertEquals(Results.selectSQLStatementStringImprovedNamingStrategy, statement.getStatement());
}
项目:yeoman-programmer    文件:SessionFactories.java   
@Override
public SessionFactory load(String sessFacKey) {
  checkNotNull(sessFacKey);
  String m = "load(String)";
  logger.debug(
      "{}: building new SessionFactory for sessFacKey [{}]",
      m, sessFacKey);
  Configuration config = new Configuration();
  config.setNamingStrategy(new ImprovedNamingStrategy());
  Optional<Properties> propsOpt =
      Optional.fromNullable(configProps
          .get(sessFacKey));
  if (propsOpt.isPresent()) {
    config.setProperties(propsOpt.get());
  } else {
    if (sessFacKey.equals(DEFAULT_SESS_FAC_KEY)) {

    } else {
      Properties props = new Properties();
      InputStream is = null;
      try {
        String fileName =
            sessFacKey
                + "-hibernate.properties";
        is = HibernateUtil.class
            .getClassLoader()
            .getResourceAsStream(
                sessFacKey
                    + "-hibernate.properties");
        Preconditions.checkState(is != null,
            "couldn't load hibernate properties file ["
                + fileName + "]");
        props.load(is);
        config.setProperties(props);
      } catch (IOException e) {
        throw Throwables.propagate(e);
      } finally {
        Closeables.closeQuietly(is);
      }
    }
  }
  if (sessFacKey.equals(DEFAULT_SESS_FAC_KEY)) {
    config.configure();
  } else {
    config.configure(sessFacKey
        + "-hibernate.cfg.xml");
  }

  ServiceRegistry serviceRegistry =
      new StandardServiceRegistryBuilder()
          .applySettings(config.getProperties())
          .build();
  SessionFactory sessionFactory = config
      .buildSessionFactory(serviceRegistry);
  configs.put(sessFacKey, config);
  configProps.remove(sessFacKey);
  return sessionFactory;
}
项目:webapp-base    文件:PersistenceConfig.java   
@Bean
public NamingStrategy namingStrategy() {
    return new ImprovedNamingStrategy();
}
项目:interview-preparation    文件:DBConfig.java   
/**
 * Adds the underscored and covert to upperCase.
 *
 * @param name
 *            the name
 * @return the string
 */
static String addUnderscoredAndCovertToUppercase(final String name) {

    return ImprovedNamingStrategy.addUnderscores(name).toLowerCase();
}
项目:interview-preparation    文件:DatabaseConfig.java   
/**
 * Adds the underscored and covert to upperCase.
 *
 * @param name
 *            the name
 * @return the string
 */
static String addUnderscoredAndCovertToUppercase(final String name) {

    return ImprovedNamingStrategy.addUnderscores(name).toLowerCase();
}