/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.osm.utils;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
/**
*
* @author slorenzo
*/
public class ConfigurationHelper {
public static Configuration ConfigurationHelper (
String classDriver,
String urlConnection,
String username,
String password,
boolean autocommit,
String resources[]) {
Configuration cfg = new Configuration();
try {
// dialect org.hibernate.dialect.MySQLDialect"
cfg.setProperty(Environment.DIALECT, "org.hibernate.dialect.MySQLDialect");
// driver_class com.mysql.jdbc.Driver
cfg.setProperty(Environment.DRIVER, classDriver);
// url jdbc:mysql://localhost:3306/base_xstudent?zeroDateTimeBehavior=convertToNull
cfg.setProperty(Environment.URL, urlConnection);
cfg.setProperty(Environment.USER, username);
cfg.setProperty(Environment.PASS, password);
cfg.setProperty(Environment.AUTOCOMMIT, autocommit ? "True" : "False");
// example: com/osm/model/academical/Task.hbm.xml
for (String resource : resources) {
cfg.addResource(resource);
}
} catch (Throwable ex) {
ex.printStackTrace();
}
return cfg;
}
}