From 0a2398c5c14d5f50dc902661585fe8a825d7864f Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Mon, 25 Aug 2014 22:30:06 +0200 Subject: [PATCH] droped dup hibernate only code. --- vasc-backend/vasc-backend-jpa/pom.xml | 6 - .../jpa/AbstractHibernateVascBackend.java | 98 ---- .../jpa/HibernateSessionProvider.java | 35 -- .../jpa/XpqlHibernateVascBackend.java | 435 ------------------ 4 files changed, 574 deletions(-) delete mode 100644 vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractHibernateVascBackend.java delete mode 100644 vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/HibernateSessionProvider.java delete mode 100644 vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java diff --git a/vasc-backend/vasc-backend-jpa/pom.xml b/vasc-backend/vasc-backend-jpa/pom.xml index 5a2efa9..ec46ef9 100644 --- a/vasc-backend/vasc-backend-jpa/pom.xml +++ b/vasc-backend/vasc-backend-jpa/pom.xml @@ -25,11 +25,5 @@ ${persistence-api.version} provided - - org.hibernate - hibernate-annotations - ${hibernate-annotations.version} - provided - diff --git a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractHibernateVascBackend.java b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractHibernateVascBackend.java deleted file mode 100644 index ce68b56..0000000 --- a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/AbstractHibernateVascBackend.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2007-2012 forwardfire.net All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided - * that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * 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 THE COPYRIGHT HOLDERS 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 - * THE COPYRIGHT HOLDER 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. - */ - -package net.forwardfire.vasc.backends.jpa; - -import java.io.Serializable; - -import net.forwardfire.vasc.backend.AbstractVascBackend; -import net.forwardfire.vasc.backend.VascBackendException; - -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(); - - @Override - public void persist(DATA_OBJECT object) throws VascBackendException { - 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(); - } - } - } - - @Override - public DATA_OBJECT merge(DATA_OBJECT object) throws VascBackendException { - Session s = getHibernateSession(); - try { - s.getTransaction().begin(); - DATA_OBJECT result = (DATA_OBJECT)s.merge(object); - s.getTransaction().commit(); - return result; - } finally { - if (s!=null && s.isOpen()) { - if (s.getTransaction().isActive()) { - s.getTransaction().rollback(); - } - //s.close(); - } - } - } - - @Override - public void delete(DATA_OBJECT object) throws VascBackendException { - 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(); - } - } - } -} \ No newline at end of file diff --git a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/HibernateSessionProvider.java b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/HibernateSessionProvider.java deleted file mode 100644 index 25dd174..0000000 --- a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/HibernateSessionProvider.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2007-2012 forwardfire.net All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided - * that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * 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 THE COPYRIGHT HOLDERS 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 - * THE COPYRIGHT HOLDER 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. - */ - -package net.forwardfire.vasc.backends.jpa; - -import org.hibernate.Session; - -/** - * - * @author Willem Cazander - * @version 1.0 Mar 21, 2009 - */ -public interface HibernateSessionProvider { - - Session getHibernateSession(); -} \ No newline at end of file diff --git a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java b/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java deleted file mode 100644 index c11610d..0000000 --- a/vasc-backend/vasc-backend-jpa/src/main/java/net/forwardfire/vasc/backends/jpa/XpqlHibernateVascBackend.java +++ /dev/null @@ -1,435 +0,0 @@ -/* - * Copyright 2007-2012 forwardfire.net All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided - * that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the - * following disclaimer. - * * 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 THE COPYRIGHT HOLDERS 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 - * THE COPYRIGHT HOLDER 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. - */ - -package net.forwardfire.vasc.backends.jpa; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.List; - -import net.forwardfire.vasc.backend.DefaultVascBackendResult; -import net.forwardfire.vasc.backend.VascBackendException; -import net.forwardfire.vasc.backend.VascBackendResult; -import net.forwardfire.vasc.backend.VascBackendState; -import net.forwardfire.vasc.backend.VascEntryFieldValue; -import net.forwardfire.vasc.backend.VascEntryRecordCreator; -import net.forwardfire.vasc.backend.data.BeanVascEntryFieldValue; -import net.forwardfire.vasc.backend.data.BeanVascEntryRecordCreator; -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(); - } - - @Override - public VascBackendResult execute(VascBackendState state) throws VascBackendException { - return new DefaultVascBackendResult(executeList(state),fetchTotalExecuteSize(state)); - } - - private List executeList(VascBackendState state) throws VascBackendException { - // 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 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() && state.getPageSize()>0) { - q.setFirstResult(state.getPageIndex()*state.getPageSize()); - q.setMaxResults(state.getPageSize()); - } - List data = q.list(); - s.getTransaction().commit(); - - return data; - } finally { - if (s!=null) { - //em.close(); - } - } - } - - /** - * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue() - */ - @Override - public VascEntryFieldValue provideVascEntryFieldValue() { - BeanVascEntryFieldValue result = new BeanVascEntryFieldValue(); - return result; - } - - /** - * @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator() - */ - @Override - public VascEntryRecordCreator provideVascEntryRecordCreator() { - 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.backend.AbstractVascBackend#isPageable() - */ - @Override - public boolean isPageable() { - if (queryTotal==null) { - return false; - } - return true; - } - - private long fetchTotalExecuteSize(VascBackendState state) { - Session s = getHibernateSession(); - try { - s.getTransaction().begin(); - Query q = s.createQuery(queryTotal.toPreparedSQL(queryTotal)); - List 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.backend.AbstractVascBackend#doRecordMoveDownById(java.lang.Object) - */ - @Override - public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascBackendException { - 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 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.backend.AbstractVascBackend#doRecordMoveUpById(java.lang.Object) - */ - @Override - public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascBackendException { - 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 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.backend.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; - } -} \ No newline at end of file