moved to sub projects
This commit is contained in:
parent
a523cc9122
commit
dff60035cf
182 changed files with 251 additions and 46 deletions
11
vasc-backends/vasc-backend-jpa/.classpath
Normal file
11
vasc-backends/vasc-backend-jpa/.classpath
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
29
vasc-backends/vasc-backend-jpa/.project
Normal file
29
vasc-backends/vasc-backend-jpa/.project
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>vasc-backend-jpa</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#Sun Dec 25 17:29:06 CET 2011
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding//src/test/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#Mon Aug 30 21:55:23 CEST 2010
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#Sun Dec 25 17:29:02 CET 2011
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#Mon Aug 30 21:55:22 CEST 2010
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
fullBuildGoals=process-test-resources
|
||||
includeModules=false
|
||||
resolveWorkspaceProjects=true
|
||||
resourceFilterGoals=process-resources resources\:testResources
|
||||
skipCompilerPlugin=true
|
||||
version=1
|
||||
32
vasc-backends/vasc-backend-jpa/pom.xml
Normal file
32
vasc-backends/vasc-backend-jpa/pom.xml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>vasc-backends</artifactId>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<version>0.3.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-backend-jpa</artifactId>
|
||||
<version>0.3.5-SNAPSHOT</version>
|
||||
<name>vasc-backend-jpa</name>
|
||||
<description>vasc-backend-jpa</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>persistence-api</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-annotations</artifactId>
|
||||
<version>3.4.0.GA</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.backends.jpa;
|
||||
|
||||
import net.forwardfire.vasc.core.AbstractVascBackend;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 21, 2007
|
||||
*/
|
||||
abstract public class AbstractHibernateVascBackend extends AbstractVascBackend {
|
||||
|
||||
/**
|
||||
* Provides a hibernate session which is closed !! when transaction is compleeted.
|
||||
* @return
|
||||
*/
|
||||
abstract Session getHibernateSession();
|
||||
|
||||
public void persist(Object object) throws VascException {
|
||||
Session s = getHibernateSession();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
s.persist(object);
|
||||
s.getTransaction().commit();
|
||||
} finally {
|
||||
if (s!=null && s.isOpen()) {
|
||||
if (s.getTransaction().isActive()) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
//s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object merge(Object object) throws VascException {
|
||||
Session s = getHibernateSession();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
Object result = s.merge(object);
|
||||
s.getTransaction().commit();
|
||||
return result;
|
||||
} finally {
|
||||
if (s!=null && s.isOpen()) {
|
||||
if (s.getTransaction().isActive()) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
//s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(Object object) throws VascException {
|
||||
Session s = getHibernateSession();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
Object newObject = s.merge(object);
|
||||
s.delete(newObject);
|
||||
s.getTransaction().commit();
|
||||
} finally {
|
||||
if (s!=null && s.isOpen()) {
|
||||
if (s.getTransaction().isActive()) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
//s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.backends.jpa;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import net.forwardfire.vasc.core.AbstractVascBackend;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 21, 2007
|
||||
*/
|
||||
abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend {
|
||||
|
||||
protected boolean emTransaction = true;
|
||||
|
||||
abstract EntityManager getEntityManager();
|
||||
|
||||
public void persist(Object object) throws VascException {
|
||||
EntityManager s = getEntityManager();
|
||||
try {
|
||||
if (emTransaction) {
|
||||
s.getTransaction().begin();
|
||||
}
|
||||
s.persist(object);
|
||||
if (emTransaction) {
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
} finally {
|
||||
if (s!=null) {
|
||||
//s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object merge(Object object) throws VascException {
|
||||
EntityManager s = getEntityManager();
|
||||
try {
|
||||
if (emTransaction) {
|
||||
s.getTransaction().begin();
|
||||
}
|
||||
Object result = s.merge(object);
|
||||
if (emTransaction) {
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
return result;
|
||||
} finally {
|
||||
if (s!=null) {
|
||||
//s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(Object object) throws VascException {
|
||||
EntityManager s = getEntityManager();
|
||||
try {
|
||||
if (emTransaction) {
|
||||
s.getTransaction().begin();
|
||||
}
|
||||
Object newObject = s.merge(object);
|
||||
s.remove(newObject);
|
||||
if (emTransaction) {
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
} finally {
|
||||
if (s!=null) {
|
||||
//s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.backends.jpa;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 21, 2009
|
||||
*/
|
||||
public interface EntityManagerProvider {
|
||||
|
||||
public EntityManager getEntityManager();
|
||||
|
||||
public boolean hasEntityManagerTransaction();
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.backends.jpa;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 21, 2009
|
||||
*/
|
||||
public interface HibernateSessionProvider {
|
||||
|
||||
public Session getHibernateSession();
|
||||
}
|
||||
|
|
@ -0,0 +1,434 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.backends.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.forwardfire.vasc.backends.BeanVascEntryFieldValue;
|
||||
import net.forwardfire.vasc.backends.BeanVascEntryRecordCreator;
|
||||
import net.forwardfire.vasc.core.VascBackendState;
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
|
||||
import net.forwardfire.vasc.xpql.query.QueryParameterValue;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
|
||||
|
||||
/**
|
||||
* Manages persistance with xpql queries
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 17, 2009
|
||||
*/
|
||||
public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
|
||||
|
||||
private HibernateSessionProvider hibernateSessionProvider = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query query = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query queryTotal = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query queryMoveUp = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query queryMoveUpDown = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query queryMoveDown = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query queryMoveDownUp = null;
|
||||
|
||||
private Class<?> resultClass = null;
|
||||
|
||||
public XpqlHibernateVascBackend() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.backends.jpa.AbstractPersistenceVascBackend#getEntityManager()
|
||||
*/
|
||||
@Override
|
||||
Session getHibernateSession() {
|
||||
return hibernateSessionProvider.getHibernateSession();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> execute(VascBackendState state) throws VascException {
|
||||
|
||||
// Copy parameters
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
query.setQueryParameter(key, value);
|
||||
if (queryTotal!=null) {
|
||||
queryTotal.setQueryParameter(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
Session s = getHibernateSession();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
Query q = s.createQuery(query.toPreparedSQL(query));
|
||||
List<QueryParameterValue> values = query.getOrderQueryParameterValues();
|
||||
int i = 0;
|
||||
for (QueryParameterValue value:values) {
|
||||
Object valueObject = value.getValue();
|
||||
if (valueObject!=null) {
|
||||
q.setParameter(i,valueObject);
|
||||
} else {
|
||||
q.setParameter(i,valueObject,Hibernate.INTEGER);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (isPageable()) {
|
||||
q.setFirstResult(state.getPageIndex());
|
||||
q.setMaxResults(state.getPageSize());
|
||||
}
|
||||
List<Object> data = q.list();
|
||||
s.getTransaction().commit();
|
||||
return data;
|
||||
} finally {
|
||||
if (s!=null) {
|
||||
//em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField)
|
||||
*/
|
||||
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
|
||||
BeanVascEntryFieldValue result = new BeanVascEntryFieldValue();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry)
|
||||
*/
|
||||
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
|
||||
return new BeanVascEntryRecordCreator(resultClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the query
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param query the query to set
|
||||
*/
|
||||
public void setQuery(net.forwardfire.vasc.xpql.query.Query query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryTotal
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQueryTotal() {
|
||||
return queryTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryTotal the queryTotal to set
|
||||
*/
|
||||
public void setQueryTotal(net.forwardfire.vasc.xpql.query.Query queryTotal) {
|
||||
this.queryTotal = queryTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resultClass
|
||||
*/
|
||||
public Class<?> getResultClass() {
|
||||
return resultClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resultClass the resultClass to set
|
||||
*/
|
||||
public void setResultClass(Class<?> resultClass) {
|
||||
this.resultClass = resultClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the hibernateSessionProvider
|
||||
*/
|
||||
public HibernateSessionProvider getHibernateSessionProvider() {
|
||||
return hibernateSessionProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param hibernateSessionProvider the hibernateSessionProvider to set
|
||||
*/
|
||||
public void setHibernateSessionProvider(HibernateSessionProvider hibernateSessionProvider) {
|
||||
this.hibernateSessionProvider = hibernateSessionProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.AbstractVascBackend#isPageable()
|
||||
*/
|
||||
@Override
|
||||
public boolean isPageable() {
|
||||
if (queryTotal==null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state)
|
||||
*/
|
||||
public long fetchTotalExecuteSize(VascBackendState state) {
|
||||
Session s = getHibernateSession();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
Query q = s.createQuery(queryTotal.toPreparedSQL(queryTotal));
|
||||
List<QueryParameterValue> values = queryTotal.getOrderQueryParameterValues();
|
||||
int i = 0;
|
||||
for (QueryParameterValue value:values) {
|
||||
Object valueObject = value.getValue();
|
||||
if (valueObject!=null) {
|
||||
q.setParameter(i,valueObject);
|
||||
} else {
|
||||
q.setParameter(i,valueObject,Hibernate.INTEGER);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
Long resultTotal = (Long)q.uniqueResult();
|
||||
s.getTransaction().commit();
|
||||
return resultTotal;
|
||||
} finally {
|
||||
if (s!=null) {
|
||||
//em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.AbstractVascBackend#doRecordMoveDownById(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException {
|
||||
long result = 0l;
|
||||
if (queryMoveDown!=null) {
|
||||
Session s = getHibernateSession();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
|
||||
// Copy parameters
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
queryMoveDown.setQueryParameter(key, value);
|
||||
}
|
||||
|
||||
// set id
|
||||
queryMoveDown.setQueryParameter("id", primaryId);
|
||||
|
||||
// execute update
|
||||
Query q = s.createQuery(queryMoveDown.toPreparedSQL(queryMoveDown));
|
||||
List<QueryParameterValue> values = queryMoveDown.getOrderQueryParameterValues();
|
||||
int i = 0;
|
||||
for (QueryParameterValue value:values) {
|
||||
Object valueObject = value.getValue();
|
||||
if (valueObject!=null) {
|
||||
q.setParameter(i,valueObject);
|
||||
} else {
|
||||
q.setParameter(i,valueObject,Hibernate.INTEGER);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
result+=q.executeUpdate();
|
||||
|
||||
// Copy parameters
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
queryMoveDownUp.setQueryParameter(key, value);
|
||||
}
|
||||
|
||||
// set id
|
||||
queryMoveDownUp.setQueryParameter("id", primaryId);
|
||||
|
||||
// execute update
|
||||
q = s.createQuery(queryMoveDownUp.toPreparedSQL(queryMoveDownUp));
|
||||
values = queryMoveDownUp.getOrderQueryParameterValues();
|
||||
i = 0;
|
||||
for (QueryParameterValue value:values) {
|
||||
Object valueObject = value.getValue();
|
||||
if (valueObject!=null) {
|
||||
q.setParameter(i,valueObject);
|
||||
} else {
|
||||
q.setParameter(i,valueObject,Hibernate.INTEGER);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
result+=q.executeUpdate();
|
||||
|
||||
s.getTransaction().commit();
|
||||
} finally {
|
||||
if (s!=null) {
|
||||
//em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.AbstractVascBackend#doRecordMoveUpById(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException {
|
||||
long result = 0l;
|
||||
if (queryMoveUp!=null) {
|
||||
Session s = getHibernateSession();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
|
||||
// Copy parameters
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
queryMoveUp.setQueryParameter(key, value);
|
||||
}
|
||||
|
||||
// set id
|
||||
queryMoveUp.setQueryParameter("id", primaryId);
|
||||
|
||||
// execute update
|
||||
Query q = s.createQuery(queryMoveUp.toPreparedSQL(queryMoveUp));
|
||||
List<QueryParameterValue> values = queryMoveUp.getOrderQueryParameterValues();
|
||||
int i = 0;
|
||||
for (QueryParameterValue value:values) {
|
||||
Object valueObject = value.getValue();
|
||||
if (valueObject!=null) {
|
||||
q.setParameter(i,valueObject);
|
||||
} else {
|
||||
q.setParameter(i,valueObject,Hibernate.INTEGER);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
result+=q.executeUpdate();
|
||||
|
||||
// Copy parameters
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
queryMoveUpDown.setQueryParameter(key, value);
|
||||
}
|
||||
|
||||
// set id
|
||||
queryMoveUpDown.setQueryParameter("id", primaryId);
|
||||
|
||||
// execute update
|
||||
q = s.createQuery(queryMoveUpDown.toPreparedSQL(queryMoveUpDown));
|
||||
values = queryMoveUpDown.getOrderQueryParameterValues();
|
||||
i = 0;
|
||||
for (QueryParameterValue value:values) {
|
||||
Object valueObject = value.getValue();
|
||||
if (valueObject!=null) {
|
||||
q.setParameter(i,valueObject);
|
||||
} else {
|
||||
q.setParameter(i,valueObject,Hibernate.INTEGER);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
result+=q.executeUpdate();
|
||||
|
||||
s.getTransaction().commit();
|
||||
} finally {
|
||||
if (s!=null) {
|
||||
//em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.AbstractVascBackend#isRecordMoveable()
|
||||
*/
|
||||
@Override
|
||||
public boolean isRecordMoveable() {
|
||||
return queryMoveUp!=null & queryMoveDown!=null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveUp
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQueryMoveUp() {
|
||||
return queryMoveUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveUp the queryMoveUp to set
|
||||
*/
|
||||
public void setQueryMoveUp(net.forwardfire.vasc.xpql.query.Query queryMoveUp) {
|
||||
this.queryMoveUp = queryMoveUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveDown
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQueryMoveDown() {
|
||||
return queryMoveDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveDown the queryMoveDown to set
|
||||
*/
|
||||
public void setQueryMoveDown(net.forwardfire.vasc.xpql.query.Query queryMoveDown) {
|
||||
this.queryMoveDown = queryMoveDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveUpDown
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQueryMoveUpDown() {
|
||||
return queryMoveUpDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveUpDown the queryMoveUpDown to set
|
||||
*/
|
||||
public void setQueryMoveUpDown(net.forwardfire.vasc.xpql.query.Query queryMoveUpDown) {
|
||||
this.queryMoveUpDown = queryMoveUpDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveDownUp
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQueryMoveDownUp() {
|
||||
return queryMoveDownUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveDownUp the queryMoveDownUp to set
|
||||
*/
|
||||
public void setQueryMoveDownUp(net.forwardfire.vasc.xpql.query.Query queryMoveDownUp) {
|
||||
this.queryMoveDownUp = queryMoveDownUp;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,439 @@
|
|||
/*
|
||||
* 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 net.forwardfire.vasc.backends.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import net.forwardfire.vasc.backends.BeanVascEntryFieldValue;
|
||||
import net.forwardfire.vasc.backends.BeanVascEntryRecordCreator;
|
||||
import net.forwardfire.vasc.core.VascBackendState;
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
|
||||
import net.forwardfire.vasc.xpql.query.QueryParameterValue;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Manages persistance with xpql queries
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 17, 2009
|
||||
*/
|
||||
public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend {
|
||||
|
||||
private EntityManagerProvider entityManagerProvider = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query query = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query queryTotal = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query queryMoveUp = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query queryMoveUpDown = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query queryMoveDown = null;
|
||||
|
||||
private net.forwardfire.vasc.xpql.query.Query queryMoveDownUp = null;
|
||||
|
||||
private Class<?> resultClass = null;
|
||||
|
||||
public XpqlPersistanceVascBackend() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.backends.jpa.AbstractPersistenceVascBackend#getEntityManager()
|
||||
*/
|
||||
@Override
|
||||
EntityManager getEntityManager() {
|
||||
emTransaction=entityManagerProvider.hasEntityManagerTransaction();
|
||||
return entityManagerProvider.getEntityManager();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> execute(VascBackendState state) throws VascException {
|
||||
|
||||
// Copy parameters
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
//System.out.println("Set para pame: "+key+" value: "+value);
|
||||
query.setQueryParameter(key, value);
|
||||
if (queryTotal!=null) {
|
||||
queryTotal.setQueryParameter(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
EntityManager em = getEntityManager();
|
||||
try {
|
||||
Query q = em.createQuery(query.toPreparedSQL(query));
|
||||
List<QueryParameterValue> values = query.getOrderQueryParameterValues();
|
||||
int i = 1;
|
||||
for (QueryParameterValue value:values) {
|
||||
Object valueObject = value.getValue();
|
||||
q.setParameter(i,valueObject);
|
||||
//System.out.println("Set para index: "+i+" value: "+valueObject+" valueClass: "+valueObject.getClass()+" valueType: "+value.getValueType());
|
||||
i++;
|
||||
}
|
||||
if (isPageable()) {
|
||||
q.setFirstResult(state.getPageIndex());
|
||||
q.setMaxResults(state.getPageSize());
|
||||
}
|
||||
if (emTransaction) {
|
||||
em.getTransaction().begin();
|
||||
}
|
||||
List<Object> data = q.getResultList();
|
||||
if (emTransaction) {
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
return data;
|
||||
} finally {
|
||||
if (em!=null) {
|
||||
//em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField)
|
||||
*/
|
||||
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
|
||||
VascEntryFieldValue result = new BeanVascEntryFieldValue();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry)
|
||||
*/
|
||||
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
|
||||
VascEntryRecordCreator result = new BeanVascEntryRecordCreator(resultClass);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the query
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param query the query to set
|
||||
*/
|
||||
public void setQuery(net.forwardfire.vasc.xpql.query.Query query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryTotal
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQueryTotal() {
|
||||
return queryTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryTotal the queryTotal to set
|
||||
*/
|
||||
public void setQueryTotal(net.forwardfire.vasc.xpql.query.Query queryTotal) {
|
||||
this.queryTotal = queryTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resultClass
|
||||
*/
|
||||
public Class<?> getResultClass() {
|
||||
return resultClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resultClass the resultClass to set
|
||||
*/
|
||||
public void setResultClass(Class<?> resultClass) {
|
||||
this.resultClass = resultClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the entityManagerProvider
|
||||
*/
|
||||
public EntityManagerProvider getEntityManagerProvider() {
|
||||
return entityManagerProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entityManagerProvider the entityManagerProvider to set
|
||||
*/
|
||||
public void setEntityManagerProvider(EntityManagerProvider entityManagerProvider) {
|
||||
this.entityManagerProvider = entityManagerProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.AbstractVascBackend#isPageable()
|
||||
*/
|
||||
@Override
|
||||
public boolean isPageable() {
|
||||
if (queryTotal==null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state)
|
||||
*/
|
||||
public long fetchTotalExecuteSize(VascBackendState state) {
|
||||
EntityManager em = getEntityManager();
|
||||
try {
|
||||
Query q = em.createQuery(queryTotal.toPreparedSQL(queryTotal));
|
||||
List<QueryParameterValue> values = queryTotal.getOrderQueryParameterValues();
|
||||
int i = 1;
|
||||
for (QueryParameterValue value:values) {
|
||||
q.setParameter(i,value.getValue());
|
||||
i++;
|
||||
}
|
||||
if (emTransaction) {
|
||||
em.getTransaction().begin();
|
||||
}
|
||||
Long resultTotal = (Long)q.getSingleResult();
|
||||
if (emTransaction) {
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
return resultTotal;
|
||||
} finally {
|
||||
if (em!=null) {
|
||||
//em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.AbstractVascBackend#doRecordMoveDownById(VascBackendState state,java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException {
|
||||
long result = 0l;
|
||||
if (queryMoveDown!=null) {
|
||||
EntityManager em = getEntityManager();
|
||||
try {
|
||||
if (emTransaction) {
|
||||
em.getTransaction().begin();
|
||||
}
|
||||
|
||||
// Copy parameters
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
queryMoveDown.setQueryParameter(key, value);
|
||||
}
|
||||
|
||||
// set id
|
||||
queryMoveDown.setQueryParameter("id", primaryId);
|
||||
|
||||
// execute update
|
||||
Query q = em.createQuery(queryMoveDown.toPreparedSQL(queryMoveDown));
|
||||
List<QueryParameterValue> values = queryMoveDown.getOrderQueryParameterValues();
|
||||
int i = 1;
|
||||
for (QueryParameterValue value:values) {
|
||||
q.setParameter(i,value.getValue());
|
||||
i++;
|
||||
}
|
||||
result+=q.executeUpdate();
|
||||
|
||||
// Copy parameters
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
queryMoveDownUp.setQueryParameter(key, value);
|
||||
}
|
||||
|
||||
// set id
|
||||
queryMoveDownUp.setQueryParameter("id", primaryId);
|
||||
|
||||
// execute update
|
||||
q = em.createQuery(queryMoveDownUp.toPreparedSQL(queryMoveDownUp));
|
||||
values = queryMoveDownUp.getOrderQueryParameterValues();
|
||||
i = 1;
|
||||
for (QueryParameterValue value:values) {
|
||||
q.setParameter(i,value.getValue());
|
||||
i++;
|
||||
}
|
||||
result+=q.executeUpdate();
|
||||
|
||||
if (emTransaction) {
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
} finally {
|
||||
if (em!=null) {
|
||||
//em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.AbstractVascBackend#doRecordMoveUpById(VascBackendState state,java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException {
|
||||
long result = 0l;
|
||||
if (queryMoveUp!=null) {
|
||||
EntityManager em = getEntityManager();
|
||||
try {
|
||||
if (emTransaction) {
|
||||
em.getTransaction().begin();
|
||||
}
|
||||
|
||||
// Copy parameters
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
queryMoveUp.setQueryParameter(key, value);
|
||||
}
|
||||
|
||||
// set id
|
||||
queryMoveUp.setQueryParameter("id", primaryId);
|
||||
|
||||
// execute update
|
||||
Query q = em.createQuery(queryMoveUp.toPreparedSQL(queryMoveUp));
|
||||
List<QueryParameterValue> values = queryMoveUp.getOrderQueryParameterValues();
|
||||
int i = 1;
|
||||
for (QueryParameterValue value:values) {
|
||||
q.setParameter(i,value.getValue());
|
||||
i++;
|
||||
}
|
||||
result+=q.executeUpdate();
|
||||
|
||||
// Copy parameters
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
queryMoveUpDown.setQueryParameter(key, value);
|
||||
}
|
||||
|
||||
// set id
|
||||
queryMoveUpDown.setQueryParameter("id", primaryId);
|
||||
|
||||
// execute update
|
||||
q = em.createQuery(queryMoveUpDown.toPreparedSQL(queryMoveUpDown));
|
||||
values = queryMoveUpDown.getOrderQueryParameterValues();
|
||||
i = 1;
|
||||
for (QueryParameterValue value:values) {
|
||||
q.setParameter(i,value.getValue());
|
||||
i++;
|
||||
}
|
||||
result+=q.executeUpdate();
|
||||
|
||||
if (emTransaction) {
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
} finally {
|
||||
if (em!=null) {
|
||||
//em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.AbstractVascBackend#isRecordMoveable()
|
||||
*/
|
||||
@Override
|
||||
public boolean isRecordMoveable() {
|
||||
return queryMoveUp!=null & queryMoveDown!=null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveUp
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQueryMoveUp() {
|
||||
return queryMoveUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveUp the queryMoveUp to set
|
||||
*/
|
||||
public void setQueryMoveUp(net.forwardfire.vasc.xpql.query.Query queryMoveUp) {
|
||||
this.queryMoveUp = queryMoveUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveDown
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQueryMoveDown() {
|
||||
return queryMoveDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveDown the queryMoveDown to set
|
||||
*/
|
||||
public void setQueryMoveDown(net.forwardfire.vasc.xpql.query.Query queryMoveDown) {
|
||||
this.queryMoveDown = queryMoveDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveUpDown
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQueryMoveUpDown() {
|
||||
return queryMoveUpDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveUpDown the queryMoveUpDown to set
|
||||
*/
|
||||
public void setQueryMoveUpDown(net.forwardfire.vasc.xpql.query.Query queryMoveUpDown) {
|
||||
this.queryMoveUpDown = queryMoveUpDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveDownUp
|
||||
*/
|
||||
public net.forwardfire.vasc.xpql.query.Query getQueryMoveDownUp() {
|
||||
return queryMoveDownUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveDownUp the queryMoveDownUp to set
|
||||
*/
|
||||
public void setQueryMoveDownUp(net.forwardfire.vasc.xpql.query.Query queryMoveDownUp) {
|
||||
this.queryMoveDownUp = queryMoveDownUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.VascBackend#isSearchable()
|
||||
*/
|
||||
public boolean isSearchable() {
|
||||
if (query.getQueryParameterValue("text_search")==null) {
|
||||
return false;
|
||||
}
|
||||
//return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
0
vasc-backends/vasc-backend-jpa/src/main/resources/.empty
Normal file
0
vasc-backends/vasc-backend-jpa/src/main/resources/.empty
Normal file
0
vasc-backends/vasc-backend-jpa/src/test/java/.empty
Normal file
0
vasc-backends/vasc-backend-jpa/src/test/java/.empty
Normal file
0
vasc-backends/vasc-backend-jpa/src/test/resources/.empty
Normal file
0
vasc-backends/vasc-backend-jpa/src/test/resources/.empty
Normal file
Loading…
Add table
Add a link
Reference in a new issue