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

项目:lams    文件:MetadataSources.java   
public MetadataSources(ServiceRegistry serviceRegistry, EntityResolver entityResolver, NamingStrategy namingStrategy) {
    this.serviceRegistry = serviceRegistry;
    this.entityResolver = entityResolver;
    this.namingStrategy = namingStrategy;

    this.jaxbHelper = new JaxbHelper( this );
    this.metadataBuilder = new MetadataBuilderImpl( this );

    // service registry really should be either BootstrapServiceRegistry or StandardServiceRegistry type...
    if ( ! isExpectedServiceRegistryType( serviceRegistry ) ) {
        LOG.debugf(
                "Unexpected ServiceRegistry type [%s] encountered during building of MetadataSources; may cause " +
                        "problems later attempting to construct MetadataBuilder",
                serviceRegistry.getClass().getName()
        );
    }
}
项目:lams    文件:SchemaExportTask.java   
private Configuration getConfiguration() throws Exception {
    Configuration cfg = new Configuration();
    if (namingStrategy!=null) {
        cfg.setNamingStrategy(
                (NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
            );
    }
    if (configurationFile != null) {
        cfg.configure( configurationFile );
    }

    String[] files = getFiles();
    for (int i = 0; i < files.length; i++) {
        String filename = files[i];
        if ( filename.endsWith(".jar") ) {
            cfg.addJar( new File(filename) );
        }
        else {
            cfg.addFile(filename);
        }
    }
    return cfg;
}
项目:lams    文件:SchemaUpdateTask.java   
private Configuration getConfiguration() throws Exception {
    Configuration cfg = new Configuration();
    if (namingStrategy!=null) {
        cfg.setNamingStrategy(
                (NamingStrategy) ReflectHelper.classForName( namingStrategy ).newInstance()
            );
    }
    if (configurationFile!=null) {
        cfg.configure( configurationFile );
    }

    String[] files = getFiles();
    for (int i = 0; i < files.length; i++) {
        String filename = files[i];
        if ( filename.endsWith(".jar") ) {
            cfg.addJar( new File(filename) );
        }
        else {
            cfg.addFile(filename);
        }
    }
    return cfg;
}
项目:lams    文件:SchemaValidatorTask.java   
private Configuration getConfiguration() throws Exception {
    Configuration cfg = new Configuration();
    if (namingStrategy!=null) {
        cfg.setNamingStrategy(
                (NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
            );
    }
    if (configurationFile!=null) {
        cfg.configure( configurationFile );
    }

    String[] files = getFiles();
    for (int i = 0; i < files.length; i++) {
        String filename = files[i];
        if ( filename.endsWith(".jar") ) {
            cfg.addJar( new File(filename) );
        }
        else {
            cfg.addFile(filename);
        }
    }
    return cfg;
}
项目: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()));
    }
}
项目:cacheonix-core    文件:SchemaExportTask.java   
private Configuration getConfiguration() throws Exception {
    Configuration cfg = new Configuration();
    if (namingStrategy!=null) {
        cfg.setNamingStrategy(
                (NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
            );
    }
    if (configurationFile != null) {
        cfg.configure( configurationFile );
    }

    String[] files = getFiles();
    for (int i = 0; i < files.length; i++) {
        String filename = files[i];
        if ( filename.endsWith(".jar") ) {
            cfg.addJar( new File(filename) );
        }
        else {
            cfg.addFile(filename);
        }
    }
    return cfg;
}
项目:cacheonix-core    文件:SchemaUpdateTask.java   
private Configuration getConfiguration() throws Exception {
    Configuration cfg = new Configuration();
    if (namingStrategy!=null) {
        cfg.setNamingStrategy(
                (NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
            );
    }
    if (configurationFile!=null) {
        cfg.configure( configurationFile );
    }

    String[] files = getFiles();
    for (int i = 0; i < files.length; i++) {
        String filename = files[i];
        if ( filename.endsWith(".jar") ) {
            cfg.addJar( new File(filename) );
        }
        else {
            cfg.addFile(filename);
        }
    }
    return cfg;
}
项目:cacheonix-core    文件:SchemaValidatorTask.java   
private Configuration getConfiguration() throws Exception {
    Configuration cfg = new Configuration();
    if (namingStrategy!=null) {
        cfg.setNamingStrategy(
                (NamingStrategy) ReflectHelper.classForName(namingStrategy).newInstance()
            );
    }
    if (configurationFile!=null) {
        cfg.configure( configurationFile );
    }

    String[] files = getFiles();
    for (int i = 0; i < files.length; i++) {
        String filename = files[i];
        if ( filename.endsWith(".jar") ) {
            cfg.addJar( new File(filename) );
        }
        else {
            cfg.addFile(filename);
        }
    }
    return cfg;
}
项目:hibernate-conventions    文件:MappingConventions.java   
private MappingConventions(Configuration configuration) {

        this.configuration = configuration;

        NamingStrategy namingStrategy = configuration.getNamingStrategy();

        if (namingStrategy == null) {
            strategy = new DefaultConventionNamingStrategy();
        } else if (namingStrategy instanceof ConventionNamingStrategy) {
            strategy = (ConventionNamingStrategy) namingStrategy;
        } else {
            throw new IllegalArgumentException(
                    "Configured namingStrategy is not a instance of ConventionNamingStrategy");
        }

        configuration.setNamingStrategy(strategy);

    }
项目: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()));
    }
}
项目:labviewer    文件:HibernateHelper.java   
/**
     * Constructor to build the hibernate helper.
     * @param namingStrategy the name strategy, if one is needed, null otherwise.
     * @param interceptor the interceptor, if one is needed, null otherwise.
     */
    public HibernateHelper(NamingStrategy namingStrategy, Interceptor interceptor) {
        try {
            configuration = new AnnotationConfiguration();
            initializeConfig(namingStrategy, interceptor);
            configuration = configuration.configure();
            // We call buildSessionFactory twice, because it appears that the annotated classes are
            // not 'activated' in the config until we build. The filters required the classes to
            // be present, so we throw away the first factory and use the second. If this is
            // removed, you'll likely see a NoClassDefFoundError in the unit tests
            configuration.buildSessionFactory();
            sessionFactory = configuration.buildSessionFactory();
        } catch (HibernateException e) {
//            LOG.error(e.getMessage(), e);
//            throw new ExceptionInInitializerError(e);
            LOG.warn("Failed to initialize HibernateHelper using hibernate.cfg.xml.  "
                    + "This is expected behavior during unit testing." , e);
            e.printStackTrace();
        }
    }
项目:cacheonix-core    文件:SchemaValidator.java   
public static void main(String[] args) {
    try {
        Configuration cfg = new Configuration();

        String propFile = null;

        for ( int i = 0; i < args.length; i++ ) {
            if ( args[i].startsWith( "--" ) ) {
                if ( args[i].startsWith( "--properties=" ) ) {
                    propFile = args[i].substring( 13 );
                }
                else if ( args[i].startsWith( "--config=" ) ) {
                    cfg.configure( args[i].substring( 9 ) );
                }
                else if ( args[i].startsWith( "--naming=" ) ) {
                    cfg.setNamingStrategy(
                            ( NamingStrategy ) ReflectHelper.classForName( args[i].substring( 9 ) ).newInstance()
                    );
                }
            }
            else {
                cfg.addFile( args[i] );
            }

        }

        if ( propFile != null ) {
            Properties props = new Properties();
            props.putAll( cfg.getProperties() );
            props.load( new FileInputStream( propFile ) );
            cfg.setProperties( props );
        }

        new SchemaValidator( cfg ).validate();
    }
    catch ( Exception e ) {
        log.error( "Error running schema update", e );
        e.printStackTrace();
    }
}
项目:hibernate-examples    文件:AbstractHibernateConfiguration.java   
/**
 * Hibernate {@link SessionFactory} 를 빌드합니다.
 *
 * @return {@link SessionFactory} instance.
 */
@Bean
public SessionFactory sessionFactory() throws IOException {
    log.info("SessionFactory Bean을 생성합니다...");

    LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();

    String[] packagenames = getMappedPackageNames();
    if (packagenames != null && packagenames.length > 0) {
        log.debug("hibernate용 entity를 scan합니다. packages=[{}]", packagenames);
        factoryBean.setPackagesToScan(packagenames);
    }

    // Naming strategy
    NamingStrategy ns = getNamingStrategy();
    if (ns != null)
        factoryBean.setNamingStrategy(ns);

    // Hibernate properties
    factoryBean.setHibernateProperties(hibernateProperties());
    factoryBean.setDataSource(dataSource());

    Interceptor interceptor = hibernateInterceptor();
    if (interceptor != null)
        factoryBean.setEntityInterceptor(hibernateInterceptor());

    setupSessionFactory(factoryBean);

    factoryBean.afterPropertiesSet();
    log.info("SessionFactory Bean을 생성했습니다!!!");

    return factoryBean.getObject();
}
项目:labviewer    文件:HibernateHelper.java   
private void initializeConfig(NamingStrategy namingStrategy, Interceptor interceptor) {
    if (namingStrategy != null) {
        configuration.setNamingStrategy(namingStrategy);
    }

    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }
}
项目:lams    文件:LegacyNamingStrategyDelegator.java   
public LegacyNamingStrategyDelegator(NamingStrategy namingStrategy) {
    this.namingStrategy = namingStrategy;
    this.hbmNamingStrategyDelegate = new LegacyHbmNamingStrategyDelegate( this );
    this.jpaNamingStrategyDelegate = new LegacyJpaNamingStrategyDelegate( this );
}
项目:lams    文件:LegacyNamingStrategyDelegator.java   
public NamingStrategy getNamingStrategy() {
    return namingStrategy;
}
项目:lams    文件:LegacyNamingStrategyDelegateAdapter.java   
protected NamingStrategy getNamingStrategy() {
    return context.getNamingStrategy();
}
项目:lams    文件:EntityBinder.java   
@Override
public String determineImplicitName(NamingStrategy strategy) {
    return strategy.classToTableName( entityName );
}
项目:lams    文件:EntityBinder.java   
@Override
public String handleExplicitName(NamingStrategy strategy, String name) {
    return strategy.tableName( name );
}
项目:lams    文件:EntityBinder.java   
public String determineImplicitName(NamingStrategy strategy) {
    // todo : throw an error?
    return null;
}
项目:lams    文件:EntityBinder.java   
public String handleExplicitName(NamingStrategy strategy, String name) {
    return strategy.tableName( name );
}
项目:lams    文件:MetadataSources.java   
public NamingStrategy getNamingStrategy() {
    return namingStrategy;
}
项目:lams    文件:MappingDocument.java   
@Override
public NamingStrategy getNamingStrategy() {
    return metadata.getNamingStrategy();
}
项目:lams    文件:IdentifierGeneratorResolver.java   
@Override
protected NamingStrategy getNamingStrategy() {
    return namingStrategy;
}
项目:lams    文件:MetadataBuilderImpl.java   
@Override
public MetadataBuilder with(NamingStrategy namingStrategy) {
    this.options.namingStrategy = namingStrategy;
    return this;
}
项目:lams    文件:MetadataBuilderImpl.java   
@Override
public NamingStrategy getNamingStrategy() {
    return namingStrategy;
}
项目:lams    文件:MetadataImpl.java   
@Override
public NamingStrategy getNamingStrategy() {
    return options.getNamingStrategy();
}
项目:lams    文件:EntityBindingContext.java   
@Override
public NamingStrategy getNamingStrategy() {
    return contextDelegate.getNamingStrategy();
}
项目:lams    文件:AnnotationBindingContextImpl.java   
@Override
public NamingStrategy getNamingStrategy() {
    return metadata.getNamingStrategy();
}
项目:lams    文件:SchemaUpdate.java   
public static void main(String[] args) {
    try {
        Configuration cfg = new Configuration();

        boolean script = true;
        // If true then execute db updates, otherwise just generate and display updates
        boolean doUpdate = true;
        String propFile = null;

        for ( int i = 0; i < args.length; i++ ) {
            if ( args[i].startsWith( "--" ) ) {
                if ( args[i].equals( "--quiet" ) ) {
                    script = false;
                }
                else if ( args[i].startsWith( "--properties=" ) ) {
                    propFile = args[i].substring( 13 );
                }
                else if ( args[i].startsWith( "--config=" ) ) {
                    cfg.configure( args[i].substring( 9 ) );
                }
                else if ( args[i].startsWith( "--text" ) ) {
                    doUpdate = false;
                }
                else if ( args[i].startsWith( "--naming=" ) ) {
                    cfg.setNamingStrategy(
                            ( NamingStrategy ) ReflectHelper.classForName( args[i].substring( 9 ) ).newInstance()
                    );
                }
            }
            else {
                cfg.addFile( args[i] );
            }

        }

        if ( propFile != null ) {
            Properties props = new Properties();
            props.putAll( cfg.getProperties() );
            props.load( new FileInputStream( propFile ) );
            cfg.setProperties( props );
        }

        StandardServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
        try {
            new SchemaUpdate( serviceRegistry, cfg ).execute( script, doUpdate );
        }
        finally {
            serviceRegistry.destroy();
        }
    }
    catch ( Exception e ) {
           LOG.unableToRunSchemaUpdate(e);
        e.printStackTrace();
    }
}
项目:lams    文件:SchemaValidator.java   
public static void main(String[] args) {
    try {
        Configuration cfg = new Configuration();

        String propFile = null;

        for ( int i = 0; i < args.length; i++ ) {
            if ( args[i].startsWith( "--" ) ) {
                if ( args[i].startsWith( "--properties=" ) ) {
                    propFile = args[i].substring( 13 );
                }
                else if ( args[i].startsWith( "--config=" ) ) {
                    cfg.configure( args[i].substring( 9 ) );
                }
                else if ( args[i].startsWith( "--naming=" ) ) {
                    cfg.setNamingStrategy(
                            ( NamingStrategy ) ReflectHelper.classForName( args[i].substring( 9 ) ).newInstance()
                    );
                }
            }
            else {
                cfg.addFile( args[i] );
            }

        }

        if ( propFile != null ) {
            Properties props = new Properties();
            props.putAll( cfg.getProperties() );
            props.load( new FileInputStream( propFile ) );
            cfg.setProperties( props );
        }

        StandardServiceRegistryImpl serviceRegistry = createServiceRegistry( cfg.getProperties() );
        try {
            new SchemaValidator( serviceRegistry, cfg ).validate();
        }
        finally {
            serviceRegistry.destroy();
        }
    }
    catch ( Exception e ) {
           LOG.unableToRunSchemaUpdate(e);
        e.printStackTrace();
    }
}
项目:document-management-system    文件:SchemaUpdate.java   
public static void main(String[] args) {
    try {
        Configuration cfg = new Configuration();
        String outFile = null;

        boolean script = true;
        // If true then execute db updates, otherwise just generate and
        // display updates
        boolean doUpdate = true;
        String propFile = null;

        for (int i = 0; i < args.length; i++) {
            if (args[i].startsWith("--")) {
                if (args[i].equals("--quiet")) {
                    script = false;
                } else if (args[i].startsWith("--properties=")) {
                    propFile = args[i].substring(13);
                } else if (args[i].startsWith("--config=")) {
                    cfg.configure(args[i].substring(9));
                } else if (args[i].startsWith("--text")) {
                    doUpdate = false;
                } else if (args[i].startsWith("--naming=")) {
                    cfg.setNamingStrategy((NamingStrategy) ReflectHelper.classForName(
                            args[i].substring(9)).newInstance());
                } else if (args[i].startsWith("--output=")) {
                    outFile = args[i].substring(9);
                }
            } else {
                cfg.addFile(args[i]);
            }

        }

        if (propFile != null) {
            Properties props = new Properties();
            props.putAll(cfg.getProperties());
            props.load(new FileInputStream(propFile));
            cfg.setProperties(props);
        }

        new SchemaUpdate(cfg).setOutputFile(outFile).execute(script, doUpdate);
    } catch (Exception e) {
        log.error("Error running schema update", e);
        e.printStackTrace();
    }
}
项目:gorm-hibernate5    文件:HibernateMappingContextSessionFactoryBean.java   
public NamingStrategy getNamingStrategy() {
    return namingStrategy;
}
项目:xap-openspaces    文件:SessionFactoryBuilder.java   
/**
 * Create and configure new hibernate session factory
 * @param hibernateFile
 * @return
 * @throws Exception
 */
public static SessionFactory getFactory(String hibernateFile)
        throws Exception
{
    Configuration config = null;

    try
    {
        // load the class using reflection to avoid JIT exceptions  
        config = configure((Configuration) ClassLoaderHelper.loadClass(ANNOTATION_CONFIGURATION_CLASS).newInstance(),
                hibernateFile);
    }
    catch (Throwable t)
    {
        try
        {
            config = configure(new Configuration(), hibernateFile);
        }
        catch (Exception e)
        {
            // if both methods failed - log first exception
            // and throw the second
            if(_logger.isLoggable(Level.SEVERE))
            {
                _logger.log(Level.SEVERE, "Failed to configure using hibernate annotations.",t);

            }

            throw e;
        }
    }
    // since hibernate doesn't support configuring naming strategies in cfg.xml.
    // added an option to configure it programatically while using the hibernate.cfg.xml
    // for example: add this to hibernate.cfg.xml
    //<property name="hibernate.naming_strategy">com.gigaspaces.test.persistent.SpaceNamingStrategy</property>

    String namingStrategyClass = config.getProperty(HIBERNATE_NAMING_STRATEGY);

    if(namingStrategyClass != null)
    {
        NamingStrategy namingStrategy = (NamingStrategy) ClassLoaderHelper.loadClass(namingStrategyClass).newInstance();
        config.setNamingStrategy(namingStrategy);
    }
    return config.buildSessionFactory();
}
项目:cacheonix-core    文件:SchemaUpdate.java   
public static void main(String[] args) {
    try {
        Configuration cfg = new Configuration();

        boolean script = true;
        // If true then execute db updates, otherwise just generate and display updates
        boolean doUpdate = true;
        String propFile = null;

        for ( int i = 0; i < args.length; i++ ) {
            if ( args[i].startsWith( "--" ) ) {
                if ( args[i].equals( "--quiet" ) ) {
                    script = false;
                }
                else if ( args[i].startsWith( "--properties=" ) ) {
                    propFile = args[i].substring( 13 );
                }
                else if ( args[i].startsWith( "--config=" ) ) {
                    cfg.configure( args[i].substring( 9 ) );
                }
                else if ( args[i].startsWith( "--text" ) ) {
                    doUpdate = false;
                }
                else if ( args[i].startsWith( "--naming=" ) ) {
                    cfg.setNamingStrategy(
                            ( NamingStrategy ) ReflectHelper.classForName( args[i].substring( 9 ) ).newInstance()
                    );
                }
            }
            else {
                cfg.addFile( args[i] );
            }

        }

        if ( propFile != null ) {
            Properties props = new Properties();
            props.putAll( cfg.getProperties() );
            props.load( new FileInputStream( propFile ) );
            cfg.setProperties( props );
        }

        new SchemaUpdate( cfg ).execute( script, doUpdate );
    }
    catch ( Exception e ) {
        log.error( "Error running schema update", e );
        e.printStackTrace();
    }
}
项目:statement-generator    文件:ResultSetStatement.java   
public ResultSetStatement(InterpretedClass interpretedClass, NamingStrategy namingStrategy) {
    super(interpretedClass, namingStrategy);
}
项目:statement-generator    文件:ResultSetStatement.java   
private String getColumnName(NamingStrategy namingStrategy, ClassField classField) {
    return (classField.hasAnnotation(COLUMN)) ? classField.getAnnotationAttribute(COLUMN, "name") : namingStrategy.columnName(classField.getName());
}
项目:statement-generator    文件:InsertPreparedStatement.java   
public InsertPreparedStatement(InterpretedClass interpretedClass, NamingStrategy namingStrategy) {
    super(interpretedClass, namingStrategy);
}
项目:statement-generator    文件:AbstractStatement.java   
public AbstractStatement(InterpretedClass interpretedClass, NamingStrategy namingStrategy) {  
    this.interpretedClass = interpretedClass;
    this.namingStrategy = namingStrategy;
}
项目:statement-generator    文件:DeleteSQLStatement.java   
public DeleteSQLStatement(InterpretedClass interpretedClass, NamingStrategy namingStrategy) {
    super(interpretedClass, namingStrategy);
}