本文整理汇总了Java中org.hibernate.cfg.Configuration.configure方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.configure方法的具体用法?Java Configuration.configure怎么用?Java Configuration.configure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.cfg.Configuration
的用法示例。
在下文中一共展示了Configuration.configure方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSessionFactory
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public static SessionFactory getSessionFactory() {
if (null != sessionFactory)
return sessionFactory;
Configuration configuration = new Configuration();
String jdbcUrl = "jdbc:mysql://"
+ System.getenv("RDS_HOSTNAME")
+ "/"
+ System.getenv("RDS_DB_NAME");
configuration.setProperty("hibernate.connection.url", jdbcUrl);
configuration.setProperty("hibernate.connection.username", System.getenv("RDS_USERNAME"));
configuration.setProperty("hibernate.connection.password", System.getenv("RDS_PASSWORD"));
configuration.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
try {
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (HibernateException e) {
System.err.println("Initial SessionFactory creation failed." + e);
throw new ExceptionInInitializerError(e);
}
return sessionFactory;
}
示例2: HibernateHelper
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public HibernateHelper(Logger log, String dialect, String driver_class, String url, String username, String password, long retry, Class<?>... annotatedClasses) throws EngineException {
this.log = log;
this.retry = retry + 1;
Document doc = XMLUtils.getDefaultDocumentBuilder().newDocument();
Element elt = doc.createElement("session-factory");
addProperty(elt, "hibernate.connection.driver_class", driver_class);
addProperty(elt, "hibernate.connection.url", url);
addProperty(elt, "hibernate.connection.username", username);
addProperty(elt, "hibernate.connection.password", password);
addProperty(elt, "hibernate.dialect", dialect);
addProperty(elt, "hibernate.hbm2ddl.auto", "update");
addProperty(elt, "hibernate.connection.autocommit", "true");
addProperty(elt, "hibernate.jdbc.batch_size", "1");
addProperty(elt, "hibernate.show_sql", "true");
doc.appendChild(doc.createElement("hibernate-configuration")).appendChild(elt);
configuration = new Configuration();
for (Class<?> annotatedClass: annotatedClasses) {
configuration.addAnnotatedClass(annotatedClass);
}
configuration.configure(doc);
}
示例3: getConfiguration
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
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;
}
示例4: getConfiguration
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
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;
}
示例5: getConfiguration
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
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;
}
示例6: createSessionFactory
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory createSessionFactory() {
SessionFactory sessionFactory = null;
try {
String resource;
Configuration configuration = new Configuration();
resource = "oswf-store.cfg.xml";
logger.info("Configuring Hibernate Mapping: " + resource);
configuration.configure(resource);
// Database configuration; H2 or MySQL
resource = "hibernate.xml";
logger.info("Configuring Hibernate Mapping: " + resource);
configuration.configure(resource);
// Attempt to create the SessionFactory; exceptions may be thrown
sessionFactory = configuration.buildSessionFactory();
} catch (Throwable e) {
logger.error(fatal, "Failed to create Hibernate SessionFactory: " + e.toString());
sessionFactory = null;
}
return sessionFactory;
}
示例7: SessionFactory
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory() {
try {
HibernateConfiguration hibernateConfiguration = ConfigurationWrapper.getInstance().getHibernateConfiguration();
Configuration configuration = new Configuration();
initHBMs(configuration);
configuration.configure(hibernateConfiguration.getPathToConfigurationFile());
StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
sessionFactory = configuration.buildSessionFactory(standardServiceRegistryBuilder.build());
}catch (Exception excetption){
}
}
示例8: createConfig
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private static Configuration createConfig()
{
Configuration config = new Configuration();
if(Settings.HIBERNATE_CONFIG_INTERNAL_PATH)
config.configure(Settings.HIBERNATE_CONFIG_FILE_PATH);
else
config.configure(new File(Settings.HIBERNATE_CONFIG_FILE_PATH));
registerEntityTypes(config);
return config;
}
示例9: configureSessionFactory
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private static SessionFactory configureSessionFactory()
throws HibernateException {
Configuration configuration = new Configuration();
configuration.configure();
Properties properties = configuration.getProperties();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().
applySettings(properties).buildServiceRegistry();
SessionFactory sessionFactory = configuration.
buildSessionFactory(serviceRegistry);
return sessionFactory;
}
示例10: main
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
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();
}
}
示例11: main
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
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();
}
}
示例12: createSessionFactory
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
private SessionFactory createSessionFactory() {
closeSessionFactory();
String[] resources = {"oswf-store.cfg.xml", RDBMS_CONFIGURATION};
Configuration configuration = new Configuration();
for (String resource : resources)
configuration.configure(resource);
return configuration.buildSessionFactory();
}