diff --git a/.project b/.project
index 4848137..6dbf548 100644
--- a/.project
+++ b/.project
@@ -5,6 +5,11 @@
+
+ org.eclipse.wst.common.project.facet.core.builder
+
+
+
com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder
@@ -58,5 +63,6 @@
org.eclipse.jem.workbench.JavaEMFNature
org.eclipse.jdt.core.javanature
org.eclipse.jem.beaninfo.BeanInfoNature
+ org.eclipse.wst.common.project.facet.core.nature
diff --git a/pom.xml b/pom.xml
index ce21f8d..352769a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -116,7 +116,7 @@
-
+
diff --git a/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java b/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java
index 3bf6e6f..f4f36ce 100644
--- a/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java
+++ b/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java
@@ -323,7 +323,6 @@ public class VascAnnotationParser {
if (method.getName().equalsIgnoreCase("get"+property)==false) { //a bit durty
continue;
}
- //logger.finer("Found property: "+property);
VascModelReference mt = method.getAnnotation(VascModelReference.class);
if (mt!=null & (annotationType.equals(VascI18n.class) | annotationType.equals(VascField.class) | annotationType.equals(VascStyle.class) )) {
Class typeClass = mt.type();
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 d60649f..ac57e7c 100644
--- a/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java
+++ b/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java
@@ -26,6 +26,8 @@
package com.idcanet.vasc.backends.jpa;
+import java.lang.reflect.Method;
+
import javax.persistence.EntityManager;
import com.idcanet.vasc.core.AbstractVascBackend;
@@ -38,14 +40,20 @@ import com.idcanet.vasc.core.VascException;
*/
abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend {
+ protected boolean emTransaction = true;
+
abstract EntityManager getEntityManager();
public void persist(Object object) throws VascException {
EntityManager s = getEntityManager();
try {
- s.getTransaction().begin();
+ if (emTransaction) {
+ s.getTransaction().begin();
+ }
s.persist(object);
- s.getTransaction().commit();
+ if (emTransaction) {
+ s.getTransaction().commit();
+ }
} finally {
if (s!=null) {
//s.close();
@@ -53,12 +61,16 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
}
}
- public Object merge(Object object) throws VascException {
+ public Object merge(Object object) throws VascException {
EntityManager s = getEntityManager();
try {
- s.getTransaction().begin();
+ if (emTransaction) {
+ s.getTransaction().begin();
+ }
Object result = s.merge(object);
- s.getTransaction().commit();
+ if (emTransaction) {
+ s.getTransaction().commit();
+ }
return result;
} finally {
if (s!=null) {
@@ -70,10 +82,14 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
public void delete(Object object) throws VascException {
EntityManager s = getEntityManager();
try {
- s.getTransaction().begin();
+ if (emTransaction) {
+ s.getTransaction().begin();
+ }
Object newObject = s.merge(object);
s.remove(newObject);
- s.getTransaction().commit();
+ if (emTransaction) {
+ s.getTransaction().commit();
+ }
} finally {
if (s!=null) {
//s.close();
diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryFieldValue.java b/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryFieldValue.java
new file mode 100644
index 0000000..d63313c
--- /dev/null
+++ b/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryFieldValue.java
@@ -0,0 +1,67 @@
+/**
+ *
+ */
+package com.idcanet.vasc.backends.jpa;
+
+import com.idcanet.vasc.core.VascEntryField;
+import com.idcanet.vasc.core.VascException;
+import com.idcanet.vasc.core.entry.VascEntryFieldValue;
+import com.idcanet.x4o.impl.DefaultElementObjectPropertyValue;
+
+/**
+ * @author willemc
+ *
+ */
+public class BeanVascEntryFieldValue implements VascEntryFieldValue {
+
+ private static final long serialVersionUID = 1L;
+ private DefaultElementObjectPropertyValue bean = new DefaultElementObjectPropertyValue();
+
+ /**
+ * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
+ */
+ public Object getValue(VascEntryField field, Object record) throws VascException {
+ try {
+ Object o = bean.getProperty(record,field.getBackendName());
+ return o;
+ } catch (Exception e) {
+ throw new VascException(e);
+ }
+ }
+
+ /**
+ * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
+ */
+ public String getDisplayValue(VascEntryField field, Object record) throws VascException {
+ Object value = getValue(field,record);
+ if (value==null) {
+ return "";
+ }
+ if (field.getDisplayName()==null) {
+ if (value instanceof String) {
+ return (String)value;
+ }
+ return ""+value;
+ }
+ try {
+ Object result = bean.getProperty(value, field.getDisplayName());
+ if (result instanceof String) {
+ return (String)result;
+ }
+ return ""+result;
+ } catch (Exception e) {
+ throw new VascException(e);
+ }
+ }
+
+ /**
+ * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
+ */
+ public void setValue(VascEntryField field, Object record,Object value) throws VascException {
+ try {
+ bean.setProperty(record, field.getBackendName(), value);
+ } catch (Exception e) {
+ throw new VascException(e);
+ }
+ }
+}
diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryRecordCreator.java b/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryRecordCreator.java
new file mode 100644
index 0000000..f77e039
--- /dev/null
+++ b/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryRecordCreator.java
@@ -0,0 +1,29 @@
+/**
+ *
+ */
+package com.idcanet.vasc.backends.jpa;
+
+import com.idcanet.vasc.core.VascEntry;
+import com.idcanet.vasc.core.entry.VascEntryRecordCreator;
+
+/**
+ * @author willemc
+ *
+ */
+public class BeanVascEntryRecordCreator implements VascEntryRecordCreator {
+
+ private static final long serialVersionUID = 1L;
+ private Class> resultClass = null;
+
+ public BeanVascEntryRecordCreator(Class> resultClass) {
+ this.resultClass=resultClass;
+ }
+
+ public Class> getObjectClass() {
+ return resultClass;
+ }
+
+ public Object newRecord(VascEntry entry) throws Exception {
+ return resultClass.newInstance();
+ }
+}
diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java b/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java
index ccb5933..16b08b0 100644
--- a/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java
+++ b/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java
@@ -37,4 +37,6 @@ import javax.persistence.EntityManager;
public interface EntityManagerProvider {
public EntityManager getEntityManager();
+
+ public boolean hasEntityManagerTransaction();
}
\ No newline at end of file
diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java
index b3e48d7..ca6739f 100644
--- a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java
+++ b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java
@@ -38,8 +38,6 @@ import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.entry.VascEntryFieldValue;
import com.idcanet.vasc.core.entry.VascEntryRecordCreator;
-import com.idcanet.x4o.element.ElementParameterHelper;
-import com.idcanet.x4o.impl.DefaultElementParameterHelper;
import com.idcanet.xtes.xpql.query.QueryParameterValue;
/**
@@ -122,58 +120,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField)
*/
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
- VascEntryFieldValue result = new VascEntryFieldValue() {
-
- private ElementParameterHelper bean = new DefaultElementParameterHelper();
-
- /**
- * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
- */
- public Object getValue(VascEntryField field, Object record) throws VascException {
- try {
- Object o = bean.getParameter(record,field.getBackendName());
- return o;
- } catch (Exception e) {
- throw new VascException(e);
- }
- }
-
- /**
- * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
- */
- public String getDisplayValue(VascEntryField field, Object record) throws VascException {
- Object value = getValue(field,record);
- if (value==null) {
- return "";
- }
- if (field.getDisplayName()==null) {
- if (value instanceof String) {
- return (String)value;
- }
- return ""+value;
- }
- try {
- Object result = bean.getParameter(value, field.getDisplayName());
- if (result instanceof String) {
- return (String)result;
- }
- return ""+result;
- } catch (Exception e) {
- throw new VascException(e);
- }
- }
-
- /**
- * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
- */
- public void setValue(VascEntryField field, Object record,Object value) throws VascException {
- try {
- bean.setParameter(record, field.getBackendName(), value);
- } catch (Exception e) {
- throw new VascException(e);
- }
- }
- };
+ BeanVascEntryFieldValue result = new BeanVascEntryFieldValue();
return result;
}
@@ -181,16 +128,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry)
*/
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
- return new VascEntryRecordCreator() {
-
- public Class> getObjectClass() {
- return resultClass;
- }
-
- public Object newRecord(VascEntry entry) throws Exception {
- return resultClass.newInstance();
- }
- };
+ return new BeanVascEntryRecordCreator(resultClass);
}
/**
diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java
index 85fd43e..6937406 100644
--- a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java
+++ b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java
@@ -37,8 +37,6 @@ import com.idcanet.vasc.core.VascEntryField;
import com.idcanet.vasc.core.VascException;
import com.idcanet.vasc.core.entry.VascEntryFieldValue;
import com.idcanet.vasc.core.entry.VascEntryRecordCreator;
-import com.idcanet.x4o.element.ElementParameterHelper;
-import com.idcanet.x4o.impl.DefaultElementParameterHelper;
import com.idcanet.xtes.xpql.query.QueryParameterValue;
/**
@@ -73,6 +71,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
*/
@Override
EntityManager getEntityManager() {
+ emTransaction=entityManagerProvider.hasEntityManagerTransaction();
return entityManagerProvider.getEntityManager();
}
@@ -104,9 +103,13 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
q.setFirstResult(state.getPageIndex());
q.setMaxResults(state.getPageSize());
}
- em.getTransaction().begin();
+ if (emTransaction) {
+ em.getTransaction().begin();
+ }
List