本文整理匯總了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();
}