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() ); } }
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; }
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; }
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; }
@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())); } }
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); }
/** * 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(); } }
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 {@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(); }
private void initializeConfig(NamingStrategy namingStrategy, Interceptor interceptor) { if (namingStrategy != null) { configuration.setNamingStrategy(namingStrategy); } if (interceptor != null) { configuration.setInterceptor(interceptor); } }
public LegacyNamingStrategyDelegator(NamingStrategy namingStrategy) { this.namingStrategy = namingStrategy; this.hbmNamingStrategyDelegate = new LegacyHbmNamingStrategyDelegate( this ); this.jpaNamingStrategyDelegate = new LegacyJpaNamingStrategyDelegate( this ); }
public NamingStrategy getNamingStrategy() { return namingStrategy; }
protected NamingStrategy getNamingStrategy() { return context.getNamingStrategy(); }
@Override public String determineImplicitName(NamingStrategy strategy) { return strategy.classToTableName( entityName ); }
@Override public String handleExplicitName(NamingStrategy strategy, String name) { return strategy.tableName( name ); }
public String determineImplicitName(NamingStrategy strategy) { // todo : throw an error? return null; }
public String handleExplicitName(NamingStrategy strategy, String name) { return strategy.tableName( name ); }
@Override public NamingStrategy getNamingStrategy() { return metadata.getNamingStrategy(); }
@Override protected NamingStrategy getNamingStrategy() { return namingStrategy; }
@Override public MetadataBuilder with(NamingStrategy namingStrategy) { this.options.namingStrategy = namingStrategy; return this; }
@Override public NamingStrategy getNamingStrategy() { return namingStrategy; }
@Override public NamingStrategy getNamingStrategy() { return options.getNamingStrategy(); }
@Override public NamingStrategy getNamingStrategy() { return contextDelegate.getNamingStrategy(); }
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(); } }
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(); } }
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(); } }
/** * 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(); }
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(); } }
public ResultSetStatement(InterpretedClass interpretedClass, NamingStrategy namingStrategy) { super(interpretedClass, namingStrategy); }
private String getColumnName(NamingStrategy namingStrategy, ClassField classField) { return (classField.hasAnnotation(COLUMN)) ? classField.getAnnotationAttribute(COLUMN, "name") : namingStrategy.columnName(classField.getName()); }
public InsertPreparedStatement(InterpretedClass interpretedClass, NamingStrategy namingStrategy) { super(interpretedClass, namingStrategy); }
public AbstractStatement(InterpretedClass interpretedClass, NamingStrategy namingStrategy) { this.interpretedClass = interpretedClass; this.namingStrategy = namingStrategy; }
public DeleteSQLStatement(InterpretedClass interpretedClass, NamingStrategy namingStrategy) { super(interpretedClass, namingStrategy); }