[svn r382] hacked jsf frontend working
This commit is contained in:
parent
37fdf22282
commit
9a605f177a
123 changed files with 7035 additions and 2418 deletions
|
|
@ -35,6 +35,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import com.idcanet.vasc.core.AbstractVascBackend;
|
||||
import com.idcanet.vasc.core.VascBackendState;
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
|
|
@ -70,13 +71,14 @@ public class JdbcVascBackend extends AbstractVascBackend {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#execute()
|
||||
* @see com.idcanet.vasc.core.VascBackend#execute(VascBackendState state)
|
||||
*/
|
||||
public List<Object> execute() throws Exception {
|
||||
public List<Object> execute(VascBackendState state) throws VascException {
|
||||
JdbcConnectionProvider prov = getJdbcConnectionProvider();
|
||||
Connection connection = prov.getJdbcConnection();
|
||||
List<Object> result = new ArrayList<Object>(50);
|
||||
List<Object> result = new ArrayList<Object>(50);
|
||||
Connection connection = null;
|
||||
try {
|
||||
connection = prov.getJdbcConnection();
|
||||
Statement s = connection.createStatement();
|
||||
s.execute(getSqlList());
|
||||
ResultSet rs = s.getResultSet();
|
||||
|
|
@ -90,9 +92,14 @@ public class JdbcVascBackend extends AbstractVascBackend {
|
|||
}
|
||||
result.add(map);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new VascException(e);
|
||||
} finally {
|
||||
if (connection!=null) {
|
||||
connection.close();
|
||||
try {
|
||||
connection.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
@ -101,20 +108,20 @@ public class JdbcVascBackend extends AbstractVascBackend {
|
|||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#merge(java.lang.Object)
|
||||
*/
|
||||
public Object merge(Object object) throws Exception {
|
||||
public Object merge(Object object) throws VascException {
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#persist(java.lang.Object)
|
||||
*/
|
||||
public void persist(Object object) throws Exception {
|
||||
public void persist(Object object) throws VascException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#delete(java.lang.Object)
|
||||
*/
|
||||
public void delete(Object object) throws Exception {
|
||||
public void delete(Object object) throws VascException {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -132,6 +139,13 @@ public class JdbcVascBackend extends AbstractVascBackend {
|
|||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
return ""+getValue(field,record); // not supported
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import com.idcanet.vasc.core.AbstractVascBackend;
|
||||
import com.idcanet.vasc.core.VascBackendState;
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
|
|
@ -82,16 +83,17 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#execute()
|
||||
* @see com.idcanet.vasc.core.VascBackend#execute(VascBackendState state)
|
||||
*/
|
||||
public List<Object> execute() throws Exception {
|
||||
public List<Object> execute(VascBackendState state) throws VascException {
|
||||
// Copy parameters
|
||||
for (String key:getDataParameterKeys()) {
|
||||
Object value = getDataParameter(key);
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
query.setQueryParameter(key, value);
|
||||
}
|
||||
Connection c = getJdbcConnectionProvider().getJdbcConnection();
|
||||
Connection c = null;
|
||||
try {
|
||||
c = getJdbcConnectionProvider().getJdbcConnection();;
|
||||
PreparedStatement q = c.prepareStatement(query.toPreparedSQL(query));
|
||||
|
||||
List<QueryParameterValue> values = query.getOrderQueryParameterValues();
|
||||
|
|
@ -114,9 +116,14 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend {
|
|||
result.add(map);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new VascException(e);
|
||||
} finally {
|
||||
if (c!=null) {
|
||||
c.close();
|
||||
try {
|
||||
c.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -124,20 +131,20 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend {
|
|||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#merge(java.lang.Object)
|
||||
*/
|
||||
public Object merge(Object object) throws Exception {
|
||||
public Object merge(Object object) throws VascException {
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#persist(java.lang.Object)
|
||||
*/
|
||||
public void persist(Object object) throws Exception {
|
||||
public void persist(Object object) throws VascException {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#delete(java.lang.Object)
|
||||
*/
|
||||
public void delete(Object object) throws Exception {
|
||||
public void delete(Object object) throws VascException {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -155,6 +162,13 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend {
|
|||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
return ""+getValue(field,record); // not supported
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ package com.idcanet.vasc.backends.jpa;
|
|||
import org.hibernate.Session;
|
||||
|
||||
import com.idcanet.vasc.core.AbstractVascBackend;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -43,36 +44,52 @@ abstract public class AbstractHibernateVascBackend extends AbstractVascBackend
|
|||
*/
|
||||
abstract Session getHibernateSession();
|
||||
|
||||
public void persist(Object object) throws Exception {
|
||||
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.close();
|
||||
if (s!=null && s.isOpen()) {
|
||||
if (s.getTransaction().isActive()) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
//s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object merge(Object object) throws Exception {
|
||||
public Object merge(Object object) throws VascException {
|
||||
Session s = getHibernateSession();
|
||||
try {
|
||||
return s.merge(object);
|
||||
s.getTransaction().begin();
|
||||
Object result = s.merge(object);
|
||||
s.getTransaction().commit();
|
||||
return result;
|
||||
} finally {
|
||||
if (s!=null) {
|
||||
s.close();
|
||||
if (s!=null && s.isOpen()) {
|
||||
if (s.getTransaction().isActive()) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
//s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(Object object) throws Exception {
|
||||
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.close();
|
||||
if (s!=null && s.isOpen()) {
|
||||
if (s.getTransaction().isActive()) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
//s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ package com.idcanet.vasc.backends.jpa;
|
|||
import javax.persistence.EntityManager;
|
||||
|
||||
import com.idcanet.vasc.core.AbstractVascBackend;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -39,7 +40,7 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
|
|||
|
||||
abstract EntityManager getEntityManager();
|
||||
|
||||
public void persist(Object object) throws Exception {
|
||||
public void persist(Object object) throws VascException {
|
||||
EntityManager s = getEntityManager();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
|
|
@ -52,7 +53,7 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
|
|||
}
|
||||
}
|
||||
|
||||
public Object merge(Object object) throws Exception {
|
||||
public Object merge(Object object) throws VascException {
|
||||
EntityManager s = getEntityManager();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
|
|
@ -66,7 +67,7 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
|
|||
}
|
||||
}
|
||||
|
||||
public void delete(Object object) throws Exception {
|
||||
public void delete(Object object) throws VascException {
|
||||
EntityManager s = getEntityManager();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
|
|
|
|||
|
|
@ -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 com.idcanet.vasc.backends.jpa;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 21, 2009
|
||||
*/
|
||||
public interface HibernateSessionProvider {
|
||||
|
||||
public Session getHibernateSession();
|
||||
}
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* 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.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
|
||||
import com.idcanet.serv5.services.hibernate3.Hibernate3Factory;
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.entry.VascEntryFieldValue;
|
||||
import com.idcanet.vasc.core.entry.VascEntryRecordCreator;
|
||||
import com.idcanet.xtes.xpql.query.QueryParameterValue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 21, 2007
|
||||
*/
|
||||
public class Serv5XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
|
||||
|
||||
private String session = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query query = null;
|
||||
|
||||
public Serv5XpqlHibernateVascBackend() {
|
||||
|
||||
}
|
||||
public Serv5XpqlHibernateVascBackend(String session,com.idcanet.xtes.xpql.query.Query query) {
|
||||
setSession(session);
|
||||
setQuery(query);
|
||||
}
|
||||
|
||||
Session getHibernateSession() {
|
||||
return Hibernate3Factory.getSession(getSession());
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> execute() throws Exception {
|
||||
// Copy parameters
|
||||
for (String key:getDataParameterKeys()) {
|
||||
Object value = getDataParameter(key);
|
||||
query.setQueryParameter(key, value);
|
||||
}
|
||||
Session s = getHibernateSession();
|
||||
try {
|
||||
Query q = s.createQuery(query.toPreparedSQL(query));
|
||||
List<QueryParameterValue> values = query.getOrderQueryParameterValues();
|
||||
int i = 1;
|
||||
for (QueryParameterValue value:values) {
|
||||
q.setParameter(i,value.getValue());
|
||||
i++;
|
||||
}
|
||||
List<Object> data = q.list();
|
||||
return data;
|
||||
} finally {
|
||||
if (s!=null) {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the session
|
||||
*/
|
||||
public String getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param session the session to set
|
||||
*/
|
||||
public void setSession(String session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the query
|
||||
*/
|
||||
public com.idcanet.xtes.xpql.query.Query getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param query the query to set
|
||||
*/
|
||||
public void setQuery(com.idcanet.xtes.xpql.query.Query query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
|
||||
return null;
|
||||
}
|
||||
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,493 @@
|
|||
/*
|
||||
* 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.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
|
||||
import com.idcanet.vasc.core.VascBackendState;
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Manages persistance with xpql queries
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Mar 17, 2009
|
||||
*/
|
||||
public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
|
||||
|
||||
private HibernateSessionProvider hibernateSessionProvider = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query query = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query queryTotal = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query queryMoveUp = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query queryMoveUpDown = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query queryMoveDown = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query queryMoveDownUp = null;
|
||||
|
||||
private Class<?> resultClass = null;
|
||||
|
||||
public XpqlHibernateVascBackend() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.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() & state.getPageSize()>0) {
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 the query
|
||||
*/
|
||||
public com.idcanet.xtes.xpql.query.Query getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param query the query to set
|
||||
*/
|
||||
public void setQuery(com.idcanet.xtes.xpql.query.Query query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryTotal
|
||||
*/
|
||||
public com.idcanet.xtes.xpql.query.Query getQueryTotal() {
|
||||
return queryTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryTotal the queryTotal to set
|
||||
*/
|
||||
public void setQueryTotal(com.idcanet.xtes.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 com.idcanet.vasc.core.AbstractVascBackend#isPageable()
|
||||
*/
|
||||
@Override
|
||||
public boolean isPageable() {
|
||||
if (queryTotal==null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.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 com.idcanet.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 com.idcanet.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 com.idcanet.vasc.core.AbstractVascBackend#isRecordMoveable()
|
||||
*/
|
||||
@Override
|
||||
public boolean isRecordMoveable() {
|
||||
return queryMoveUp!=null & queryMoveDown!=null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveUp
|
||||
*/
|
||||
public com.idcanet.xtes.xpql.query.Query getQueryMoveUp() {
|
||||
return queryMoveUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveUp the queryMoveUp to set
|
||||
*/
|
||||
public void setQueryMoveUp(com.idcanet.xtes.xpql.query.Query queryMoveUp) {
|
||||
this.queryMoveUp = queryMoveUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveDown
|
||||
*/
|
||||
public com.idcanet.xtes.xpql.query.Query getQueryMoveDown() {
|
||||
return queryMoveDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveDown the queryMoveDown to set
|
||||
*/
|
||||
public void setQueryMoveDown(com.idcanet.xtes.xpql.query.Query queryMoveDown) {
|
||||
this.queryMoveDown = queryMoveDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveUpDown
|
||||
*/
|
||||
public com.idcanet.xtes.xpql.query.Query getQueryMoveUpDown() {
|
||||
return queryMoveUpDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveUpDown the queryMoveUpDown to set
|
||||
*/
|
||||
public void setQueryMoveUpDown(com.idcanet.xtes.xpql.query.Query queryMoveUpDown) {
|
||||
this.queryMoveUpDown = queryMoveUpDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveDownUp
|
||||
*/
|
||||
public com.idcanet.xtes.xpql.query.Query getQueryMoveDownUp() {
|
||||
return queryMoveDownUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveDownUp the queryMoveDownUp to set
|
||||
*/
|
||||
public void setQueryMoveDownUp(com.idcanet.xtes.xpql.query.Query queryMoveDownUp) {
|
||||
this.queryMoveDownUp = queryMoveDownUp;
|
||||
}
|
||||
}
|
||||
|
|
@ -31,6 +31,7 @@ import java.util.List;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import com.idcanet.vasc.core.VascBackendState;
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
|
|
@ -47,13 +48,21 @@ import com.idcanet.xtes.xpql.query.QueryParameterValue;
|
|||
* @version 1.0 Mar 17, 2009
|
||||
*/
|
||||
public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend {
|
||||
|
||||
|
||||
private EntityManagerProvider entityManagerProvider = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query query = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query queryTotal = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query queryMoveUp = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query queryMoveUpDown = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query queryMoveDown = null;
|
||||
|
||||
private com.idcanet.xtes.xpql.query.Query queryMoveDownUp = null;
|
||||
|
||||
private Class<?> resultClass = null;
|
||||
|
||||
public XpqlPersistanceVascBackend() {
|
||||
|
|
@ -70,51 +79,34 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
|
|||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> execute() throws Exception {
|
||||
public List<Object> execute(VascBackendState state) throws VascException {
|
||||
|
||||
// Copy parameters
|
||||
for (String key:getDataParameterKeys()) {
|
||||
Object value = getDataParameter(key);
|
||||
for (String key:state.getDataParameterKeys()) {
|
||||
Object value = state.getDataParameter(key);
|
||||
query.setQueryParameter(key, value);
|
||||
if (queryTotal!=null) {
|
||||
queryTotal.setQueryParameter(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
//if (isPageable()) {
|
||||
//query.setQueryParameter("offset", getPageIndex());
|
||||
//query.setQueryParameter("limit", getPageSize());
|
||||
//}
|
||||
|
||||
EntityManager em = getEntityManager();
|
||||
try {
|
||||
if (queryTotal!=null) {
|
||||
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++;
|
||||
}
|
||||
Long resultTotal = (Long)q.getSingleResult();
|
||||
setPagesTotalRecords(resultTotal);
|
||||
}
|
||||
|
||||
Query q = em.createQuery(query.toPreparedSQL(query));
|
||||
List<QueryParameterValue> values = query.getOrderQueryParameterValues();
|
||||
int i = 1;
|
||||
for (QueryParameterValue value:values) {
|
||||
q.setParameter(i,value.getValue());
|
||||
Object valueObject = value.getValue();
|
||||
q.setParameter(i,valueObject);
|
||||
i++;
|
||||
}
|
||||
if (isPageable()) {
|
||||
q.setFirstResult(getPageIndex());
|
||||
q.setMaxResults(getPageSize());
|
||||
if (isPageable() & state.getPageSize()>0) {
|
||||
q.setFirstResult(state.getPageIndex());
|
||||
q.setMaxResults(state.getPageSize());
|
||||
}
|
||||
em.getTransaction().begin();
|
||||
List<Object> data = q.getResultList();
|
||||
if (queryTotal==null) {
|
||||
setPagesTotalRecords(data.size());
|
||||
}
|
||||
em.getTransaction().commit();
|
||||
return data;
|
||||
} finally {
|
||||
if (em!=null) {
|
||||
|
|
@ -143,6 +135,31 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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)
|
||||
*/
|
||||
|
|
@ -237,14 +254,213 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
|
|||
if (queryTotal==null) {
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
if (query.getQueryParameterValue("offset")==null) {
|
||||
return false;
|
||||
}
|
||||
if (query.getQueryParameterValue("limit")==null) {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.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++;
|
||||
}
|
||||
em.getTransaction().begin();
|
||||
Long resultTotal = (Long)q.getSingleResult();
|
||||
em.getTransaction().commit();
|
||||
return resultTotal;
|
||||
} finally {
|
||||
if (em!=null) {
|
||||
//em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see com.idcanet.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 {
|
||||
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();
|
||||
|
||||
em.getTransaction().commit();
|
||||
} finally {
|
||||
if (em!=null) {
|
||||
//em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.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 {
|
||||
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();
|
||||
|
||||
em.getTransaction().commit();
|
||||
} finally {
|
||||
if (em!=null) {
|
||||
//em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.AbstractVascBackend#isRecordMoveable()
|
||||
*/
|
||||
@Override
|
||||
public boolean isRecordMoveable() {
|
||||
return queryMoveUp!=null & queryMoveDown!=null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveUp
|
||||
*/
|
||||
public com.idcanet.xtes.xpql.query.Query getQueryMoveUp() {
|
||||
return queryMoveUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveUp the queryMoveUp to set
|
||||
*/
|
||||
public void setQueryMoveUp(com.idcanet.xtes.xpql.query.Query queryMoveUp) {
|
||||
this.queryMoveUp = queryMoveUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveDown
|
||||
*/
|
||||
public com.idcanet.xtes.xpql.query.Query getQueryMoveDown() {
|
||||
return queryMoveDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveDown the queryMoveDown to set
|
||||
*/
|
||||
public void setQueryMoveDown(com.idcanet.xtes.xpql.query.Query queryMoveDown) {
|
||||
this.queryMoveDown = queryMoveDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveUpDown
|
||||
*/
|
||||
public com.idcanet.xtes.xpql.query.Query getQueryMoveUpDown() {
|
||||
return queryMoveUpDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveUpDown the queryMoveUpDown to set
|
||||
*/
|
||||
public void setQueryMoveUpDown(com.idcanet.xtes.xpql.query.Query queryMoveUpDown) {
|
||||
this.queryMoveUpDown = queryMoveUpDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryMoveDownUp
|
||||
*/
|
||||
public com.idcanet.xtes.xpql.query.Query getQueryMoveDownUp() {
|
||||
return queryMoveDownUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryMoveDownUp the queryMoveDownUp to set
|
||||
*/
|
||||
public void setQueryMoveDownUp(com.idcanet.xtes.xpql.query.Query queryMoveDownUp) {
|
||||
this.queryMoveDownUp = queryMoveDownUp;
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import com.idcanet.vasc.core.AbstractVascBackend;
|
||||
import com.idcanet.vasc.core.VascBackendState;
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
import com.idcanet.vasc.core.VascEntryField;
|
||||
import com.idcanet.vasc.core.VascException;
|
||||
|
|
@ -79,7 +80,7 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#execute()
|
||||
*/
|
||||
public List<Object> execute() throws Exception {
|
||||
public List<Object> execute(VascBackendState state) throws VascException {
|
||||
LdapConnectionProvider prov = getLdapConnectionProvider();
|
||||
LDAPConnection connection = prov.getLdapConnection();
|
||||
List<Object> result = new ArrayList<Object>(50);
|
||||
|
|
@ -110,10 +111,21 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
while (i.hasNext()) {
|
||||
LDAPAttribute attr = i.next();
|
||||
//System.out.println("ATTR: "+attr.getName()+" value: "+attr.getStringValue());
|
||||
map.put(attr.getName(), attr.getStringValueArray());
|
||||
String[] s = attr.getStringValueArray();
|
||||
if (s.length==1) {
|
||||
map.put(attr.getName(), attr.getStringValue());
|
||||
} else {
|
||||
List<String> multiValue = new ArrayList<String>(s.length);
|
||||
for (String ss:s) {
|
||||
multiValue.add(ss);
|
||||
}
|
||||
map.put(attr.getName(), multiValue );
|
||||
}
|
||||
}
|
||||
result.add(map);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new VascException(e);
|
||||
} finally {
|
||||
if (connection!=null) {
|
||||
connection.clone();
|
||||
|
|
@ -125,7 +137,7 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#merge(java.lang.Object)
|
||||
*/
|
||||
public Object merge(Object object) throws Exception {
|
||||
public Object merge(Object object) throws VascException {
|
||||
LdapConnectionProvider prov = getLdapConnectionProvider();
|
||||
LDAPConnection connection = prov.getLdapConnection();
|
||||
try {
|
||||
|
|
@ -141,7 +153,7 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#persist(java.lang.Object)
|
||||
*/
|
||||
public void persist(Object object) throws Exception {
|
||||
public void persist(Object object) throws VascException {
|
||||
LdapConnectionProvider prov = getLdapConnectionProvider();
|
||||
LDAPConnection connection = prov.getLdapConnection();
|
||||
try {
|
||||
|
|
@ -149,6 +161,8 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
// entry.getAttributeSet().
|
||||
|
||||
connection.add(entry);
|
||||
} catch (Exception e) {
|
||||
throw new VascException(e);
|
||||
} finally {
|
||||
if (connection!=null) {
|
||||
connection.clone();
|
||||
|
|
@ -159,7 +173,7 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
/**
|
||||
* @see com.idcanet.vasc.core.VascBackend#delete(java.lang.Object)
|
||||
*/
|
||||
public void delete(Object object) throws Exception {
|
||||
public void delete(Object object) throws VascException {
|
||||
LdapConnectionProvider prov = getLdapConnectionProvider();
|
||||
LDAPConnection connection = prov.getLdapConnection();
|
||||
try {
|
||||
|
|
@ -198,16 +212,20 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
@SuppressWarnings("unchecked")
|
||||
public Object getValue(VascEntryField field, Object record) throws VascException {
|
||||
Map<String,Object> map = (Map<String,Object>)record;
|
||||
String[] r = (String[])map.get(field.getBackendName());
|
||||
Object r = map.get(field.getBackendName());
|
||||
if (r==null) {
|
||||
return ""; // create new value, ldap does not return data for field that an user does not have, but other do,...
|
||||
}
|
||||
if (r.length==1) {
|
||||
return r[0];
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
return ""+getValue(field,record); // not supported (this)ldap is already fully string based.
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -33,8 +33,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import com.idcanet.vasc.core.AbstractVascBackend;
|
||||
import com.idcanet.vasc.core.VascBackendState;
|
||||
import com.idcanet.vasc.core.VascEntry;
|
||||
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;
|
||||
|
||||
|
|
@ -51,18 +53,18 @@ public class MetaModelVascBackend extends AbstractVascBackend {
|
|||
|
||||
// interface
|
||||
|
||||
public void delete(Object object) throws Exception {
|
||||
public void delete(Object object) throws VascException {
|
||||
}
|
||||
|
||||
public List<Object> execute() throws Exception {
|
||||
public List<Object> execute(VascBackendState state) throws VascException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object merge(Object object) throws Exception {
|
||||
public Object merge(Object object) throws VascException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void persist(Object object) throws Exception {
|
||||
public void persist(Object object) throws VascException {
|
||||
}
|
||||
|
||||
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue