git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngine@150568 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
38ce4eb4b5
commit
dbaedc1ce7
|
@ -22,7 +22,7 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
|
9
pom.xml
9
pom.xml
|
@ -67,11 +67,6 @@
|
|||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dom4j</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>graphlayout</groupId>
|
||||
<artifactId>graphlayout</artifactId>
|
||||
|
@ -233,8 +228,8 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
package org.gcube.contentmanagement.lexicalmatcher.utils;
|
||||
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Node;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
|
@ -30,78 +25,41 @@ public class DatabaseFactory {
|
|||
return DBSessionFactory;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static SessionFactory initDBConnection(String configurationFile, LexicalEngineConfiguration config) throws Exception {
|
||||
|
||||
|
||||
if (config==null)
|
||||
return initDBConnection(configurationFile);
|
||||
|
||||
InputStream stream;
|
||||
try {
|
||||
File fl = new File(configurationFile);
|
||||
stream = new FileInputStream(fl);
|
||||
} catch (Exception e) {
|
||||
stream = ClassLoader.getSystemResourceAsStream(configurationFile);
|
||||
}
|
||||
SAXReader saxReader = new SAXReader();
|
||||
Document document = saxReader.read(stream);
|
||||
|
||||
List<Node> nodes = document.selectNodes("//hibernate-configuration/session-factory/property");
|
||||
Iterator<Node> nodesIterator = nodes.iterator();
|
||||
|
||||
// System.out.println("--- DATABASE Configuration --- ");
|
||||
|
||||
while (nodesIterator.hasNext()) {
|
||||
Node currentnode = nodesIterator.next();
|
||||
String element = currentnode.valueOf("@name");
|
||||
if (element.equals("connection.driver_class"))
|
||||
if (config.getDatabaseDriver() != null){
|
||||
currentnode.setText(config.getDatabaseDriver());
|
||||
}
|
||||
if (element.equals("connection.url")) {
|
||||
if (config.getDatabaseURL() != null)
|
||||
currentnode.setText(config.getDatabaseURL());
|
||||
}
|
||||
if (element.equals("connection.username")) {
|
||||
if (config.getDatabaseUserName() != null)
|
||||
currentnode.setText(config.getDatabaseUserName());
|
||||
}
|
||||
if (element.equals("connection.password")) {
|
||||
if (config.getDatabasePassword() != null)
|
||||
currentnode.setText(config.getDatabasePassword());
|
||||
}
|
||||
if (element.equals("dialect")) {
|
||||
AnalysisLogger.getLogger().trace("Dialect -> "+config.getDatabaseDialect());
|
||||
if (config.getDatabaseDialect() != null)
|
||||
currentnode.setText(config.getDatabaseDialect());
|
||||
}
|
||||
if (element.equals("c3p0.idleConnectionTestPeriod")) {
|
||||
if (config.getDatabaseIdleConnectionTestPeriod() != null)
|
||||
currentnode.setText(config.getDatabaseIdleConnectionTestPeriod());
|
||||
}
|
||||
if (element.equals("c3p0.automaticTestTable")) {
|
||||
if (config.getDatabaseAutomaticTestTable() != null)
|
||||
currentnode.setText(config.getDatabaseAutomaticTestTable());
|
||||
}
|
||||
}
|
||||
InputStream stream= null;
|
||||
try{
|
||||
if (config==null)
|
||||
return initDBConnection(configurationFile);
|
||||
|
||||
Configuration cfg = new Configuration();
|
||||
cfg = cfg.configure(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(document.asXML().getBytes())));
|
||||
cfg.setProperty("hibernate.hbm2ddl.auto", "create");
|
||||
|
||||
SessionFactory DBSessionFactory = null;
|
||||
DBSessionFactory = cfg.buildSessionFactory();
|
||||
|
||||
// close stream
|
||||
stream.close();
|
||||
|
||||
return DBSessionFactory;
|
||||
try {
|
||||
File fl = new File(configurationFile);
|
||||
stream = new FileInputStream(fl);
|
||||
} catch (Exception e) {
|
||||
stream = ClassLoader.getSystemResourceAsStream(configurationFile);
|
||||
}
|
||||
|
||||
Configuration cfg = new Configuration();
|
||||
cfg = cfg.configure(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(stream));
|
||||
cfg.setProperty("hibernate.hbm2ddl.auto", "create");
|
||||
|
||||
SessionFactory DBSessionFactory = null;
|
||||
DBSessionFactory = cfg.buildSessionFactory();
|
||||
|
||||
// close stream
|
||||
stream.close();
|
||||
|
||||
return DBSessionFactory;
|
||||
}finally{
|
||||
if (stream!=null)
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static List<Object> executeHQLQuery(String query, SessionFactory DBSessionFactory, boolean useSQL) {
|
||||
|
||||
|
||||
List<Object> obj = null;
|
||||
Session ss = null;
|
||||
try {
|
||||
|
@ -126,15 +84,15 @@ public class DatabaseFactory {
|
|||
|
||||
if (result != null && result.size() == 0)
|
||||
System.out.println(String.format("found nothing in database"));
|
||||
*/
|
||||
*/
|
||||
if (result != null && result.size() != 0) {
|
||||
obj = result;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
// System.out.println(String.format("Error while executing query: %1$s %2$s", query, e.getMessage()));
|
||||
// e.printStackTrace();
|
||||
// System.out.println(String.format("Error while executing query: %1$s %2$s", query, e.getMessage()));
|
||||
// e.printStackTrace();
|
||||
System.out.println(String.format("Error while executing query: %1$s %2$s", query, e.getMessage()));
|
||||
rollback(ss);
|
||||
}
|
||||
|
@ -144,13 +102,13 @@ public class DatabaseFactory {
|
|||
}
|
||||
|
||||
public static void executeHQLUpdate(String query, SessionFactory DBSessionFactory, boolean useSQL) throws Exception{
|
||||
// System.out.println("executing query: " + query);
|
||||
// System.out.println("executing query: " + query);
|
||||
Session ss = null;
|
||||
|
||||
try {
|
||||
|
||||
ss = DBSessionFactory.getCurrentSession();
|
||||
// System.out.println("executing query");
|
||||
// System.out.println("executing query");
|
||||
ss.beginTransaction();
|
||||
Query qr = null;
|
||||
|
||||
|
|
|
@ -9,29 +9,59 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public class FileTools {
|
||||
|
||||
public static String readXMLDoc(String xmlFilePath) throws Exception {
|
||||
String xml = null;
|
||||
InputStream stream;
|
||||
try {
|
||||
File fl = new File(xmlFilePath);
|
||||
stream = new FileInputStream(fl);
|
||||
} catch (Exception e) {
|
||||
stream = ClassLoader.getSystemResourceAsStream(xmlFilePath);
|
||||
}
|
||||
SAXReader saxReader = new SAXReader();
|
||||
Document document = saxReader.read(stream);
|
||||
xml = document.asXML();
|
||||
stream.close();
|
||||
InputStream stream = null;
|
||||
try{
|
||||
try {
|
||||
File fl = new File(xmlFilePath);
|
||||
stream = new FileInputStream(fl);
|
||||
} catch (Exception e) {
|
||||
stream = ClassLoader.getSystemResourceAsStream(xmlFilePath);
|
||||
}
|
||||
DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance()
|
||||
.newDocumentBuilder();
|
||||
|
||||
return xml;
|
||||
Document doc = dBuilder.parse(stream);
|
||||
xml = toString(doc);
|
||||
return xml;
|
||||
}finally{
|
||||
if (stream!=null)
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static String toString(Document doc) {
|
||||
try {
|
||||
StringWriter sw = new StringWriter();
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
Transformer transformer = tf.newTransformer();
|
||||
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
|
||||
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
|
||||
|
||||
transformer.transform(new DOMSource(doc), new StreamResult(sw));
|
||||
return sw.toString();
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Error converting to String", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveString2File(String filename, String string2save) throws Exception {
|
||||
|
|
|
@ -8,14 +8,12 @@ import java.sql.Connection;
|
|||
import java.sql.DriverManager;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Node;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.gcube.contentmanagement.lexicalmatcher.analysis.core.LexicalEngineConfiguration;
|
||||
import org.gcube.contentmanagement.lexicalmatcher.utils.FileTools;
|
||||
import org.gcube.dataanalysis.ecoengine.datatypes.DatabaseType;
|
||||
|
@ -25,6 +23,9 @@ import org.hibernate.Query;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
public class DatabaseFactory{
|
||||
|
||||
|
@ -37,110 +38,86 @@ public class DatabaseFactory{
|
|||
return DBSessionFactory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<StatisticalType> getDefaultDatabaseConfiguration(String configurationFile) throws Exception {
|
||||
|
||||
List<StatisticalType> defaultconfig = new ArrayList<StatisticalType>();
|
||||
|
||||
final List<StatisticalType> defaultconfig = new ArrayList<StatisticalType>();
|
||||
|
||||
// take the configuration file
|
||||
File fl = new File(configurationFile);
|
||||
FileInputStream stream = new FileInputStream(fl);
|
||||
|
||||
SAXReader saxReader = new SAXReader();
|
||||
Document document = saxReader.read(stream);
|
||||
List<Node> nodes = document.selectNodes("//hibernate-configuration/session-factory/property");
|
||||
Iterator<Node> nodesIterator = nodes.iterator();
|
||||
|
||||
while (nodesIterator.hasNext()) {
|
||||
|
||||
Node currentnode = nodesIterator.next();
|
||||
String element = currentnode.valueOf("@name");
|
||||
if (element.equals("connection.driver_class"))
|
||||
defaultconfig.add(new DatabaseType(DatabaseParameters.DATABASEDRIVER, "DatabaseDriver", "db driver",currentnode.getText()));
|
||||
if (element.equals("connection.url"))
|
||||
defaultconfig.add(new DatabaseType(DatabaseParameters.DATABASEURL, "DatabaseURL", "db url",currentnode.getText()));
|
||||
if (element.equals("connection.username"))
|
||||
defaultconfig.add(new DatabaseType(DatabaseParameters.DATABASEUSERNAME, "DatabaseUserName", "db user name",currentnode.getText()));
|
||||
if (element.equals("connection.password"))
|
||||
defaultconfig.add(new DatabaseType(DatabaseParameters.DATABASEPASSWORD, "DatabasePassword", "db password",currentnode.getText()));
|
||||
if (element.equals("dialect"))
|
||||
defaultconfig.add(new DatabaseType(DatabaseParameters.DATABASEDIALECT, "DatabaseDialect", "db dialect",currentnode.getText()));
|
||||
}
|
||||
|
||||
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
|
||||
|
||||
parser.parse(stream, new DefaultHandler(){
|
||||
|
||||
private DatabaseParameters actualparameter = null;
|
||||
private String actualParameterDescription= null;
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName,
|
||||
String qName, Attributes attributes) throws SAXException {
|
||||
|
||||
if (localName.equals("property")){
|
||||
String element = attributes.getValue("name");
|
||||
|
||||
if (element.equals("connection.driver_class")){
|
||||
actualparameter = DatabaseParameters.DATABASEDRIVER;
|
||||
actualParameterDescription = "DatabaseDriver";
|
||||
}else if (element.equals("connection.url")) {
|
||||
actualparameter = DatabaseParameters.DATABASEURL;
|
||||
actualParameterDescription = "DatabaseURL";
|
||||
}else if (element.equals("connection.username")){
|
||||
actualparameter = DatabaseParameters.DATABASEUSERNAME;
|
||||
actualParameterDescription = "DatabaseUserName";
|
||||
}else if (element.equals("connection.password")){
|
||||
actualparameter = DatabaseParameters.DATABASEPASSWORD;
|
||||
actualParameterDescription = "DATABASEPASSWORD";
|
||||
}else if (element.equals("dialect")){
|
||||
actualparameter = DatabaseParameters.DATABASEDIALECT;
|
||||
actualParameterDescription = "DATABASEDIALECT";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char ch[], int start, int length) throws SAXException {
|
||||
|
||||
if (actualParameterDescription!=null){
|
||||
defaultconfig.add(new DatabaseType(actualparameter, actualParameterDescription, actualParameterDescription, new String(ch, start, length)));
|
||||
actualparameter = null;
|
||||
actualParameterDescription= null;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
return defaultconfig;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static SessionFactory initDBConnection(String configurationFile, LexicalEngineConfiguration config) throws Exception {
|
||||
|
||||
|
||||
|
||||
if (config==null)
|
||||
return initDBConnection(configurationFile);
|
||||
|
||||
|
||||
|
||||
|
||||
// take the configuration file
|
||||
File fl = new File(configurationFile);
|
||||
FileInputStream stream = new FileInputStream(fl);
|
||||
|
||||
SAXReader saxReader = new SAXReader();
|
||||
Document document = saxReader.read(stream);
|
||||
List<Node> nodes = document.selectNodes("//hibernate-configuration/session-factory/property");
|
||||
Iterator<Node> nodesIterator = nodes.iterator();
|
||||
|
||||
while (nodesIterator.hasNext()) {
|
||||
Node currentnode = nodesIterator.next();
|
||||
String element = currentnode.valueOf("@name");
|
||||
if (element.equals("connection.driver_class")){
|
||||
if ((config.getDatabaseDriver() != null)&&(config.getDatabaseDriver().length()>0))
|
||||
currentnode.setText(config.getDatabaseDriver());
|
||||
else
|
||||
config.setDatabaseDriver(currentnode.getText());
|
||||
}
|
||||
if (element.equals("connection.url")) {
|
||||
if ((config.getDatabaseURL() != null)&&(config.getDatabaseURL().length()>0))
|
||||
currentnode.setText(config.getDatabaseURL());
|
||||
else
|
||||
config.setDatabaseURL(currentnode.getText());
|
||||
}
|
||||
if (element.equals("connection.username")) {
|
||||
if ((config.getDatabaseUserName() != null)&&(config.getDatabaseUserName().length()>0))
|
||||
currentnode.setText(config.getDatabaseUserName());
|
||||
else
|
||||
config.setDatabaseUserName(currentnode.getText());
|
||||
}
|
||||
if (element.equals("connection.password")) {
|
||||
if ((config.getDatabasePassword() != null)&&(config.getDatabasePassword().length()>0))
|
||||
currentnode.setText(config.getDatabasePassword());
|
||||
else
|
||||
config.setDatabasePassword(currentnode.getText());
|
||||
}
|
||||
if (element.equals("dialect")) {
|
||||
if ((config.getDatabaseDialect() != null)&&(config.getDatabaseDialect().length()>0))
|
||||
currentnode.setText(config.getDatabaseDialect());
|
||||
else
|
||||
config.setDatabaseDialect(currentnode.getText());
|
||||
}
|
||||
if (element.equals("c3p0.idleConnectionTestPeriod")) {
|
||||
if (config.getDatabaseIdleConnectionTestPeriod() != null)
|
||||
currentnode.setText(config.getDatabaseIdleConnectionTestPeriod());
|
||||
else
|
||||
config.setDatabaseIdleConnectionTestPeriod(currentnode.getText());
|
||||
}
|
||||
if (element.equals("c3p0.automaticTestTable")) {
|
||||
if (config.getDatabaseAutomaticTestTable() != null)
|
||||
currentnode.setText(config.getDatabaseAutomaticTestTable());
|
||||
else
|
||||
config.setDatabaseAutomaticTestTable(currentnode.getText());
|
||||
}
|
||||
}
|
||||
|
||||
Configuration cfg = new Configuration();
|
||||
cfg = cfg.configure(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(document.asXML().getBytes())));
|
||||
cfg = cfg.configure(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(stream));
|
||||
cfg.setProperty("hibernate.hbm2ddl.auto", "create");
|
||||
|
||||
SessionFactory DBSessionFactory = null;
|
||||
DBSessionFactory = cfg.buildSessionFactory();
|
||||
|
||||
|
||||
// close stream
|
||||
stream.close();
|
||||
return DBSessionFactory;
|
||||
|
@ -150,43 +127,43 @@ public class DatabaseFactory{
|
|||
public static List<Object> executeHQLQuery(String query, SessionFactory DBSessionFactory, boolean useSQL) {
|
||||
List<Object> obj = null;
|
||||
Session ss = null;
|
||||
ss = DBSessionFactory.getCurrentSession();
|
||||
ss = DBSessionFactory.getCurrentSession();
|
||||
|
||||
ss.beginTransaction();
|
||||
ss.beginTransaction();
|
||||
|
||||
Query qr = null;
|
||||
Query qr = null;
|
||||
|
||||
if (useSQL)
|
||||
qr = ss.createSQLQuery(query);
|
||||
else
|
||||
qr = ss.createQuery(query);
|
||||
List<Object> result = null;
|
||||
try{
|
||||
result = qr.list();
|
||||
ss.getTransaction().commit();
|
||||
}catch(Exception e){
|
||||
System.out.println("Could not execute query "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
rollback(ss);
|
||||
}
|
||||
if (useSQL)
|
||||
qr = ss.createSQLQuery(query);
|
||||
else
|
||||
qr = ss.createQuery(query);
|
||||
List<Object> result = null;
|
||||
try{
|
||||
result = qr.list();
|
||||
ss.getTransaction().commit();
|
||||
}catch(Exception e){
|
||||
System.out.println("Could not execute query "+e.getMessage());
|
||||
e.printStackTrace();
|
||||
rollback(ss);
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
System.out.println("Hibernate doesn't return a valid object when org.gcube.contentmanagement.lexicalmatcher retrieve UserState Object");
|
||||
if (result == null)
|
||||
System.out.println("Hibernate doesn't return a valid object when org.gcube.contentmanagement.lexicalmatcher retrieve UserState Object");
|
||||
|
||||
// if (result != null && result.size() == 0)
|
||||
// System.out.println(String.format("found nothing in database for query: "+query));
|
||||
// if (result != null && result.size() == 0)
|
||||
// System.out.println(String.format("found nothing in database for query: "+query));
|
||||
|
||||
if (result != null && result.size() != 0) {
|
||||
obj = result;
|
||||
}
|
||||
|
||||
|
||||
// rollback(ss);
|
||||
if (result != null && result.size() != 0) {
|
||||
obj = result;
|
||||
}
|
||||
|
||||
|
||||
// rollback(ss);
|
||||
|
||||
return obj;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Connection getDBConnection(String drivername,String username, String password, String databaseurl) throws Exception{
|
||||
// Load the database driver
|
||||
Class.forName(drivername) ;
|
||||
|
@ -196,63 +173,63 @@ public class DatabaseFactory{
|
|||
}
|
||||
|
||||
public static void executeUpdateNoTransaction(final String query, String drivername,String username, String password, String databaseurl, boolean useSQL) throws Exception{
|
||||
|
||||
|
||||
// Load the database driver
|
||||
Class.forName(drivername) ;
|
||||
|
||||
// Get a connection to the database
|
||||
Connection conn = DriverManager.getConnection(databaseurl,username,password) ;
|
||||
// Get a connection to the database
|
||||
Connection conn = DriverManager.getConnection(databaseurl,username,password) ;
|
||||
|
||||
// Get a statement from the connection
|
||||
Statement stmt = conn.createStatement() ;
|
||||
// Get a statement from the connection
|
||||
Statement stmt = conn.createStatement() ;
|
||||
|
||||
// Execute the query
|
||||
stmt.executeUpdate( query) ;
|
||||
|
||||
stmt.close() ;
|
||||
conn.close() ;
|
||||
|
||||
// Execute the query
|
||||
stmt.executeUpdate( query) ;
|
||||
|
||||
stmt.close() ;
|
||||
conn.close() ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void executeUpdateNoTransaction(final String query, SessionFactory DBSessionFactory, boolean useSQL) throws Exception{
|
||||
// System.out.println("executing query: " + query);
|
||||
// System.out.println("executing query: " + query);
|
||||
Session ss = null;
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
ss = DBSessionFactory.getCurrentSession();
|
||||
|
||||
|
||||
// System.out.println("executing query");
|
||||
ss.doWork(new Work() {
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(Connection conn) throws SQLException {
|
||||
Statement stmt = conn.createStatement() ;
|
||||
// Execute the query
|
||||
ResultSet rs = stmt.executeQuery(query) ;
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
*/
|
||||
*/
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void executeHQLUpdate(String query, SessionFactory DBSessionFactory, boolean useSQL) throws Exception{
|
||||
// System.out.println("executing query: " + query);
|
||||
// System.out.println("executing query: " + query);
|
||||
Session ss = null;
|
||||
|
||||
try {
|
||||
|
||||
ss = DBSessionFactory.getCurrentSession();
|
||||
// System.out.println("executing query");
|
||||
// System.out.println("executing query");
|
||||
ss.beginTransaction();
|
||||
Query qr = null;
|
||||
|
||||
|
@ -266,25 +243,25 @@ public class DatabaseFactory{
|
|||
|
||||
} catch (Exception e) {
|
||||
rollback(ss);
|
||||
// e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void executeNativeUpdate(String query, SessionFactory DBSessionFactory) {
|
||||
// System.out.println("executing query: " + query);
|
||||
// System.out.println("executing query: " + query);
|
||||
Session ss = null;
|
||||
|
||||
try {
|
||||
|
||||
ss = DBSessionFactory.getCurrentSession();
|
||||
|
||||
|
||||
System.out.println("executing query");
|
||||
ss.beginTransaction();
|
||||
Query qr = null;
|
||||
|
||||
|
||||
|
||||
|
||||
qr = DBSessionFactory.getCurrentSession().getNamedQuery("mySp").setParameter("param", query);
|
||||
|
||||
qr.executeUpdate();
|
||||
|
@ -295,14 +272,14 @@ public class DatabaseFactory{
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void executeSQLUpdate(String query, SessionFactory DBSessionFactory) throws Exception {
|
||||
executeHQLUpdate(query, DBSessionFactory, true);
|
||||
}
|
||||
|
||||
public static List<Object> executeSQLQuery(String query, SessionFactory DBSessionFactory) {
|
||||
// System.out.println("QUERY: "+query);
|
||||
// System.out.println("QUERY: "+query);
|
||||
return executeHQLQuery(query, DBSessionFactory, true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue