(10);
+ }
+ };
}
}
\ No newline at end of file
diff --git a/src/main/java/com/idcanet/vasc/backends/jdbc/JdniDataSourceJdbcConnectionProvider.java b/src/main/java/com/idcanet/vasc/backends/jdbc/JdniDataSourceJdbcConnectionProvider.java
new file mode 100644
index 0000000..0679f86
--- /dev/null
+++ b/src/main/java/com/idcanet/vasc/backends/jdbc/JdniDataSourceJdbcConnectionProvider.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2004-2007 IDCA. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
+ * following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
+ * the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the authors and
+ * should not be interpreted as representing official policies, either expressed or implied, of IDCA.
+ */
+
+package com.idcanet.vasc.backends.jdbc;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+/**
+ *
+ * @author Willem Cazander
+ * @version 1.0 Mar 15, 2009
+ */
+public class JdniDataSourceJdbcConnectionProvider implements JdbcConnectionProvider {
+
+ /** The context in which database data sources are found. */
+ private String dataSourceContext = "java:comp/env/jdbc/";
+
+ private String dataSourceName = null;
+
+ /**
+ * @see com.idcanet.vasc.backends.jdbc.JdbcConnectionProvider#getJdbcConnection()
+ */
+ public Connection getJdbcConnection() throws SQLException {
+ Connection connection = getDataSource(dataSourceName).getConnection();
+ return connection;
+ }
+
+
+ /**
+ * Gets a DataSource out of the JNDI context.
+ *
+ * @param name The name of the data source in the JDNI context.
+ * @return The data source.
+ */
+ private DataSource getDataSource(String name) throws SQLException {
+
+ try {
+ Context initialContext = new InitialContext();
+ if ( initialContext == null ) {
+ throw new SQLException("Cannot get Initial Context");
+ }
+ DataSource datasource = (DataSource)initialContext.lookup(dataSourceContext+name);
+ if ( datasource == null ) {
+ throw new SQLException("Cannot lookup datasource: "+name);
+ }
+ return datasource;
+ } catch ( NamingException e ) {
+ throw new SQLException("Cannot get connection " + e,e);
+ }
+ }
+
+
+ /**
+ * @return the dataSourceContext
+ */
+ public String getDataSourceContext() {
+ return dataSourceContext;
+ }
+
+
+ /**
+ * @param dataSourceContext the dataSourceContext to set
+ */
+ public void setDataSourceContext(String dataSourceContext) {
+ this.dataSourceContext = dataSourceContext;
+ }
+
+
+ /**
+ * @return the dataSourceName
+ */
+ public String getDataSourceName() {
+ return dataSourceName;
+ }
+
+
+ /**
+ * @param dataSourceName the dataSourceName to set
+ */
+ public void setDataSourceName(String dataSourceName) {
+ this.dataSourceName = dataSourceName;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/idcanet/vasc/backends/jdbc/SimpleJdbcConnectionProvider.java b/src/main/java/com/idcanet/vasc/backends/jdbc/SimpleJdbcConnectionProvider.java
new file mode 100644
index 0000000..317477f
--- /dev/null
+++ b/src/main/java/com/idcanet/vasc/backends/jdbc/SimpleJdbcConnectionProvider.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2004-2007 IDCA. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
+ * following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
+ * the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
+ * and the following disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the authors and
+ * should not be interpreted as representing official policies, either expressed or implied, of IDCA.
+ */
+
+package com.idcanet.vasc.backends.jdbc;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+
+/**
+ *
+ * @author Willem Cazander
+ * @version 1.0 Mar 15, 2009
+ */
+public class SimpleJdbcConnectionProvider implements JdbcConnectionProvider {
+
+ private String driverClassName = null;
+ private String dbUrl = null;
+ private String dbUser = null;
+ private String dbPassword = null;
+ private boolean loadedDriver = false;
+
+ /**
+ * @see com.idcanet.vasc.backends.jdbc.JdbcConnectionProvider#getJdbcConnection()
+ */
+ public Connection getJdbcConnection() throws SQLException {
+ if (loadedDriver==false) {
+ try {
+ Class.forName(driverClassName);
+ loadedDriver = true;
+ } catch (ClassNotFoundException e) {
+ throw new SQLException("Could not load driver: "+driverClassName+" error: "+e.getMessage(),e);
+ }
+ }
+ Connection connection = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
+ return connection;
+ }
+
+ /**
+ * @return the driverClassName
+ */
+ public String getDriverClassName() {
+ return driverClassName;
+ }
+
+ /**
+ * @param driverClassName the driverClassName to set
+ */
+ public void setDriverClassName(String driverClassName) {
+ this.driverClassName = driverClassName;
+ }
+
+ /**
+ * @return the dbUrl
+ */
+ public String getDbUrl() {
+ return dbUrl;
+ }
+
+ /**
+ * @param dbUrl the dbUrl to set
+ */
+ public void setDbUrl(String dbUrl) {
+ this.dbUrl = dbUrl;
+ }
+
+ /**
+ * @return the dbUser
+ */
+ public String getDbUser() {
+ return dbUser;
+ }
+
+ /**
+ * @param dbUser the dbUser to set
+ */
+ public void setDbUser(String dbUser) {
+ this.dbUser = dbUser;
+ }
+
+ /**
+ * @return the dbPassword
+ */
+ public String getDbPassword() {
+ return dbPassword;
+ }
+
+ /**
+ * @param dbPassword the dbPassword to set
+ */
+ public void setDbPassword(String dbPassword) {
+ this.dbPassword = dbPassword;
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java
index c2242df..3e50c35 100644
--- a/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java
+++ b/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java
@@ -37,19 +37,17 @@ import com.idcanet.vasc.core.AbstractVascBackend;
*/
abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend {
- /**
- * Provides a hibernate session which is closed !! when transaction is compleeted.
- * @return
- */
abstract EntityManager getEntityManager();
public void persist(Object object) throws Exception {
EntityManager s = getEntityManager();
try {
+ s.getTransaction().begin();
s.persist(object);
+ s.getTransaction().commit();
} finally {
if (s!=null) {
- s.close();
+ //s.close();
}
}
}
@@ -57,10 +55,13 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
public Object merge(Object object) throws Exception {
EntityManager s = getEntityManager();
try {
- return s.merge(object);
+ s.getTransaction().begin();
+ Object result = s.merge(object);
+ s.getTransaction().commit();
+ return result;
} finally {
if (s!=null) {
- s.close();
+ //s.close();
}
}
}
@@ -68,11 +69,13 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
public void delete(Object object) throws Exception {
EntityManager s = getEntityManager();
try {
+ s.getTransaction().begin();
Object newObject = s.merge(object);
s.remove(newObject);
+ s.getTransaction().commit();
} finally {
if (s!=null) {
- s.close();
+ //s.close();
}
}
}
diff --git a/src/main/java/com/idcanet/vasc/validators/VascValidatorField.java b/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java
similarity index 78%
rename from src/main/java/com/idcanet/vasc/validators/VascValidatorField.java
rename to src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java
index b4893f2..ccb5933 100644
--- a/src/main/java/com/idcanet/vasc/validators/VascValidatorField.java
+++ b/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2008 IDCA. All rights reserved.
+ * Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
@@ -24,24 +24,17 @@
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
-package com.idcanet.vasc.validators;
+package com.idcanet.vasc.backends.jpa;
+
+import javax.persistence.EntityManager;
/**
- * The VascValidator interface
*
* @author Willem Cazander
- * @version 1.0 Sep 5, 2008
+ * @version 1.0 Mar 21, 2009
*/
-public class VascValidatorField {
-
- final private String propertyName = null;
- final private String message = null;
- final private Object value = null;
- final private Class beanClass = null;
- final private Object beanObject = null;
+public interface EntityManagerProvider {
- public VascValidatorField() {
-
- }
+ public EntityManager getEntityManager();
}
\ No newline at end of file
diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/Serv5XpqlHibernateVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/Serv5XpqlHibernateVascBackend.java
index bcf3b8f..06ae566 100644
--- a/src/main/java/com/idcanet/vasc/backends/jpa/Serv5XpqlHibernateVascBackend.java
+++ b/src/main/java/com/idcanet/vasc/backends/jpa/Serv5XpqlHibernateVascBackend.java
@@ -64,11 +64,16 @@ public class Serv5XpqlHibernateVascBackend extends AbstractHibernateVascBackend
@SuppressWarnings("unchecked")
public List