2
0
Fork 0

WIP: left over open files for long...

This commit is contained in:
Willem 2017-06-10 02:22:01 +02:00
parent 0a2398c5c1
commit 76aa74990e
165 changed files with 4299 additions and 3373 deletions

View file

@ -124,10 +124,6 @@
<!-- Java EE -->
<javaee-api.version>6.0</javaee-api.version>
<ejb-api.version>3.0</ejb-api.version>
<jta.version>1.1</jta.version>
<persistence-api.version>1.0.2</persistence-api.version>
<servlet-api.version>3.0-alpha-1</servlet-api.version>
<jsr181-api.version>1.0-MR1</jsr181-api.version> <!-- ws annotations -->
<jstl.version>1.2</jstl.version>
<jsp-api.version>2.2.1-b03</jsp-api.version>

View file

@ -35,3 +35,4 @@
- create XML-RPC frontend
- export interface + exports
- graphs of numeric value columns
- Add JETT export templates support

View file

@ -18,5 +18,6 @@
<module>vasc-backend-metamodel</module>
<module>vasc-backend-api</module>
<module>vasc-backend-test</module>
<module>vasc-backend-object</module>
</modules>
</project>

View file

@ -1,142 +0,0 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend;
import java.io.Serializable;
/**
* AbstractVascBackend.
*
*
* @author Willem Cazander
* @version 1.0 Aug 2, 2007
*/
abstract public class AbstractVascBackend<DATA_OBJECT extends Serializable> implements VascBackend<DATA_OBJECT> {
private String id = null;
/**
* @see net.forwardfire.vasc.backend.VascBackend#getId()
*/
@Override
public String getId() {
return id;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#setId(java.lang.String)
*/
@Override
public void setId(String id) {
if (id==null) {
throw new IllegalArgumentException("id may not be null");
}
this.id=id;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#startBackend()
*/
@Override
public void startBackend() {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#stopBackend()
*/
@Override
public void stopBackend() {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isReadOnly()
*/
@Override
public boolean isReadOnly() {
return false;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isPageable()
*/
@Override
public boolean isPageable() {
return false;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isSearchable()
*/
@Override
public boolean isSearchable() {
return false;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isSortable()
*/
@Override
public boolean isSortable() {
return false;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isRecordMoveable()
*/
@Override
public boolean isRecordMoveable() {
return false;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#doRecordMoveDownById(java.lang.Object)
*/
@Override
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascBackendException {
return 0l;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#doRecordMoveUpById(java.lang.Object)
*/
@Override
public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascBackendException {
return 0l;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#hasPageSummary()
*/
@Override
public boolean hasPageSummary() {
return false;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#hasTotalSummary()
*/
@Override
public boolean hasTotalSummary() {
return false;
}
}

View file

@ -22,14 +22,12 @@
package net.forwardfire.vasc.backend;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* AbstractVascBackendControllerLocal
*
@ -38,18 +36,16 @@ import java.util.Map;
*/
abstract public class AbstractVascBackendControllerLocal implements VascBackendControllerLocal {
private Map<String,VascBackend<Serializable>> backends = null;
private Map<String,VascBackend> backends = null;
public AbstractVascBackendControllerLocal() {
backends = new HashMap<String,VascBackend<Serializable>>(1000);
backends = new HashMap<String,VascBackend>(1000);
}
/**
* @see net.forwardfire.vasc.backend.VascBackendController#getVascBackendById(java.lang.String)
*/
@Override
public VascBackend<Serializable> getVascBackendById(String id) {
return backends.get(id);
@SuppressWarnings("unchecked")
public <BACKEND_TYPE extends VascBackend> BACKEND_TYPE getVascBackendById(Class<BACKEND_TYPE> clazz,String id) {
return (BACKEND_TYPE) backends.get(id);
}
/**
@ -66,42 +62,47 @@ abstract public class AbstractVascBackendControllerLocal implements VascBackendC
}
/**
* @see net.forwardfire.vasc.backend.VascBackendControllerLocal#addVascBackend(net.forwardfire.vasc.backend.VascBackend)
* @see net.forwardfire.vasc.backend.VascBackendControllerLocal#addVascBackend(net.forwardfire.vasc.backend.crud.VascBackendCrud)
*/
@SuppressWarnings("unchecked")
@Override
public void addVascBackend(VascBackend<? extends Serializable> backend) {
public void addVascBackend(VascBackend backend) {
if (backend==null) {
throw new NullPointerException("backend must not be null.");
}
if (backend.getId()==null) {
throw new IllegalArgumentException("The backend must have an id.");
}
backend.startBackend();
VascBackend<Serializable> castedBackend = (VascBackend<Serializable>) backend;
backends.put(backend.getId(), castedBackend);
backends.put(backend.getId(), backend);
}
/**
* @see net.forwardfire.vasc.backend.VascBackendControllerLocal#removeVascBackendById(java.lang.String)
*/
@Override
public void removeVascBackendById(String backendId) {
VascBackend<? extends Serializable> backend = getVascBackendById(backendId);
if (backend==null) {
throw new NullPointerException("Could not find backend to remove with id: "+backendId);
public VascBackend removeVascBackend(VascBackend backend) {
VascBackend result = getVascBackendById(VascBackend.class,backend.getId());
if (result==null) {
throw new NullPointerException("Could not find backend to remove with id: "+backend.getId());
}
backend.stopBackend();
backends.remove(backendId);
return backends.remove(backend.getId());
}
/**
* @see net.forwardfire.vasc.backend.VascBackendControllerLocal#clearAndStopBackends()
*/
@Override
public void clearAndStopBackends() {
public void stopBackends() {
for (String backendId:getVascBackendIds()) {
removeVascBackendById(backendId);
VascBackend vb = getVascBackendById(VascBackend.class,backendId);
if (vb instanceof VascBackendLocal) {
VascBackendLocal vbl = (VascBackendLocal)vb;
vbl.stopBackend();
}
}
}
@Override
public void startBackends() {
for (String backendId:getVascBackendIds()) {
VascBackend vb = getVascBackendById(VascBackend.class,backendId);
if (vb instanceof VascBackendLocal) {
VascBackendLocal vbl = (VascBackendLocal)vb;
vbl.startBackend();
}
}
}
}

View file

@ -0,0 +1,87 @@
package net.forwardfire.vasc.backend;
import java.io.Serializable;
import java.util.Collection;
import java.util.Objects;
abstract public class AbstractVascBackendLocal<DATA_PK extends Serializable> implements VascBackendLocal<DATA_PK> {
private static final String CHECK_MSG_ID = " in ";
private String id = null;
private volatile boolean running = false;
/**
* @see net.forwardfire.vasc.backend.crud.VascBackend#getId()
*/
@Override
final public String getId() {
return id;
}
/**
* @see net.forwardfire.vasc.backend.crud.VascBackendLocal#setId(java.lang.String)
*/
@Override
final public void setId(String id) {
if (id==null) {
throw new IllegalArgumentException("id may not be null");
}
if (this.id!=null) {
throw new IllegalStateException("Can't change id after setting.");
}
this.id=id;
}
abstract protected void startBackendLocal();
protected void stopBackendLocal() {
}
/**
* @see net.forwardfire.vasc.backend.crud.VascBackendLocal#startBackend()
*/
@Override
final public void startBackend() {
requireNonEmpty(getId(),"id is empty.");
startBackendLocal();
running = true;
}
/**
* @see net.forwardfire.vasc.backend.crud.VascBackendLocal#stopBackend()
*/
@Override
final public void stopBackend() {
stopBackendLocal();
running = false;
}
/**
* @see net.forwardfire.vasc.backend.VascBackendLifeCycle#isRunning()
*/
@Override
final public boolean isRunning() {
return running;
}
final private String createCheckMessage(String message) {
return message + CHECK_MSG_ID + getId();
}
final protected void requireNonNull(Object value, String message) {
Objects.requireNonNull(value, createCheckMessage(message));
}
final protected void requireNonEmpty(String value, String message) {
requireNonNull(value, message);
if (value.isEmpty()) {
throw new IllegalArgumentException(createCheckMessage(message));
}
}
final protected void requireNonEmpty(Collection<?> value, String message) {
requireNonNull(value, message);
if (value.isEmpty()) {
throw new IllegalArgumentException(createCheckMessage(message));
}
}
}

View file

@ -0,0 +1,8 @@
package net.forwardfire.vasc.backend;
import java.io.Serializable;
public abstract interface AbstractVascBackendRecord <K extends Serializable,T extends Serializable> extends VascBackend<K> {
VascBackendAccessDataRecord<K,T> createVascBackendAccessDataRecord();
}

View file

@ -1,96 +1,10 @@
/*
* 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;
import java.io.Serializable;
/**
* VascBackend provides stateless data access to a data source.
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
*/
public interface VascBackend<DATA_OBJECT extends Serializable> {
public interface VascBackend <DATA_PK extends Serializable> {
String getId();
void setId(String id);
void startBackend();
void stopBackend();
VascBackendResult<DATA_OBJECT> execute(VascBackendState state) throws VascBackendException;
boolean isReadOnly();
//public DATA_OBJECT fetch(Map<String,Serializable> pks) throws VascBackendException;
void persist(DATA_OBJECT record) throws VascBackendException;
DATA_OBJECT merge(DATA_OBJECT record) throws VascBackendException;
void delete(DATA_OBJECT record) throws VascBackendException;
/**
* Creates a new Field acces obj the the given field entry.
* note: Do not use inline class here because it needs to be seriabable and the backend is not seriabbzle.
* @return
*/
VascEntryFieldValue<DATA_OBJECT> provideVascEntryFieldValue();
/**
* Creates a new RecordCreater obj the the given entry.
* note: Do not use inline class here because it needs to be seriabable and the backend is not seriabbzle.
* @return
*/
VascEntryRecordCreator<DATA_OBJECT> provideVascEntryRecordCreator();
/**
* Defines if the backend supports sorting
* @return
*/
boolean isSortable();
/**
* Defines if the backend supports pageing
* @return
*/
boolean isPageable();
/**
* Defines if the backend supports pageing
* @return
*/
boolean isSearchable();
/**
* Defines if the backend supports moveing an record up or down.
* @return
*/
boolean isRecordMoveable();
long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascBackendException;
long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascBackendException;
boolean hasPageSummary();
boolean hasTotalSummary();
VascBackendAccessDataKey<DATA_PK> createVascBackendAccessDataKey();
}

View file

@ -23,28 +23,21 @@
package net.forwardfire.vasc.backend;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* DefaultVascBackendResult.
* VascEntryFieldValue
*
* @author Willem Cazander
* @version 1.0 Aug 23, 2014
* @version 1.0 Oct 24, 2014
*/
public final class DefaultVascBackendResult<DATA_OBJECT extends Serializable> extends AbstractVascBackendResult<DATA_OBJECT> {
public interface VascBackendAccessDataKey<DATA_PK extends Serializable> extends Serializable {
public DefaultVascBackendResult(List<DATA_OBJECT> pageData) {
this(pageData,-1);
}
Map<String,Class<?>> getKeyMapType();
Map<String,Serializable> getKeyMapFromPrimaryKey(DATA_PK primaryKey) throws VascBackendException;
DATA_PK getPrimaryKeyFromKeyMap(Map<String,Serializable> keyMap) throws VascBackendException;
public DefaultVascBackendResult(List<DATA_OBJECT> pageData,long totalSize) {
this(pageData,totalSize,null,null);
}
public DefaultVascBackendResult(List<DATA_OBJECT> pageData, long totalSize,
Map<String, Serializable> pageSummary,
Map<String, Serializable> totalSummary) {
super(pageData, totalSize, pageSummary, totalSummary);
}
Map<String,String> getStringMapFromPrimaryKey(DATA_PK primaryKey) throws VascBackendException;
DATA_PK getPrimaryKeyFromStringMap(Map<String,String> keyMap) throws VascBackendException;
}

View file

@ -31,11 +31,11 @@ import java.io.Serializable;
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
*/
public interface VascEntryFieldValue<DATA_OBJECT extends Serializable> extends Serializable {
public interface VascBackendAccessDataRecord<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends Serializable {
Serializable getValue(String backendName,DATA_OBJECT record) throws VascBackendException;
DATA_PK getPrimaryKey(DATA_RECORD record) throws VascBackendException;
String getDisplayValue(String backendName,DATA_OBJECT record) throws VascBackendException;
Serializable getValue(String backendName,DATA_RECORD record) throws VascBackendException;
void setValue(String backendName,DATA_OBJECT record,Serializable value) throws VascBackendException;
void setValue(String backendName,DATA_RECORD record,Serializable value) throws VascBackendException;
}

View file

@ -22,18 +22,17 @@
package net.forwardfire.vasc.backend;
import java.io.Serializable;
import java.util.List;
/**
* VascBackendController.
*
* @author Willem Cazander
* @version 1.0 Sep 4, 2008
*/
public interface VascBackendController {
VascBackend<Serializable> getVascBackendById(String id);
<BACKEND_TYPE extends VascBackend> BACKEND_TYPE getVascBackendById(Class<BACKEND_TYPE> clazz,String id);
List<String> getVascBackendIds();
}

View file

@ -22,9 +22,6 @@
package net.forwardfire.vasc.backend;
import java.io.Serializable;
/**
*
* @author Willem Cazander
@ -32,9 +29,11 @@ import java.io.Serializable;
*/
public interface VascBackendControllerLocal extends VascBackendController {
void addVascBackend(VascBackend<? extends Serializable> backend);
void addVascBackend(VascBackend backend);
void removeVascBackendById(String backendId);
VascBackend removeVascBackend(VascBackend backend);
void clearAndStopBackends();
void startBackends();
void stopBackends();
}

View file

@ -0,0 +1,10 @@
package net.forwardfire.vasc.backend;
import java.io.Serializable;
public interface VascBackendLifeCycle<DATA_PK extends Serializable> extends VascBackend<DATA_PK> {
void startBackend();
void stopBackend();
boolean isRunning();
}

View file

@ -0,0 +1,8 @@
package net.forwardfire.vasc.backend;
import java.io.Serializable;
public interface VascBackendLocal<DATA_PK extends Serializable> extends VascBackendLifeCycle<DATA_PK> {
void setId(String id);
}

View file

@ -20,26 +20,28 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend.crud;
package net.forwardfire.vasc.backend.mongodb;
import java.io.Serializable;
import net.forwardfire.vasc.backend.AbstractVascBackendRecord;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
import com.mongodb.BasicDBObject;
/**
* Provides a mongodb object to create a new row.
* VascBackendCrud provides stateless data access to a data source.
*
* @author Willem Cazander
* @version 1.0 Dec 30, 2011
* @version 1.0 Mar 21, 2007
*/
public class MongodbVascEntryRecordCreator implements VascEntryRecordCreator<BasicDBObject> {
public interface VascBackendCrud<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends AbstractVascBackendRecord<DATA_PK,DATA_RECORD> {
private static final long serialVersionUID = -9213830731796787384L;
public DATA_RECORD fetch(DATA_PK recordPK) throws VascBackendException;
@Override
public BasicDBObject newRecord() throws VascBackendException {
return new BasicDBObject();
}
DATA_RECORD persist(DATA_RECORD record) throws VascBackendException;
DATA_RECORD merge(DATA_RECORD record) throws VascBackendException;
void delete(DATA_PK recordPK) throws VascBackendException;
DATA_RECORD newRecord() throws VascBackendException;
}

View file

@ -20,26 +20,24 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend.data;
package net.forwardfire.vasc.backend.crud;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
/**
* MapVascEntryRecordCreator creates a new HashMap for Map based record backends.
* VascBackendCrudRevision idea test.
*
* @author Willem Cazander
* @version 1.0 Dec 05, 2009
* @version 1.0 Mar 25, 2014
*/
public class HashMapVascEntryRecordCreator implements VascEntryRecordCreator<HashMap<String,Serializable>> {
public interface VascBackendCrudRevision<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends VascBackendCrud<DATA_PK,DATA_RECORD> {
private static final long serialVersionUID = 1L;
List<?> revisionList(DATA_PK recordPK) throws VascBackendException;
@Override
public HashMap<String,Serializable> newRecord() throws VascBackendException {
return new HashMap<String,Serializable>(10);
}
void revisionDelete(String version) throws VascBackendException;
DATA_RECORD revisionFetch(DATA_PK recordPK,String version) throws VascBackendException;
}

View file

@ -0,0 +1,8 @@
/**
*
*/
/**
* @author willemc
*
*/
package net.forwardfire.vasc.backend.crud;

View file

@ -20,38 +20,35 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend.mongodb;
package net.forwardfire.vasc.backend.data;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import net.forwardfire.vasc.backend.VascBackendAccessDataKey;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import com.mongodb.BasicDBObject;
/**
* Provides a mongodb field entry knowlege.
* AbstractVascBackendAccessDataKey.
* note: all types need to have a String constructor ot
*
* @author Willem Cazander
* @version 1.0 Dec 30, 2011
* @version 1.0 Oct 27, 2014
*/
public class MongodbVascEntryFieldValue implements VascEntryFieldValue<BasicDBObject> {
@SuppressWarnings("serial")
abstract public class AbstractVascBackendAccessDataKey<DATA_PK extends Serializable> implements VascBackendAccessDataKey<DATA_PK> {
private static final long serialVersionUID = -7371273796529818557L;
private final Map<String,Class<?>> keyMapType;
@Override
public Serializable getValue(String backendName, BasicDBObject row) throws VascBackendException {
Serializable data = (Serializable) row.get(backendName);
return data;
public AbstractVascBackendAccessDataKey(Map<String,Class<?>> keyMapType) {
this.keyMapType = keyMapType;
}
@Override
public String getDisplayValue(String field, BasicDBObject row) throws VascBackendException {
return ""+getValue(field,row);
}
@Override
public void setValue(String backendName, BasicDBObject row, Serializable value) throws VascBackendException {
row.put(backendName, value);
public final Map<String, Class<?>> getKeyMapType() {
return keyMapType;
}
}

View file

@ -0,0 +1,75 @@
/*
* 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.data;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import net.forwardfire.vasc.backend.VascBackendAccessDataKey;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import org.x4o.xml.element.DefaultElementObjectPropertyValue;
/**
* BeanVascBackendAccessDataKey provides primary key support on beans.
*
* @author Willem Cazander
* @version 1.0 Oct 27, 2014
*/
@SuppressWarnings("serial")
public class BeanVascBackendAccessDataKey<DATA_PK extends Serializable> extends AbstractVascBackendAccessDataKey<DATA_PK> {
private final Class<?> primaryKeyType;
private final DefaultElementObjectPropertyValue bean = new DefaultElementObjectPropertyValue();
public BeanVascBackendAccessDataKey(Class<?> primaryKeyType,Map<String,Class<?>> keyMapType) {
super(keyMapType);
this.primaryKeyType=primaryKeyType;
}
@Override
public Map<String, Serializable> getKeyMapFromPrimaryKey(DATA_PK primaryKey) throws VascBackendException {
Map<String, Serializable> result = new HashMap<String, Serializable>();
return result;
}
@Override
public DATA_PK getPrimaryKeyFromKeyMap(Map<String, Serializable> keyMap) throws VascBackendException {
//DATA_PK result = primaryKeyType.newInstance();
return null;
}
@Override
public Map<String, String> getStringMapFromPrimaryKey(DATA_PK primaryKey) throws VascBackendException {
return null;
}
@Override
public DATA_PK getPrimaryKeyFromStringMap(Map<String, String> keyMap) throws VascBackendException {
return null;
}
}

View file

@ -26,26 +26,40 @@ package net.forwardfire.vasc.backend.data;
import java.io.Serializable;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import org.x4o.xml.element.DefaultElementObjectPropertyValue;
/**
* BeanVascEntryFieldValue provides get/set support for bean based backends.
* BeanVascBackendAccessDataRecord provides get/set support for bean based backends.
*
* @author Willem Cazander
* @version 1.0 Dec 05, 2009
*/
public class BeanVascEntryFieldValue<DATA_OBJECT extends Serializable> implements VascEntryFieldValue<DATA_OBJECT> {
@SuppressWarnings("serial")
public class BeanVascBackendAccessDataRecord<DATA_PK extends Serializable,DATA_RECORD extends Serializable> implements VascBackendAccessDataRecord<DATA_PK,DATA_RECORD> {
private static final long serialVersionUID = 1L;
private final String primaryKeyProperty;
private DefaultElementObjectPropertyValue bean = new DefaultElementObjectPropertyValue();
public BeanVascBackendAccessDataRecord(String primaryKeyProperty) {
this.primaryKeyProperty = primaryKeyProperty;
}
/**
* @see net.forwardfire.vasc.core.entry.VascEntryFieldValue#getValue(java.lang.String, java.lang.Object)
* @see net.forwardfire.vasc.backend.VascBackendAccessDataRecord#getPrimaryKey(java.io.Serializable)
*/
@Override
public Serializable getValue(String backendName, DATA_OBJECT record) throws VascBackendException {
@SuppressWarnings("unchecked")
public DATA_PK getPrimaryKey(DATA_RECORD record) throws VascBackendException {
return (DATA_PK) getValue(primaryKeyProperty, record);
}
/**
* @see net.forwardfire.vasc.core.entry.VascBackendAccessDataRecord#getValue(java.lang.String, java.lang.Object)
*/
@Override
public Serializable getValue(String backendName, DATA_RECORD record) throws VascBackendException {
if (backendName==null) {
throw new NullPointerException("Can't get value of null backendName.");
}
@ -61,40 +75,10 @@ public class BeanVascEntryFieldValue<DATA_OBJECT extends Serializable> implement
}
/**
* @see net.forwardfire.vasc.core.entry.VascEntryFieldValue#getDisplayValue(java.lang.String, java.lang.Object)
* @see net.forwardfire.vasc.core.entry.VascBackendAccessDataRecord#setValue(java.lang.String, java.lang.Object, java.lang.Object)
*/
@Override
public String getDisplayValue(String backendName, DATA_OBJECT record) throws VascBackendException {
Serializable value = getValue(backendName,record);
if (value==null) {
return "";
}
return value.toString();
/* TODO: move
if (field.getDisplayName()==null) {
if (value instanceof String) {
return (String)value;
}
return ""+value;
}
try {
Object result = bean.getProperty(value, field.getDisplayName());
if (result instanceof String) {
return (String)result;
}
return ""+result;
} catch (Exception e) {
throw new VascBackendException(e);
}
*/
}
/**
* @see net.forwardfire.vasc.core.entry.VascEntryFieldValue#setValue(java.lang.String, java.lang.Object, java.lang.Object)
*/
@Override
public void setValue(String backendName, DATA_OBJECT record,Serializable value) throws VascBackendException {
public void setValue(String backendName, DATA_RECORD record,Serializable value) throws VascBackendException {
if (backendName==null) {
throw new NullPointerException("Can't set value of null backendName.");
}

View file

@ -0,0 +1,104 @@
/*
* 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.data;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import net.forwardfire.vasc.backend.VascBackendException;
/**
* HashMapVascBackendAccessDataKey provides get/set support on Map key object.
* note: all types need to have a String constructor.
*
* @author Willem Cazander
* @version 1.0 Oct 26, 2014
*/
@SuppressWarnings("serial")
public class HashMapVascBackendAccessDataKey extends AbstractVascBackendAccessDataKey<HashMap<String,Serializable>> {
public HashMapVascBackendAccessDataKey(Map<String,Class<?>> keyMapType) {
super(keyMapType);
}
@Override
public Map<String, Serializable> getKeyMapFromPrimaryKey(HashMap<String, Serializable> primaryKey) throws VascBackendException {
return new HashMap<String, Serializable>(primaryKey); // wrap only as key is already object map
}
@Override
public HashMap<String, Serializable> getPrimaryKeyFromKeyMap(Map<String, Serializable> keyMap) throws VascBackendException {
return new HashMap<String, Serializable>(keyMap); // wrap only as key is already object map
}
@Override
public Map<String, String> getStringMapFromPrimaryKey(HashMap<String, Serializable> primaryKey) throws VascBackendException {
HashMap<String,String> result = new HashMap<String,String>(primaryKey.size());
for (String key:primaryKey.keySet()) {
Serializable value = primaryKey.get(key);
if (value == null) {
result.put(key, null);
} else {
result.put(key, value.toString());
}
}
return result;
}
@Override
public HashMap<String, Serializable> getPrimaryKeyFromStringMap(Map<String, String> keyMap) throws VascBackendException {
try {
HashMap<String,Serializable> result = new HashMap<String,Serializable>(keyMap.size());
for (String key:keyMap.keySet()) {
String valueStr = keyMap.get(key);
Class<?> valueType = getKeyMapType().get(key);
if (valueType == null) {
throw new IllegalArgumentException("unknown key: "+key);
}
if (valueStr == null) {
result.put(key, null);
continue;
}
Constructor<?> valueObj = valueType.getConstructor(new Class<?>[]{String.class});
Object value = valueObj.newInstance(new Object[]{valueStr});
result.put(key, (Serializable)value);
}
return result;
} catch (NoSuchMethodException e) {
throw new VascBackendException(e);
} catch (SecurityException e) {
throw new VascBackendException(e);
} catch (InstantiationException e) {
throw new VascBackendException(e);
} catch (IllegalAccessException e) {
throw new VascBackendException(e);
} catch (IllegalArgumentException e) {
throw new VascBackendException(e);
} catch (InvocationTargetException e) {
throw new VascBackendException(e);
}
}
}

View file

@ -24,22 +24,40 @@ package net.forwardfire.vasc.backend.data;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
/**
* MapVascEntryFieldValue provides get/set support on Map record object.
* HashMapVascBackendAccessDataRecord provides get/set support on Map record object.
*
* @author Willem Cazander
* @version 1.0 Dec 05, 2009
*/
public class HashMapVascEntryFieldValue implements VascEntryFieldValue<HashMap<String,Serializable>> {
@SuppressWarnings("serial")
public class HashMapVascBackendAccessDataRecord implements VascBackendAccessDataRecord<HashMap<String,Serializable>,HashMap<String,Serializable>> {
private static final long serialVersionUID = 1L;
private final Map<String,Class<?>> keyMapType;
public HashMapVascBackendAccessDataRecord(Map<String,Class<?>> keyMapType) {
this.keyMapType = keyMapType;
}
/**
* @see net.forwardfire.vasc.core.entry.VascEntryFieldValue#getValue(java.lang.String, java.lang.Object)
* @see net.forwardfire.vasc.backend.VascBackendAccessDataRecord#getPrimaryKey(java.io.Serializable)
*/
@Override
public HashMap<String, Serializable> getPrimaryKey(HashMap<String, Serializable> record) throws VascBackendException {
HashMap<String, Serializable> result = new HashMap<String, Serializable>(keyMapType.size());
for (String key:keyMapType.keySet()) {
result.put(key, record.get(key));
}
return result;
}
/**
* @see net.forwardfire.vasc.core.entry.VascBackendAccessDataRecord#getValue(java.lang.String, java.lang.Object)
*/
@Override
public Serializable getValue(String backendName,HashMap<String,Serializable> map) throws VascBackendException {
@ -54,19 +72,7 @@ public class HashMapVascEntryFieldValue implements VascEntryFieldValue<HashMap<S
}
/**
* @see net.forwardfire.vasc.core.entry.VascEntryFieldValue#getDisplayValue(net.forwardfire.vasc.core.VascEntryField, java.lang.Object)
*/
@Override
public String getDisplayValue(String field, HashMap<String,Serializable> record) throws VascBackendException {
Serializable fieldValue = getValue(field,record);
if (fieldValue==null) {
fieldValue = "";
}
return fieldValue.toString();
}
/**
* @see net.forwardfire.vasc.core.entry.VascEntryFieldValue#setValue(java.lang.String, java.lang.Object, java.lang.Object)
* @see net.forwardfire.vasc.core.entry.VascBackendAccessDataRecord#setValue(java.lang.String, java.lang.Object, java.lang.Object)
*/
@Override
public void setValue(String backendName, HashMap<String,Serializable> map,Serializable value) throws VascBackendException {

View file

@ -20,20 +20,23 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend;
package net.forwardfire.vasc.backend.list;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* Holds the state for the backend
*
* @author Willem Cazander
* @version 1.0 May 26, 2009
*/
abstract public class AbstractVascBackendState implements VascBackendState {
@SuppressWarnings("serial")
public class DefaultVascBackendListRequest implements VascBackendListRequest {
private static final long serialVersionUID = 1L;
protected Map<String,Object> parameters = null;
private int pageIndex = 0;
private int pageSize = 0;
@ -41,38 +44,25 @@ abstract public class AbstractVascBackendState implements VascBackendState {
private String sortField = null;
private String searchString = null;
private boolean ascending = true;
//private long pagesTotalRecords = 0;
public AbstractVascBackendState() {
public DefaultVascBackendListRequest() {
parameters = new HashMap<String,Object>(10);
}
/**
* @see net.forwardfire.vasc.backend.VascBackendState#setDataParameter(java.lang.String, java.lang.Object)
*/
@Override
public void setDataParameter(String key, Object data) {
parameters.put(key,data);
}
/**
* @see net.forwardfire.vasc.backend.VascBackendState#removeDataParameter(java.lang.String)
*/
@Override
public void removeDataParameter(String key) {
parameters.remove(key);
}
/**
* @see net.forwardfire.vasc.backend.VascBackendState#removeDataParameterAll()
*/
@Override
public void removeDataParameterAll() {
parameters.clear();
}
/**
* @see net.forwardfire.vasc.backend.VascBackendState#getDataParameter(java.lang.String)
* @see net.forwardfire.vasc.backend.list.VascBackendListRequest#getDataParameter(java.lang.String)
*/
@Override
public Object getDataParameter(String key) {
@ -80,7 +70,7 @@ abstract public class AbstractVascBackendState implements VascBackendState {
}
/**
* @see net.forwardfire.vasc.backend.VascBackendState#getDataParameterKeys()
* @see net.forwardfire.vasc.backend.list.VascBackendListRequest#getDataParameterKeys()
*/
@Override
public Set<String> getDataParameterKeys() {
@ -88,81 +78,61 @@ abstract public class AbstractVascBackendState implements VascBackendState {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#getPageIndex()
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#getPageIndex()
*/
@Override
public int getPageIndex() {
return pageIndex;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#setPageIndex(int)
*/
@Override
public void setPageIndex(int pageIndex) {
this.pageIndex=pageIndex;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#getPageSize()
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#getPageSize()
*/
@Override
public int getPageSize() {
return pageSize;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#setPageSize(int)
*/
@Override
public void setPageSize(int pageSize) {
this.pageSize=pageSize;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#getSearchString()
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#getSearchString()
*/
@Override
public String getSearchString() {
return searchString;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#setSearchString(java.lang.String)
*/
@Override
public void setSearchString(String searchString) {
this.searchString=searchString;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isSortAscending()
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#isSortAscending()
*/
@Override
public boolean isSortAscending() {
return ascending;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#setSortAscending(boolean)
*/
@Override
public void setSortAscending(boolean ascending) {
this.ascending=ascending;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#getSortField()
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#getSortField()
*/
@Override
public String getSortField() {
return sortField;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#setSortField(java.lang.String)
*/
@Override
public void setSortField(String sortField) {
this.sortField=sortField;
}
@ -175,10 +145,6 @@ abstract public class AbstractVascBackendState implements VascBackendState {
return pageSizeMax;
}
/**
* @param pageSizeMax the pageSizeMax to set
*/
@Override
public void setPageSizeMax(int pageSizeMax) {
this.pageSizeMax = pageSizeMax;
}

View file

@ -20,61 +20,60 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend;
package net.forwardfire.vasc.backend.list;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* AbstractVascBackendResult.
* DefaultVascBackendResult.
*
* @author Willem Cazander
* @version 1.0 Aug 23, 2014
*/
abstract public class AbstractVascBackendResult<DATA_OBJECT extends Serializable> implements VascBackendResult<DATA_OBJECT> {
@SuppressWarnings("serial")
public final class DefaultVascBackendListResult<DATA_OBJECT extends Serializable> implements VascBackendListResult<DATA_OBJECT> {
private final List<DATA_OBJECT> pageData;
private final long totalSize;
private final Map<String, Serializable> pageSummary;
private final Map<String, Serializable> totalSummary;
private final List<DATA_OBJECT> data;
private final long totalRecordCount;
private final Map<String,Map<String,Serializable>> dataExtra;
public AbstractVascBackendResult(List<DATA_OBJECT> pageData,long totalSize,Map<String, Serializable> pageSummary,Map<String, Serializable> totalSummary) {
this.pageData = pageData;
this.totalSize = totalSize;
this.pageSummary = pageSummary;
this.totalSummary = totalSummary;
public DefaultVascBackendListResult(List<DATA_OBJECT> data) {
this(data,data.size());
}
public DefaultVascBackendListResult(List<DATA_OBJECT> data,long totalRecordCount) {
this(data,totalRecordCount,null);
}
public DefaultVascBackendListResult(List<DATA_OBJECT> data,long totalRecordCount,Map<String,Map<String,Serializable>> dataExtra) {
this.data = data;
this.totalRecordCount = totalRecordCount;
this.dataExtra = dataExtra;
}
/**
* @see net.forwardfire.vasc.backend.VascBackendResult#getPageData()
* @see net.forwardfire.vasc.backend.list.VascBackendListResult#getData()
*/
@Override
public List<DATA_OBJECT> getPageData() {
return pageData;
public List<DATA_OBJECT> getData() {
return data;
}
/**
* @see net.forwardfire.vasc.backend.VascBackendResult#getTotalSize()
* @see net.forwardfire.vasc.backend.list.VascBackendListResult#getTotalRecordCount()
*/
@Override
public long getTotalSize() {
return totalSize;
public long getTotalRecordCount() {
return totalRecordCount;
}
/**
* @see net.forwardfire.vasc.backend.VascBackendResult#getPageSummary()
* @see net.forwardfire.vasc.backend.list.VascBackendListResult#getDataExtra()
*/
@Override
public Map<String, Serializable> getPageSummary() {
return pageSummary;
}
/**
* @see net.forwardfire.vasc.backend.VascBackendResult#getTotalSummary()
*/
@Override
public Map<String, Serializable> getTotalSummary() {
return totalSummary;
public Map<String,Map<String,Serializable>> getDataExtra() {
return dataExtra;
}
}

View file

@ -0,0 +1,71 @@
/*
* 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.list;
import java.io.Serializable;
import java.util.EnumSet;
import java.util.List;
import net.forwardfire.vasc.backend.AbstractVascBackendRecord;
import net.forwardfire.vasc.backend.VascBackendException;
/**
* VascBackendList provides stateless data access to a data source which result one or multiple results.
*
* @author Willem Cazander
* @version 1.0 Aug 25, 2014
*/
public interface VascBackendList<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends AbstractVascBackendRecord<DATA_PK,DATA_RECORD> {
final static String ROW_ACTION_MOVE_UP = "rowActionMoveUp";
final static String ROW_ACTION_MOVE_DOWN = "rowActionMoveDown";
final static String ROW_ACTION_DELETE = "rowActionDelete";
/**
* Defines the features this list backend supports.
* @return An enum set of feature flags.
*/
EnumSet<VascBackendListFeature> getSupportedFeatures();
/**
* Executes the list request with parameters to return a list result.
* @param request
* @return
* @throws VascBackendException
*/
VascBackendListResult<DATA_RECORD> execute(VascBackendListRequest request) throws VascBackendException;
/**
* @return Returns the action names of the row actions we support.
*/
List<String> getSupportedRowActions();
/**
* Executes a single row action on one or more rows of fresh data.
* @param request
* @param recordPKs
* @param actionName
* @throws VascBackendException
*/
void executeRowAction(VascBackendListRequest request,List<DATA_PK> recordPKs,String actionName) throws VascBackendException;
}

View file

@ -20,16 +20,28 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend;
package net.forwardfire.vasc.backend.list;
/**
* Holds the state for the backend
* VascBackendListFeatures.
*
* @author Willem Cazander
* @version 1.0 May 26, 2009
* @version 1.0 Aug 26, 2014
*/
public class DefaultVascBackendState extends AbstractVascBackendState {
public enum VascBackendListFeature {
private static final long serialVersionUID = 8828343641448595993L;
/** Defines if the backend supports sorting. */
SORT_DATA,
SORT_DATA_PROXY,
/** Defines if the backend supports paging. */
PAGE_DATA,
PAGE_DATA_PROXY,
/** Defines if the backend support full text search. */
TEXT_SEARCH,
TEXT_SEARCH_PROXY,
DATA_EXTRA,
DATA_EXTRA_PROXY;
}

View file

@ -20,7 +20,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend;
package net.forwardfire.vasc.backend.list;
import java.io.Serializable;
import java.util.Set;
@ -31,28 +31,20 @@ import java.util.Set;
* @author Willem Cazander
* @version 1.0 May 26, 2009
*/
public interface VascBackendState extends Serializable {
public interface VascBackendListRequest extends Serializable {
void setDataParameter(String key,Object data);
void removeDataParameter(String key);
void removeDataParameterAll();
Object getDataParameter(String key);
Set<String> getDataParameterKeys();
String getSortField();
void setSortField(String name);
boolean isSortAscending();
void setSortAscending(boolean ascending);
void setPageSize(int size);
boolean isSortAscending();
int getPageSize();
void setPageSizeMax(int size);
int getPageSizeMax();
void setPageIndex(int index);
int getPageIndex();
void setSearchString(String searchString);
String getSearchString();
}

View file

@ -20,7 +20,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend;
package net.forwardfire.vasc.backend.list;
import java.io.Serializable;
import java.util.List;
@ -32,10 +32,9 @@ import java.util.Map;
* @author Willem Cazander
* @version 1.0 Aug 23, 2014
*/
public interface VascBackendResult<DATA_OBJECT extends Serializable> {
public interface VascBackendListResult<DATA_OBJECT extends Serializable> extends Serializable {
List<DATA_OBJECT> getPageData();
long getTotalSize();
Map<String,Serializable> getPageSummary();
Map<String,Serializable> getTotalSummary();
List<DATA_OBJECT> getData();
long getTotalRecordCount();
Map<String,Map<String,Serializable>> getDataExtra();
}

View file

@ -0,0 +1,8 @@
/**
*
*/
/**
* @author willemc
*
*/
package net.forwardfire.vasc.backend.list;

View file

@ -0,0 +1,62 @@
package net.forwardfire.vasc.backend.select;
import java.io.Serializable;
public class DefaultVascBackendSelectItem<DATA_PK extends Serializable> implements VascBackendSelectItem<DATA_PK> {
private final boolean header;
private final boolean enabled;
private final String name;
private final boolean nameI18nKey;
private final String description;
private final boolean descriptionI18nKey;
private final DATA_PK primaryKey;
public DefaultVascBackendSelectItem(boolean header, boolean enabled,
String name, boolean nameI18nKey, String description,
boolean descriptionI18nKey, DATA_PK primaryKey) {
super();
this.header = header;
this.enabled = enabled;
this.name = name;
this.nameI18nKey = nameI18nKey;
this.description = description;
this.descriptionI18nKey = descriptionI18nKey;
this.primaryKey = primaryKey;
}
@Override
public boolean isHeader() {
return header;
}
@Override
public boolean isEnabled() {
return enabled;
}
@Override
public String getName() {
return name;
}
@Override
public boolean isNameI18nKey() {
return nameI18nKey;
}
@Override
public String getDescription() {
return description;
}
@Override
public boolean isDescriptionI18nKey() {
return descriptionI18nKey;
}
@Override
public DATA_PK getPrimaryKey() {
return primaryKey;
}
}

View file

@ -0,0 +1,12 @@
package net.forwardfire.vasc.backend.select;
import java.io.Serializable;
import java.util.List;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendException;
public interface VascBackendSelect<DATA_PK extends Serializable> extends VascBackend<DATA_PK> {
List<VascBackendSelectItem<DATA_PK>> execute() throws VascBackendException;
}

View file

@ -20,17 +20,22 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend;
package net.forwardfire.vasc.backend.select;
import java.io.Serializable;
/**
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
* @version 1.0 Aug 12, 2007
*/
public interface VascEntryRecordCreator<DATA_OBJECT extends Serializable> extends Serializable {
public interface VascBackendSelectItem<DATA_PK extends Serializable> {
DATA_OBJECT newRecord() throws VascBackendException;
boolean isHeader();
boolean isEnabled();
String getName();
boolean isNameI18nKey();
String getDescription();
boolean isDescriptionI18nKey();
DATA_PK getPrimaryKey();
}

View file

@ -0,0 +1,8 @@
/**
*
*/
/**
* @author willemc
*
*/
package net.forwardfire.vasc.backend.select;

View file

@ -0,0 +1,87 @@
/*
* 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.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import net.forwardfire.vasc.backend.AbstractVascBackendLocal;
import net.forwardfire.vasc.backend.VascBackendAccessDataKey;
import net.forwardfire.vasc.backend.data.HashMapVascBackendAccessDataKey;
/**
* AbstractJdbcVascBackend.
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
abstract public class AbstractJdbcVascBackend extends AbstractVascBackendLocal<HashMap<String,Serializable>> {
private JdbcConnectionProvider jdbcConnectionProvider = null;
private final Map<String,Class<?>> keyMapType = new HashMap<String,Class<?>>(5);
abstract protected void startBackendJdbc();
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackendLocal#startBackendLocal()
*/
@Override
protected final void startBackendLocal() {
requireNonNull(getJdbcConnectionProvider(), "jdbcConnectionProvider is null.");
requireNonEmpty(keyMapType.keySet(), "No primary keys defined.");
startBackendJdbc();
}
protected final void addKeyMapType(String field,Class<?> fieldType) {
requireNonEmpty(field,"field has to have value");
requireNonNull(fieldType,"field has to have value");
keyMapType.put(field, fieldType);
}
protected final Map<String,Class<?>> getKeyMapType() {
return keyMapType;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#createVascBackendAccessDataKey()
*/
@Override
public final VascBackendAccessDataKey<HashMap<String, Serializable>> createVascBackendAccessDataKey() {
return new HashMapVascBackendAccessDataKey(keyMapType);
}
/**
* @return the JdbcConnectionProvider
*/
public final JdbcConnectionProvider getJdbcConnectionProvider() {
return jdbcConnectionProvider;
}
/**
* @param JdbcConnectionProvider the JdbcConnectionProvider to set
*/
public final void setJdbcConnectionProvider(JdbcConnectionProvider jdbcConnectionProvider) {
this.jdbcConnectionProvider = jdbcConnectionProvider;
}
}

View file

@ -1,169 +0,0 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.backend.DefaultVascBackendResult;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
import net.forwardfire.vasc.backend.data.HashMapVascEntryFieldValue;
import net.forwardfire.vasc.backend.data.HashMapVascEntryRecordCreator;
/**
* JdbcVascBackend Simple jdbc vasc backend.
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class JdbcVascBackend extends AbstractVascBackend<HashMap<String,Object>> {
private JdbcConnectionProvider jdbcConnectionProvider = null;
private String sqlList = null;
//private String idColumn = null;
//private String sqlDelete = null;
//private String sqlUpdate = null;
//private String sqlInsert = null;
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isReadOnly()
*/
@Override
public boolean isReadOnly() {
return true;
}
/**
* @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)
*/
@Override
public VascBackendResult<HashMap<String,Object>> execute(VascBackendState state) throws VascBackendException {
JdbcConnectionProvider prov = getJdbcConnectionProvider();
List<HashMap<String,Object>> result = new ArrayList<HashMap<String,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()) {
HashMap<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 (SQLException e) {
throw new VascBackendException(e);
} finally {
if (connection!=null) {
try {
connection.close();
} catch (Exception e) {
}
}
}
return new DefaultVascBackendResult<HashMap<String,Object>>(result);
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#merge(java.lang.Object)
*/
@Override
public HashMap<String,Object> merge(HashMap<String,Object> object) throws VascBackendException {
return object;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object)
*/
@Override
public void persist(HashMap<String,Object> object) throws VascBackendException {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#delete(java.lang.Object)
*/
@Override
public void delete(HashMap<String,Object> object) throws VascBackendException {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue(net.forwardfire.vasc.core.VascEntryField)
*/
@Override
public VascEntryFieldValue provideVascEntryFieldValue() {
return new HashMapVascEntryFieldValue();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator(net.forwardfire.vasc.core.VascEntry)
*/
@Override
public VascEntryRecordCreator provideVascEntryRecordCreator() {
return new HashMapVascEntryRecordCreator();
}
/**
* @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,147 @@
/*
* 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.io.Serializable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.data.HashMapVascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendList;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
/**
* JdbcVascBackend Simple jdbc vasc backend.
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class JdbcVascBackendList extends AbstractJdbcVascBackend implements VascBackendList<HashMap<String,Serializable>,HashMap<String,Serializable>> {
private final EnumSet<VascBackendListFeature> features = EnumSet.noneOf(VascBackendListFeature.class);
private final List<String> rowActions = new ArrayList<String>();
private String query = null;
private String queryExtra = null;
@Override
protected void startBackendJdbc() {
requireNonEmpty(getQuery(), "query is empty.");
if (queryExtra!=null && !queryExtra.isEmpty()) {
features.add(VascBackendListFeature.DATA_EXTRA);
}
}
@Override
public VascBackendAccessDataRecord<HashMap<String, Serializable>, HashMap<String, Serializable>> createVascBackendAccessDataRecord() {
return new HashMapVascBackendAccessDataRecord(getKeyMapType());
}
@Override
public EnumSet<VascBackendListFeature> getSupportedFeatures() {
return features;
}
@Override
public List<String> getSupportedRowActions() {
return rowActions;
}
@Override
public void executeRowAction(VascBackendListRequest request,List<HashMap<String, Serializable>> recordPKs, String actionName) throws VascBackendException {
}
/**
* @see net.forwardfire.vasc.backend.crud.VascBackendList#execute(VascBackendListRequest state)
*/
@Override
public VascBackendListResult<HashMap<String,Serializable>> execute(VascBackendListRequest state) throws VascBackendException {
JdbcConnectionProvider prov = getJdbcConnectionProvider();
List<HashMap<String,Serializable>> result = new ArrayList<HashMap<String,Serializable>>(50);
Connection connection = null;
try {
connection = prov.getJdbcConnection();
Statement s = connection.createStatement();
s.execute(getQuery());
ResultSet rs = s.getResultSet();
int cols = rs.getMetaData().getColumnCount();
while (rs.next()) {
HashMap<String,Serializable> map = new HashMap<String,Serializable>(cols);
for (int i=1;i<=cols;i++) {
String columnName = rs.getMetaData().getColumnName(i);
Serializable columnObject = (Serializable) rs.getObject(i);
map.put(columnName, columnObject);
}
result.add(map);
}
} catch (SQLException e) {
throw new VascBackendException(e);
} finally {
if (connection!=null) {
try {
connection.close();
} catch (Exception e) {
}
}
}
return new DefaultVascBackendListResult<HashMap<String,Serializable>>(result);
}
/**
* @return the query
*/
public String getQuery() {
return query;
}
/**
* @param query the query to set
*/
public void setQuery(String query) {
this.query = query;
}
/**
* @return the queryExtra
*/
public String getQueryExtra() {
return queryExtra;
}
/**
* @param queryExtra the queryExtra to set
*/
public void setQueryExtra(String queryExtra) {
this.queryExtra = queryExtra;
}
}

View file

@ -0,0 +1,111 @@
/*
* 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.io.Serializable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.data.HashMapVascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendList;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.backend.select.VascBackendSelect;
import net.forwardfire.vasc.backend.select.VascBackendSelectItem;
/**
* JdbcVascBackend Simple jdbc vasc backend.
*
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class JdbcVascBackendSelect extends AbstractJdbcVascBackend implements VascBackendSelect<HashMap<String,Serializable>> {
private String query = null;
@Override
protected void startBackendJdbc() {
requireNonEmpty(getQuery(), "query is empty.");
}
@Override
public List<VascBackendSelectItem<HashMap<String, Serializable>>> execute() throws VascBackendException {
return null;
}
public VascBackendListResult<HashMap<String,Serializable>> execute(VascBackendListRequest state) throws VascBackendException {
JdbcConnectionProvider prov = getJdbcConnectionProvider();
List<HashMap<String,Serializable>> result = new ArrayList<HashMap<String,Serializable>>(50);
Connection connection = null;
try {
connection = prov.getJdbcConnection();
Statement s = connection.createStatement();
s.execute(getQuery());
ResultSet rs = s.getResultSet();
int cols = rs.getMetaData().getColumnCount();
while (rs.next()) {
HashMap<String,Serializable> map = new HashMap<String,Serializable>(cols);
for (int i=1;i<=cols;i++) {
String columnName = rs.getMetaData().getColumnName(i);
Serializable columnObject = (Serializable) rs.getObject(i);
map.put(columnName, columnObject);
}
result.add(map);
}
} catch (SQLException e) {
throw new VascBackendException(e);
} finally {
if (connection!=null) {
try {
connection.close();
} catch (Exception e) {
}
}
}
return new DefaultVascBackendListResult<HashMap<String,Serializable>>(result);
}
/**
* @return the query
*/
public String getQuery() {
return query;
}
/**
* @param query the query to set
*/
public void setQuery(String query) {
this.query = query;
}
}

View file

@ -20,25 +20,26 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend.jdbc;
package net.forwardfire.vasc.backend.jdbc.xpql;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.backend.DefaultVascBackendResult;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
import net.forwardfire.vasc.backend.data.HashMapVascEntryFieldValue;
import net.forwardfire.vasc.backend.data.HashMapVascEntryRecordCreator;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.jdbc.AbstractJdbcVascBackend;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendList;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.xpql.query.QueryParameterValue;
/**
@ -47,53 +48,46 @@ import net.forwardfire.vasc.xpql.query.QueryParameterValue;
* @author Willem Cazander
* @version 1.0 Sep 5, 2008
*/
public class JdbcVascBackendXpql extends AbstractVascBackend<HashMap<String,Object>> {
private JdbcConnectionProvider jdbcConnectionProvider = null;
public class JdbcVascBackendXpqlList extends AbstractJdbcVascBackend implements VascBackendList<HashMap<String,Serializable>,HashMap<String,Serializable>> {
private final EnumSet<VascBackendListFeature> features = EnumSet.noneOf(VascBackendListFeature.class);
private final List<String> rowActions = new ArrayList<String>();
private net.forwardfire.vasc.xpql.query.Query query = null;
private net.forwardfire.vasc.xpql.query.Query queryExtra = null;
@Override
protected void startBackendJdbc() {
requireNonNull(getQuery(), "query is null.");
if (queryExtra!=null) {
features.add(VascBackendListFeature.DATA_EXTRA);
}
}
@Override
public VascBackendAccessDataRecord<HashMap<String, Serializable>, HashMap<String, Serializable>> createVascBackendAccessDataRecord() {
// TODO Auto-generated method stub
return null;
}
@Override
public EnumSet<VascBackendListFeature> getSupportedFeatures() {
return features;
}
@Override
public List<String> getSupportedRowActions() {
return rowActions;
}
@Override
public void executeRowAction(VascBackendListRequest request,List<HashMap<String, Serializable>> recordPKs, String actionName) throws VascBackendException {
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isReadOnly()
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#execute(VascBackendListRequest state)
*/
@Override
public boolean isReadOnly() {
return true;
}
/**
* @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)
*/
@Override
public VascBackendResult<HashMap<String,Object>> execute(VascBackendState state) throws VascBackendException {
public VascBackendListResult<HashMap<String,Serializable>> execute(VascBackendListRequest state) throws VascBackendException {
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
@ -113,17 +107,17 @@ public class JdbcVascBackendXpql extends AbstractVascBackend<HashMap<String,Obje
q.execute();
ResultSet rs = q.getResultSet();
int cols = rs.getMetaData().getColumnCount();
List<HashMap<String,Object>> result = new ArrayList<HashMap<String,Object>>(50);
List<HashMap<String,Serializable>> result = new ArrayList<HashMap<String,Serializable>>(50);
while (rs.next()) {
HashMap<String,Object> map = new HashMap<String,Object>(cols);
HashMap<String,Serializable> map = new HashMap<String,Serializable>(cols);
for (int i=1;i<=cols;i++) {
String columnName = rs.getMetaData().getColumnName(i);
Object columnObject = rs.getObject(i);
Serializable columnObject = (Serializable) rs.getObject(i);
map.put(columnName, columnObject);
}
result.add(map);
}
return new DefaultVascBackendResult<HashMap<String,Object>>(result);
return new DefaultVascBackendListResult<HashMap<String,Serializable>>(result);
} catch (SQLException e) {
throw new VascBackendException(e);
} finally {
@ -137,40 +131,16 @@ public class JdbcVascBackendXpql extends AbstractVascBackend<HashMap<String,Obje
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#merge(java.lang.Object)
* @return the query
*/
@Override
public HashMap<String,Object> merge(HashMap<String,Object> object) throws VascBackendException {
return object;
public net.forwardfire.vasc.xpql.query.Query getQuery() {
return query;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object)
* @param query the query to set
*/
@Override
public void persist(HashMap<String,Object> object) throws VascBackendException {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#delete(java.lang.Object)
*/
@Override
public void delete(HashMap<String,Object> object) throws VascBackendException {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue()
*/
@Override
public VascEntryFieldValue provideVascEntryFieldValue() {
return new HashMapVascEntryFieldValue();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator()
*/
@Override
public VascEntryRecordCreator provideVascEntryRecordCreator() {
return new HashMapVascEntryRecordCreator();
public void setQuery(net.forwardfire.vasc.xpql.query.Query query) {
this.query = query;
}
}

View file

@ -0,0 +1,8 @@
/**
*
*/
/**
* @author willemc
*
*/
package net.forwardfire.vasc.backend.jdbc.xpql;

View file

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vasc-backend</artifactId>
@ -20,9 +21,9 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>${persistence-api.version}</version>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee-api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

View file

@ -26,73 +26,54 @@ import java.io.Serializable;
import javax.persistence.EntityManager;
import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.AbstractVascBackendLocal;
/**
* AbstractPersistenceVascBackend.
*
* @author Willem Cazander
* @version 1.0 Mar 21, 2007
* @version 1.0 Aug 25, 2014
*/
abstract public class AbstractPersistenceVascBackend<DATA_OBJECT extends Serializable> extends AbstractVascBackend<DATA_OBJECT> {
abstract public class AbstractPersistenceVascBackend<DATA_PK extends Serializable> extends AbstractVascBackendLocal<DATA_PK> {
protected boolean emTransaction = true;
private Boolean emTransaction;
abstract EntityManager getEntityManager();
private EntityManagerProvider entityManagerProvider = null;
abstract protected void startBackendPersistence();
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackendLocal#startBackendLocal()
*/
@Override
public void persist(DATA_OBJECT object) throws VascBackendException {
EntityManager s = getEntityManager();
try {
if (emTransaction) {
s.getTransaction().begin();
}
s.persist(object);
if (emTransaction) {
s.getTransaction().commit();
}
} finally {
if (s!=null) {
//s.close();
}
}
protected final void startBackendLocal() {
requireNonNull(getEntityManagerProvider(), "entityManagerProvider is null.");
//requireNonEmpty(keyMapType.keySet(), "No primary keys defined.");
startBackendPersistence();
}
@Override
public DATA_OBJECT merge(DATA_OBJECT object) throws VascBackendException {
EntityManager s = getEntityManager();
try {
if (emTransaction) {
s.getTransaction().begin();
}
DATA_OBJECT result = (DATA_OBJECT)s.merge(object);
if (emTransaction) {
s.getTransaction().commit();
}
return result;
} finally {
if (s!=null) {
//s.close();
}
protected final EntityManager getEntityManager() {
if (emTransaction == null) {
emTransaction=entityManagerProvider.hasEntityManagerTransaction();
}
return entityManagerProvider.getEntityManager();
}
@Override
public void delete(DATA_OBJECT object) throws VascBackendException {
EntityManager s = getEntityManager();
try {
if (emTransaction) {
s.getTransaction().begin();
}
Object newObject = s.merge(object);
s.remove(newObject);
if (emTransaction) {
s.getTransaction().commit();
}
} finally {
if (s!=null) {
//s.close();
protected final boolean hasTransaction() {
return emTransaction;
}
/**
* @return the entityManagerProvider
*/
public final EntityManagerProvider getEntityManagerProvider() {
return entityManagerProvider;
}
/**
* @param entityManagerProvider the entityManagerProvider to set
*/
public final void setEntityManagerProvider(EntityManagerProvider entityManagerProvider) {
this.entityManagerProvider = entityManagerProvider;
}
}

View file

@ -0,0 +1,161 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backends.jpa;
import java.io.Serializable;
import javax.persistence.EntityManager;
import net.forwardfire.vasc.backend.VascBackendAccessDataKey;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
/**
* Manages persistance with xpql queries
*
* @author Willem Cazander
* @version 1.0 Mar 17, 2009
*/
public class PersistanceVascBackendCrud<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends AbstractPersistenceVascBackend<DATA_PK> implements VascBackendCrud<DATA_PK,DATA_RECORD> {
private Class<DATA_RECORD> recordClass = null;
public PersistanceVascBackendCrud() {
}
public PersistanceVascBackendCrud(Class<DATA_RECORD> recordClass) {
setRecordClass(recordClass);
}
@Override
protected void startBackendPersistence() {
requireNonNull(getRecordClass(), "recordClass is null");
}
@Override
public VascBackendAccessDataRecord<DATA_PK, DATA_RECORD> createVascBackendAccessDataRecord() {
// TODO Auto-generated method stub
return null;
}
@Override
public VascBackendAccessDataKey<DATA_PK> createVascBackendAccessDataKey() {
// TODO Auto-generated method stub
return null;
}
@Override
public DATA_RECORD newRecord() throws VascBackendException {
try {
return getRecordClass().newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new VascBackendException(e);
}
}
@Override
public DATA_RECORD fetch(DATA_PK recordPK) throws VascBackendException {
EntityManager s = getEntityManager();
try {
if (hasTransaction()) {
s.getTransaction().begin();
}
DATA_RECORD record = s.find(getRecordClass(), recordPK);
if (hasTransaction()) {
s.getTransaction().commit();
}
return record;
} finally {
if (s!=null) {
//s.close();
}
}
}
@Override
public DATA_RECORD persist(DATA_RECORD record) throws VascBackendException {
EntityManager s = getEntityManager();
try {
if (hasTransaction()) {
s.getTransaction().begin();
}
s.persist(record);
if (hasTransaction()) {
s.getTransaction().commit();
}
return record;
} finally {
if (s!=null) {
//s.close();
}
}
}
@Override
public DATA_RECORD merge(DATA_RECORD record) throws VascBackendException {
EntityManager s = getEntityManager();
try {
if (hasTransaction()) {
s.getTransaction().begin();
}
DATA_RECORD result = (DATA_RECORD)s.merge(record);
if (hasTransaction()) {
s.getTransaction().commit();
}
return result;
} finally {
if (s!=null) {
//s.close();
}
}
}
@Override
public void delete(DATA_PK recordPK) throws VascBackendException {
EntityManager s = getEntityManager();
try {
if (hasTransaction()) {
s.getTransaction().begin();
}
Object newObject = s.find(Object.class,recordPK);
s.remove(newObject);
if (hasTransaction()) {
s.getTransaction().commit();
}
} finally {
if (s!=null) {
//s.close();
}
}
}
public Class<DATA_RECORD> getRecordClass() {
return recordClass;
}
public void setRecordClass(Class<DATA_RECORD> recordClass) {
this.recordClass = recordClass;
}
}

View file

@ -23,32 +23,30 @@
package net.forwardfire.vasc.backends.jpa;
import java.io.Serializable;
import java.util.EnumSet;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import net.forwardfire.vasc.backend.DefaultVascBackendResult;
import net.forwardfire.vasc.backend.VascBackendAccessDataKey;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
import net.forwardfire.vasc.backend.data.BeanVascEntryFieldValue;
import net.forwardfire.vasc.backend.data.BeanVascEntryRecordCreator;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.data.BeanVascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendList;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.xpql.query.QueryParameterValue;
/**
* Manages persistance with xpql queries
*
* @author Willem Cazander
* @version 1.0 Mar 17, 2009
*/
public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extends AbstractPersistenceVascBackend<DATA_OBJECT> {
private EntityManagerProvider entityManagerProvider = null;
public class PersistanceVascBackendXpqlList<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends AbstractPersistenceVascBackend<DATA_PK> implements VascBackendList<DATA_PK,DATA_RECORD> {
private net.forwardfire.vasc.xpql.query.Query query = null;
@ -62,32 +60,56 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
private net.forwardfire.vasc.xpql.query.Query queryMoveDownUp = null;
private Class<?> resultClass = null;
public XpqlPersistanceVascBackend() {
}
/**
* @see net.forwardfire.vasc.backends.jpa.AbstractPersistenceVascBackend#getEntityManager()
*/
@Override
EntityManager getEntityManager() {
emTransaction=entityManagerProvider.hasEntityManagerTransaction();
return entityManagerProvider.getEntityManager();
public PersistanceVascBackendXpqlList() {
}
@Override
public VascBackendResult<DATA_OBJECT> execute(VascBackendState state) throws VascBackendException {
return new DefaultVascBackendResult<DATA_OBJECT>(executeList(state),fetchTotalExecuteSize(state));
protected void startBackendPersistence() {
// TODO Auto-generated method stub
}
@Override
public VascBackendAccessDataRecord<DATA_PK, DATA_RECORD> createVascBackendAccessDataRecord() {
// TODO Auto-generated method stub
return null;
}
@Override
public VascBackendAccessDataKey<DATA_PK> createVascBackendAccessDataKey() {
// TODO Auto-generated method stub
return null;
}
@Override
public EnumSet<VascBackendListFeature> getSupportedFeatures() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<String> getSupportedRowActions() {
// TODO Auto-generated method stub
return null;
}
@Override
public void executeRowAction(VascBackendListRequest request,List<DATA_PK> recordPKs, String actionName) throws VascBackendException {
// TODO Auto-generated method stub
}
@Override
public VascBackendListResult<DATA_RECORD> execute(VascBackendListRequest state) throws VascBackendException {
return new DefaultVascBackendListResult<DATA_RECORD>(executeList(state),fetchTotalExecuteSize(state));
}
@SuppressWarnings("unchecked")
private List<DATA_OBJECT> executeList(VascBackendState state) throws VascBackendException {
private List<DATA_RECORD> executeList(VascBackendListRequest state) throws VascBackendException {
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
//System.out.println("Set para pame: "+key+" value: "+value);
query.setQueryParameter(key, value);
if (queryTotal!=null) {
queryTotal.setQueryParameter(key, value);
@ -109,11 +131,11 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
q.setFirstResult(state.getPageIndex()*state.getPageSize());
q.setMaxResults(state.getPageSize());
}
if (emTransaction) {
if (hasTransaction()) {
em.getTransaction().begin();
}
List<DATA_OBJECT> data = q.getResultList();
if (emTransaction) {
List<DATA_RECORD> data = q.getResultList();
if (hasTransaction()) {
em.getTransaction().commit();
}
return data;
@ -124,24 +146,6 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
}
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue()
*/
@Override
public VascEntryFieldValue provideVascEntryFieldValue() {
VascEntryFieldValue result = new BeanVascEntryFieldValue();
return result;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator()
*/
@Override
public VascEntryRecordCreator provideVascEntryRecordCreator() {
VascEntryRecordCreator result = new BeanVascEntryRecordCreator(resultClass);
return result;
}
/**
* @return the query
*/
@ -171,37 +175,8 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
}
/**
* @return the resultClass
* @see net.forwardfire.vasc.backend.crud.VascBackendList#isPageable()
*/
public Class<?> getResultClass() {
return resultClass;
}
/**
* @param resultClass the resultClass to set
*/
public void setResultClass(Class<?> resultClass) {
this.resultClass = resultClass;
}
/**
* @return the entityManagerProvider
*/
public EntityManagerProvider getEntityManagerProvider() {
return entityManagerProvider;
}
/**
* @param entityManagerProvider the entityManagerProvider to set
*/
public void setEntityManagerProvider(EntityManagerProvider entityManagerProvider) {
this.entityManagerProvider = entityManagerProvider;
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isPageable()
*/
@Override
public boolean isPageable() {
if (queryTotal==null) {
return false;
@ -209,7 +184,7 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
return true;
}
private long fetchTotalExecuteSize(VascBackendState state) {
private long fetchTotalExecuteSize(VascBackendListRequest state) {
EntityManager em = getEntityManager();
try {
Query q = em.createQuery(queryTotal.toPreparedSQL(queryTotal));
@ -219,11 +194,11 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
q.setParameter(i,value.getValue());
i++;
}
if (emTransaction) {
if (hasTransaction()) {
em.getTransaction().begin();
}
Long resultTotal = (Long)q.getSingleResult();
if (emTransaction) {
if (hasTransaction()) {
em.getTransaction().commit();
}
return resultTotal;
@ -234,25 +209,23 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
}
}
/**
* @see net.forwardfire.vasc.core.AbstractVascBackend#doRecordMoveDownById(VascBackendState state,java.lang.Object)
*/
@Override
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascBackendException {
public long doRecordMoveDownById(Object primaryId) throws VascBackendException {
long result = 0l;
if (queryMoveDown!=null) {
EntityManager em = getEntityManager();
try {
if (emTransaction) {
if (hasTransaction()) {
em.getTransaction().begin();
}
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveDown.setQueryParameter(key, value);
}
// for (String key:state.getDataParameterKeys()) {
// Object value = state.getDataParameter(key);
// queryMoveDown.setQueryParameter(key, value);
// }
// set id
queryMoveDown.setQueryParameter("id", primaryId);
@ -268,10 +241,10 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
result+=q.executeUpdate();
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveDownUp.setQueryParameter(key, value);
}
// for (String key:state.getDataParameterKeys()) {
// Object value = state.getDataParameter(key);
// queryMoveDownUp.setQueryParameter(key, value);
// }
// set id
queryMoveDownUp.setQueryParameter("id", primaryId);
@ -286,7 +259,7 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
}
result+=q.executeUpdate();
if (emTransaction) {
if (hasTransaction()) {
em.getTransaction().commit();
}
} finally {
@ -301,21 +274,20 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
/**
* @see net.forwardfire.vasc.core.AbstractVascBackend#doRecordMoveUpById(VascBackendState state,java.lang.Object)
*/
@Override
public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascBackendException {
public long doRecordMoveUpById(Object primaryId) throws VascBackendException {
long result = 0l;
if (queryMoveUp!=null) {
EntityManager em = getEntityManager();
try {
if (emTransaction) {
em.getTransaction().begin();
}
// if (emTransaction) {
// em.getTransaction().begin();
// }
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveUp.setQueryParameter(key, value);
}
// for (String key:state.getDataParameterKeys()) {
// Object value = state.getDataParameter(key);
// queryMoveUp.setQueryParameter(key, value);
// }
// set id
queryMoveUp.setQueryParameter("id", primaryId);
@ -331,10 +303,10 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
result+=q.executeUpdate();
// Copy parameters
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
queryMoveUpDown.setQueryParameter(key, value);
}
// for (String key:state.getDataParameterKeys()) {
// Object value = state.getDataParameter(key);
// queryMoveUpDown.setQueryParameter(key, value);
// }
// set id
queryMoveUpDown.setQueryParameter("id", primaryId);
@ -349,9 +321,9 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
}
result+=q.executeUpdate();
if (emTransaction) {
em.getTransaction().commit();
}
// if (emTransaction) {
// em.getTransaction().commit();
// }
} finally {
if (em!=null) {
//em.close();
@ -361,10 +333,20 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
return result;
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isRecordMoveable()
* @see net.forwardfire.vasc.backend.crud.VascBackendList#isSearchable()
*/
public boolean isSearchable() {
if (query.getQueryParameterValue("text_search")!=null) {
return true;
}
return false;
}
/**
* @see net.forwardfire.vasc.backend.crud.AbstractVascBackendCrud#isRecordMoveable()
*/
@Override
public boolean isRecordMoveable() {
return queryMoveUp!=null & queryMoveDown!=null;
}
@ -424,16 +406,4 @@ public class XpqlPersistanceVascBackend<DATA_OBJECT extends Serializable> extend
public void setQueryMoveDownUp(net.forwardfire.vasc.xpql.query.Query queryMoveDownUp) {
this.queryMoveDownUp = queryMoveDownUp;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isSearchable()
*/
@Override
public boolean isSearchable() {
if (query.getQueryParameterValue("text_search")==null) {
return false;
}
//return true;
return false;
}
}

View file

@ -0,0 +1,119 @@
/*
* 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.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPException;
import net.forwardfire.vasc.backend.AbstractVascBackendLocal;
import net.forwardfire.vasc.backend.VascBackendAccessDataKey;
import net.forwardfire.vasc.backend.data.HashMapVascBackendAccessDataKey;
/**
* LdapVascBackend provides abstract data access for ldap.
*
* @author Willem Cazander
* @version 1.0 Sep 4, 2008
*/
abstract public class AbstractLdapVascBackend extends AbstractVascBackendLocal<HashMap<String,Serializable>> {
private Logger logger = Logger.getLogger(AbstractLdapVascBackend.class.getName());
private LdapConnectionProvider ldapConnectionProvider = null;
private String baseDN = null;
private final Map<String,Class<?>> keyMapType = new HashMap<String,Class<?>>(5);
abstract protected void startBackendLdap();
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackendLocal#startBackendLocal()
*/
@Override
protected final void startBackendLocal() {
requireNonEmpty(getBaseDN(), "baseDN requires value.");
requireNonEmpty(keyMapType.keySet(), "No primary keys defined.");
startBackendLdap();
}
protected void safeDisconnect(LDAPConnection connection) {
if (connection==null) {
return;
}
try {
connection.disconnect();
} catch (LDAPException e) {
logger.warning("Error while disconnecting: "+e.getMessage());
}
}
protected final void addKeyMapType(String field,Class<?> fieldType) {
requireNonEmpty(field,"field has to have value");
requireNonNull(fieldType,"field has to have value");
keyMapType.put(field, fieldType);
}
protected final Map<String,Class<?>> getKeyMapType() {
return keyMapType;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#createVascBackendAccessDataKey()
*/
@Override
public final VascBackendAccessDataKey<HashMap<String, Serializable>> createVascBackendAccessDataKey() {
return new HashMapVascBackendAccessDataKey(keyMapType);
}
/**
* @return the ldapConnectionProvider.
*/
public final LdapConnectionProvider getLdapConnectionProvider() {
return ldapConnectionProvider;
}
/**
* @param ldapConnectionProvider the ldapConnectionProvider to set.
*/
public final void setLdapConnectionProvider(LdapConnectionProvider ldapConnectionProvider) {
this.ldapConnectionProvider = ldapConnectionProvider;
}
/**
* @return the baseDN.
*/
public final String getBaseDN() {
return baseDN;
}
/**
* @param baseDN the baseDN to set.
*/
public final void setBaseDN(String baseDN) {
this.baseDN = baseDN;
}
}

View file

@ -22,25 +22,18 @@
package net.forwardfire.vasc.backend.ldap;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.backend.DefaultVascBackendResult;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
import net.forwardfire.vasc.backend.data.HashMapVascEntryFieldValue;
import net.forwardfire.vasc.backend.data.HashMapVascEntryRecordCreator;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.data.HashMapVascBackendAccessDataRecord;
import com.novell.ldap.LDAPAttribute;
import com.novell.ldap.LDAPAttributeSet;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPEntry;
import com.novell.ldap.LDAPException;
@ -54,91 +47,39 @@ import com.novell.ldap.LDAPSearchResults;
* @author Willem Cazander
* @version 1.0 Sep 4, 2008
*/
public class LdapVascBackend extends AbstractVascBackend<HashMap<String,Object>> {
public class LdapVascBackendCrud extends AbstractLdapVascBackend implements VascBackendCrud<HashMap<String,Serializable>,HashMap<String,Serializable>> {
private Logger logger = Logger.getLogger(LdapVascBackend.class.getName());
private LdapConnectionProvider ldapConnectionProvider = null;
private String baseDN = null;
private Logger logger = Logger.getLogger(LdapVascBackendCrud.class.getName());
private String keyAttribute = null;
private String ldapFilter = null;
private String createObjectClass = null;
private int timeLimit = 10000;
private boolean referralFollowing = true;
/**
* @return the ldapConnectionProvider.
*/
public LdapConnectionProvider getLdapConnectionProvider() {
return ldapConnectionProvider;
@Override
protected void startBackendLdap() {
}
@Override
public VascBackendAccessDataRecord<HashMap<String, Serializable>, HashMap<String, Serializable>> createVascBackendAccessDataRecord() {
return new HashMapVascBackendAccessDataRecord(getKeyMapType());
}
@Override
public HashMap<String, Serializable> fetch(HashMap<String, Serializable> recordPK) throws VascBackendException {
return null;
}
@Override
public HashMap<String, Serializable> newRecord() throws VascBackendException {
return new HashMap<String,Serializable>();
}
/**
* @param ldapConnectionProvider the ldapConnectionProvider to set.
*/
public void setLdapConnectionProvider(LdapConnectionProvider ldapConnectionProvider) {
this.ldapConnectionProvider = ldapConnectionProvider;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#execute()
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#merge(java.lang.Object)
*/
@Override
public VascBackendResult<HashMap<String,Object>> execute(VascBackendState state) throws VascBackendException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
List<HashMap<String,Object>> result = new ArrayList<HashMap<String,Object>>(50);
try {
LDAPSearchConstraints cons = new LDAPSearchConstraints();
cons.setBatchSize( 0 );
cons.setTimeLimit(getTimeLimit() ) ;
cons.setReferralFollowing(isReferralFollowing());
connection.setConstraints(cons);
int searchScope = LDAPConnection.SCOPE_ONE;
String searchBase = baseDN;
LDAPSearchResults searchResults = connection.search(
searchBase, // object to read
searchScope, // scope - read single object
getLdapFilter(), // search filter
null, // return all attributes
false); // return attrs and values
while (searchResults.hasMore()) {
LDAPEntry entry = searchResults.next();
HashMap<String,Object> map = new HashMap<String,Object>(10);
LDAPAttributeSet attributeSet = entry.getAttributeSet();
Iterator<LDAPAttribute> i = attributeSet.iterator();
while (i.hasNext()) {
LDAPAttribute attr = i.next();
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 (LDAPException e) {
throw new VascBackendException(e);
} finally {
safeDisconnect(connection);
}
return new DefaultVascBackendResult<HashMap<String,Object>>(result);
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#merge(java.lang.Object)
*/
@Override
public HashMap<String,Object> merge(HashMap<String,Object> map) throws VascBackendException {
public HashMap<String,Serializable> merge(HashMap<String,Serializable> map) throws VascBackendException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
try {
@ -149,7 +90,7 @@ public class LdapVascBackend extends AbstractVascBackend<HashMap<String,Object>>
cons.setReferralFollowing(isReferralFollowing());
connection.setConstraints(cons);
int searchScope = LDAPConnection.SCOPE_ONE;
String searchBase = baseDN;
String searchBase = getBaseDN();
String filter = "(&"+ldapFilter+"("+keyAttribute+"="+keyValue+"))";
LDAPSearchResults searchResults = connection.search(
searchBase, // object to read
@ -216,15 +157,15 @@ public class LdapVascBackend extends AbstractVascBackend<HashMap<String,Object>>
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object)
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#persist(java.lang.Object)
*/
@Override
public void persist(HashMap<String,Object> map) throws VascBackendException {
public HashMap<String,Serializable> persist(HashMap<String,Serializable> map) throws VascBackendException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
try {
String keyValue = (String)map.get(keyAttribute);
LDAPEntry entry = new LDAPEntry(keyAttribute+"="+keyValue+","+baseDN);
LDAPEntry entry = new LDAPEntry(keyAttribute+"="+keyValue+","+getBaseDN());
LDAPAttribute ob = new LDAPAttribute("objectClass");
String[] obs = createObjectClass.split(",");
@ -248,19 +189,20 @@ public class LdapVascBackend extends AbstractVascBackend<HashMap<String,Object>>
} finally {
safeDisconnect(connection);
}
return fetch(map);
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#delete(java.lang.Object)
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#delete(java.lang.Object)
*/
@Override
public void delete(HashMap<String,Object> map) throws VascBackendException {
public void delete(HashMap<String,Serializable> map) throws VascBackendException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
try {
String keyValue = (String)map.get(keyAttribute);
int searchScope = LDAPConnection.SCOPE_ONE;
String searchBase = baseDN;
String searchBase = getBaseDN();
String filter = "(&"+ldapFilter+"("+keyAttribute+"="+keyValue+"))";
LDAPSearchResults searchResults = connection.search(
searchBase, // object to read
@ -282,47 +224,6 @@ public class LdapVascBackend extends AbstractVascBackend<HashMap<String,Object>>
}
}
private void safeDisconnect(LDAPConnection connection) {
if (connection==null) {
return;
}
try {
connection.disconnect();
} catch (LDAPException e) {
logger.warning("Error while disconnecting: "+e.getMessage());
}
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator()
*/
@Override
public VascEntryRecordCreator provideVascEntryRecordCreator() {
return new HashMapVascEntryRecordCreator();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue()
*/
@Override
public VascEntryFieldValue provideVascEntryFieldValue() {
return new HashMapVascEntryFieldValue();
}
/**
* @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.
*/

View file

@ -0,0 +1,220 @@
/*
* 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.io.Serializable;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.data.HashMapVascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendList;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import com.novell.ldap.LDAPAttribute;
import com.novell.ldap.LDAPAttributeSet;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPEntry;
import com.novell.ldap.LDAPException;
import com.novell.ldap.LDAPModification;
import com.novell.ldap.LDAPSearchConstraints;
import com.novell.ldap.LDAPSearchResults;
/**
* LdapVascBackend provides abstract data access for ldap.
*
* @author Willem Cazander
* @version 1.0 Sep 4, 2008
*/
public class LdapVascBackendList extends AbstractLdapVascBackend implements VascBackendList<HashMap<String,Serializable>,HashMap<String,Serializable>> {
private Logger logger = Logger.getLogger(LdapVascBackendList.class.getName());
private final EnumSet<VascBackendListFeature> features = EnumSet.noneOf(VascBackendListFeature.class);
private final List<String> rowActions = new ArrayList<String>();
private String keyAttribute = null;
private String ldapFilter = null;
private String createObjectClass = null;
private int timeLimit = 10000;
private boolean referralFollowing = true;
@Override
protected void startBackendLdap() {
// TODO Auto-generated method stub
}
@Override
public VascBackendAccessDataRecord<HashMap<String, Serializable>, HashMap<String, Serializable>> createVascBackendAccessDataRecord() {
return new HashMapVascBackendAccessDataRecord(getKeyMapType());
}
@Override
public EnumSet<VascBackendListFeature> getSupportedFeatures() {
return features;
}
@Override
public List<String> getSupportedRowActions() {
return rowActions;
}
@Override
public void executeRowAction(VascBackendListRequest request,List<HashMap<String, Serializable>> recordPKs, String actionName) throws VascBackendException {
}
/**
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#execute()
*/
@Override
public VascBackendListResult<HashMap<String,Serializable>> execute(VascBackendListRequest state) throws VascBackendException {
LdapConnectionProvider prov = getLdapConnectionProvider();
LDAPConnection connection = prov.getLdapConnection();
List<HashMap<String,Serializable>> result = new ArrayList<HashMap<String,Serializable>>(50);
try {
LDAPSearchConstraints cons = new LDAPSearchConstraints();
cons.setBatchSize( 0 );
cons.setTimeLimit(getTimeLimit() ) ;
cons.setReferralFollowing(isReferralFollowing());
connection.setConstraints(cons);
int searchScope = LDAPConnection.SCOPE_ONE;
String searchBase = getBaseDN();
LDAPSearchResults searchResults = connection.search(
searchBase, // object to read
searchScope, // scope - read single object
getLdapFilter(), // search filter
null, // return all attributes
false); // return attrs and values
while (searchResults.hasMore()) {
LDAPEntry entry = searchResults.next();
HashMap<String,Serializable> map = new HashMap<String,Serializable>(10);
LDAPAttributeSet attributeSet = entry.getAttributeSet();
Iterator<LDAPAttribute> i = attributeSet.iterator();
while (i.hasNext()) {
LDAPAttribute attr = i.next();
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(), (Serializable)multiValue );
}
}
result.add(map);
}
} catch (LDAPException e) {
throw new VascBackendException(e);
} finally {
safeDisconnect(connection);
}
return new DefaultVascBackendListResult<HashMap<String,Serializable>>(result);
}
/**
* @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;
}
/**
* @return the createObjectClass.
*/
public String getCreateObjectClass() {
return createObjectClass;
}
/**
* @param createObjectClass the createObjectClass to set.
*/
public void setCreateObjectClass(String createObjectClass) {
this.createObjectClass = createObjectClass;
}
/**
* @return the timeLimit.
*/
public int getTimeLimit() {
return timeLimit;
}
/**
* @param timeLimit the timeLimit to set.
*/
public void setTimeLimit(int timeLimit) {
this.timeLimit = timeLimit;
}
/**
* @return the referralFollowing.
*/
public boolean isReferralFollowing() {
return referralFollowing;
}
/**
* @param referralFollowing the referralFollowing to set.
*/
public void setReferralFollowing(boolean referralFollowing) {
this.referralFollowing = referralFollowing;
}
}

View file

@ -0,0 +1,142 @@
/*
* 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.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.eobjects.metamodel.DataContext;
import net.forwardfire.vasc.backend.AbstractVascBackendLocal;
import net.forwardfire.vasc.backend.VascBackendAccessDataKey;
import net.forwardfire.vasc.backend.data.HashMapVascBackendAccessDataKey;
/**
* AbstractMetaModelVascBackend provides shared metamodel options.
*
* @author Willem Cazander
* @version 1.0 Oct 27, 2014
*/
abstract public class AbstractMetaModelVascBackend extends AbstractVascBackendLocal<HashMap<String,Serializable>> {
private Logger logger = Logger.getLogger(MetaModelVascBackendCrud.class.getName());
private MetaModelDataContextProvider dataContextProvider = null;
private DataContext dataContext = null;
private String table = null;
private String tableId = null;
private final Map<String,Class<?>> keyMapType = new HashMap<String,Class<?>>(5);
abstract protected void startBackendMetaModel();
@Override
protected void stopBackendLocal() {
dataContext = null;
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackendLocal#startBackendLocal()
*/
@Override
protected final void startBackendLocal() {
requireNonNull(getDataContextProvider(), "dataContextProvider is null.");
requireNonEmpty(keyMapType.keySet(), "No primary keys defined.");
requireNonNull(table,"table needs value");
//requireNonNull(tableId,"table needs value");
long startTime = System.currentTimeMillis();
dataContext = dataContextProvider.getDataContext();
requireNonNull(dataContext,"dataContextProvider created null dataContext.");
long stopTime = System.currentTimeMillis();
logger.fine(dataContext.getClass().getSimpleName()+" created for: "+table+" in: "+(stopTime-startTime)+" ms.");
startBackendMetaModel();
}
protected final void addKeyMapType(String field,Class<?> fieldType) {
requireNonEmpty(field,"field has to have value");
requireNonNull(fieldType,"field has to have value");
keyMapType.put(field, fieldType);
}
protected final Map<String,Class<?>> getKeyMapType() {
return keyMapType;
}
protected DataContext getDataContext() {
return dataContext;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#createVascBackendAccessDataKey()
*/
@Override
public final VascBackendAccessDataKey<HashMap<String, Serializable>> createVascBackendAccessDataKey() {
return new HashMapVascBackendAccessDataKey(keyMapType);
}
/**
* @return the dataContextProvider
*/
public final MetaModelDataContextProvider getDataContextProvider() {
return dataContextProvider;
}
/**
* @param dataContextProvider the dataContextProvider to set
*/
public final void setDataContextProvider(MetaModelDataContextProvider dataContextProvider) {
this.dataContextProvider = dataContextProvider;
}
/**
* @return the table
*/
public final String getTable() {
return table;
}
/**
* @param table the table to set
*/
public final void setTable(String table) {
this.table = table;
}
/**
* @return the tableId
*/
public final String getTableId() {
return tableId;
}
/**
* @param tableId the tableId to set
*/
public final void setTableId(String tableId) {
this.tableId = tableId;
}
}

View file

@ -1,20 +1,36 @@
package net.forwardfire.vasc.backend.metamodel;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.eobjects.metamodel.data.Row;
import org.eobjects.metamodel.query.SelectItem;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.metamodel.crud.UpdateableRow;
public class RowVascEntryFieldValue implements VascEntryFieldValue<Row> {
@SuppressWarnings("serial")
public class MetaModelVascBackendAccessDataRecord implements VascBackendAccessDataRecord<HashMap<String,Serializable>,Row> {
private static final long serialVersionUID = -806674640688182132L;
private final Map<String,Class<?>> keyMapType;
public MetaModelVascBackendAccessDataRecord(Map<String,Class<?>> keyMapType) {
this.keyMapType = keyMapType;
}
@Override
public HashMap<String, Serializable> getPrimaryKey(Row record) throws VascBackendException {
HashMap<String, Serializable> result = new HashMap<String, Serializable>();
for (String key:keyMapType.keySet()) {
result.put(key, getValue(key,record));
}
return result;
}
/**
* @see net.forwardfire.vasc.backend.VascEntryFieldValue#getValue(java.lang.String, java.lang.Object)
* @see net.forwardfire.vasc.backend.VascBackendAccessDataRecord#getValue(java.lang.String, java.lang.Object)
*/
@Override
public Serializable getValue(String backendName, Row record) throws VascBackendException {
@ -47,19 +63,7 @@ public class RowVascEntryFieldValue implements VascEntryFieldValue<Row> {
}
/**
* @see net.forwardfire.vasc.backend.VascEntryFieldValue#getDisplayValue(java.lang.String, java.lang.Object)
*/
@Override
public String getDisplayValue(String backendName, Row record) throws VascBackendException {
Object fieldValue = getValue(backendName,record);
if (fieldValue==null) {
fieldValue = "";
}
return fieldValue.toString();
}
/**
* @see net.forwardfire.vasc.backend.VascEntryFieldValue#setValue(java.lang.String, java.lang.Object, java.lang.Object)
* @see net.forwardfire.vasc.backend.VascBackendAccessDataRecord#setValue(java.lang.String, java.lang.Object, java.lang.Object)
*/
@Override
public void setValue(String backendName, Row record,Serializable value) throws VascBackendException {

View file

@ -0,0 +1,143 @@
/*
* 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.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
import org.eobjects.metamodel.DataContext;
import org.eobjects.metamodel.UpdateableDataContext;
import org.eobjects.metamodel.data.DataSet;
import org.eobjects.metamodel.data.Row;
import org.eobjects.metamodel.jdbc.JdbcDataContext;
import org.eobjects.metamodel.query.OrderByItem.Direction;
import org.eobjects.metamodel.query.Query;
import org.eobjects.metamodel.query.SelectItem;
import org.eobjects.metamodel.query.builder.SatisfiedQueryBuilder;
import org.eobjects.metamodel.query.builder.SatisfiedWhereBuilder;
import org.eobjects.metamodel.schema.Column;
import org.eobjects.metamodel.schema.Schema;
import org.eobjects.metamodel.schema.Table;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.backend.metamodel.crud.CrudDataContext;
import net.forwardfire.vasc.backend.metamodel.crud.UpdateableRow;
import net.forwardfire.vasc.backend.metamodel.crud.CrudDataContextImpl;
import net.forwardfire.vasc.backend.metamodel.crud.UpdateableRowMapImpl;
/**
* MetaModelVascBackend provides vasc backend for metamodel.
*
* @author Willem Cazander
* @version 1.0 Dec 31, 2011
*/
public class MetaModelVascBackendCrud extends AbstractMetaModelVascBackend implements VascBackendCrud<HashMap<String,Serializable>,Row> {
private Logger logger = Logger.getLogger(MetaModelVascBackendCrud.class.getName());
private CrudDataContext crudDataContext = null;
@Override
protected void startBackendMetaModel() {
// if (isUpdateableDataContext()) {
// CrudDataContextImpl crudDataContextImpl = new CrudDataContextImpl(getUpdateableDataContext());
// if (tableId!=null && tableId.isEmpty()==false) {
// List<String> ids = new ArrayList<String>(1);
// ids.add(tableId);
// crudDataContextImpl.overridePrimaryKeysForTable(table,ids);
// }
// crudDataContext = crudDataContextImpl;
// }
}
@Override
public VascBackendAccessDataRecord<HashMap<String, Serializable>, Row> createVascBackendAccessDataRecord() {
// TODO Auto-generated method stub
return null;
}
@Override
public Row newRecord() throws VascBackendException {
return crudDataContext.createRow(crudDataContext.getTableByQualifiedLabel(getTable()));
}
@Override
public Row fetch(HashMap<String, Serializable> recordPK) throws VascBackendException {
// TODO Auto-generated method stub
return null;
}
/**
* Returns casted version of data context.
*/
private UpdateableDataContext getUpdateableDataContext() {
return (UpdateableDataContext)getDataContext();
}
/**
* Returns true when data context in updateable.
*/
private boolean isUpdateableDataContext() {
return getDataContext() instanceof UpdateableDataContext;
}
public boolean isReadOnly() {
return isUpdateableDataContext()==false;
}
@Override
public Row persist(Row object) throws VascBackendException {
if (crudDataContext==null) {
return object;
}
crudDataContext.persist((UpdateableRow) object);
return object;
}
@Override
public Row merge(Row object) throws VascBackendException {
if (crudDataContext==null) {
return object;
}
return crudDataContext.merge((UpdateableRow) object);
}
@Override
public void delete(HashMap<String, Serializable> recordPK) throws VascBackendException {
if (crudDataContext==null) {
return;
}
//crudDataContext.delete((UpdateableRow) object);
}
}

View file

@ -22,8 +22,11 @@
package net.forwardfire.vasc.backend.metamodel;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
@ -42,12 +45,15 @@ import org.eobjects.metamodel.schema.Column;
import org.eobjects.metamodel.schema.Schema;
import org.eobjects.metamodel.schema.Table;
import net.forwardfire.vasc.backend.AbstractVascBackend;
import net.forwardfire.vasc.backend.DefaultVascBackendResult;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.data.HashMapVascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendList;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.backend.metamodel.crud.CrudDataContext;
import net.forwardfire.vasc.backend.metamodel.crud.UpdateableRow;
import net.forwardfire.vasc.backend.metamodel.crud.CrudDataContextImpl;
@ -59,91 +65,39 @@ import net.forwardfire.vasc.backend.metamodel.crud.UpdateableRowMapImpl;
* @author Willem Cazander
* @version 1.0 Dec 31, 2011
*/
public class MetaModelVascBackend extends AbstractVascBackend<Row> {
public class MetaModelVascBackendList extends AbstractMetaModelVascBackend implements VascBackendList<HashMap<String,Serializable>,Row> {
private Logger logger = Logger.getLogger(MetaModelVascBackend.class.getName());
private MetaModelDataContextProvider dataContextProvider = null;
private DataContext dataContext = null;
private CrudDataContext crudDataContext = null;
private String table = null;
private String tableId = null;
private Logger logger = Logger.getLogger(MetaModelVascBackendList.class.getName());
private final EnumSet<VascBackendListFeature> features = EnumSet.noneOf(VascBackendListFeature.class);
private final List<String> rowActions = new ArrayList<String>();
/**
* Returns casted version of data context.
*/
private UpdateableDataContext getUpdateableDataContext() {
return (UpdateableDataContext)dataContext;
}
/**
* Returns true when data context in updateable.
*/
private boolean isUpdateableDataContext() {
return dataContext instanceof UpdateableDataContext;
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isReadOnly()
*/
@Override
public boolean isReadOnly() {
return isUpdateableDataContext()==false;
protected void startBackendMetaModel() {
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#startBackend()
*/
@Override
public void startBackend() {
if (table==null) {
throw new NullPointerException("Can't start with null table.");
}
if (table.isEmpty()) {
throw new NullPointerException("Can't start with empty table.");
}
long startTime = System.currentTimeMillis();
dataContext = dataContextProvider.getDataContext();
if (isUpdateableDataContext()) {
CrudDataContextImpl crudDataContextImpl = new CrudDataContextImpl(getUpdateableDataContext());
if (tableId!=null && tableId.isEmpty()==false) {
List<String> ids = new ArrayList<String>(1);
ids.add(tableId);
crudDataContextImpl.overridePrimaryKeysForTable(table,ids);
}
crudDataContext = crudDataContextImpl;
}
long stopTime = System.currentTimeMillis();
logger.fine(dataContext.getClass().getSimpleName()+" created for: "+table+" in: "+(stopTime-startTime)+" ms.");
public VascBackendAccessDataRecord<HashMap<String,Serializable>,Row> createVascBackendAccessDataRecord() {
return new MetaModelVascBackendAccessDataRecord(getKeyMapType());
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#stopBackend()
*/
@Override
public void stopBackend() {
dataContext = null;
public EnumSet<VascBackendListFeature> getSupportedFeatures() {
return features;
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isPageable()
*/
@Override
public boolean isPageable() {
return true;
public List<String> getSupportedRowActions() {
return rowActions;
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isSortable()
*/
@Override
public boolean isSortable() {
return true;
public void executeRowAction(VascBackendListRequest request,List<HashMap<String, Serializable>> recordPKs, String actionName) throws VascBackendException {
}
private long fetchTotalExecuteSize(VascBackendState state) {
private long fetchTotalExecuteSize(VascBackendListRequest state) {
DataContext dataContext = getDataContext();
Schema schema = dataContext.getDefaultSchema();
Table t = schema.getTableByName(table);
Table t = schema.getTableByName(getTable());
Query q = createFilterQuery(state,t,true);
DataSet ds = dataContext.executeQuery(q);
if (ds.next()==false) {
@ -156,7 +110,9 @@ public class MetaModelVascBackend extends AbstractVascBackend<Row> {
return result.longValue();
}
private Query createFilterQuery(VascBackendState state,Table t,boolean count) {
private Query createFilterQuery(VascBackendListRequest state,Table t,boolean count) {
DataContext dataContext = getDataContext();
Object qWhere = null;
if (count==false) {
qWhere = dataContext.query().from(t).select(t.getColumns());
@ -208,18 +164,19 @@ public class MetaModelVascBackend extends AbstractVascBackend<Row> {
}
@Override
public VascBackendResult<Row> execute(VascBackendState state) throws VascBackendException {
return new DefaultVascBackendResult<Row>(executeList(state),fetchTotalExecuteSize(state));
public VascBackendListResult<Row> execute(VascBackendListRequest state) throws VascBackendException {
return new DefaultVascBackendListResult<Row>(executeList(state),fetchTotalExecuteSize(state));
}
private List<Row> executeList(VascBackendState state) throws VascBackendException {
private List<Row> executeList(VascBackendListRequest state) throws VascBackendException {
DataContext dataContext = getDataContext();
Schema schema = dataContext.getDefaultSchema();
Table t = schema.getTableByName(table);
Table t = schema.getTableByName(getTable());
if (t==null) {
throw new VascBackendException("Could not get meta table for: '"+table+"'.");
throw new VascBackendException("Could not get meta table for: '"+getTable()+"'.");
}
Query q = createFilterQuery(state,t,false);
if (isSortable() && state.getSortField() != null) {
if (state.getSortField() != null) {
Column orderColumn = t.getColumnByName(state.getSortField());
if (state.isSortAscending()) {
q.orderBy(orderColumn,Direction.ASC);
@ -227,7 +184,7 @@ public class MetaModelVascBackend extends AbstractVascBackend<Row> {
q.orderBy(orderColumn,Direction.DESC);
}
}
if (isPageable() && state.getPageSize()>0) {
if (state.getPageSize()>0) {
if (state.getPageIndex()>0) {
q.setFirstRow((state.getPageIndex()*state.getPageSize())+1); // MM is 1 based ??
@ -239,12 +196,12 @@ public class MetaModelVascBackend extends AbstractVascBackend<Row> {
q.setMaxRows(state.getPageSize());
}
List<Row> result = new ArrayList<Row>(50);
if (crudDataContext!=null) {
DataSet ds = crudDataContext.executeQuery(q);
result.addAll(ds.toRows());
ds.close();
return result;
}
// if (crudDataContext!=null) {
// DataSet ds = crudDataContext.executeQuery(q);
// result.addAll(ds.toRows());
// ds.close();
// return result;
// }
DataSet ds = dataContext.executeQuery(q);
while (ds.next()) {
@ -252,7 +209,7 @@ public class MetaModelVascBackend extends AbstractVascBackend<Row> {
SelectItem[] cols = row.getSelectItems();
List<String> keys = new ArrayList<String>(1);
keys.add(cols[0].getColumn().getName());
UpdateableRowMapImpl rowMM = new UpdateableRowMapImpl(dataContext.getDefaultSchema().getTableByName(table),keys,cols);
UpdateableRowMapImpl rowMM = new UpdateableRowMapImpl(dataContext.getDefaultSchema().getTableByName(getTable()),keys,cols);
for (SelectItem col:cols) {
Object value = row.getValue(col);
rowMM.setValue(col, value);
@ -263,80 +220,4 @@ public class MetaModelVascBackend extends AbstractVascBackend<Row> {
return result;
}
@Override
public void persist(Row object) throws VascBackendException {
if (crudDataContext==null) {
return;
}
crudDataContext.persist((UpdateableRow) object);
}
@Override
public Row merge(Row object) throws VascBackendException {
if (crudDataContext==null) {
return object;
}
return crudDataContext.merge((UpdateableRow) object);
}
@Override
public void delete(Row object) throws VascBackendException {
if (crudDataContext==null) {
return;
}
crudDataContext.delete((UpdateableRow) object);
}
@Override
public RowVascEntryFieldValue provideVascEntryFieldValue() {
return new RowVascEntryFieldValue();
}
@Override
public VascEntryRecordCreator<Row> provideVascEntryRecordCreator() {
return new RowVascEntryRecordCreator(crudDataContext,crudDataContext.getDefaultSchema().getTableByName(table));
}
/**
* @return the dataContextProvider
*/
public MetaModelDataContextProvider getDataContextProvider() {
return dataContextProvider;
}
/**
* @param dataContextProvider the dataContextProvider to set
*/
public void setDataContextProvider(MetaModelDataContextProvider dataContextProvider) {
this.dataContextProvider = dataContextProvider;
}
/**
* @return the table
*/
public String getTable() {
return table;
}
/**
* @param table the table to set
*/
public void setTable(String table) {
this.table = table;
}
/**
* @return the tableId
*/
public String getTableId() {
return tableId;
}
/**
* @param tableId the tableId to set
*/
public void setTableId(String tableId) {
this.tableId = tableId;
}
}

View file

@ -1,25 +0,0 @@
package net.forwardfire.vasc.backend.metamodel;
import org.eobjects.metamodel.data.Row;
import org.eobjects.metamodel.schema.Table;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
import net.forwardfire.vasc.backend.metamodel.crud.CrudDataContext;
public class RowVascEntryRecordCreator implements VascEntryRecordCreator<Row> {
private static final long serialVersionUID = -1182678362367989090L;
private CrudDataContext dataContext = null;
private Table table = null;
public RowVascEntryRecordCreator(CrudDataContext dataContext,Table table) {
this.dataContext=dataContext;
this.table=table;
}
@Override
public Row newRecord() throws VascBackendException {
return dataContext.createRow(table);
}
}

View file

@ -0,0 +1,104 @@
/*
* 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 org.bson.types.ObjectId;
import net.forwardfire.vasc.backend.AbstractVascBackendLocal;
import net.forwardfire.vasc.backend.VascBackendAccessDataKey;
import net.forwardfire.vasc.backend.VascBackendException;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
/**
* AbstractMongodbVascBackend
*
* @author Willem Cazander
* @version 1.0 Oct 26, 2014
*/
abstract public class AbstractMongodbVascBackend extends AbstractVascBackendLocal<ObjectId> {
public static final String PK_FIELD_NAME = "_id";
private MongodbConnectionProvider connectionProvider = null;
private String collection = null;
private DB database = null;
@Override
public final void startBackendLocal() {
requireNonNull(connectionProvider, "Can't start with null connectionProvider.");
requireNonEmpty(collection, "Can't start without collection.");
database = connectionProvider.getMongodbConnection();
requireNonNull(database, "connectionProvider provided us a null database.");
}
@Override
public final void stopBackendLocal() {
database = null;
}
protected final DBCollection getDBCollection() {
return database.getCollection(collection);
}
protected final void deleteById(ObjectId objectId) throws VascBackendException {
getDBCollection().remove(new BasicDBObject(PK_FIELD_NAME,objectId)); // remove by _id
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#createVascBackendAccessDataKey()
*/
@Override
public final VascBackendAccessDataKey<ObjectId> createVascBackendAccessDataKey() {
return new MongodbVascBackendAccessDataKey();
}
/**
* @return the connectionProvider
*/
public final MongodbConnectionProvider getConnectionProvider() {
return connectionProvider;
}
/**
* @param connectionProvider the connectionProvider to set
*/
public final void setConnectionProvider(MongodbConnectionProvider connectionProvider) {
this.connectionProvider = connectionProvider;
}
/**
* @return the collection
*/
public final String getCollection() {
return collection;
}
/**
* @param collection the collection to set
*/
public final void setCollection(String collection) {
this.collection = collection;
}
}

View file

@ -1,191 +0,0 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.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.DefaultVascBackendResult;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.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;
/**
* MongodbVascBackend Provides backend for mongodb.
*
* @author Willem Cazander
* @version 1.0 Dec 30, 2011
*/
public class MongodbVascBackend extends AbstractVascBackend<BasicDBObject> {
private Logger logger = null;
private MongodbConnectionProvider connectionProvider = null;
private String collection = null;
private DB database = null;
public MongodbVascBackend() {
logger = Logger.getLogger(MongodbVascBackend.class.getName());
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#startBackend()
*/
@Override
public void startBackend() {
if (connectionProvider==null) {
throw new NullPointerException("Can't start backend with null connectionProvider.");
}
database = connectionProvider.getMongodbConnection();
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#stopBackend()
*/
@Override
public void stopBackend() {
database = null;
}
/**
* @see net.forwardfire.vasc.backend.AbstractVascBackend#isPageable()
*/
@Override
public boolean isPageable() {
return true;
}
private long fetchTotalExecuteSize(VascBackendState state) {
DBCollection coll = getDBCollection();
DBObject query = createFilterQuery(state);
long result = coll.count(query);
return result;
}
private DBObject createFilterQuery(VascBackendState state) {
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+"'");
}
return query;
}
@Override
public VascBackendResult<BasicDBObject> execute(VascBackendState state) throws VascBackendException {
return new DefaultVascBackendResult<BasicDBObject>(executeList(state),fetchTotalExecuteSize(state));
}
private List<BasicDBObject> executeList(VascBackendState state) throws VascBackendException {
DBCollection coll = getDBCollection();
DBObject query = createFilterQuery(state);
DBCursor cur = coll.find(query);
if (isPageable() && state.getPageSize()>0) {
cur.limit(state.getPageSize());
cur.skip(state.getPageIndex());
}
List<BasicDBObject> result = new ArrayList<BasicDBObject>(cur.count());
while (cur.hasNext()) {
DBObject row = cur.next();
result.add((BasicDBObject)row);
}
return result;
}
@Override
public void persist(BasicDBObject object) throws VascBackendException {
DBCollection coll = getDBCollection();
coll.insert(object);
}
@Override
public BasicDBObject merge(BasicDBObject row) throws VascBackendException {
DBCollection coll = getDBCollection();
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 row;
}
@Override
public void delete(BasicDBObject object) throws VascBackendException {
DBCollection coll = getDBCollection();
DBObject query = new BasicDBObject();
query.put("_id",object.get("_id"));
coll.remove(query); // remove by _id
}
@Override
public MongodbVascEntryFieldValue provideVascEntryFieldValue() {
return new MongodbVascEntryFieldValue();
}
@Override
public VascEntryRecordCreator<BasicDBObject> provideVascEntryRecordCreator() {
return new MongodbVascEntryRecordCreator();
}
private DBCollection getDBCollection() {
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,78 @@
/*
* 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.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.bson.types.ObjectId;
import net.forwardfire.vasc.backend.VascBackendAccessDataKey;
import net.forwardfire.vasc.backend.VascBackendException;
/**
* MongodbVascBackendAccessDataKey convert key type to string and back.
*
* @author Willem Cazander
* @version 1.0 Oct 26, 2014
*/
@SuppressWarnings("serial")
public class MongodbVascBackendAccessDataKey implements VascBackendAccessDataKey<ObjectId> {
private final Map<String,Class<?>> keyMapType;
public MongodbVascBackendAccessDataKey() {
keyMapType = new HashMap<String,Class<?>>(1);
keyMapType.put(AbstractMongodbVascBackend.PK_FIELD_NAME, ObjectId.class);
}
@Override
public Map<String, Class<?>> getKeyMapType() {
return keyMapType;
}
@Override
public Map<String, Serializable> getKeyMapFromPrimaryKey(ObjectId primaryKey) throws VascBackendException {
Map<String, Serializable> result = new HashMap<String,Serializable>(1);
result.put(MongodbVascBackendCrud.PK_FIELD_NAME, primaryKey);
return result;
}
@Override
public ObjectId getPrimaryKeyFromKeyMap(Map<String, Serializable> keyMap) throws VascBackendException {
return (ObjectId)keyMap.get(MongodbVascBackendCrud.PK_FIELD_NAME);
}
@Override
public Map<String, String> getStringMapFromPrimaryKey(ObjectId primaryKey) throws VascBackendException {
Map<String, String> result = new HashMap<String,String>(1);
result.put(MongodbVascBackendCrud.PK_FIELD_NAME, primaryKey.toString());
return result;
}
@Override
public ObjectId getPrimaryKeyFromStringMap(Map<String, String> keyMap) throws VascBackendException {
return new ObjectId(keyMap.get(MongodbVascBackendCrud.PK_FIELD_NAME));
}
}

View file

@ -20,41 +20,47 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend.data;
package net.forwardfire.vasc.backend.mongodb;
import java.io.Serializable;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
import org.bson.types.ObjectId;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import com.mongodb.BasicDBObject;
/**
* BeanVascEntryRecordCreator creates a new backend record based on class object.
* Provides a mongodb field entry knowlege.
*
* @author Willem Cazander
* @version 1.0 Dec 05, 2009
* @version 1.0 Dec 30, 2011
*/
public class BeanVascEntryRecordCreator<DATA_OBJECT extends Serializable> implements VascEntryRecordCreator<DATA_OBJECT> {
@SuppressWarnings("serial")
public class MongodbVascBackendAccessDataRecord implements VascBackendAccessDataRecord<ObjectId,BasicDBObject> {
private static final long serialVersionUID = 1L;
private Class<?> resultClass = null;
public BeanVascEntryRecordCreator(Class<?> resultClass) {
if (resultClass==null) {
throw new NullPointerException("Can't provide creator service with null class object.");
}
this.resultClass=resultClass;
}
@SuppressWarnings("unchecked")
/**
* @see net.forwardfire.vasc.backend.VascBackendAccessDataRecord#getPrimaryKey(java.io.Serializable)
*/
@Override
public DATA_OBJECT newRecord() throws VascBackendException {
try {
return (DATA_OBJECT)resultClass.newInstance();
} catch (InstantiationException e) {
throw new VascBackendException(e);
} catch (IllegalAccessException e) {
throw new VascBackendException(e);
}
public ObjectId getPrimaryKey(BasicDBObject record) throws VascBackendException {
return record.getObjectId(AbstractMongodbVascBackend.PK_FIELD_NAME);
}
/**
* @see net.forwardfire.vasc.backend.VascBackendAccessDataRecord#getValue(java.lang.String, java.io.Serializable)
*/
@Override
public Serializable getValue(String backendName, BasicDBObject record) throws VascBackendException {
return (Serializable) record.get(backendName);
}
/**
* @see net.forwardfire.vasc.backend.VascBackendAccessDataRecord#setValue(java.lang.String, java.io.Serializable, java.io.Serializable)
*/
@Override
public void setValue(String backendName, BasicDBObject record,Serializable value) throws VascBackendException {
record.put(backendName, value);
}
}

View file

@ -0,0 +1,91 @@
/*
* 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.logging.Logger;
import org.bson.types.ObjectId;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.BasicDBObject;
import com.mongodb.WriteConcern;
import com.mongodb.WriteResult;
/**
* MongodbVascBackend Provides backend for mongodb.
*
* @author Willem Cazander
* @version 1.0 Dec 30, 2011
*/
public class MongodbVascBackendCrud extends AbstractMongodbVascBackend implements VascBackendCrud<ObjectId,BasicDBObject> {
private Logger logger = null;
public MongodbVascBackendCrud() {
logger = Logger.getLogger(MongodbVascBackendCrud.class.getName());
}
@Override
public BasicDBObject newRecord() throws VascBackendException {
return new BasicDBObject();
}
@Override
public BasicDBObject fetch(ObjectId recordPK) throws VascBackendException {
return (BasicDBObject)getDBCollection().findOne(new BasicDBObject(PK_FIELD_NAME,recordPK));
}
@Override
public BasicDBObject persist(BasicDBObject object) throws VascBackendException {
getDBCollection().insert(object);
return fetch(object.getObjectId(AbstractMongodbVascBackend.PK_FIELD_NAME));
}
@Override
public BasicDBObject merge(BasicDBObject row) throws VascBackendException {
DBCollection coll = getDBCollection();
DBObject query = new BasicDBObject();
query.put(AbstractMongodbVascBackend.PK_FIELD_NAME,row.getObjectId(AbstractMongodbVascBackend.PK_FIELD_NAME));
WriteResult wr = coll.update(query,row,false,false,WriteConcern.SAFE);
logger.finer("WriteResult: "+wr);
return fetch(row.getObjectId(AbstractMongodbVascBackend.PK_FIELD_NAME));
}
@Override
public void delete(ObjectId objectId) throws VascBackendException {
deleteById(objectId);
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#createVascBackendAccessDataRecord()
*/
@Override
public VascBackendAccessDataRecord<ObjectId, BasicDBObject> createVascBackendAccessDataRecord() {
return new MongodbVascBackendAccessDataRecord();
}
}

View file

@ -0,0 +1,127 @@
/*
* 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.EnumSet;
import java.util.List;
import java.util.logging.Logger;
import org.bson.types.ObjectId;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendList;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.BasicDBObject;
/**
* MongodbVascBackendList Provides backend for mongodb.
*
* @author Willem Cazander
* @version 1.0 Dec 30, 2011
*/
public class MongodbVascBackendList extends AbstractMongodbVascBackend implements VascBackendList<ObjectId,BasicDBObject> {
private Logger logger = null;
private final EnumSet<VascBackendListFeature> features = EnumSet.noneOf(VascBackendListFeature.class);
private final List<String> rowActions = new ArrayList<String>();
public MongodbVascBackendList() {
logger = Logger.getLogger(MongodbVascBackendList.class.getName());
features.add(VascBackendListFeature.PAGE_DATA);
rowActions.add(ROW_ACTION_DELETE);
}
@Override
public EnumSet<VascBackendListFeature> getSupportedFeatures() {
return features;
}
private long fetchTotalExecuteSize(VascBackendListRequest state) {
DBCollection coll = getDBCollection();
DBObject query = createFilterQuery(state);
long result = coll.count(query);
return result;
}
private DBObject createFilterQuery(VascBackendListRequest state) {
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+"'");
}
return query;
}
@Override
public VascBackendListResult<BasicDBObject> execute(VascBackendListRequest state) throws VascBackendException {
return new DefaultVascBackendListResult<BasicDBObject>(executeList(state),fetchTotalExecuteSize(state));
}
private List<BasicDBObject> executeList(VascBackendListRequest state) throws VascBackendException {
DBCollection coll = getDBCollection();
DBObject query = createFilterQuery(state);
DBCursor cur = coll.find(query);
if (state.getPageSize()>0) {
cur.limit(state.getPageSize());
cur.skip(state.getPageIndex());
}
List<BasicDBObject> result = new ArrayList<BasicDBObject>(cur.count());
while (cur.hasNext()) {
DBObject row = cur.next();
result.add((BasicDBObject)row);
}
return result;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#createVascBackendAccessDataRecord()
*/
@Override
public VascBackendAccessDataRecord<ObjectId, BasicDBObject> createVascBackendAccessDataRecord() {
return new MongodbVascBackendAccessDataRecord();
}
@Override
public List<String> getSupportedRowActions() {
return rowActions;
}
@Override
public void executeRowAction(VascBackendListRequest request,List<ObjectId> recordPKs, String actionName) throws VascBackendException {
if (ROW_ACTION_DELETE.equals(actionName)) {
for (ObjectId objectId:recordPKs) {
deleteById(objectId);
}
}
}
}

View file

@ -0,0 +1,70 @@
/*
* 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 org.bson.types.ObjectId;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.select.DefaultVascBackendSelectItem;
import net.forwardfire.vasc.backend.select.VascBackendSelect;
import net.forwardfire.vasc.backend.select.VascBackendSelectItem;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.BasicDBObject;
/**
* MongodbVascBackendSelect Provides backend for mongodb.
*
* @author Willem Cazander
* @version 1.0 Dec 30, 2011
*/
public class MongodbVascBackendSelect extends AbstractMongodbVascBackend implements VascBackendSelect<ObjectId> {
@Override
public List<VascBackendSelectItem<ObjectId>> execute() throws VascBackendException {
DBCollection coll = getDBCollection();
DBObject query = new BasicDBObject();
DBCursor cur = coll.find(query);
List<VascBackendSelectItem<ObjectId>> result = new ArrayList<VascBackendSelectItem<ObjectId>>(cur.count());
while (cur.hasNext()) {
BasicDBObject row = (BasicDBObject)cur.next();
boolean header = false;
boolean enabled = true;
String name = row.getString("toto");
boolean nameI18nKey = false;
String description = row.getString("sdf");
boolean descriptionI18nKey = false;
ObjectId primaryKey = row.getObjectId(PK_FIELD_NAME);
result.add(new DefaultVascBackendSelectItem<ObjectId>(header,enabled,name,nameI18nKey,description,descriptionI18nKey,primaryKey));
}
return result;
}
}

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>vasc-backend-object</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,18 @@
<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>
<groupId>net.forwardfire.vasc.backend</groupId>
<artifactId>vasc-backend</artifactId>
<version>0.4.2-SNAPSHOT</version>
</parent>
<artifactId>vasc-backend-object</artifactId>
<name>vasc-backend-object</name>
<description>vasc-backend-object</description>
<dependencies>
<dependency>
<groupId>net.forwardfire.vasc.backend</groupId>
<artifactId>vasc-backend-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,141 @@
/*
* 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.object;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import net.forwardfire.vasc.backend.AbstractVascBackendLocal;
import net.forwardfire.vasc.backend.VascBackendAccessDataKey;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.select.DefaultVascBackendSelectItem;
import net.forwardfire.vasc.backend.select.VascBackendSelect;
import net.forwardfire.vasc.backend.select.VascBackendSelectItem;
/**
* ObjectEnumVascBackendSelect uses an Enum as select backend.
*
* @author Willem Cazander
* @version 1.0 Oct 27, 2007
*/
public class ObjectEnumVascBackendSelect<ENUM_RETURN_TYPE extends Serializable> extends AbstractVascBackendLocal<ENUM_RETURN_TYPE> implements VascBackendSelect<ENUM_RETURN_TYPE> {
private Class<? extends Enum<?>> enumClass = null;
private ObjectEnumVascBackendSelectType enumReturnType = null;
private String enumReturnMethod = null;
@Override
protected void startBackendLocal() {
requireNonNull(enumClass, "enumClass is null");
requireNonNull(enumReturnType, "enumClass is null");
}
@Override
public VascBackendAccessDataKey<ENUM_RETURN_TYPE> createVascBackendAccessDataKey() {
return null;
}
@Override
public List<VascBackendSelectItem<ENUM_RETURN_TYPE>> execute() throws VascBackendException {
List<VascBackendSelectItem<ENUM_RETURN_TYPE>> result = new ArrayList<VascBackendSelectItem<ENUM_RETURN_TYPE>>();
for (Enum<?> enumObject:enumClass.getEnumConstants()) {
boolean header = false;
boolean enabled = true;
String name = enumObject.name();
boolean nameI18nKey = false;
String description = enumObject.name();
boolean descriptionI18nKey = false;
ENUM_RETURN_TYPE primaryKey = (ENUM_RETURN_TYPE)getEnumValue(enumObject);
result.add(new DefaultVascBackendSelectItem<ENUM_RETURN_TYPE>(header,enabled,name,nameI18nKey,description,descriptionI18nKey,primaryKey));
}
return result;
}
private Object getEnumValue(Enum<?> enumObject) {
switch (enumReturnType) {
case VALUE:
return enumObject;
case METHOD:
try {
return enumObject.getClass().getMethod(enumReturnMethod, new Class<?>[]{}).invoke(null, new Object[]{});
} catch (Exception e) {
throw new IllegalStateException("Could not get static return method value: "+e.getMessage(),e);
}
case NAME:
return enumObject.name();
case ORDINAL:
return enumObject.ordinal();
default:
throw new IllegalStateException("Unknown enum return type: "+enumReturnType.name());
}
}
/*
public List<VascBackendSelectItem> getVascSelectItems(VascEntry currentEntry) throws VascException {
List<VascBackendSelectItem> result = new ArrayList<VascBackendSelectItem>(100);
if (nullLabel!=null) {
if (nullKeyValue==null) {
nullKeyValue = "null";
}
nullLabel = currentEntry.getVascFrontendController().getVascEntryResourceResolver().getTextValue(nullLabel);
VascBackendSelectItem item = new VascBackendSelectItem(nullLabel,null,nullKeyValue);
result.add(item);
}
if (enumClass!=null) {
for (Object o:enumClass.getEnumConstants()) {
String value = o.toString();
result.add(new VascBackendSelectItem(value,value,value));
}
}
if (data==null) {
return result;
}
if (data instanceof String) {
String[] values = ((String)data).split(",");
for (String value:values) {
result.add(new VascBackendSelectItem(value,value,value));
}
} else if (data instanceof List) {
List<?> values = (List<?>)data;
for (Object o:values) {
String value = ""+o;
result.add(new VascBackendSelectItem(value,value,value));
}
}
return result;
}
*/
}

View file

@ -0,0 +1,9 @@
package net.forwardfire.vasc.backend.object;
public enum ObjectEnumVascBackendSelectType {
VALUE,
NAME,
ORDINAL,
METHOD,
}

View file

@ -20,7 +20,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.impl.ui;
package net.forwardfire.vasc.backend.object;
import java.io.Serializable;
import java.util.ArrayList;
@ -28,17 +28,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.forwardfire.vasc.backend.DefaultVascBackendState;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascEntryFieldLocal;
import net.forwardfire.vasc.core.VascEntryLocal;
import net.forwardfire.vasc.core.ui.VascSelectItem;
import net.forwardfire.vasc.core.ui.VascSelectItemModel;
import net.forwardfire.vasc.core.VascException;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListRequest;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.backend.select.VascBackendSelectItem;
/**
* The DefaultVascSelectItemModel
@ -46,8 +40,9 @@ import net.forwardfire.vasc.core.VascException;
* @author Willem Cazander
* @version 1.0 Oct 27, 2007
*/
public class VascSelectItemModelEntry implements VascSelectItemModel {
public class VascSelectItemModelEntry /*implements VascSelectItemModel*/ {
/*
private static final long serialVersionUID = 1L;
private String entryId = null;
private String keyFieldId = null;
@ -59,12 +54,9 @@ public class VascSelectItemModelEntry implements VascSelectItemModel {
private Map<String,String> entryParameterFieldIds = new HashMap<String,String>(3);
private Boolean useParentFields = null;
/**
* @see net.forwardfire.vasc.core.ui.VascSelectItemModel#getVascSelectItems(net.forwardfire.vasc.core.VascEntry)
*/
@Override
public List<VascSelectItem> getVascSelectItems(VascEntry currentEntry) throws VascException {
List<VascSelectItem> result = new ArrayList<VascSelectItem>(100);
public List<VascBackendSelectItem> getVascSelectItems(VascEntry currentEntry) throws VascException {
List<VascBackendSelectItem> result = new ArrayList<VascBackendSelectItem>(100);
VascEntryLocal entry = (VascEntryLocal)currentEntry.getVascFrontendController().getVascController().getVascEntryController().getVascEntryById(entryId);
if (keyFieldId==null) {
@ -85,7 +77,7 @@ public class VascSelectItemModelEntry implements VascSelectItemModel {
// set frontend data for new clone, we need te get better lifecycle management for stats/entry/etc
entry.setVascFrontendController(currentEntry.getVascFrontendController());
VascBackend<Serializable> back = currentEntry.getVascFrontendController().getVascController().getVascEntryConfigController().configVascBackendProxied(currentEntry.getVascFrontendController().getVascController(), entry);
VascBackendCrud<Serializable,Serializable> back = currentEntry.getVascFrontendController().getVascController().getVascEntryConfigController().configVascBackendProxied(currentEntry.getVascFrontendController().getVascController(), entry);
try {
if (nullLabel!=null) {
if (nullKeyValue==null) {
@ -93,14 +85,14 @@ public class VascSelectItemModelEntry implements VascSelectItemModel {
}
nullLabel = currentEntry.getVascFrontendController().getVascEntryResourceResolver().getTextValue(nullLabel);
if (nullObjectValue==null) {
result.add(new VascSelectItem(nullLabel,null,nullKeyValue));
result.add(new VascBackendSelectItem(nullLabel,null,nullKeyValue));
} else {
result.add(new VascSelectItem(nullLabel,nullObjectValue,nullKeyValue));
result.add(new VascBackendSelectItem(nullLabel,nullObjectValue,nullKeyValue));
}
}
// set def para
VascBackendState state = new DefaultVascBackendState();
DefaultVascBackendListRequest state = new DefaultVascBackendListRequest();
for (String key2:entry.getEntryParameterKeys()) {
Object value = entry.getEntryParameter(key2);
@ -137,7 +129,7 @@ public class VascSelectItemModelEntry implements VascSelectItemModel {
}
VascEntryField field = fieldOrg.clone();
field.getVascValidators().clear();
VascEntryFieldValue<Serializable> v = fieldEntry.getVascFrontendController().getVascEntryState().getVascBackend().provideVascEntryFieldValue();
VascBackendAccessDataRecord<Serializable,Serializable> v = fieldEntry.getVascFrontendController().getVascEntryState().getVascBackend().provideVascEntryFieldValue();
Serializable record = fieldEntry.getVascFrontendController().getVascEntryState().getEntryDataObject();
if (record==null) {
@ -157,7 +149,7 @@ public class VascSelectItemModelEntry implements VascSelectItemModel {
VascEntryField fieldClone = key.clone();
fieldClone.getVascValidators().clear();
VascEntryFieldValue<Serializable> v = currentEntry.getVascFrontendController().getVascEntryState().getVascBackend().provideVascEntryFieldValue();
VascBackendAccessDataRecord<Serializable,Serializable> v = currentEntry.getVascFrontendController().getVascEntryState().getVascBackend().provideVascEntryFieldValue();
key.setVascEntryFieldValue(v);
}
if (dis.getVascEntryFieldValue()==null) {
@ -165,7 +157,7 @@ public class VascSelectItemModelEntry implements VascSelectItemModel {
VascEntryField fieldClone = dis.clone();
fieldClone.getVascValidators().clear();
VascEntryFieldValue<Serializable> v = currentEntry.getVascFrontendController().getVascEntryState().getVascBackend().provideVascEntryFieldValue();
VascBackendAccessDataRecord<Serializable,Serializable> v = currentEntry.getVascFrontendController().getVascEntryState().getVascBackend().provideVascEntryFieldValue();
dis.setVascEntryFieldValue(v);
}
@ -173,12 +165,12 @@ public class VascSelectItemModelEntry implements VascSelectItemModel {
// execute
for (Serializable o:back.execute(state).getPageData()) {
Serializable keyId = key.getVascEntryFieldValue().getValue(key.getBackendName(), o);
String nameId = dis.getVascEntryFieldValue().getDisplayValue(dis.getBackendName(), o);
String nameId = ""+dis.getVascEntryFieldValue().getValue(dis.getBackendName(), o);
if (returnKeyValue!=null && false==returnKeyValue) {
VascSelectItem item = new VascSelectItem(nameId,o,""+keyId);
VascBackendSelectItem item = new VascBackendSelectItem(nameId,o,""+keyId);
result.add(item);
} else {
VascSelectItem item = new VascSelectItem(nameId,keyId,""+keyId); // per default return keyID object.
VascBackendSelectItem item = new VascBackendSelectItem(nameId,keyId,""+keyId); // per default return keyID object.
result.add(item);
}
}
@ -187,132 +179,133 @@ public class VascSelectItemModelEntry implements VascSelectItemModel {
}
return result;
}
/**
* @return the entryId
*/
public String getEntryId() {
return entryId;
}
/**
* @param entryId the entryId to set
*/
public void setEntryId(String entryId) {
this.entryId = entryId;
}
/**
* @return the keyFieldId
*/
public String getKeyFieldId() {
return keyFieldId;
}
/**
* @param keyFieldId the keyFieldId to set
*/
public void setKeyFieldId(String keyFieldId) {
this.keyFieldId = keyFieldId;
}
/**
* @return the displayFieldId
*/
public String getDisplayFieldId() {
return displayFieldId;
}
/**
* @param displayFieldId the displayFieldId to set
*/
public void setDisplayFieldId(String displayFieldId) {
this.displayFieldId = displayFieldId;
}
/**
* @return the nullLabel
*/
@Override
public String getNullLabel() {
return nullLabel;
}
/**
* @param nullLabel the nullLabel to set
*/
@Override
public void setNullLabel(String nullLabel) {
this.nullLabel = nullLabel;
}
/**
* @return the nullKeyValue
*/
@Override
public String getNullKeyValue() {
return nullKeyValue;
}
/**
* @param nullKeyValue the nullKeyValue to set
*/
@Override
public void setNullKeyValue(String nullKeyValue) {
this.nullKeyValue = nullKeyValue;
}
/**
* @return the returnKeyValue
*/
public Boolean getReturnKeyValue() {
return returnKeyValue;
}
/**
* @param returnKeyValue the returnKeyValue to set
*/
public void setReturnKeyValue(Boolean returnKeyValue) {
this.returnKeyValue = returnKeyValue;
}
public String getEntryParameterFieldId(String parameterName) {
return entryParameterFieldIds.get(parameterName);
}
public void addEntryParameterFieldId(String parameterName,String valueFieldId) {
entryParameterFieldIds.put(parameterName, valueFieldId);
}
public List<String> getEntryParameterFieldIdKeys() {
return new ArrayList<String>(entryParameterFieldIds.keySet());
}
/**
* @return the useParentFields
*/
public Boolean getUseParentFields() {
return useParentFields;
}
/**
* @param useParentFields the useParentFields to set
*/
public void setUseParentFields(Boolean useParentFields) {
this.useParentFields = useParentFields;
}
/**
* @return the nullObjectValue
*/
public String getNullObjectValue() {
return nullObjectValue;
}
/**
* @param nullObjectValue the nullObjectValue to set
*/
public void setNullObjectValue(String nullObjectValue) {
this.nullObjectValue = nullObjectValue;
}
/*
//
// /**
// * @return the entryId
// */
// public String getEntryId() {
// return entryId;
// }
//
// /**
// * @param entryId the entryId to set
// */
// public void setEntryId(String entryId) {
// this.entryId = entryId;
// }
//
// /**
// * @return the keyFieldId
// */
// public String getKeyFieldId() {
// return keyFieldId;
// }
//
// /**
// * @param keyFieldId the keyFieldId to set
// */
// public void setKeyFieldId(String keyFieldId) {
// this.keyFieldId = keyFieldId;
// }
//
// /**
// * @return the displayFieldId
// */
// public String getDisplayFieldId() {
// return displayFieldId;
// }
//
// /**
// * @param displayFieldId the displayFieldId to set
// */
// public void setDisplayFieldId(String displayFieldId) {
// this.displayFieldId = displayFieldId;
// }
//
// /**
// * @return the nullLabel
// */
// @Override
// public String getNullLabel() {
// return nullLabel;
// }
//
// /**
// * @param nullLabel the nullLabel to set
// */
// @Override
// public void setNullLabel(String nullLabel) {
// this.nullLabel = nullLabel;
// }
//
// /**
// * @return the nullKeyValue
// */
// @Override
// public String getNullKeyValue() {
// return nullKeyValue;
// }
//
// /**
// * @param nullKeyValue the nullKeyValue to set
// */
// @Override
// public void setNullKeyValue(String nullKeyValue) {
// this.nullKeyValue = nullKeyValue;
// }
//
// /**
// * @return the returnKeyValue
// */
// public Boolean getReturnKeyValue() {
// return returnKeyValue;
// }
//
// /**
// * @param returnKeyValue the returnKeyValue to set
// */
// public void setReturnKeyValue(Boolean returnKeyValue) {
// this.returnKeyValue = returnKeyValue;
// }
//
// public String getEntryParameterFieldId(String parameterName) {
// return entryParameterFieldIds.get(parameterName);
// }
// public void addEntryParameterFieldId(String parameterName,String valueFieldId) {
// entryParameterFieldIds.put(parameterName, valueFieldId);
// }
// public List<String> getEntryParameterFieldIdKeys() {
// return new ArrayList<String>(entryParameterFieldIds.keySet());
// }
//
// /**
// * @return the useParentFields
// */
// public Boolean getUseParentFields() {
// return useParentFields;
// }
//
// /**
// * @param useParentFields the useParentFields to set
// */
// public void setUseParentFields(Boolean useParentFields) {
// this.useParentFields = useParentFields;
// }
//
// /**
// * @return the nullObjectValue
// */
// public String getNullObjectValue() {
// return nullObjectValue;
// }
//
// /**
// * @param nullObjectValue the nullObjectValue to set
// */
// public void setNullObjectValue(String nullObjectValue) {
// this.nullObjectValue = nullObjectValue;
// }
//
}

View file

@ -0,0 +1,8 @@
/**
*
*/
/**
* @author willemc
*
*/
package net.forwardfire.vasc.backend.object;

View file

@ -4,12 +4,12 @@ import java.io.Serializable;
import junit.framework.TestCase;
import net.forwardfire.vasc.backend.DefaultVascBackendController;
import net.forwardfire.vasc.backend.DefaultVascBackendState;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListRequest;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.metamodel.MetaModelDataContextJdbc;
import net.forwardfire.vasc.backend.metamodel.MetaModelVascBackend;
import net.forwardfire.vasc.backend.metamodel.MetaModelVascBackendCrud;
import org.testng.annotations.Test;
@ -27,7 +27,7 @@ public class CrudTest extends TestCase {
mmDB.setUsername("postgres");
mmDB.setPassword("postgresql");
MetaModelVascBackend mm = new MetaModelVascBackend();
MetaModelVascBackendCrud mm = new MetaModelVascBackendCrud();
mm.setId("mm");
mm.setTable("country");
mm.setTableId("country_id");
@ -42,21 +42,23 @@ public class CrudTest extends TestCase {
setup();
VascBackend<Serializable> backend = (VascBackend<Serializable>) backends.getVascBackendById("mm");
VascBackendCrud<Serializable,Serializable> backend = (VascBackendCrud<Serializable,Serializable>) backends.getVascBackendById(VascBackendCrud.class,"mm");
assertNotNull(backend);
DefaultVascBackendState state = new DefaultVascBackendState();
VascBackendResult<Serializable> result = backend.execute(state);
assertNotNull(result);
assertFalse(result.getPageData().isEmpty());
VascEntryFieldValue<Serializable> values = backend.provideVascEntryFieldValue();
for (Serializable record:result.getPageData()) {
Object id = values.getValue("country_id", record);
Object name = values.getValue("name", record);
Object code = values.getValue("code", record);
System.out.println("line: "+id+" name: "+name+" code: "+code);
}
//
// DefaultVascBackendListRequest state = new DefaultVascBackendListRequest();
// VascBackendListResult<Serializable> result = backend.execute(state);
// assertNotNull(result);
// assertFalse(result.getData().isEmpty());
//
// VascBackendAccessDataRecord<Serializable,Serializable> values = backend.provideVascEntryFieldValue();
//
// for (Serializable record:result.getData()) {
// Object id = values.getValue("country_id", record);
// Object name = values.getValue("name", record);
// Object code = values.getValue("code", record);
// System.out.println("line: "+id+" name: "+name+" code: "+code);
// }
}
}

View file

@ -1,4 +1,5 @@
<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">
<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>
<groupId>net.forwardfire.vasc</groupId>
@ -15,9 +16,9 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>${ejb-api.version}</version>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee-api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

View file

@ -26,12 +26,12 @@ import java.io.Serializable;
import java.util.List;
import java.util.Map;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
/**
* VascServiceRemoteBackend wraps VascBasckend to the ejb3 context.
@ -39,7 +39,7 @@ import net.forwardfire.vasc.backend.VascEntryRecordCreator;
* @author Willem Cazander
* @version 1.0 18 Nov 2012
*/
public class VascServiceRemoteBackend<DATA_OBJECT extends Serializable> implements VascBackend<DATA_OBJECT> {
public class VascServiceRemoteBackend<DATA_OBJECT extends Serializable,DATA_PK extends Serializable> implements VascBackendCrud<DATA_OBJECT,DATA_PK> {
private String backendId = null;
private VascServiceManager vascManager = null;
@ -68,13 +68,13 @@ public class VascServiceRemoteBackend<DATA_OBJECT extends Serializable> implemen
// we cant change id
}
public void delete(DATA_OBJECT object) throws VascBackendException {
public void delete(DATA_PK object) throws VascBackendException {
Object[] args = new Object[1];
args[0]=object;
vascManager.invokeBackendMethod(backendId, "delete", args);
}
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascBackendException {
public long doRecordMoveDownById(VascBackendListRequest state,Object primaryId) throws VascBackendException {
Object[] args = new Object[2];
args[0]=state;
args[1]=primaryId;
@ -82,7 +82,7 @@ public class VascServiceRemoteBackend<DATA_OBJECT extends Serializable> implemen
return (Long)result;
}
public long doRecordMoveUpById(VascBackendState state, Object primaryId) throws VascBackendException {
public long doRecordMoveUpById(VascBackendListRequest state, Object primaryId) throws VascBackendException {
Object[] args = new Object[2];
args[0]=state;
args[1]=primaryId;
@ -91,14 +91,14 @@ public class VascServiceRemoteBackend<DATA_OBJECT extends Serializable> implemen
}
@SuppressWarnings("unchecked")
public VascBackendResult<DATA_OBJECT> execute(VascBackendState state) throws VascBackendException {
public VascBackendListResult<DATA_OBJECT> execute(VascBackendListRequest state) throws VascBackendException {
Object[] args = new Object[1];
args[0]=state;
Object result = vascManager.invokeBackendMethod(backendId, "execute", args);
return (VascBackendResult<DATA_OBJECT>)result;
return (VascBackendListResult<DATA_OBJECT>)result;
}
public long fetchTotalExecuteSize(VascBackendState state) {
public long fetchTotalExecuteSize(VascBackendListRequest state) {
Object[] args = new Object[1];
args[0]=state;
Object result = vascManager.invokeBackendMethod(backendId, "fetchTotalExecuteSize", args);
@ -144,10 +144,10 @@ public class VascServiceRemoteBackend<DATA_OBJECT extends Serializable> implemen
}
@Override
public VascEntryFieldValue provideVascEntryFieldValue() {
public VascBackendAccessDataRecord provideVascEntryFieldValue() {
Object[] args = new Object[0];
Object result = vascManager.invokeBackendMethod(backendId, "provideVascEntryFieldValue", args);
return (VascEntryFieldValue)result;
return (VascBackendAccessDataRecord)result;
}
@Override

View file

@ -1,4 +1,5 @@
<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">
<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>
<groupId>net.forwardfire.vasc</groupId>
@ -20,15 +21,9 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>${ejb-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>${persistence-api.version}</version>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee-api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

View file

@ -45,7 +45,7 @@ import javax.persistence.EntityManager;
import org.x4o.xml.io.X4OReader;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backends.jpa.EntityManagerProvider;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry;
@ -224,7 +224,7 @@ public class VascServiceManagerImpl implements VascServiceManagerRemote,VascServ
public Object invokeBackendMethod(String backendId,String method,Object[] args) {
VascController v = getVascController();
VascBackend vb = v.getVascBackendController().getVascBackendById(backendId);
VascBackendCrud vb = v.getVascBackendController().getVascBackendById(backendId);
Method vbm = null;
for (Method m:vb.getClass().getMethods()) {
if (m.getName().equals(method)) {

View file

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>vasc</artifactId>
@ -25,9 +26,9 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>${persistence-api.version}</version>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>

View file

@ -26,7 +26,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import net.forwardfire.vasc.core.ui.VascSelectItem;
import net.forwardfire.vasc.backend.select.VascBackendSelectItem;
import net.forwardfire.vasc.core.ui.VascSelectItemModel;
import net.forwardfire.vasc.core.VascException;
@ -54,8 +54,8 @@ public class VascChoicesSelectItemModel implements VascSelectItemModel,Serializa
* @see net.forwardfire.vasc.core.ui.VascSelectItemModel#getVascSelectItems(net.forwardfire.vasc.core.VascEntry)
*/
@Override
public List<VascSelectItem> getVascSelectItems(net.forwardfire.vasc.core.VascEntry entry) throws VascException {
List<VascSelectItem> result = new ArrayList<VascSelectItem>(10);
public List<VascBackendSelectItem> getVascSelectItems(net.forwardfire.vasc.core.VascEntry entry) throws VascException {
List<VascBackendSelectItem> result = new ArrayList<VascBackendSelectItem>(10);
if ("null".equals(vascChoices.nullLabel())==false) {
nullLabel = vascChoices.nullLabel();
nullKeyValue = vascChoices.nullKeyValue();
@ -65,7 +65,7 @@ public class VascChoicesSelectItemModel implements VascSelectItemModel,Serializa
nullKeyValue = "null";
}
String nullLabelText = entry.getVascFrontendController().getVascEntryResourceResolver().getTextValue(nullLabel);
VascSelectItem item = new VascSelectItem(nullLabelText,null,nullKeyValue);
VascBackendSelectItem item = new VascBackendSelectItem(nullLabelText,null,nullKeyValue);
result.add(item);
}
int index = 0;
@ -78,7 +78,7 @@ public class VascChoicesSelectItemModel implements VascSelectItemModel,Serializa
throw new IllegalStateException("Can't have unequal sizes of array of keys and values of vascChoices annotation.");
}
for (String key:a) {
VascSelectItem item = new VascSelectItem();
VascBackendSelectItem item = new VascBackendSelectItem();
String name = null;
if (val) {
name = key;

View file

@ -23,13 +23,14 @@
package net.forwardfire.vasc.backend.proxy;
import java.io.Serializable;
import java.util.EnumSet;
import java.util.List;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
import net.forwardfire.vasc.backend.list.VascBackendList;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.core.VascEntry;
/**
@ -38,19 +39,25 @@ import net.forwardfire.vasc.core.VascEntry;
* @author Willem Cazander
* @version 1.0 Apr 1, 2009
*/
abstract public class AbstractVascBackendProxy implements VascBackendProxy {
abstract public class AbstractVascBackendProxy<DATA_PK extends Serializable,DATA_RECORD extends Serializable> implements VascBackendProxy<DATA_PK,DATA_RECORD> {
protected VascBackend<Serializable> backend = null;
protected VascBackendList<DATA_PK,DATA_RECORD> backend = null;
protected VascEntry entry = null;
private volatile boolean running = false;
@Override
abstract public VascBackendProxy clone() throws CloneNotSupportedException;
abstract public VascBackendProxy<DATA_PK,DATA_RECORD> clone() throws CloneNotSupportedException;
protected void startBackendProxy() {
}
protected void stopBackendProxy() {
}
/**
* @see net.forwardfire.vasc.backend.proxy.VascBackendProxy#initProxy(net.forwardfire.vasc.backend.VascBackend, net.forwardfire.vasc.core.VascEntry)
* @see net.forwardfire.vasc.backend.proxy.VascBackendProxy#initProxy(net.forwardfire.vasc.backend.crud.VascBackendList, net.forwardfire.vasc.core.VascEntry)
*/
@Override
public void initProxy(VascBackend<Serializable> backend, VascEntry entry) {
final public void initProxy(VascBackendList<DATA_PK,DATA_RECORD> backend, VascEntry entry) {
if (backend==null) {
throw new NullPointerException("backend object may not be null.");
}
@ -59,6 +66,33 @@ abstract public class AbstractVascBackendProxy implements VascBackendProxy {
}
this.backend=backend;
this.entry=entry;
startBackend();
}
/**
* @see net.forwardfire.vasc.backend.VascBackendLifeCycle#startBackend()
*/
@Override
final public void startBackend() {
startBackendProxy();
running = true;
}
/**
* @see net.forwardfire.vasc.backend.VascBackendLifeCycle#stopBackend()
*/
@Override
final public void stopBackend() {
running = false;
stopBackendProxy();
}
/**
* @see net.forwardfire.vasc.backend.VascBackendLifeCycle#isRunning()
*/
@Override
public boolean isRunning() {
return running;
}
/**
@ -70,104 +104,7 @@ abstract public class AbstractVascBackendProxy implements VascBackendProxy {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#startBackend()
*/
@Override
public void startBackend() {
backend.startBackend();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#stopBackend()
*/
@Override
public void stopBackend() {
backend.stopBackend();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isReadOnly()
*/
@Override
public boolean isReadOnly() {
return backend.isReadOnly();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isSortable()
*/
@Override
public boolean isSortable() {
return backend.isSortable();
}
/**
* @throws Exception
* @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state)
*/
@Override
public VascBackendResult<Serializable> execute(VascBackendState state) throws VascBackendException {
return backend.execute(state);
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#delete(java.lang.Object)
*/
@Override
public void delete(Serializable object) throws VascBackendException {
backend.delete(object);
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isPageable()
*/
@Override
public boolean isPageable() {
return backend.isPageable();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isSearchable()
*/
@Override
public boolean isSearchable() {
return backend.isSearchable();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#merge(java.lang.Object)
*/
@Override
public Serializable merge(Serializable object) throws VascBackendException {
return backend.merge(object);
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object)
*/
@Override
public void persist(Serializable object) throws VascBackendException {
backend.persist(object);
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryFieldValue()
*/
@Override
public VascEntryFieldValue<Serializable> provideVascEntryFieldValue() {
return backend.provideVascEntryFieldValue();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#provideVascEntryRecordCreator()
*/
@Override
public VascEntryRecordCreator<Serializable> provideVascEntryRecordCreator() {
return backend.provideVascEntryRecordCreator();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#getId()
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#getId()
*/
@Override
public String getId() {
@ -175,50 +112,25 @@ abstract public class AbstractVascBackendProxy implements VascBackendProxy {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#setId(java.lang.String)
* @see net.forwardfire.vasc.backend.list.VascBackendList#getSupportedFeatures()
*/
@Override
public void setId(String id) {
backend.setId(id);
public EnumSet<VascBackendListFeature> getSupportedFeatures() {
return backend.getSupportedFeatures(); // backend will always provide cloned copy
}
/**
* @see net.forwardfire.vasc.core.VascBackend#doRecordMoveDownById(VascBackendState state,java.lang.Object)
*/
@Override
public long doRecordMoveDownById(VascBackendState state,Object primaryId) throws VascBackendException {
return backend.doRecordMoveDownById(state,primaryId);
public VascBackendListResult<DATA_RECORD> execute(VascBackendListRequest request) throws VascBackendException {
return backend.execute(request);
}
/**
* @see net.forwardfire.vasc.core.VascBackend#doRecordMoveUpById(VascBackendState state,java.lang.Object)
*/
@Override
public long doRecordMoveUpById(VascBackendState state,Object primaryId) throws VascBackendException {
return backend.doRecordMoveUpById(state,primaryId);
public List<String> getSupportedRowActions() {
return backend.getSupportedRowActions();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isRecordMoveable()
*/
@Override
public boolean isRecordMoveable() {
return backend.isRecordMoveable();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#hasPageSummary()
*/
@Override
public boolean hasPageSummary() {
return backend.hasPageSummary();
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#hasTotalSummary()
*/
@Override
public boolean hasTotalSummary() {
return backend.hasTotalSummary();
public void executeRowAction(VascBackendListRequest request,List<DATA_PK> recordPKs,String actionName) throws VascBackendException {
executeRowAction(request, recordPKs, actionName);
}
}

View file

@ -20,88 +20,45 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.core.ui;
package net.forwardfire.vasc.backend.proxy;
import java.io.Serializable;
import java.util.EnumSet;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
/**
* AbstractVascBackendProxyFeature to implement single features of the backend.
*
* @author Willem Cazander
* @version 1.0 Aug 12, 2007
* @version 1.0 Aug 27, 2014
*/
public class VascSelectItem {
abstract public class AbstractVascBackendProxyFeature<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends AbstractVascBackendProxy<DATA_PK,DATA_RECORD> {
private String label = null;
private Serializable value = null;
private String keyValue = null;
private boolean disabled = false;
private final VascBackendListFeature proxyFeature;
private final VascBackendListFeature proxyFeatureExtraFlag;
public VascSelectItem() {
}
public VascSelectItem(String label,Serializable value) {
setLabel(label);
setValue(value);
}
public VascSelectItem(String label,Serializable value,String keyValue) {
setLabel(label);
setValue(value);
setKeyValue(keyValue);
protected AbstractVascBackendProxyFeature(VascBackendListFeature proxyFeature,VascBackendListFeature proxyFeatureExtraFlag) {
this.proxyFeature=proxyFeature;
this.proxyFeatureExtraFlag=proxyFeatureExtraFlag;
}
/**
* @return the label
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#isProxyNeeded()
*/
public String getLabel() {
return label;
@Override
final public boolean isProxyNeeded() {
return !backend.getSupportedFeatures().contains(proxyFeature);
}
/**
* @param label the label to set
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#getSupportedFeatures()
*/
public void setLabel(String label) {
this.label = label;
}
/**
* @return the value
*/
public Serializable getValue() {
return value;
}
/**
* @param value the value to set
*/
public void setValue(Serializable value) {
this.value = value;
}
/**
* @return the keyValue
*/
public String getKeyValue() {
return keyValue;
}
/**
* @param keyValue the keyValue to set
*/
public void setKeyValue(String keyValue) {
this.keyValue = keyValue;
}
/**
* @return the disabled
*/
public boolean isDisabled() {
return disabled;
}
/**
* @param disabled the disabled to set
*/
public void setDisabled(boolean disabled) {
this.disabled = disabled;
@Override
final public EnumSet<VascBackendListFeature> getSupportedFeatures() {
EnumSet<VascBackendListFeature> result = super.getSupportedFeatures();
result.add(proxyFeature);
result.add(proxyFeatureExtraFlag);
return result;
}
}

View file

@ -24,7 +24,8 @@ package net.forwardfire.vasc.backend.proxy;
import java.io.Serializable;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendLifeCycle;
import net.forwardfire.vasc.backend.list.VascBackendList;
import net.forwardfire.vasc.core.VascEntry;
/**
@ -33,11 +34,11 @@ import net.forwardfire.vasc.core.VascEntry;
* @author Willem Cazander
* @version 1.0 May 9, 2012
*/
public interface VascBackendProxy extends VascBackend<Serializable>,Cloneable {
public interface VascBackendProxy<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends VascBackendList<DATA_PK,DATA_RECORD>,VascBackendLifeCycle<DATA_PK>,Cloneable {
void initProxy(VascBackend<Serializable> backend,VascEntry entry);
void initProxy(VascBackendList<DATA_PK,DATA_RECORD> backend,VascEntry entry);
boolean isProxyNeeded();
VascBackendProxy clone() throws CloneNotSupportedException;
VascBackendProxy<DATA_PK,DATA_RECORD> clone() throws CloneNotSupportedException;
}

View file

@ -1,167 +0,0 @@
/*
* Copyright 2007-2012 forwardfire.net All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.forwardfire.vasc.backend.proxy;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
/**
* Does simple caching for the data.
*
* @author Willem Cazander
* @version 1.0 Nov 19, 2009
*/
public class VascBackendProxyCache extends AbstractVascBackendProxy {
private VascBackendResult<Serializable> data = null;
private String searchString = null;
private Map<String,Object> dataState = null;
private int pageIndex = 0;
private int pageSize = 0;
private int pageSizeMax = 0;
private String sortField = null;
private boolean sortDir = true;
private boolean requestFlush = false;
public VascBackendProxyCache() {
dataState = new HashMap<String,Object>(10);
}
/**
* @see java.lang.Object#clone()
*/
@Override
public VascBackendProxy clone() throws CloneNotSupportedException {
VascBackendProxyCache result = new VascBackendProxyCache();
return result;
}
private boolean isStateChanged(VascBackendState state) {
boolean changed = false;
for (String key:state.getDataParameterKeys()) {
Object value = state.getDataParameter(key);
Object valueLast = dataState.get(key);
dataState.put(key, value);
if (value==null & valueLast==null) {
continue;
}
if (value==null & valueLast!=null) {
changed = true;
break;
}
if (value.equals(valueLast)==false) {
changed = true;
break;
}
}
if (state.getSortField()!=null && state.getSortField().equals(sortField)==false) {
changed = true;
}
sortField = state.getSortField();
if (state.isSortAscending()==sortDir) {
changed = true;
}
sortDir = state.isSortAscending();
if (state.getPageSizeMax()==pageSizeMax) {
changed = true;
}
pageSizeMax = state.getPageSizeMax();
if (state.getPageSize()==pageSize) {
changed = true;
}
pageSize = state.getPageSize();
if (state.getPageIndex()==pageIndex) {
changed = true;
}
pageIndex = state.getPageIndex();
if (state.getSearchString()!=null && state.getSearchString().equals(searchString)==false) {
changed = true;
}
searchString = state.getSearchString();
if (requestFlush) {
requestFlush = false;
changed = true;
}
return changed;
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#stopBackend()
*/
@Override
public void stopBackend() {
super.stopBackend();
data = null;
dataState.clear();
requestFlush = true;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state)
*/
@Override
public VascBackendResult<Serializable> execute(VascBackendState state) throws VascBackendException {
boolean changed = isStateChanged(state);
if (data==null | changed) {
data = backend.execute(state);
}
return data;
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#delete(java.lang.Object)
*/
@Override
public void delete(Serializable object) throws VascBackendException {
requestFlush = true;
super.delete(object);
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#merge(java.lang.Object)
*/
@Override
public Serializable merge(Serializable object) throws VascBackendException {
requestFlush = true;
return super.merge(object);
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#persist(java.lang.Object)
*/
@Override
public void persist(Serializable object) throws VascBackendException {
requestFlush = true;
super.persist(object);
}
}

View file

@ -26,10 +26,10 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.entry.VascEntryBackendEventListener;
import net.forwardfire.vasc.core.entry.VascEntryBackendEventListener.VascBackendEventType;
@ -40,7 +40,7 @@ import net.forwardfire.vasc.core.entry.VascEntryBackendEventListener.VascBackend
* @author Willem Cazander
* @version 1.0 Sep 21, 2010
*/
public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy {
public class VascBackendProxyEventExecutor<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends AbstractVascBackendProxy<DATA_PK,DATA_RECORD> {
private List<VascEntryBackendEventListener> listeners = null;
@ -48,13 +48,13 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy {
* @see java.lang.Object#clone()
*/
@Override
public VascBackendProxy clone() throws CloneNotSupportedException {
VascBackendProxyEventExecutor result = new VascBackendProxyEventExecutor();
public VascBackendProxy<DATA_PK,DATA_RECORD> clone() throws CloneNotSupportedException {
VascBackendProxyEventExecutor<DATA_PK,DATA_RECORD> result = new VascBackendProxyEventExecutor<>();
return result;
}
@Override
public void initProxy(VascBackend<Serializable> backend,VascEntry entry) {
public void initProxy(VascBackendCrud<Serializable> backend,VascEntry entry) {
super.initProxy(backend, entry);
this.entry=entry;
this.listeners=new ArrayList<VascEntryBackendEventListener>(10);
@ -115,10 +115,10 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy {
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveDownById(net.forwardfire.vasc.backend.VascBackendState, java.lang.Object)
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveDownById(net.forwardfire.vasc.backend.list.VascBackendListRequest, java.lang.Object)
*/
@Override
public long doRecordMoveDownById(VascBackendState state, Object primaryId) throws VascBackendException {
public long doRecordMoveDownById(VascBackendListRequest state, Object primaryId) throws VascBackendException {
fireVascEvent(VascBackendEventType.PRE_MOVE_DOWN,primaryId);
Long result = super.doRecordMoveDownById(state, primaryId);
fireVascEvent(VascBackendEventType.POST_MOVE_DOWN,result);
@ -126,10 +126,10 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy {
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveUpById(net.forwardfire.vasc.backend.VascBackendState, java.lang.Object)
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveUpById(net.forwardfire.vasc.backend.list.VascBackendListRequest, java.lang.Object)
*/
@Override
public long doRecordMoveUpById(VascBackendState state, Object primaryId) throws VascBackendException {
public long doRecordMoveUpById(VascBackendListRequest state, Object primaryId) throws VascBackendException {
fireVascEvent(VascBackendEventType.PRE_MOVE_UP,primaryId);
Long result = super.doRecordMoveUpById(state, primaryId);
fireVascEvent(VascBackendEventType.POST_MOVE_UP,result);
@ -137,12 +137,12 @@ public class VascBackendProxyEventExecutor extends AbstractVascBackendProxy {
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#execute(net.forwardfire.vasc.backend.VascBackendState)
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#execute(net.forwardfire.vasc.backend.list.VascBackendListRequest)
*/
@Override
public VascBackendResult<Serializable> execute(VascBackendState state) throws VascBackendException {
public VascBackendListResult<Serializable> execute(VascBackendListRequest state) throws VascBackendException {
fireVascEvent(VascBackendEventType.PRE_EXECUTE,state);
VascBackendResult<Serializable> result = super.execute(state);
VascBackendListResult<Serializable> result = super.execute(state);
fireVascEvent(VascBackendEventType.POST_EXECUTE,result);
return result;
}

View file

@ -26,12 +26,10 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import net.forwardfire.vasc.backend.DefaultVascBackendResult;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
/**
* Simple filter support
@ -39,7 +37,7 @@ import net.forwardfire.vasc.core.VascEntry;
* @author Willem Cazander
* @version 1.0 Oct 27, 2007
*/
public class VascBackendProxyFilter extends AbstractVascBackendProxy {
public class VascBackendProxyFilter<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends AbstractVascBackendProxy<DATA_PK,DATA_RECORD> {
private List<VascProxyFilter> filters = null;
@ -47,17 +45,16 @@ public class VascBackendProxyFilter extends AbstractVascBackendProxy {
* @see java.lang.Object#clone()
*/
@Override
public VascBackendProxy clone() throws CloneNotSupportedException {
VascBackendProxyFilter result = new VascBackendProxyFilter();
public VascBackendProxy<DATA_PK,DATA_RECORD> clone() throws CloneNotSupportedException {
VascBackendProxyFilter<DATA_PK,DATA_RECORD> result = new VascBackendProxyFilter<>();
return result;
}
/**
* @see net.forwardfire.vasc.backend.proxy.VascBackendProxy#initProxy(net.forwardfire.vasc.backend.VascBackend, net.forwardfire.vasc.core.VascEntry)
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#startBackendProxy()
*/
@Override
public void initProxy(VascBackend<Serializable> backend, VascEntry entry) {
super.initProxy(backend,entry);
protected void startBackendProxy() {
filters = entry.getVascBackendFilters();
for (VascProxyFilter filter:filters) {
filter.initFilter(entry);
@ -76,19 +73,19 @@ public class VascBackendProxyFilter extends AbstractVascBackendProxy {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state)
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#execute(VascBackendListRequest state)
*/
@Override
public VascBackendResult<Serializable> execute(VascBackendState state) throws VascBackendException {
VascBackendResult<Serializable> result = backend.execute(state);
public VascBackendListResult<Serializable> execute(VascBackendListRequest state) throws VascBackendException {
VascBackendListResult<Serializable> result = backend.execute(state);
if (filters==null) {
return result;
}
if (filters.isEmpty()) {
return result;
}
List<Serializable> search = new ArrayList<Serializable>(result.getPageData().size()/2);
for (Serializable o:result.getPageData()) {
List<Serializable> search = new ArrayList<Serializable>(result.getData().size()/2);
for (Serializable o:result.getData()) {
for (VascProxyFilter filter:filters) {
Serializable r = filter.filterObject(o);
if (r!=null) {
@ -96,6 +93,6 @@ public class VascBackendProxyFilter extends AbstractVascBackendProxy {
}
}
}
return new DefaultVascBackendResult<Serializable>(search,search.size());
return new DefaultVascBackendListResult<Serializable>(search,search.size());
}
}

View file

@ -26,10 +26,11 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import net.forwardfire.vasc.backend.DefaultVascBackendResult;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
/**
* Simulates a real pages backend.
@ -37,42 +38,26 @@ import net.forwardfire.vasc.backend.VascBackendState;
* @author Willem Cazander
* @version 1.0 Oct 27, 2007
*/
public class VascBackendProxyPaged extends AbstractVascBackendProxy {
public class VascBackendProxyPaged<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends AbstractVascBackendProxyFeature<DATA_PK,DATA_RECORD> {
public VascBackendProxyPaged() {
super(VascBackendListFeature.PAGE_DATA,VascBackendListFeature.PAGE_DATA_PROXY);
}
/**
* @see java.lang.Object#clone()
*/
@Override
public VascBackendProxy clone() throws CloneNotSupportedException {
VascBackendProxyPaged result = new VascBackendProxyPaged();
return result;
public VascBackendProxy<DATA_PK,DATA_RECORD> clone() throws CloneNotSupportedException {
return new VascBackendProxyPaged<DATA_PK,DATA_RECORD>();
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#isProxyNeeded()
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#execute(VascBackendListRequest state)
*/
@Override
public boolean isProxyNeeded() {
if (backend.isPageable()) {
return false;
}
return true;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isPageable()
*/
@Override
public boolean isPageable() {
return true;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state)
*/
@Override
public VascBackendResult<Serializable> execute(VascBackendState state) throws VascBackendException {
VascBackendResult<Serializable> allData = backend.execute(state);
public VascBackendListResult<DATA_RECORD> execute(VascBackendListRequest state) throws VascBackendException {
VascBackendListResult<Serializable> allData = backend.execute(state);
int pageSize = state.getPageSize();
if (pageSize==0) {
return allData;
@ -81,12 +66,12 @@ public class VascBackendProxyPaged extends AbstractVascBackendProxy {
int off = state.getPageIndex()*pageSize;
int offMax = off+state.getPageSize();
for (int i=off;i<offMax;i++) {
if (i>=allData.getPageData().size()) {
if (i>=allData.getData().size()) {
break;
}
Serializable o = allData.getPageData().get(i);
Serializable o = allData.getData().get(i);
paged.add(o);
}
return new DefaultVascBackendResult<Serializable>(paged,allData.getPageData().size());
return new DefaultVascBackendListResult<DATA_RECORD>(paged,allData.getData().size());
}
}

View file

@ -26,11 +26,12 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import net.forwardfire.vasc.backend.DefaultVascBackendResult;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.core.VascEntryField;
/**
@ -39,42 +40,27 @@ import net.forwardfire.vasc.core.VascEntryField;
* @author Willem Cazander
* @version 1.0 Oct 27, 2007
*/
public class VascBackendProxySearch extends AbstractVascBackendProxy {
public class VascBackendProxySearch<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends AbstractVascBackendProxyFeature<DATA_PK,DATA_RECORD> {
public VascBackendProxySearch() {
super(VascBackendListFeature.TEXT_SEARCH,VascBackendListFeature.TEXT_SEARCH_PROXY);
}
/**
* @see java.lang.Object#clone()
*/
@Override
public VascBackendProxy clone() throws CloneNotSupportedException {
VascBackendProxySearch result = new VascBackendProxySearch();
public VascBackendProxy<DATA_PK,DATA_RECORD> clone() throws CloneNotSupportedException {
VascBackendProxySearch<DATA_PK,DATA_RECORD> result = new VascBackendProxySearch<>();
return result;
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#isProxyNeeded()
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#execute(VascBackendListRequest state)
*/
@Override
public boolean isProxyNeeded() {
if (backend.isSearchable()) {
return false;
}
return true;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#isSearchable()
*/
@Override
public boolean isSearchable() {
return true;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state)
*/
@Override
public VascBackendResult<Serializable> execute(VascBackendState state) throws VascBackendException {
VascBackendResult<Serializable> result = backend.execute(state);
public VascBackendListResult<Serializable> execute(VascBackendListRequest state) throws VascBackendException {
VascBackendListResult<Serializable> result = backend.execute(state);
if (state.getSearchString()==null) {
return result;
}
@ -82,10 +68,10 @@ public class VascBackendProxySearch extends AbstractVascBackendProxy {
return result;
}
String searchString = state.getSearchString().toLowerCase();
List<Serializable> search = new ArrayList<Serializable>(result.getPageData().size()/4);
for (Serializable record:result.getPageData()) {
List<Serializable> search = new ArrayList<Serializable>(result.getData().size()/4);
for (Serializable record:result.getData()) {
for (VascEntryField field:entry.getVascEntryFields()) {
VascEntryFieldValue<Serializable> fieldValue = backend.provideVascEntryFieldValue();
VascBackendAccessDataRecord<Serializable,Serializable> fieldValue = backend.provideVascEntryFieldValue();
Serializable value = fieldValue.getValue(field.getBackendName(), record);
if (value==null) {
continue; // can't search null values.
@ -96,45 +82,7 @@ public class VascBackendProxySearch extends AbstractVascBackendProxy {
break;
}
}
/*
for (Method method:o.getClass().getMethods()) {
if (method.getName().startsWith("get")==false) { //a bit durty
continue;
}
if (method.getName().equals("getClass")) {
continue;
}
if (method.getReturnType().isAssignableFrom(Collection.class)) {
continue;
}
if (method.getReturnType().isAssignableFrom(List.class)) {
continue;
}
if (method.getReturnType().isAssignableFrom(Set.class)) {
continue;
}
if (method.getReturnType().isAssignableFrom(Map.class)) {
continue;
}
Object res;
try {
res = method.invoke(o,new Object[]{});
} catch (Exception e) {
throw new VascException(e);
}
if (res==null) {
continue;
}
String r = res.toString().toLowerCase();
if (r.contains(searchString)) {
search.add(o);
break;
}
}
*/
}
//records = search.size();
return new DefaultVascBackendResult<Serializable>(search);
return new DefaultVascBackendListResult<Serializable>(search);
}
}

View file

@ -27,9 +27,10 @@ import java.util.Collections;
import java.util.Comparator;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.list.VascBackendListFeature;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.core.VascEntryField;
/**
@ -38,28 +39,21 @@ import net.forwardfire.vasc.core.VascEntryField;
* @author Willem Cazander
* @version 1.0 Oct 27, 2007
*/
public class VascBackendProxySort extends AbstractVascBackendProxy {
public class VascBackendProxySort<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends AbstractVascBackendProxyFeature<DATA_PK,DATA_RECORD> {
public VascBackendProxySort() {
super(VascBackendListFeature.SORT_DATA,VascBackendListFeature.SORT_DATA_PROXY);
}
/**
* @see java.lang.Object#clone()
*/
@Override
public VascBackendProxy clone() throws CloneNotSupportedException {
VascBackendProxySort result = new VascBackendProxySort();
public VascBackendProxy<DATA_PK,DATA_RECORD> clone() throws CloneNotSupportedException {
VascBackendProxySort<DATA_PK,DATA_RECORD> result = new VascBackendProxySort<>();
return result;
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#isProxyNeeded()
*/
@Override
public boolean isProxyNeeded() {
if (backend.isSortable()) {
return false;
}
return true;
}
public VascEntryField getVascEntryFieldByBackendName(String linkId) {
for (VascEntryField a:entry.getVascEntryFields()) {
if (a.getBackendName().equals(linkId)) {
@ -70,31 +64,32 @@ public class VascBackendProxySort extends AbstractVascBackendProxy {
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state)
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#execute(VascBackendListRequest state)
*/
@SuppressWarnings("unchecked")
@Override
public VascBackendResult<Serializable> execute(final VascBackendState state) throws VascBackendException {
VascBackendResult<Serializable> result = backend.execute(state);
public VascBackendListResult<DATA_RECORD> execute(final VascBackendListRequest state) throws VascBackendException {
VascBackendListResult<DATA_RECORD> result = backend.execute(state);
if (state.getSortField()==null) {
return result;
}
final VascEntryField field = getVascEntryFieldByBackendName(state.getSortField());
final VascEntryFieldValue<Serializable> fieldValue = backend.provideVascEntryFieldValue();
Collections.sort(result.getPageData(), new Comparator<Serializable>() {
final VascBackendAccessDataRecord<Serializable,Serializable> fieldValue = backend.provideVascEntryFieldValue();
Collections.sort(result.getData(), new Comparator<Serializable>() {
@SuppressWarnings("rawtypes")
@Override
public int compare(Serializable o1, Serializable o2) {
try {
Comparable c1 = null;
Comparable c2 = null;
if (field.getDisplayName()!=null) {
c1 = fieldValue.getDisplayValue(field.getBackendName(), o1);
c2 = fieldValue.getDisplayValue(field.getBackendName(), o2);
} else {
// if (field.getDisplayName()!=null) {
// c1 = fieldValue.getValue(field.getBackendName(), o1);
// c2 = fieldValue.getValue(field.getBackendName(), o2);
// } else {
// TODO: fix none Comparable goes toString
c1 = (Comparable)fieldValue.getValue(field.getBackendName(), o1);
c2 = (Comparable)fieldValue.getValue(field.getBackendName(), o2);
}
// }
if (c1==null & c2==null) {
return 0;
}

View file

@ -27,8 +27,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
/**
* Does simple timer logging for the backend actions.
@ -36,7 +36,7 @@ import net.forwardfire.vasc.backend.VascBackendState;
* @author Willem Cazander
* @version 1.0 Nov 19, 2009
*/
public class VascBackendProxyTimerLogger extends AbstractVascBackendProxy {
public class VascBackendProxyTimerLogger<DATA_PK extends Serializable,DATA_RECORD extends Serializable> extends AbstractVascBackendProxy<DATA_PK,DATA_RECORD> {
protected Logger logger = null;
protected Level logLevel = Level.INFO;
@ -49,17 +49,17 @@ public class VascBackendProxyTimerLogger extends AbstractVascBackendProxy {
* @see java.lang.Object#clone()
*/
@Override
public VascBackendProxy clone() throws CloneNotSupportedException {
VascBackendProxyTimerLogger result = new VascBackendProxyTimerLogger();
public VascBackendProxy<DATA_PK,DATA_RECORD> clone() throws CloneNotSupportedException {
VascBackendProxyTimerLogger<DATA_PK,DATA_RECORD> result = new VascBackendProxyTimerLogger<>();
result.logLevel=logLevel;
return result;
}
/**
* @see net.forwardfire.vasc.backend.VascBackend#execute(VascBackendState state)
* @see net.forwardfire.vasc.backend.crud.VascBackendCrud#execute(VascBackendListRequest state)
*/
@Override
public VascBackendResult<Serializable> execute(VascBackendState state) throws VascBackendException {
public VascBackendListResult<Serializable> execute(VascBackendListRequest state) throws VascBackendException {
long t1 = System.currentTimeMillis();
try {
return backend.execute(state);
@ -70,13 +70,13 @@ public class VascBackendProxyTimerLogger extends AbstractVascBackendProxy {
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveDownById(net.forwardfire.vasc.backend.VascBackendState, java.lang.Object)
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveDownById(net.forwardfire.vasc.backend.list.VascBackendListRequest, java.lang.Object)
*/
@Override
public long doRecordMoveDownById(VascBackendState state, Object primaryId) throws VascBackendException {
public long doRecordMoveDownById(VascBackendListRequest request,Serializable recordPK) throws VascBackendException {
long t1 = System.currentTimeMillis();
try {
return backend.doRecordMoveDownById(state, primaryId);
return backend.doRecordMoveDownById(request, recordPK);
} finally {
long t2 = System.currentTimeMillis();
logger.log(logLevel,"vasc-doRecordMoveDownById backend: "+getId()+" in "+(t2-t1)+" ms");
@ -84,61 +84,19 @@ public class VascBackendProxyTimerLogger extends AbstractVascBackendProxy {
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveUpById(net.forwardfire.vasc.backend.VascBackendState, java.lang.Object)
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#doRecordMoveUpById(net.forwardfire.vasc.backend.list.VascBackendListRequest, java.lang.Object)
*/
@Override
public long doRecordMoveUpById(VascBackendState state, Object primaryId) throws VascBackendException {
public long doRecordMoveUpById(VascBackendListRequest request,Serializable recordPK) throws VascBackendException {
long t1 = System.currentTimeMillis();
try {
return backend.doRecordMoveUpById(state, primaryId);
return backend.doRecordMoveUpById(request, recordPK);
} finally {
long t2 = System.currentTimeMillis();
logger.log(logLevel,"vasc-doRecordMoveUpById backend: "+getId()+" in "+(t2-t1)+" ms");
}
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#delete(java.lang.Object)
*/
@Override
public void delete(Serializable object) throws VascBackendException {
long t1 = System.currentTimeMillis();
try {
backend.delete(object);
} finally {
long t2 = System.currentTimeMillis();
logger.log(logLevel,"vasc-delete backend: "+getId()+" in "+(t2-t1)+" ms");
}
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#merge(java.lang.Object)
*/
@Override
public Serializable merge(Serializable object) throws VascBackendException {
long t1 = System.currentTimeMillis();
try {
return backend.merge(object);
} finally {
long t2 = System.currentTimeMillis();
logger.log(logLevel,"vasc-merge backend: "+getId()+" in "+(t2-t1)+" ms");
}
}
/**
* @see net.forwardfire.vasc.backend.proxy.AbstractVascBackendProxy#persist(java.lang.Object)
*/
@Override
public void persist(Serializable object) throws VascBackendException {
long t1 = System.currentTimeMillis();
try {
backend.persist(object);
} finally {
long t2 = System.currentTimeMillis();
logger.log(logLevel,"vasc-persist backend: "+getId()+" in "+(t2-t1)+" ms");
}
}
/**
* @return the logLevel
*/

View file

@ -26,7 +26,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.core.base.AbstractVascBaseIdRoleCrudOrderMetaLocal;
import net.forwardfire.vasc.validators.VascValidator;
@ -43,7 +43,7 @@ abstract public class AbstractVascEntryFieldLocal extends AbstractVascBaseIdRole
private String backendName = null;
private String displayName = null;
private VascEntryFieldType vascEntryFieldType = null;
private VascEntryFieldValue<Serializable> vascEntryFieldValue = null;
private VascBackendAccessDataRecord<Serializable,Serializable> vascEntryFieldValue = null;
private List<VascValidator> vascValidators = null;
private Serializable defaultValue = null;
private Integer sizeList = null;
@ -147,7 +147,7 @@ abstract public class AbstractVascEntryFieldLocal extends AbstractVascBaseIdRole
* @return the vascEntryFieldValue
*/
@Override
public VascEntryFieldValue<Serializable> getVascEntryFieldValue() {
public VascBackendAccessDataRecord<Serializable,Serializable> getVascEntryFieldValue() {
return vascEntryFieldValue;
}
@ -155,7 +155,7 @@ abstract public class AbstractVascEntryFieldLocal extends AbstractVascBaseIdRole
* @param vascEntryFieldValue the vascEntryFieldValue to set
*/
@Override
public void setVascEntryFieldValue(VascEntryFieldValue<Serializable> vascEntryFieldValue) {
public void setVascEntryFieldValue(VascBackendAccessDataRecord<Serializable,Serializable> vascEntryFieldValue) {
this.vascEntryFieldValue = vascEntryFieldValue;
}

View file

@ -28,8 +28,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
/**
* Holds all default state values
@ -43,11 +43,11 @@ abstract public class AbstractVascEntryState implements VascEntryState {
private List<Serializable> entryDataList = null;
private Serializable entryDataObject = null;
private Long totalBackendRecords = null;
private VascBackendState vascBackendState = null;
private VascBackendListRequest vascBackendState = null;
private VascEntryState state = null;
private Map<Integer,Boolean> multiActionSelection = null;
private boolean isEditCreate = false;
private VascBackend<Serializable> vascBackend = null;
private VascBackendCrud<Serializable,Serializable> vascBackend = null;
private VascEntry vascEntry = null;
public AbstractVascEntryState() {
@ -91,7 +91,7 @@ abstract public class AbstractVascEntryState implements VascEntryState {
* @return the vascBackendState
*/
@Override
public VascBackendState getVascBackendState() {
public VascBackendListRequest getVascBackendState() {
return vascBackendState;
}
@ -99,7 +99,7 @@ abstract public class AbstractVascEntryState implements VascEntryState {
* @param vascBackendState the vascBackendState to set
*/
@Override
public void setVascBackendState(VascBackendState vascBackendState) {
public void setVascBackendState(VascBackendListRequest vascBackendState) {
this.vascBackendState = vascBackendState;
}
@ -143,7 +143,7 @@ abstract public class AbstractVascEntryState implements VascEntryState {
* @return the vascBackend
*/
@Override
public VascBackend<Serializable> getVascBackend() {
public VascBackendCrud<Serializable,Serializable> getVascBackend() {
return vascBackend;
}
@ -151,7 +151,7 @@ abstract public class AbstractVascEntryState implements VascEntryState {
* @param vascBackend the vascBackend to set
*/
@Override
public void setVascBackend(VascBackend<Serializable> vascBackend) {
public void setVascBackend(VascBackendCrud<Serializable,Serializable> vascBackend) {
this.vascBackend = vascBackend;
}

View file

@ -25,7 +25,7 @@ package net.forwardfire.vasc.core;
import java.io.Serializable;
import java.util.List;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.core.entry.VascEntryExport;
import net.forwardfire.vasc.core.VascException;
@ -46,9 +46,9 @@ public interface VascEntryConfigController {
void configVascEntry(VascController vascController,VascEntryLocal vascEntry) throws VascException;
VascBackend<Serializable> configVascBackendProxied(VascController vascController,VascEntry vascEntry) throws VascException;
VascBackendCrud<Serializable,Serializable> configVascBackendProxied(VascController vascController,VascEntry vascEntry) throws VascException;
VascBackend<Serializable> configVascBackendProxied(VascController vascController,VascEntry vascEntry,VascBackend<Serializable> realBackend) throws VascException;
VascBackendCrud<Serializable,Serializable> configVascBackendProxied(VascController vascController,VascEntry vascEntry,VascBackendCrud<Serializable,Serializable> realBackend) throws VascException;
List<String> getVascEntryExporterIds();

View file

@ -24,7 +24,7 @@ package net.forwardfire.vasc.core;
import java.util.List;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.backend.proxy.VascBackendProxy;
import net.forwardfire.vasc.core.entry.VascEntryExport;
import net.forwardfire.vasc.core.entry.VascEntryFieldValidatorService;
@ -60,7 +60,7 @@ public interface VascEntryConfigControllerLocal extends VascEntryConfigControlle
void removeVascEntryExporter(VascEntryExport exporter);
VascBackendState getMasterVascBackendState();
VascBackendListRequest getMasterVascBackendState();
void setResourceBundle(String resourceBundle);

View file

@ -25,7 +25,7 @@ package net.forwardfire.vasc.core;
import java.io.Serializable;
import java.util.List;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.core.base.VascBaseIdRoleCrudOrderMeta;
import net.forwardfire.vasc.validators.VascValidator;
@ -56,7 +56,7 @@ public interface VascEntryField extends VascBaseIdRoleCrudOrderMeta {
/**
* @return the vascEntryFieldValue
*/
VascEntryFieldValue<Serializable> getVascEntryFieldValue();
VascBackendAccessDataRecord<Serializable,Serializable> getVascEntryFieldValue();
/**
* @return the vascValidators

View file

@ -24,7 +24,7 @@ package net.forwardfire.vasc.core;
import java.io.Serializable;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.core.base.VascBaseIdRoleCrudOrderMetaLocal;
import net.forwardfire.vasc.validators.VascValidator;
@ -55,7 +55,7 @@ public interface VascEntryFieldLocal extends VascEntryField,VascBaseIdRoleCrudOr
/**
* @param vascEntryFieldValue the vascEntryFieldValue to set
*/
void setVascEntryFieldValue(VascEntryFieldValue<Serializable> vascEntryFieldValue);
void setVascEntryFieldValue(VascBackendAccessDataRecord<Serializable,Serializable> vascEntryFieldValue);
/**
* @param vascValidator the vascValidator to add

View file

@ -26,8 +26,8 @@ import java.io.Serializable;
import java.util.List;
import java.util.Map;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
/**
* Holds all the data for state.
@ -61,12 +61,12 @@ public interface VascEntryState extends Serializable {
/**
* @return the vascBackendState
*/
VascBackendState getVascBackendState();
VascBackendListRequest getVascBackendState();
/**
* @param vascBackendState the vascBackendState to set
*/
void setVascBackendState(VascBackendState vascBackendState);
void setVascBackendState(VascBackendListRequest vascBackendState);
/**
* @return the totalBackendRecords
@ -97,12 +97,12 @@ public interface VascEntryState extends Serializable {
/**
* @return the vascBackend
*/
public VascBackend<Serializable> getVascBackend();
public VascBackendCrud<Serializable,Serializable> getVascBackend();
/**
* @param vascBackend the vascBackend to set
*/
void setVascBackend(VascBackend<Serializable> vascBackend);
void setVascBackend(VascBackendCrud<Serializable,Serializable> vascBackend);
/**
* @return the isEditCreate

View file

@ -1,6 +1,6 @@
package net.forwardfire.vasc.core;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.frontend.VascFrontendActions;
import net.forwardfire.vasc.frontend.VascFrontendControllerLocal;
import net.forwardfire.vasc.frontend.VascFrontendDataSelector;
@ -19,7 +19,7 @@ public interface VascInterfaceLoader {
VascEntryState createVascEntryStateImpl();
VascBackendState createVascBackendStateImpl();
VascBackendListRequest createVascBackendStateImpl();
VascFrontendControllerLocal createVascFrontendControllerLocalImpl();

View file

@ -25,6 +25,7 @@ package net.forwardfire.vasc.core.ui;
import java.io.Serializable;
import java.util.List;
import net.forwardfire.vasc.backend.select.VascBackendSelectItem;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascException;
@ -42,7 +43,7 @@ public interface VascSelectItemModel extends Serializable {
* @return
* @throws VascException
*/
List<VascSelectItem> getVascSelectItems(VascEntry entry) throws VascException;
List<VascBackendSelectItem> getVascSelectItems(VascEntry entry) throws VascException;
/**
* @return the nullLabel

View file

@ -30,10 +30,10 @@ import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import net.forwardfire.vasc.backend.DefaultVascBackendState;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListRequest;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.backend.proxy.VascBackendProxy;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntry;
@ -69,7 +69,7 @@ public class DefaultVascEntryConfigController implements VascEntryConfigControll
private Map<VascInterfaceKey,Class<?>> vascInterfaceImpls = null;
private Map<VascInterfaceKeyFrontend,Class<?>> vascInterfaceImplFrontends = null;
private VascInterfaceLoader vascInterfaceLoader = null;
private VascBackendState masterVascBackendState = null;
private VascBackendListRequest masterVascBackendState = null;
private String resourceBundle = null;
public DefaultVascEntryConfigController() {
@ -80,7 +80,7 @@ public class DefaultVascEntryConfigController implements VascEntryConfigControll
vascInterfaceImpls = new HashMap<VascInterfaceKey,Class<?>>(VascInterfaceKey.values().length);
vascInterfaceImplFrontends = new HashMap<VascInterfaceKeyFrontend,Class<?>>(VascInterfaceKeyFrontend.values().length);
vascInterfaceLoader = new DefaultVascInterfaceLoader(this);
masterVascBackendState = new DefaultVascBackendState();
masterVascBackendState = new DefaultVascBackendListRequest();
masterVascBackendState.setPageSize(100);
masterVascBackendState.setPageSizeMax(1500);
}
@ -177,8 +177,8 @@ public class DefaultVascEntryConfigController implements VascEntryConfigControll
* @see net.forwardfire.vasc.core.VascEntryConfigController#configVascBackendProxied(net.forwardfire.vasc.core.VascController, net.forwardfire.vasc.core.VascEntry)
*/
@Override
public VascBackend<Serializable> configVascBackendProxied(VascController vascController,VascEntry vascEntry) throws VascException {
VascBackend<Serializable> realBackend = vascController.getVascBackendController().getVascBackendById(vascEntry.getBackendId());
public VascBackendCrud<Serializable,Serializable> configVascBackendProxied(VascController vascController,VascEntry vascEntry) throws VascException {
VascBackendCrud<Serializable,Serializable> realBackend = vascController.getVascBackendController().getVascBackendById(VascBackendCrud.class,vascEntry.getBackendId());
if (realBackend==null) {
throw new VascException("Could not find backend: "+vascEntry.getBackendId());
}
@ -186,11 +186,11 @@ public class DefaultVascEntryConfigController implements VascEntryConfigControll
}
/**
* @see net.forwardfire.vasc.core.VascEntryConfigController#configVascBackendProxied(net.forwardfire.vasc.core.VascController, net.forwardfire.vasc.core.VascEntry, net.forwardfire.vasc.backend.VascBackend)
* @see net.forwardfire.vasc.core.VascEntryConfigController#configVascBackendProxied(net.forwardfire.vasc.core.VascController, net.forwardfire.vasc.core.VascEntry, net.forwardfire.vasc.backend.crud.VascBackendCrud)
*/
@Override
public VascBackend<Serializable> configVascBackendProxied(VascController vascController,VascEntry vascEntry, VascBackend<Serializable> realBackend) throws VascException {
VascBackend<Serializable> backend = realBackend;
public VascBackendCrud<Serializable,Serializable> configVascBackendProxied(VascController vascController,VascEntry vascEntry, VascBackendCrud<Serializable,Serializable> realBackend) throws VascException {
VascBackendCrud<Serializable,Serializable> backend = realBackend;
for (VascBackendProxy proxy:backendProxies) {
VascBackendProxy proxyClone;
try {
@ -217,7 +217,7 @@ public class DefaultVascEntryConfigController implements VascEntryConfigControll
// get the interface loader and create some impl objects
VascInterfaceLoader loader = getVascInterfaceLoader();
VascFrontendControllerLocal controller = loader.createVascFrontendControllerLocalImpl();
VascBackendState backendState = loader.createVascBackendStateImpl();
VascBackendListRequest backendState = loader.createVascBackendStateImpl();
VascEntryState state = loader.createVascEntryStateImpl();
// Add impl to tree
@ -234,7 +234,7 @@ public class DefaultVascEntryConfigController implements VascEntryConfigControll
controller.setVascFrontendUserSettingController( loader.createVascFrontendUserSettingControllerImpl(entry));
// Config backend state from master template
VascBackendState master = getMasterVascBackendState();
VascBackendListRequest master = getMasterVascBackendState();
for (String key:master.getDataParameterKeys()) {
backendState.setDataParameter(key, master.getDataParameter(key));
}
@ -257,14 +257,14 @@ public class DefaultVascEntryConfigController implements VascEntryConfigControll
}
// Add backend to entry
VascBackend<Serializable> backend = vascController.getVascEntryConfigController().configVascBackendProxied(vascController, entry);
VascBackendCrud<Serializable,Serializable> backend = vascController.getVascEntryConfigController().configVascBackendProxied(vascController, entry);
controller.getVascEntryState().setVascBackend(backend);
controller.getVascEntryState().setVascEntry(entry);
// Fetch all data field value impl for this backend.
for (VascEntryField field:entry.getVascEntryFields()) {
if (field.getVascEntryFieldValue()==null) {
VascEntryFieldValue<Serializable> v = backend.provideVascEntryFieldValue();
VascBackendAccessDataRecord<Serializable,Serializable> v = backend.provideVascEntryFieldValue();
((VascEntryFieldLocal)field).setVascEntryFieldValue(v);
}
}
@ -422,7 +422,7 @@ public class DefaultVascEntryConfigController implements VascEntryConfigControll
* @see net.forwardfire.vasc.core.VascEntryConfigControllerLocal#getMasterVascBackendState()
*/
@Override
public VascBackendState getMasterVascBackendState() {
public VascBackendListRequest getMasterVascBackendState() {
return masterVascBackendState;
}
}

View file

@ -23,7 +23,7 @@
package net.forwardfire.vasc.impl;
import net.forwardfire.vasc.backend.DefaultVascBackendController;
import net.forwardfire.vasc.backend.DefaultVascBackendState;
import net.forwardfire.vasc.backend.list.DefaultVascBackendListRequest;
import net.forwardfire.vasc.backend.proxy.VascBackendProxyCache;
import net.forwardfire.vasc.backend.proxy.VascBackendProxyEventExecutor;
import net.forwardfire.vasc.backend.proxy.VascBackendProxyFilter;
@ -73,7 +73,7 @@ public class DefaultVascFactory {
vascConfig.putVascInterfaceImplemention(VascInterfaceKey.VASC_ENTRY_LINK, DefaultVascEntryLink.class);
vascConfig.putVascInterfaceImplemention(VascInterfaceKey.VASC_ENTRY_LIST_OPTION, DefaultVascEntryListOption.class);
vascConfig.putVascInterfaceImplemention(VascInterfaceKey.VASC_BACKEND_STATE, DefaultVascBackendState.class);
vascConfig.putVascInterfaceImplemention(VascInterfaceKey.VASC_BACKEND_STATE, DefaultVascBackendListRequest.class);
vascConfig.putVascInterfaceImplemention(VascInterfaceKey.VASC_FRONTEND_CONTROLLER_LOCAL, DefaultVascFrontendController.class);
vascConfig.putVascInterfaceImplementionFrontend(VascInterfaceKeyFrontend.VASC_FRONTEND_ACTIONS, DefaultVascFrontendActions.class);

View file

@ -22,7 +22,7 @@
package net.forwardfire.vasc.impl;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryConfigControllerLocal;
import net.forwardfire.vasc.core.VascEntryField;
@ -114,8 +114,8 @@ public class DefaultVascInterfaceLoader implements VascInterfaceLoader {
* @see net.forwardfire.vasc.core.VascInterfaceLoader#createVascBackendStateImpl()
*/
@Override
public VascBackendState createVascBackendStateImpl() {
return (VascBackendState)createImpl(VascInterfaceKey.VASC_BACKEND_STATE);
public VascBackendListRequest createVascBackendStateImpl() {
return (VascBackendListRequest)createImpl(VascInterfaceKey.VASC_BACKEND_STATE);
}
/**

View file

@ -22,7 +22,7 @@
package net.forwardfire.vasc.impl.entry;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.entry.VascEntryBackendEventListener;
@ -74,8 +74,8 @@ public class SetParameterBackendListener implements VascEntryBackendEventListene
*/
@Override
public void vascEvent(VascEntry entry, Object data) {
if (data instanceof VascBackendState) {
VascBackendState state = (VascBackendState)data;
if (data instanceof VascBackendListRequest) {
VascBackendListRequest state = (VascBackendListRequest)data;
if (isUserValue) {
if (value==null) {
value="id";

View file

@ -27,7 +27,7 @@ import java.util.Locale;
import org.x4o.xml.conv.ObjectConverterException;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascEntryConfigFinalizer;
@ -59,7 +59,7 @@ public class VascDefaultsFinalizer implements VascEntryConfigFinalizer {
}
// Check if backendId is valid
VascBackend<Serializable> back = vascController.getVascBackendController().getVascBackendById( entry.getBackendId() );
VascBackendCrud<Serializable,Serializable> back = vascController.getVascBackendController().getVascBackendById( VascBackendCrud.class, entry.getBackendId() );
if (back==null) {
throw new IllegalArgumentException("The VascEntry backend is not found in backends: '"+entry.getBackendId()+"' in entryId: "+id);
}

View file

@ -24,7 +24,7 @@ package net.forwardfire.vasc.impl.entry.config;
import java.io.Serializable;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascEntryFieldSet;
@ -68,7 +68,7 @@ public class VascIdCheckFinalizer implements VascEntryConfigFinalizer {
}
// Check if backendId is valid
VascBackend<Serializable> back = vascController.getVascBackendController().getVascBackendById( entry.getBackendId() );
VascBackendCrud<Serializable> back = vascController.getVascBackendController().getVascBackendById( entry.getBackendId() );
if (back==null) {
throw new IllegalArgumentException("The VascEntry backend is not found in backends: '"+entry.getBackendId()+"' in entryId: "+id);
}

View file

@ -27,8 +27,8 @@ import java.util.Date;
import java.util.logging.Logger;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascBackendResult;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.list.VascBackendListResult;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.backend.proxy.VascProxyFilter;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
@ -210,7 +210,7 @@ public class DefaultVascFrontendActions implements VascFrontendActions {
// Fire pre read event
entry.getVascFrontendController().fireVascFrontendEvent(entry,VascEntryFrontendEventListener.VascFrontendEventType.PRE_READ, null);
entry.getVascFrontendController().getVascEntryState().setEntryDataObject(null);
VascBackendState backendState = entry.getVascFrontendController().getVascEntryState().getVascBackendState();
VascBackendListRequest backendState = entry.getVascFrontendController().getVascEntryState().getVascBackendState();
// check and correct max page size
if (backendState.getPageSize() > backendState.getPageSizeMax()) {
@ -226,7 +226,7 @@ public class DefaultVascFrontendActions implements VascFrontendActions {
}
}
VascBackendResult<Serializable> result;
VascBackendListResult<Serializable> result;
try {
result = entry.getVascFrontendController().getVascEntryState().getVascBackend().execute(backendState);
} catch (VascBackendException ve) {
@ -234,11 +234,11 @@ public class DefaultVascFrontendActions implements VascFrontendActions {
}
// Set data in frontend
entry.getVascFrontendController().getVascEntryState().setEntryDataList(result.getPageData());
entry.getVascFrontendController().getVascEntryState().setTotalBackendRecords(result.getTotalSize());
entry.getVascFrontendController().getVascEntryState().setEntryDataList(result.getData());
entry.getVascFrontendController().getVascEntryState().setTotalBackendRecords(result.getTotalRecordCount());
// check if we need to change the current page if table size if changed in between
int pages = new Long(result.getTotalSize()/backendState.getPageSize()).intValue();
int pages = new Long(result.getTotalRecordCount()/backendState.getPageSize()).intValue();
if (backendState.getPageIndex() > pages) {
backendState.setPageIndex(pages);
}

View file

@ -28,7 +28,7 @@ import java.util.List;
import java.util.logging.Logger;
import net.forwardfire.vasc.backend.VascBackendException;
import net.forwardfire.vasc.backend.VascEntryFieldValue;
import net.forwardfire.vasc.backend.VascBackendAccessDataRecord;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.VascEntryField;
import net.forwardfire.vasc.core.VascEntryLink;
@ -202,10 +202,10 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper {
return "no-selection";
}
VascEntryField v = entry.getVascEntryFieldById(entry.getDisplayNameFieldId());
VascEntryFieldValue<Serializable> ve = v.getVascEntryFieldValue();
VascBackendAccessDataRecord<Serializable,Serializable> ve = v.getVascEntryFieldValue();
String result = "no-data";
try {
result = ve.getDisplayValue(v.getBackendName(), row);
result = ""+ve.getValue(v.getBackendName(), row);
} catch (VascBackendException e) {
throw new RuntimeException("Could not get selected name DisplayValue: "+e.getMessage(),e);
}
@ -224,10 +224,10 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper {
return "no-selection";
}
VascEntryField v = parent.getVascEntryFieldById(parent.getDisplayNameFieldId());
VascEntryFieldValue<Serializable> ve = v.getVascEntryFieldValue();
VascBackendAccessDataRecord<Serializable,Serializable> ve = v.getVascEntryFieldValue();
String result = "no-data";
try {
result = ve.getDisplayValue(v.getBackendName(), row);
result = ""+ve.getValue(v.getBackendName(), row);
} catch (VascBackendException e) {
throw new RuntimeException("Could not get parent name DisplayValue: "+e.getMessage(),e);
}

View file

@ -26,7 +26,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import net.forwardfire.vasc.backend.VascBackendState;
import net.forwardfire.vasc.backend.list.VascBackendListRequest;
import net.forwardfire.vasc.core.VascEntry;
import net.forwardfire.vasc.core.entry.VascEntryFrontendEventListener;
import net.forwardfire.vasc.frontend.VascFrontendPageInfoNumber;
@ -156,7 +156,7 @@ public class DefaultVascFrontendPager implements VascFrontendPageInfo {
@Override
public List<VascFrontendPageInfoNumber> getTablePagesFromBackend() {
List<VascFrontendPageInfoNumber> result = new ArrayList<VascFrontendPageInfoNumber>(30);
VascBackendState state = entry.getVascFrontendController().getVascEntryState().getVascBackendState();
VascBackendListRequest state = entry.getVascFrontendController().getVascEntryState().getVascBackendState();
if (state.getPageSize()==0) {
return result; // paging disabled
}

View file

@ -33,9 +33,9 @@ import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
import net.forwardfire.vasc.backend.VascBackend;
import net.forwardfire.vasc.backend.VascBackendController;
import net.forwardfire.vasc.backend.VascBackendControllerLocal;
import net.forwardfire.vasc.backend.crud.VascBackendCrud;
import net.forwardfire.vasc.core.VascController;
import net.forwardfire.vasc.core.VascControllerLocal;
import net.forwardfire.vasc.core.VascControllerProvider;
@ -130,7 +130,7 @@ public class JndiVascControllerFactory implements ObjectFactory {
return backendController.getVascBackendIds();
}
@Override
public VascBackend<Serializable> getVascBackendById(String id) {
public VascBackendCrud<Serializable> getVascBackendById(String id) {
return backendController.getVascBackendById(id);
}
});

Some files were not shown because too many files have changed in this diff Show more