2
Fork 0

[svn r380] added all kinds of objects

This commit is contained in:
willemc 2009-04-13 19:19:48 +02:00
parent a9520b3804
commit 37fdf22282
140 changed files with 7679 additions and 901 deletions

View file

@ -27,6 +27,7 @@
package com.idcanet.vasc.backends.jdbc;
import java.sql.Connection;
import java.sql.SQLException;
/**
@ -36,5 +37,5 @@ import java.sql.Connection;
*/
public interface JdbcConnectionProvider {
public Connection getJdbcConnection();
public Connection getJdbcConnection() throws SQLException;
}

View file

@ -26,11 +26,18 @@
package com.idcanet.vasc.backends.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.idcanet.vasc.core.AbstractVascBackend;
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;
@ -42,6 +49,11 @@ import com.idcanet.vasc.core.entry.VascEntryRecordCreator;
public class JdbcVascBackend extends AbstractVascBackend {
private JdbcConnectionProvider jdbcConnectionProvider = null;
private String sqlList = null;
private String idColumn = null;
private String sqlDelete = null;
private String sqlUpdate = null;
private String sqlInsert = null;
/**
* @return the JdbcConnectionProvider
@ -57,14 +69,33 @@ public class JdbcVascBackend extends AbstractVascBackend {
this.jdbcConnectionProvider = jdbcConnectionProvider;
}
/**
* @see com.idcanet.vasc.core.VascBackend#execute()
*/
public List<Object> execute() throws Exception {
return null;
JdbcConnectionProvider prov = getJdbcConnectionProvider();
Connection connection = prov.getJdbcConnection();
List<Object> result = new ArrayList<Object>(50);
try {
Statement s = connection.createStatement();
s.execute(getSqlList());
ResultSet rs = s.getResultSet();
int cols = rs.getMetaData().getColumnCount();
while (rs.next()) {
Map<String,Object> map = new HashMap<String,Object>(cols);
for (int i=1;i<=cols;i++) {
String columnName = rs.getMetaData().getColumnName(i);
Object columnObject = rs.getObject(i);
map.put(columnName, columnObject);
}
result.add(map);
}
} finally {
if (connection!=null) {
connection.close();
}
}
return result;
}
/**
@ -90,13 +121,59 @@ public class JdbcVascBackend extends AbstractVascBackend {
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField)
*/
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return null;
VascEntryFieldValue result = new VascEntryFieldValue() {
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
*/
@SuppressWarnings("unchecked")
public Object getValue(VascEntryField field, Object record) throws VascException {
Map<String,Object> map = (Map<String,Object>)record;
Object o = map.get(field.getBackendName());
return o;
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
*/
@SuppressWarnings("unchecked")
public void setValue(VascEntryField field, Object record,Object value) throws VascException {
Map<String,Object> map = (Map<String,Object>)record;
map.put(field.getBackendName(), value);
}
};
return result;
}
/**
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry)
*/
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return null;
return new VascEntryRecordCreator() {
public Class<?> getObjectClass() {
return Map.class;
}
public Object newRecord(VascEntry entry) throws Exception {
return new HashMap<String,Object>(10);
}
};
}
/**
* @return the sqlList
*/
public String getSqlList() {
return sqlList;
}
/**
* @param sqlList the sqlList to set
*/
public void setSqlList(String sqlList) {
this.sqlList = sqlList;
}
}

View file

@ -37,6 +37,7 @@ import java.util.Map;
import com.idcanet.vasc.core.AbstractVascBackend;
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.xtes.xpql.query.QueryParameterValue;
@ -65,33 +66,54 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend {
public void setJdbcConnectionProvider(JdbcConnectionProvider jdbcConnectionProvider) {
this.jdbcConnectionProvider = jdbcConnectionProvider;
}
/**
* @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;
}
/**
* @see com.idcanet.vasc.core.VascBackend#execute()
*/
public List<Object> execute() throws Exception {
// Copy parameters
for (String key:getDataParameterKeys()) {
Object value = getDataParameter(key);
query.setQueryParameter(key, value);
}
Connection c = getJdbcConnectionProvider().getJdbcConnection();
try {
PreparedStatement q = c.prepareStatement(query.toPreparedSQL(query));
List<QueryParameterValue> values = query.getOrderQueryParameterValues();
int i = 0;
int ii = 1;
for (QueryParameterValue value:values) {
q.setObject(i,value.getValue());
i++;
q.setObject(ii,value.getValue());
ii++;
}
q.execute();
ResultSet rs = q.getResultSet();
List<Object> data = new ArrayList<Object>(100);
do {
Map<String,Object> obj = new HashMap<String,Object>(10);
for (i=0;i<rs.getMetaData().getColumnCount();i++) {
obj.put(rs.getMetaData().getCatalogName(i), rs.getObject(i));
}
data.add(obj);
} while (rs.next());
return data;
int cols = rs.getMetaData().getColumnCount();
List<Object> result = new ArrayList<Object>(50);
while (rs.next()) {
Map<String,Object> map = new HashMap<String,Object>(cols);
for (int i=1;i<=cols;i++) {
String columnName = rs.getMetaData().getColumnName(i);
Object columnObject = rs.getObject(i);
map.put(columnName, columnObject);
}
result.add(map);
}
return result;
} finally {
if (c!=null) {
c.close();
@ -122,13 +144,42 @@ public class JdbcXpqlVascBackend extends AbstractVascBackend {
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField)
*/
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return null;
VascEntryFieldValue result = new VascEntryFieldValue() {
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object)
*/
@SuppressWarnings("unchecked")
public Object getValue(VascEntryField field, Object record) throws VascException {
Map<String,Object> map = (Map<String,Object>)record;
Object o = map.get(field.getBackendName());
return o;
}
/**
* @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
*/
@SuppressWarnings("unchecked")
public void setValue(VascEntryField field, Object record,Object value) throws VascException {
Map<String,Object> map = (Map<String,Object>)record;
map.put(field.getBackendName(), value);
}
};
return result;
}
/**
* @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry)
*/
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return null;
return new VascEntryRecordCreator() {
public Class<?> getObjectClass() {
return Map.class;
}
public Object newRecord(VascEntry entry) throws Exception {
return new HashMap<String,Object>(10);
}
};
}
}

View file

@ -0,0 +1,112 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.backends.jdbc;
import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 15, 2009
*/
public class JdniDataSourceJdbcConnectionProvider implements JdbcConnectionProvider {
/** The context in which database data sources are found. */
private String dataSourceContext = "java:comp/env/jdbc/";
private String dataSourceName = null;
/**
* @see com.idcanet.vasc.backends.jdbc.JdbcConnectionProvider#getJdbcConnection()
*/
public Connection getJdbcConnection() throws SQLException {
Connection connection = getDataSource(dataSourceName).getConnection();
return connection;
}
/**
* Gets a DataSource out of the JNDI context.
* <p>
* @param name The name of the data source in the JDNI context.
* @return The data source.
*/
private DataSource getDataSource(String name) throws SQLException {
try {
Context initialContext = new InitialContext();
if ( initialContext == null ) {
throw new SQLException("Cannot get Initial Context");
}
DataSource datasource = (DataSource)initialContext.lookup(dataSourceContext+name);
if ( datasource == null ) {
throw new SQLException("Cannot lookup datasource: "+name);
}
return datasource;
} catch ( NamingException e ) {
throw new SQLException("Cannot get connection " + e,e);
}
}
/**
* @return the dataSourceContext
*/
public String getDataSourceContext() {
return dataSourceContext;
}
/**
* @param dataSourceContext the dataSourceContext to set
*/
public void setDataSourceContext(String dataSourceContext) {
this.dataSourceContext = dataSourceContext;
}
/**
* @return the dataSourceName
*/
public String getDataSourceName() {
return dataSourceName;
}
/**
* @param dataSourceName the dataSourceName to set
*/
public void setDataSourceName(String dataSourceName) {
this.dataSourceName = dataSourceName;
}
}

View file

@ -0,0 +1,121 @@
/*
* Copyright 2004-2007 IDCA. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the authors and
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
*/
package com.idcanet.vasc.backends.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 15, 2009
*/
public class SimpleJdbcConnectionProvider implements JdbcConnectionProvider {
private String driverClassName = null;
private String dbUrl = null;
private String dbUser = null;
private String dbPassword = null;
private boolean loadedDriver = false;
/**
* @see com.idcanet.vasc.backends.jdbc.JdbcConnectionProvider#getJdbcConnection()
*/
public Connection getJdbcConnection() throws SQLException {
if (loadedDriver==false) {
try {
Class.forName(driverClassName);
loadedDriver = true;
} catch (ClassNotFoundException e) {
throw new SQLException("Could not load driver: "+driverClassName+" error: "+e.getMessage(),e);
}
}
Connection connection = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
return connection;
}
/**
* @return the driverClassName
*/
public String getDriverClassName() {
return driverClassName;
}
/**
* @param driverClassName the driverClassName to set
*/
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
/**
* @return the dbUrl
*/
public String getDbUrl() {
return dbUrl;
}
/**
* @param dbUrl the dbUrl to set
*/
public void setDbUrl(String dbUrl) {
this.dbUrl = dbUrl;
}
/**
* @return the dbUser
*/
public String getDbUser() {
return dbUser;
}
/**
* @param dbUser the dbUser to set
*/
public void setDbUser(String dbUser) {
this.dbUser = dbUser;
}
/**
* @return the dbPassword
*/
public String getDbPassword() {
return dbPassword;
}
/**
* @param dbPassword the dbPassword to set
*/
public void setDbPassword(String dbPassword) {
this.dbPassword = dbPassword;
}
}

View file

@ -37,19 +37,17 @@ import com.idcanet.vasc.core.AbstractVascBackend;
*/
abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend {
/**
* Provides a hibernate session which is closed !! when transaction is compleeted.
* @return
*/
abstract EntityManager getEntityManager();
public void persist(Object object) throws Exception {
EntityManager s = getEntityManager();
try {
s.getTransaction().begin();
s.persist(object);
s.getTransaction().commit();
} finally {
if (s!=null) {
s.close();
//s.close();
}
}
}
@ -57,10 +55,13 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
public Object merge(Object object) throws Exception {
EntityManager s = getEntityManager();
try {
return s.merge(object);
s.getTransaction().begin();
Object result = s.merge(object);
s.getTransaction().commit();
return result;
} finally {
if (s!=null) {
s.close();
//s.close();
}
}
}
@ -68,11 +69,13 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend
public void delete(Object object) throws Exception {
EntityManager s = getEntityManager();
try {
s.getTransaction().begin();
Object newObject = s.merge(object);
s.remove(newObject);
s.getTransaction().commit();
} finally {
if (s!=null) {
s.close();
//s.close();
}
}
}

View file

@ -0,0 +1,40 @@
/*
* 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 javax.persistence.EntityManager;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2009
*/
public interface EntityManagerProvider {
public EntityManager getEntityManager();
}

View file

@ -64,11 +64,16 @@ public class Serv5XpqlHibernateVascBackend extends AbstractHibernateVascBackend
@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 = 0;
int i = 1;
for (QueryParameterValue value:values) {
q.setParameter(i,value.getValue());
i++;

View file

@ -0,0 +1,250 @@
/*
* 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 javax.persistence.EntityManager;
import javax.persistence.Query;
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 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 Class<?> resultClass = null;
public XpqlPersistanceVascBackend() {
}
/**
* @see com.idcanet.vasc.backends.jpa.AbstractPersistenceVascBackend#getEntityManager()
*/
@Override
EntityManager getEntityManager() {
return entityManagerProvider.getEntityManager();
}
@SuppressWarnings("unchecked")
public List<Object> execute() throws Exception {
// Copy parameters
for (String key:getDataParameterKeys()) {
Object value = 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());
i++;
}
if (isPageable()) {
q.setFirstResult(getPageIndex());
q.setMaxResults(getPageSize());
}
List<Object> data = q.getResultList();
if (queryTotal==null) {
setPagesTotalRecords(data.size());
}
return data;
} finally {
if (em!=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#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 entityManagerProvider
*/
public EntityManagerProvider getEntityManagerProvider() {
return entityManagerProvider;
}
/**
* @param entityManagerProvider the entityManagerProvider to set
*/
public void setEntityManagerProvider(EntityManagerProvider entityManagerProvider) {
this.entityManagerProvider = entityManagerProvider;
}
/**
* @see com.idcanet.vasc.core.AbstractVascBackend#isPageable()
*/
@Override
public boolean isPageable() {
if (queryTotal==null) {
return false;
}
/*
if (query.getQueryParameterValue("offset")==null) {
return false;
}
if (query.getQueryParameterValue("limit")==null) {
return false;
}
*/
return true;
}
}

View file

@ -27,7 +27,6 @@
package com.idcanet.vasc.backends.ldap;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -94,7 +93,7 @@ public class LdapVascBackend extends AbstractVascBackend {
int searchScope = LDAPConnection.SCOPE_ONE;
String searchBase = baseDN;
System.out.println("\n\tReading object :" + searchBase + " with filter: " + ldapFilter);
//System.out.println("Reading object :" + searchBase + " with filter: " + ldapFilter);
LDAPSearchResults searchResults = connection.search(
searchBase, // object to read
searchScope, // scope - read single object
@ -102,18 +101,15 @@ public class LdapVascBackend extends AbstractVascBackend {
null, // return all attributes
false); // return attrs and values
System.out.println("Got object :" + searchResults.getCount());
while (searchResults.hasMore()) {
LDAPEntry entry = searchResults.next();
System.out.println("We found "+entry.getDN());
Map<String,Object> map = new HashMap<String,Object>(10);
LDAPAttributeSet attributeSet = entry.getAttributeSet();
Iterator i = attributeSet.iterator();
Iterator<LDAPAttribute> i = attributeSet.iterator();
while (i.hasNext()) {
LDAPAttribute attr = (LDAPAttribute)i.next();
System.out.println("ATTR: "+attr.getName()+" value: "+attr.getStringValue());
LDAPAttribute attr = i.next();
//System.out.println("ATTR: "+attr.getName()+" value: "+attr.getStringValue());
map.put(attr.getName(), attr.getStringValueArray());
}
result.add(map);

View file

@ -0,0 +1,75 @@
/*
* 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.meta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.idcanet.vasc.core.AbstractVascBackend;
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 dk.eobjects.metamodel.query.Query;
/**
*
* @author Willem Cazander
* @version 1.0 Dec 19, 2008
*/
public class MetaModelVascBackend extends AbstractVascBackend {
private Query listQuery = null;
// interface
public void delete(Object object) throws Exception {
}
public List<Object> execute() throws Exception {
return null;
}
public Object merge(Object object) throws Exception {
return null;
}
public void persist(Object object) throws Exception {
}
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return null;
}
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return null;
}
}