2
0
Fork 0

Small refactor for comming converters

This commit is contained in:
Willem Cazander 2012-01-22 08:16:15 +01:00
parent 75b3d5e0a0
commit 1c308a684a
178 changed files with 5865 additions and 1531 deletions

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vasc-backend-jdbc</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
#Sat Dec 31 04:21:23 CET 2011
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View file

@ -0,0 +1,6 @@
#Sat Dec 31 04:21:23 CET 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

View file

@ -0,0 +1,5 @@
#Sat Dec 31 04:21:23 CET 2011
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -0,0 +1,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vasc-backend</artifactId>
<groupId>net.forwardfire.vasc</groupId>
<version>0.3.5-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>vasc-backend-jdbc</artifactId>
<name>vasc-backend-jdbc</name>
<description>vasc-backend-jdbc</description>
<dependencies>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,37 @@
/*
* 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.backend.jdbc;
import java.sql.Connection;
import java.sql.SQLException;
/**
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public interface JdbcConnectionProvider {
public Connection getJdbcConnection() throws SQLException;
}

View file

@ -0,0 +1,117 @@
/*
* 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.backend.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 15, 2009
*/
public class JdbcConnectionProviderImpl implements JdbcConnectionProvider {
private String driverClassName = null;
private String dbUrl = null;
private String dbUser = null;
private String dbPassword = null;
private boolean loadedDriver = false;
/**
* @see net.forwardfire.vasc.backend.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

@ -0,0 +1,108 @@
/*
* 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.backend.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 JdbcConnectionProviderJdniImpl implements JdbcConnectionProvider {
/** The context in which database data sources are found. */
private String dataSourceContext = "java:/";
private String dataSourceName = null;
/**
* @see net.forwardfire.vasc.backend.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,157 @@
/*
* 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.backend.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 net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.data.MapVascEntryFieldValue;
import net.forwardfire.vasc.backend.data.MapVascEntryRecordCreator;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
/**
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
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
*/
public JdbcConnectionProvider getJdbcConnectionProvider() {
return jdbcConnectionProvider;
}
/**
* @param JdbcConnectionProvider the JdbcConnectionProvider to set
*/
public void setJdbcConnectionProvider(JdbcConnectionProvider jdbcConnectionProvider) {
this.jdbcConnectionProvider = jdbcConnectionProvider;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state)
*/
public List<Object> execute(VascBackendState state) throws VascException {
JdbcConnectionProvider prov = getJdbcConnectionProvider();
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();
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);
}
} catch (Exception e) {
throw new VascException(e);
} finally {
if (connection!=null) {
try {
connection.close();
} catch (Exception e) {
}
}
}
return result;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#merge(java.lang.Object)
*/
public Object merge(Object object) throws VascException {
return object;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object)
*/
public void persist(Object object) throws VascException {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#delete(java.lang.Object)
*/
public void delete(Object object) throws VascException {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField)
*/
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return new MapVascEntryFieldValue();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry)
*/
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new MapVascEntryRecordCreator();
}
/**
* @return the sqlList
*/
public String getSqlList() {
return sqlList;
}
/**
* @param sqlList the sqlList to set
*/
public void setSqlList(String sqlList) {
this.sqlList = sqlList;
}
}

View file

@ -0,0 +1,163 @@
/*
* 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.backend.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.data.MapVascEntryFieldValue;
import net.forwardfire.vasc.backend.data.MapVascEntryRecordCreator;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
import net.forwardfire.vasc.xpql.query.QueryParameterValue;
/**
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class JdbcVascBackendXpql extends AbstractVascBackend {
private JdbcConnectionProvider jdbcConnectionProvider = null;
private net.forwardfire.vasc.xpql.query.Query query = null;
/**
* @return the JdbcConnectionProvider
*/
public JdbcConnectionProvider getJdbcConnectionProvider() {
return jdbcConnectionProvider;
}
/**
* @param JdbcConnectionProvider the JdbcConnectionProvider to set
*/
public void setJdbcConnectionProvider(JdbcConnectionProvider jdbcConnectionProvider) {
this.jdbcConnectionProvider = jdbcConnectionProvider;
}
/**
* @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;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state)
*/
public List<Object> execute(VascBackendState state) throws VascException {
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
query.setQueryParameter(key, value);
}
Connection c = null;
try {
c = getJdbcConnectionProvider().getJdbcConnection();;
PreparedStatement q = c.prepareStatement(query.toPreparedSQL(query));
List<QueryParameterValue> values = query.getOrderQueryParameterValues();
int ii = 1;
for (QueryParameterValue value:values) {
q.setObject(ii,value.getValue());
ii++;
}
q.execute();
ResultSet rs = q.getResultSet();
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;
} catch (Exception e) {
throw new VascException(e);
} finally {
if (c!=null) {
try {
c.close();
} catch (Exception e) {
}
}
}
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#merge(java.lang.Object)
*/
public Object merge(Object object) throws VascException {
return object;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object)
*/
public void persist(Object object) throws VascException {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#delete(java.lang.Object)
*/
public void delete(Object object) throws VascException {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField)
*/
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return new MapVascEntryFieldValue();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry)
*/
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new MapVascEntryRecordCreator();
}
}

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<eld:root xmlns:eld="http://eld.x4o.org/eld/eld-lang.eld">
<eld:elementClass tag="jdbcBackend" objectClassName="net.forwardfire.vasc.backend.jdbc.JdbcVascBackend">
<eld:elementConfigurator bean.class="net.forwardfire.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
</eld:elementClass>
<eld:elementClass tag="jdbcConnectionProvider" objectClassName="net.forwardfire.vasc.backend.jdbc.JdbcConnectionProviderImpl"/>
<eld:elementClass tag="jdbcConnectionProviderJndi" objectClassName="net.forwardfire.vasc.backend.jdbc.JdbcConnectionProviderJdniImpl"/>
<eld:elementClass tag="jdbcBackendXpql" objectClassName="net.forwardfire.vasc.backend.jdbc.JdbcVascBackendXpql">
<eld:elementConfigurator bean.class="net.forwardfire.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
</eld:elementClass>
</eld:root>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>
Vasc namespace for the jdbc backend
</comment>
<entry key="eld.http://vasc.forwardfire.net/eld/vasc-backend-jdbc.eld">vasc-backend-jdbc.eld</entry>
</properties>

View file

@ -16,12 +16,12 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>

View file

@ -22,7 +22,7 @@
package net.forwardfire.vasc.backends.jpa;
import net.forwardfire.vasc.core.AbstractVascBackend;
import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.core.VascException;
import org.hibernate.Session;

View file

@ -26,7 +26,7 @@ import java.lang.reflect.Method;
import javax.persistence.EntityManager;
import net.forwardfire.vasc.core.AbstractVascBackend;
import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.core.VascException;

View file

@ -24,9 +24,9 @@ package net.forwardfire.vasc.backends.jpa;
import java.util.List;
import net.forwardfire.vasc.backends.BeanVascEntryFieldValue;
import net.forwardfire.vasc.backends.BeanVascEntryRecordCreator;
import net.forwardfire.vasc.core.VascBackendState;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.data.BeanVascEntryFieldValue;
import net.forwardfire.vasc.backend.data.BeanVascEntryRecordCreator;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
@ -116,7 +116,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
}
/**
* @see net.forwardfire.vasc.core.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField)
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField)
*/
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
BeanVascEntryFieldValue result = new BeanVascEntryFieldValue();
@ -124,7 +124,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
}
/**
* @see net.forwardfire.vasc.core.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry)
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry)
*/
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new BeanVascEntryRecordCreator(resultClass);
@ -187,7 +187,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
}
/**
* @see net.forwardfire.vasc.core.AbstractVascBackend#isPageable()
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isPageable()
*/
@Override
public boolean isPageable() {
@ -198,7 +198,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
}
/**
* @see net.forwardfire.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state)
* @see net.forwardfire.vasc.backend.VascBackend#fetchTotalExecuteSize(VascBackendState state)
*/
public long fetchTotalExecuteSize(VascBackendState state) {
Session s = getHibernateSession();
@ -227,7 +227,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
}
/**
* @see net.forwardfire.vasc.core.AbstractVascBackend#doRecordMoveDownById(java.lang.Object)
* @see net.forwardfire.vasc.backend.AbstractVascBackend#doRecordMoveDownById(java.lang.Object)
*/
@Override
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascException {
@ -296,7 +296,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
}
/**
* @see net.forwardfire.vasc.core.AbstractVascBackend#doRecordMoveUpById(java.lang.Object)
* @see net.forwardfire.vasc.backend.AbstractVascBackend#doRecordMoveUpById(java.lang.Object)
*/
@Override
public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascException {
@ -365,7 +365,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend {
}
/**
* @see net.forwardfire.vasc.core.AbstractVascBackend#isRecordMoveable()
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isRecordMoveable()
*/
@Override
public boolean isRecordMoveable() {

View file

@ -27,9 +27,9 @@ import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import net.forwardfire.vasc.backends.BeanVascEntryFieldValue;
import net.forwardfire.vasc.backends.BeanVascEntryRecordCreator;
import net.forwardfire.vasc.core.VascBackendState;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.data.BeanVascEntryFieldValue;
import net.forwardfire.vasc.backend.data.BeanVascEntryRecordCreator;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
@ -121,7 +121,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
}
/**
* @see net.forwardfire.vasc.core.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField)
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField)
*/
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
VascEntryFieldValue result = new BeanVascEntryFieldValue();
@ -129,7 +129,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
}
/**
* @see net.forwardfire.vasc.core.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry)
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry)
*/
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
VascEntryRecordCreator result = new BeanVascEntryRecordCreator(resultClass);
@ -193,7 +193,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
}
/**
* @see net.forwardfire.vasc.core.AbstractVascBackend#isPageable()
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isPageable()
*/
@Override
public boolean isPageable() {
@ -204,7 +204,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
}
/**
* @see net.forwardfire.vasc.core.VascBackend#fetchTotalExecuteSize(VascBackendState state)
* @see net.forwardfire.vasc.backend.VascBackend#fetchTotalExecuteSize(VascBackendState state)
*/
public long fetchTotalExecuteSize(VascBackendState state) {
EntityManager em = getEntityManager();
@ -359,7 +359,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
}
/**
* @see net.forwardfire.vasc.core.AbstractVascBackend#isRecordMoveable()
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isRecordMoveable()
*/
@Override
public boolean isRecordMoveable() {
@ -423,7 +423,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend
}
/**
* @see net.forwardfire.vasc.core.VascBackend#isSearchable()
* @see net.forwardfire.vasc.backend.VascBackend#isSearchable()
*/
public boolean isSearchable() {
if (query.getQueryParameterValue("text_search")==null) {

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<eld:root xmlns:eld="http://eld.x4o.org/eld/eld-lang.eld">
<!--
<eld:elementClass tag="ldapBackend" objectClassName="net.forwardfire.vasc.backend.ldap.LdapVascBackend">
<eld:elementConfigurator bean.class="net.forwardfire.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
</eld:elementClass>
<eld:elementClass tag="ldapConnectionProvider" objectClassName="net.forwardfire.vasc.backend.ldap.LdapConnectionProviderImpl"/>
-->
<eld:elementClass tag="xpqlPersistanceBackend" objectClassName="net.forwardfire.vasc.backends.jpa.XpqlPersistanceVascBackend">
<eld:elementConfigurator bean.class="net.forwardfire.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
<eld:elementClassAttribute attributeName="resultClass">
<eld:attributeClassConverter/>
</eld:elementClassAttribute>
</eld:elementClass>
<eld:elementClass tag="xpqlHibernateBackend" objectClassName="net.forwardfire.vasc.backends.jpa.XpqlHibernateVascBackend">
<eld:elementConfigurator bean.class="net.forwardfire.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
<eld:elementClassAttribute attributeName="resultClass">
<eld:attributeClassConverter/>
</eld:elementClassAttribute>
</eld:elementClass>
</eld:root>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>
Vasc namespace for the jpa backend
</comment>
<entry key="eld.http://vasc.forwardfire.net/eld/vasc-backend-jpa.eld">vasc-backend-jpa.eld</entry>
</properties>

View file

@ -0,0 +1,35 @@
/*
* 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.backend.ldap;
import com.novell.ldap.LDAPConnection;
/**
*
* @author Willem Cazander
* @version 1.0 Sep 4, 2008
*/
public interface LdapConnectionProvider {
public LDAPConnection getLdapConnection();
}

View file

@ -0,0 +1,133 @@
/*
* 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.backend.ldap;
import com.novell.ldap.LDAPConnection;
/**
*
* @author Willem Cazander
* @version 1.0 Sep 4, 2008
*/
public class LdapConnectionProviderImpl implements LdapConnectionProvider {
private String ldapHost = "localhost";
private int ldapPort = LDAPConnection.DEFAULT_PORT;
private int ldapVersion = LDAPConnection.LDAP_V3;
private String bindUser = null;
private String bindPass = null;
/**
* @see net.forwardfire.vasc.backend.ldap.LdapConnectionProvider#getLdapConnection()
*/
public LDAPConnection getLdapConnection() {
try {
// if ssl;
//Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
//System.setProperty("javax.net.ssl.trustStore", "/tmp/somewhere/ldap.root.crt");
//LDAPSocketFactory ssf = new LDAPJSSESecureSocketFactory();
// Set the socket factory as the default for all future connections
//LDAPConnection.setSocketFactory(ssf);
LDAPConnection lc = new LDAPConnection();
lc.connect( ldapHost, ldapPort );
if (bindUser!=null && bindPass!=null) {
lc.bind( ldapVersion, bindUser, bindPass.getBytes("UTF8") );
}
return lc;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* @return the ldapHost
*/
public String getLdapHost() {
return ldapHost;
}
/**
* @param ldapHost the ldapHost to set
*/
public void setLdapHost(String ldapHost) {
this.ldapHost = ldapHost;
}
/**
* @return the ldapPort
*/
public int getLdapPort() {
return ldapPort;
}
/**
* @param ldapPort the ldapPort to set
*/
public void setLdapPort(int ldapPort) {
this.ldapPort = ldapPort;
}
/**
* @return the ldapVersion
*/
public int getLdapVersion() {
return ldapVersion;
}
/**
* @param ldapVersion the ldapVersion to set
*/
public void setLdapVersion(int ldapVersion) {
this.ldapVersion = ldapVersion;
}
/**
* @return the bindUser
*/
public String getBindUser() {
return bindUser;
}
/**
* @param bindUser the bindUser to set
*/
public void setBindUser(String bindUser) {
this.bindUser = bindUser;
}
/**
* @return the bindPass
*/
public String getBindPass() {
return bindPass;
}
/**
* @param bindPass the bindPass to set
*/
public void setBindPass(String bindPass) {
this.bindPass = bindPass;
}
}

View file

@ -0,0 +1,334 @@
/*
* 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.backend.ldap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.data.MapVascEntryFieldValue;
import net.forwardfire.vasc.backend.data.MapVascEntryRecordCreator;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
import com.novell.ldap.LDAPAttribute;
import com.novell.ldap.LDAPAttributeSet;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPEntry;
import com.novell.ldap.LDAPModification;
import com.novell.ldap.LDAPSearchConstraints;
import com.novell.ldap.LDAPSearchResults;
/**
* Provides backend for ldap.
*
* @author Willem Cazander
* @version 1.0 Sep 4, 2008
*/
public class LdapVascBackend extends AbstractVascBackend {
private LdapConnectionProvider ldapConnectionProvider = null;
private String baseDN = null;
private String keyAttribute = null;
private String ldapFilter = null;
/**
* @return the ldapConnectionProvider
*/
public LdapConnectionProvider getLdapConnectionProvider() {
return ldapConnectionProvider;
}
/**
* @param ldapConnectionProvider the ldapConnectionProvider to set
*/
public void setLdapConnectionProvider(LdapConnectionProvider ldapConnectionProvider) {
this.ldapConnectionProvider = ldapConnectionProvider;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#execute()
*/
public List<Object> execute(VascBackendState state) throws VascException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
List<Object> result = new ArrayList<Object>(50);
try {
LDAPSearchConstraints cons = new LDAPSearchConstraints();
cons.setBatchSize( 0 );
cons.setTimeLimit( 10000 ) ;
cons.setReferralFollowing(true);
connection.setConstraints(cons);
int searchScope = LDAPConnection.SCOPE_ONE;
String searchBase = baseDN;
//System.out.println("Reading object :" + searchBase + " with filter: " + ldapFilter);
LDAPSearchResults searchResults = connection.search(
searchBase, // object to read
searchScope, // scope - read single object
ldapFilter, // search filter
null, // return all attributes
false); // return attrs and values
while (searchResults.hasMore()) {
LDAPEntry entry = searchResults.next();
Map<String,Object> map = new HashMap<String,Object>(10);
LDAPAttributeSet attributeSet = entry.getAttributeSet();
Iterator<LDAPAttribute> i = attributeSet.iterator();
while (i.hasNext()) {
LDAPAttribute attr = i.next();
//System.out.println("ATTR: "+attr.getName()+" value: "+attr.getStringValue());
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();
}
}
return result;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#merge(java.lang.Object)
*/
public Object merge(Object object) throws VascException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
try {
Map<String,Object> map = (Map)object;
String keyValue = (String)map.get(keyAttribute);
LDAPSearchConstraints cons = new LDAPSearchConstraints();
cons.setBatchSize( 0 );
cons.setTimeLimit( 10000 ) ;
cons.setReferralFollowing(true);
connection.setConstraints(cons);
int searchScope = LDAPConnection.SCOPE_ONE;
String searchBase = baseDN;
String filter = "(&("+keyAttribute+"="+keyValue+"))";
System.out.println("ldap filter: "+filter);
LDAPSearchResults searchResults = connection.search(
searchBase, // object to read
searchScope, // scope - read single object
filter, // search filter
null, // return all attributes
false); // return attrs and values
if (searchResults.hasMore()==false) {
// no result to mod
return object;
}
LDAPEntry entry = searchResults.next();
List<LDAPModification> mods = new ArrayList<LDAPModification>(20);
for (String key:map.keySet()) {
Object value = map.get(key);
LDAPAttribute attr = entry.getAttribute(key);
if (attr==null) {
LDAPModification mod = new LDAPModification(LDAPModification.ADD,new LDAPAttribute(key,(String)value));
mods.add(mod);
continue;
}
String[] s = attr.getStringValueArray();
if (s.length==1) {
String v = (String)value;
if (attr.getStringValue().equals(v)==false) {
LDAPModification mod = new LDAPModification(LDAPModification.REPLACE,new LDAPAttribute(key,v));
mods.add(mod);
}
map.put(attr.getName(), attr.getStringValue());
} else {
List<String> multiValue = new ArrayList<String>(s.length);
for (String ss:s) {
multiValue.add(ss);
}
List<String> v = null;
if (value instanceof String) {
v = new ArrayList<String>(1);
v.add((String)value);
} else {
v = (List<String>)value;
}
if (v.equals(multiValue)==false) {
LDAPAttribute a = new LDAPAttribute(key);
for (String vv:v) {
a.addValue(vv);
}
LDAPModification mod = new LDAPModification(LDAPModification.REPLACE,a);
mods.add(mod);
}
}
}
LDAPModification[] m = new LDAPModification[mods.size()];
mods.toArray(m);
connection.modify(entry.getDN(), m);
return object;
} catch (Exception e) {
throw new VascException(e);
} finally {
if (connection!=null) {
connection.clone();
}
}
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object)
*/
public void persist(Object object) throws VascException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
try {
LDAPEntry entry = new LDAPEntry();
// entry.getAttributeSet().
connection.add(entry);
} catch (Exception e) {
throw new VascException(e);
} finally {
if (connection!=null) {
connection.clone();
}
}
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#delete(java.lang.Object)
*/
public void delete(Object object) throws VascException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
try {
Map<String,Object> map = (Map)object;
String keyValue = (String)map.get(keyAttribute);
int searchScope = LDAPConnection.SCOPE_ONE;
String searchBase = baseDN;
String filter = "(&("+ldapFilter+")("+keyAttribute+"="+keyValue+"))";
LDAPSearchResults searchResults = connection.search(
searchBase, // object to read
searchScope, // scope - read single object
filter, // search filter
null, // return all attributes
false); // return attrs and values
if (searchResults.hasMore()==false) {
// no result to mod
return;
}
LDAPEntry entry = searchResults.next();
connection.delete(entry.getDN());
} catch (Exception e) {
throw new VascException(e);
} finally {
if (connection!=null) {
connection.clone();
}
}
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry)
*/
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new MapVascEntryRecordCreator();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField)
*/
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return new MapVascEntryFieldValue();
}
/**
* @return the baseDN
*/
public String getBaseDN() {
return baseDN;
}
/**
* @param baseDN the baseDN to set
*/
public void setBaseDN(String baseDN) {
this.baseDN = baseDN;
}
/**
* @return the keyAttribute
*/
public String getKeyAttribute() {
return keyAttribute;
}
/**
* @param keyAttribute the keyAttribute to set
*/
public void setKeyAttribute(String keyAttribute) {
this.keyAttribute = keyAttribute;
}
/**
* @return the ldapFilter
*/
public String getLdapFilter() {
return ldapFilter;
}
/**
* @param ldapFilter the ldapFilter to set
*/
public void setLdapFilter(String ldapFilter) {
this.ldapFilter = ldapFilter;
}
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<eld:root xmlns:eld="http://eld.x4o.org/eld/eld-lang.eld">
<eld:elementClass tag="ldapBackend" objectClassName="net.forwardfire.vasc.backend.ldap.LdapVascBackend">
<eld:elementConfigurator bean.class="net.forwardfire.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
</eld:elementClass>
<eld:elementClass tag="ldapConnectionProvider" objectClassName="net.forwardfire.vasc.backend.ldap.LdapConnectionProviderImpl"/>
</eld:root>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>
Vasc namespace for the ldap backend
</comment>
<entry key="eld.http://vasc.forwardfire.net/eld/vasc-backend-ldap.eld">vasc-backend-ldap.eld</entry>
</properties>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vasc-backend-metamodel</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,7 @@
#Sat Dec 31 05:51:03 CET 2011
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View file

@ -0,0 +1,6 @@
#Sat Dec 31 05:51:03 CET 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5

View file

@ -0,0 +1,5 @@
#Sat Dec 31 05:51:03 CET 2011
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -0,0 +1,24 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vasc-backend</artifactId>
<groupId>net.forwardfire.vasc</groupId>
<version>0.3.5-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>vasc-backend-metamodel</artifactId>
<name>vasc-backend-metamodel</name>
<description>vasc-backend-metamodel</description>
<dependencies>
<dependency>
<groupId>net.forwardfire.vasc</groupId>
<artifactId>vasc-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eobjects.metamodel</groupId>
<artifactId>MetaModel-core</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,97 @@
/*
* 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.backend.metamodel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eobjects.metamodel.DataContext;
import org.eobjects.metamodel.data.DataSet;
import org.eobjects.metamodel.data.Row;
import org.eobjects.metamodel.query.Query;
import org.eobjects.metamodel.query.SelectItem;
import org.eobjects.metamodel.schema.Schema;
import org.eobjects.metamodel.schema.Table;
import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.data.MapVascEntryFieldValue;
import net.forwardfire.vasc.backend.data.MapVascEntryRecordCreator;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
/**
* Provides backend for metamodel.
*
* @author Willem Cazander
* @version 1.0 Dec 31, 2011
*/
public class MetaModelVascBackend extends AbstractVascBackend {
private DataContext dataContext = null;
private String table = null;
public List<Object> execute(VascBackendState state) throws VascException {
Schema schema = dataContext.getDefaultSchema();
Table t = schema.getTableByName(table);
//dataContext.query().from("").select("").where("").
Query q = dataContext.query().from(t).select(t.getColumns()).toQuery();
DataSet ds = dataContext.executeQuery(q);
List<Object> result = new ArrayList<Object>(50);
while (ds.next()) {
Row row = ds.getRow();
SelectItem[] cols = row.getSelectItems();
Map<String,Object> map = new HashMap<String,Object>(cols.length);
for (SelectItem col:cols) {
Object value = row.getValue(col);
map.put(col.getColumn().getName(), value);
}
result.add(map);
}
return result;
}
public void persist(Object object) throws VascException {
}
public Object merge(Object object) throws VascException {
return object;
}
public void delete(Object object) throws VascException {
}
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return new MapVascEntryFieldValue();
}
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new MapVascEntryRecordCreator();
}
}

View file

@ -0,0 +1,40 @@
/*
* 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.backend.mongodb;
import com.mongodb.DB;
/**
* Provides an mongodb DB connection to the backend.
*
* @author Willem Cazander
* @version 1.0 Dec 30, 2011
*/
public interface MongodbConnectionProvider {
/**
* Returns a DB connection.
* @return An DB connection to mongodb
*/
public DB getMongodbConnection();
}

View file

@ -0,0 +1,163 @@
/*
* 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.backend.mongodb;
import java.net.UnknownHostException;
import java.util.logging.Logger;
import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoOptions;
import com.mongodb.ServerAddress;
/**
* Provides an mongodb DB connection to the backend.
*
* @author Willem Cazander
* @version 1.0 Dec 30, 2011
*/
public class MongodbConnectionProviderImpl implements MongodbConnectionProvider {
private Logger logger = Logger.getLogger(MongodbConnectionProviderImpl.class.getName());
private String hostname = "localhost";
private int port = 27017;
private String database = null;
private String username = null;
private String password = null;
private boolean readonly = false;
protected static Mongo mongo = null;
protected static DB db = null;
public DB getMongodbConnection() {
if (db!=null) {
return db;
}
synchronized (this) {
ServerAddress server;
try {
server = new ServerAddress(hostname,port);
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
MongoOptions options = new MongoOptions();
mongo = new Mongo(server,options);
db = mongo.getDB(database);
if (username!=null && password!=null) {
boolean auth = db.authenticate(username, password.toCharArray());
if (auth==false) {
throw new RuntimeException("Could not auth to db: "+database+" with username: "+username);
}
}
if (readonly) {
db.setReadOnly(true);
}
logger.info("Connection to: "+db.getName());
}
return db;
}
/**
* @return the hostname
*/
public String getHostname() {
return hostname;
}
/**
* @param hostname the hostname to set
*/
public void setHostname(String hostname) {
this.hostname = hostname;
}
/**
* @return the port
*/
public int getPort() {
return port;
}
/**
* @param port the port to set
*/
public void setPort(int port) {
this.port = port;
}
/**
* @return the database
*/
public String getDatabase() {
return database;
}
/**
* @param database the database to set
*/
public void setDatabase(String database) {
this.database = database;
}
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @param username the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return the readonly
*/
public boolean isReadonly() {
return readonly;
}
/**
* @param readonly the readonly to set
*/
public void setReadonly(boolean readonly) {
this.readonly = readonly;
}
}

View file

@ -0,0 +1,151 @@
/*
* 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.backend.mongodb;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.BasicDBObject;
import com.mongodb.WriteConcern;
import com.mongodb.WriteResult;
/**
* Provides backend for mongodb.
*
* @author Willem Cazander
* @version 1.0 Dec 30, 2011
*/
public class MongodbVascBackend extends AbstractVascBackend {
private Logger logger = null;
private MongodbConnectionProvider connectionProvider = null;
private String collection = null;
private DB database = null;
public MongodbVascBackend() {
logger = Logger.getLogger(MongodbVascBackend.class.getName());
}
public List<Object> execute(VascBackendState state) throws VascException {
DBCollection coll = getDBCollection();
DBObject query = new BasicDBObject();
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
query.put(key, value);
logger.finer("Setting query parameter key: '"+key+"' value: '"+value+"'");
}
DBCursor cur = coll.find(query);
//cur.count();
List<Object> result = new ArrayList<Object>(cur.count());
while (cur.hasNext()) {
DBObject row = cur.next();
result.add(row);
}
return result;
}
public void persist(Object object) throws VascException {
DBCollection coll = getDBCollection();
coll.insert((DBObject)object);
}
public Object merge(Object object) throws VascException {
DBCollection coll = getDBCollection();
DBObject row = (DBObject)object;
DBObject query = new BasicDBObject();
query.put("_id",row.get("_id"));
WriteResult wr = coll.update(query,row,false,false,WriteConcern.SAFE);
logger.info("WriteResult: "+wr);
return object;
}
public void delete(Object object) throws VascException {
DBCollection coll = getDBCollection();
DBObject query = new BasicDBObject();
query.put("_id",((DBObject)object).get("_id"));
coll.remove(query); // remove by _id
}
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
return new MongodbVascEntryFieldValue();
}
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
return new MongodbVascEntryRecordCreator();
}
private DBCollection getDBCollection() {
if (database!=null) {
return database.getCollection(collection);
}
if (connectionProvider==null) {
throw new RuntimeException("Can't get DBCollection from null connectionProvider.");
}
synchronized (connectionProvider) {
database = connectionProvider.getMongodbConnection();
}
return database.getCollection(collection);
}
/**
* @return the connectionProvider
*/
public MongodbConnectionProvider getConnectionProvider() {
return connectionProvider;
}
/**
* @param connectionProvider the connectionProvider to set
*/
public void setConnectionProvider(MongodbConnectionProvider connectionProvider) {
this.connectionProvider = connectionProvider;
}
/**
* @return the collection
*/
public String getCollection() {
return collection;
}
/**
* @param collection the collection to set
*/
public void setCollection(String collection) {
this.collection = collection;
}
}

View file

@ -0,0 +1,59 @@
/*
* 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.backend.mongodb;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
import com.mongodb.BasicDBObject;
/**
* Provides a mongodb field entry knowlege.
*
* @author Willem Cazander
* @version 1.0 Dec 30, 2011
*/
public class MongodbVascEntryFieldValue implements VascEntryFieldValue {
private static final long serialVersionUID = -7371273796529818557L;
public Object getValue(VascEntryField field, Object record) throws VascException {
BasicDBObject row = (BasicDBObject)record;
Object r = row.get(field.getBackendName());
if (r==null) {
return ""; // create new value, TODO
}
return r;
}
public String getDisplayValue(VascEntryField field, Object record) throws VascException {
return ""+getValue(field,record); // not supported TODO
}
public void setValue(VascEntryField field, Object record, Object value) throws VascException {
BasicDBObject row = (BasicDBObject)record;
row.put(field.getBackendName(), value);
}
}

View file

@ -0,0 +1,49 @@
/*
* 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.backend.mongodb;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
import com.mongodb.BasicDBObject;
/**
* Provides a mongodb object to create a new row.
*
* @author Willem Cazander
* @version 1.0 Dec 30, 2011
*/
public class MongodbVascEntryRecordCreator implements VascEntryRecordCreator {
private static final long serialVersionUID = -9213830731796787384L;
public Object newRecord(VascEntry entry) throws Exception {
return new BasicDBObject();
}
public Class<?> getObjectClass() {
return BasicDBObject.class;
}
}

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<eld:root xmlns:eld="http://eld.x4o.org/eld/eld-lang.eld">
<eld:elementClass tag="mongodbBackend" objectClassName="net.forwardfire.vasc.backend.mongodb.MongodbVascBackend">
<eld:elementConfigurator bean.class="net.forwardfire.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
</eld:elementClass>
<eld:elementClass tag="mongodbConnectionProvider" objectClassName="net.forwardfire.vasc.backend.mongodb.MongodbConnectionProviderImpl"/>
</eld:root>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>
Vasc namespace for the mongodb backend
</comment>
<entry key="eld.http://vasc.forwardfire.net/eld/vasc-backend-mongodb.eld">vasc-backend-mongodb.eld</entry>
</properties>