Split backend to backend api.
This commit is contained in:
parent
4bd244f4e5
commit
a13719f008
116 changed files with 1029 additions and 815 deletions
|
|
@ -2,7 +2,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>vasc-backend</artifactId>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<groupId>net.forwardfire.vasc.backend</groupId>
|
||||
<version>0.4.2-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
|
@ -11,8 +11,8 @@
|
|||
<description>vasc-backend-metamodel</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-core</artifactId>
|
||||
<groupId>net.forwardfire.vasc.backend</groupId>
|
||||
<artifactId>vasc-backend-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -1,528 +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.metamodel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.eobjects.metamodel.DataContext;
|
||||
import org.eobjects.metamodel.schema.Column;
|
||||
import org.eobjects.metamodel.schema.Relationship;
|
||||
import org.eobjects.metamodel.schema.Table;
|
||||
|
||||
import net.forwardfire.vasc.backend.VascBackend;
|
||||
import net.forwardfire.vasc.backend.VascBackendControllerLocal;
|
||||
import net.forwardfire.vasc.core.VascController;
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryAccessType;
|
||||
import net.forwardfire.vasc.core.VascEntryControllerLocal;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascEntryFieldLocal;
|
||||
import net.forwardfire.vasc.core.VascEntryGroupLocal;
|
||||
import net.forwardfire.vasc.core.VascEntryLinkType;
|
||||
import net.forwardfire.vasc.core.VascEntryLocal;
|
||||
|
||||
import net.forwardfire.vasc.impl.DefaultVascEntry;
|
||||
import net.forwardfire.vasc.impl.DefaultVascEntryField;
|
||||
import net.forwardfire.vasc.impl.DefaultVascEntryLink;
|
||||
import net.forwardfire.vasc.impl.ui.VascSelectItemModelEntry;
|
||||
|
||||
/**
|
||||
* MetaModelSchemaAutoEntry
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 2, 2012
|
||||
*/
|
||||
public class MetaModelSchemaAutoEntry {
|
||||
|
||||
private Logger logger = null;
|
||||
private VascController vascController = null;
|
||||
private MetaModelDataContextProvider dataContextProvider = null;
|
||||
private List<String> tables = null;
|
||||
private String tableInclude = null;
|
||||
private String tableExclude = null;
|
||||
private String entryPrefix = null;
|
||||
private String vascGroupId = null;
|
||||
private String veLinkPostfix = "_velink";
|
||||
private String veListPostfix = "_velist";
|
||||
|
||||
private Map<String,VascEntryLocal> resultEntries = null;
|
||||
private Map<String,VascEntryGroupLocal> resultEntryGroups = null;
|
||||
private Map<String,MetaModelVascBackend> resultBackends = null;
|
||||
|
||||
public MetaModelSchemaAutoEntry() {
|
||||
logger = Logger.getLogger(MetaModelSchemaAutoEntry.class.getName());
|
||||
tables = new ArrayList<String>();
|
||||
resultEntries = new HashMap<String,VascEntryLocal>();
|
||||
resultEntryGroups = new HashMap<String,VascEntryGroupLocal>();
|
||||
resultBackends = new HashMap<String,MetaModelVascBackend>();
|
||||
}
|
||||
|
||||
public void autoFillResult(VascController vascController) {
|
||||
if (getDataContextProvider()==null) {
|
||||
throw new NullPointerException("Can't auto create entries with null dataContextProvider.");
|
||||
}
|
||||
if (getEntryPrefix()==null) {
|
||||
throw new NullPointerException("Can't auto create with null entryPrefix.");
|
||||
}
|
||||
this.vascController=vascController;
|
||||
|
||||
DataContext ds = getDataContextProvider().getDataContext();
|
||||
for (String table:ds.getDefaultSchema().getTableNames()) {
|
||||
if (tables.isEmpty()==false && tables.contains(table)==false) {
|
||||
logger.finer("Excluding table: "+table+" because not in table list.");
|
||||
continue;
|
||||
}
|
||||
if (getTableInclude()!=null && table.matches(getTableInclude())==false) {
|
||||
logger.finer("Excluding table: "+table+" from include rule.");
|
||||
continue;
|
||||
}
|
||||
if (getTableExclude()!=null && table.matches(getTableExclude())) {
|
||||
logger.finer("Excluding table: "+table+" from exclude rule.");
|
||||
continue;
|
||||
}
|
||||
createMetaEntry(ds,getEntryPrefix()+"_"+table,table);
|
||||
}
|
||||
}
|
||||
|
||||
public void autoAddResultToController() {
|
||||
for (VascBackend backend:resultBackends.values()) {
|
||||
((VascBackendControllerLocal)getVascController().getVascBackendController()).addVascBackend(backend);
|
||||
}
|
||||
for (VascEntryLocal ve:resultEntries.values()) {
|
||||
((VascEntryControllerLocal)getVascController().getVascEntryController()).addVascEntry(ve);
|
||||
}
|
||||
for (VascEntryGroupLocal veg:resultEntryGroups.values()) {
|
||||
((VascEntryControllerLocal)getVascController().getVascEntryController()).addVascEntryGroup(veg);
|
||||
}
|
||||
}
|
||||
|
||||
private VascController getVascController() {
|
||||
return vascController;
|
||||
}
|
||||
|
||||
private void createMetaEntry(DataContext ds,String id,String tableName) {
|
||||
logger.fine("Creating entry id: "+id+" of table: "+tableName);
|
||||
Table metaTable = null;
|
||||
if (tableName==null) {
|
||||
metaTable = ds.getDefaultSchema().getTable(0);
|
||||
} else {
|
||||
metaTable = ds.getDefaultSchema().getTableByName(tableName);
|
||||
}
|
||||
Column[] keys = metaTable.getPrimaryKeys();
|
||||
Column[] cols = metaTable.getColumns();
|
||||
if (cols.length==0) {
|
||||
return; // vasc needs at least one column
|
||||
}
|
||||
|
||||
MetaModelVascBackend backend = new MetaModelVascBackend();
|
||||
backend.setId(id+"_backend");
|
||||
backend.setDataContextProvider(getDataContextProvider());
|
||||
backend.setTable(metaTable.getName());
|
||||
if (keys.length>0) {
|
||||
backend.setTableId(keys[0].getName());
|
||||
} else {
|
||||
backend.setTableId(cols[0].getName());
|
||||
//TODO backend.setRequestReadOnly(true);
|
||||
}
|
||||
|
||||
DefaultVascEntry ve = new DefaultVascEntry();
|
||||
ve.setId(id);
|
||||
ve.setBackendId(id+"_backend");
|
||||
ve.setPrimaryKeyFieldId(backend.getTableId());
|
||||
ve.setVascGroupId(getVascGroupId());
|
||||
createFields(ve,cols);
|
||||
|
||||
for (Relationship rs:metaTable.getRelationships()) {
|
||||
logger.finer("Found relation FT: "+rs.getForeignTable().getName()+" PT: "+rs.getPrimaryTable().getName());
|
||||
if (tableName.equals(rs.getForeignTable().getName())==false) {
|
||||
logger.finer("Creating Link entry for: "+rs.getForeignColumns()[0].getName()+" of table: "+rs.getForeignTable().getName());
|
||||
createLinkEntry(rs,ve,metaTable);
|
||||
} else {
|
||||
logger.finer("Creating List entry for: "+rs.getPrimaryColumns()[0].getName()+" of table: "+rs.getPrimaryTable().getName());
|
||||
createListEntry(rs,ve,metaTable);
|
||||
}
|
||||
}
|
||||
|
||||
resultBackends.put(backend.getId(),backend);
|
||||
resultEntries.put(ve.getId(),ve);
|
||||
}
|
||||
|
||||
private void createLinkEntry(Relationship rs2,VascEntryLocal ve,Table metaTable) {
|
||||
String id = getEntryPrefix()+"_"+rs2.getForeignTable().getName()+getVeLinkPostfix();
|
||||
MetaModelVascBackend backendLink = new MetaModelVascBackend();
|
||||
backendLink.setId(id+"_backend");
|
||||
backendLink.setDataContextProvider(getDataContextProvider());
|
||||
backendLink.setTable(rs2.getForeignTable().getName());
|
||||
|
||||
Column[] keys = rs2.getForeignTable().getPrimaryKeys();
|
||||
Column[] cols = rs2.getForeignTable().getColumns();
|
||||
if (cols.length==0) {
|
||||
return;
|
||||
}
|
||||
if (keys.length>0) {
|
||||
backendLink.setTableId(keys[0].getName());
|
||||
} else {
|
||||
backendLink.setTableId(cols[0].getName());
|
||||
}
|
||||
|
||||
DefaultVascEntry veLink = new DefaultVascEntry();
|
||||
veLink.setId(id);
|
||||
veLink.setBackendId(id+"_backend");
|
||||
veLink.setPrimaryKeyFieldId(backendLink.getTableId());
|
||||
veLink.setVascGroupId(getVascGroupId());
|
||||
veLink.setAccessType(VascEntryAccessType.ENTRY_LINK);
|
||||
createFields(veLink,cols);
|
||||
|
||||
if (resultBackends.containsKey(backendLink.getId())==false) {
|
||||
resultBackends.put(backendLink.getId(),backendLink);
|
||||
resultEntries.put(veLink.getId(),veLink);
|
||||
}
|
||||
|
||||
for (Relationship rs:rs2.getForeignTable().getRelationships()) {
|
||||
logger.finer("Found relation FT: "+rs.getForeignTable().getName()+" PT: "+rs.getPrimaryTable().getName());
|
||||
if (rs2.getForeignTable().getName().equals(rs.getForeignTable().getName())==false) {
|
||||
//logger.info("Creating Link entry for: "+rs.getForeignColumns()[0].getName()+" of table: "+rs.getForeignTable().getName());
|
||||
//createLinkEntry(rs,veLink,rs2.getForeignTable());
|
||||
} else {
|
||||
logger.fine("Creating List entry for: "+rs.getPrimaryColumns()[0].getName()+" of table: "+rs.getPrimaryTable().getName());
|
||||
createListEntry(rs,veLink,rs2.getForeignTable());
|
||||
}
|
||||
}
|
||||
|
||||
DefaultVascEntryLink vle = new DefaultVascEntryLink();
|
||||
vle.setId(id+"Link");
|
||||
vle.setVascEntryLinkType(VascEntryLinkType.DEFAULT_TYPE);
|
||||
vle.setVascEntryId(id);
|
||||
vle.addEntryParameterFieldId(rs2.getForeignColumns()[0].getName(), rs2.getPrimaryColumns()[0].getName());
|
||||
|
||||
ve.addVascEntryLink(vle);
|
||||
}
|
||||
|
||||
private void createListEntry(Relationship rs,VascEntry ve,Table metaTable) {
|
||||
String id = getEntryPrefix()+"_"+rs.getPrimaryTable().getName()+getVeListPostfix();
|
||||
MetaModelVascBackend backendList = new MetaModelVascBackend();
|
||||
backendList.setId(id+"_backend");
|
||||
backendList.setDataContextProvider(getDataContextProvider());
|
||||
backendList.setTable(rs.getPrimaryTable().getName());
|
||||
|
||||
Column[] keys = rs.getPrimaryTable().getPrimaryKeys();
|
||||
Column[] cols = rs.getPrimaryTable().getColumns();
|
||||
if (cols.length==0) {
|
||||
return;
|
||||
}
|
||||
if (keys.length>0) {
|
||||
backendList.setTableId(keys[0].getName());
|
||||
} else {
|
||||
backendList.setTableId(cols[0].getName());
|
||||
}
|
||||
DefaultVascEntry veList = new DefaultVascEntry();
|
||||
veList.setId(id);
|
||||
veList.setBackendId(id+"_backend");
|
||||
veList.setPrimaryKeyFieldId(backendList.getTableId());
|
||||
veList.setVascGroupId(getVascGroupId());
|
||||
veList.setAccessType(VascEntryAccessType.ENTRY_LIST);
|
||||
createFields(veList,cols);
|
||||
|
||||
if (resultBackends.containsKey(backendList.getId())==false) {
|
||||
resultBackends.put(backendList.getId(),backendList);
|
||||
resultEntries.put(veList.getId(),veList);
|
||||
}
|
||||
|
||||
VascEntryFieldLocal vef = (VascEntryFieldLocal)ve.getVascEntryFieldById(rs.getForeignColumns()[0].getName());
|
||||
if (vef==null) {
|
||||
logger.warning("Could not find: "+rs.getForeignColumns()[0].getName()+" in ve: "+ve.getId());
|
||||
return;
|
||||
}
|
||||
vef.setVascEntryFieldType(getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeById("ListField"));
|
||||
|
||||
VascSelectItemModelEntry itemModel = new VascSelectItemModelEntry();
|
||||
itemModel.setEntryId(veList.getId());
|
||||
if (veList.getDisplayNameFieldId()==null) {
|
||||
itemModel.setDisplayFieldId(veList.getPrimaryKeyFieldId()); // display can be null see createFields(), in vasc display is not null but defaulted on primary id.
|
||||
} else {
|
||||
itemModel.setDisplayFieldId(veList.getDisplayNameFieldId());
|
||||
}
|
||||
|
||||
vef.getVascEntryFieldType().setDataObject(itemModel);
|
||||
|
||||
}
|
||||
|
||||
private void createFields(VascEntryLocal ve,Column[] cols) {
|
||||
for (Column c:cols) {
|
||||
String name = c.getName().toLowerCase();
|
||||
DefaultVascEntryField vef = new DefaultVascEntryField();
|
||||
vef.setId(c.getName());
|
||||
vef.setVascEntryFieldType(getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeByClass(c.getType().getJavaEquivalentClass()));
|
||||
|
||||
if (vef.getId().equals(ve.getPrimaryKeyFieldId())) {
|
||||
vef.setEditReadOnly(true);
|
||||
vef.setCreate(false);
|
||||
}
|
||||
|
||||
if (vef.getVascEntryFieldType()==null || "TextField".equals(vef.getVascEntryFieldType().getId())) {
|
||||
if (name.contains("desc") || name.contains("text") || name.contains("comment") || name.contains("memo") ) {
|
||||
vef.setVascEntryFieldType(getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeById("TextAreaField"));
|
||||
}
|
||||
if (name.contains("active")) {
|
||||
vef.setDefaultValue("true");
|
||||
vef.setVascEntryFieldType(getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeById("BooleanField"));
|
||||
} /* todo
|
||||
if (c.getName().toLowerCase().contains("email")) {
|
||||
vef.setVascEntryFieldType(getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeById("EmailField"));
|
||||
}
|
||||
if (c.getName().toLowerCase().contains("url")) {
|
||||
vef.setVascEntryFieldType(getVascController().getVascEntryFieldTypeController().getVascEntryFieldTypeById("URLField"));
|
||||
} */
|
||||
}
|
||||
|
||||
if (vef.getVascEntryFieldType()!=null && vef.getVascEntryFieldType().getAutoDetectClass()==Date.class) {
|
||||
vef.setDefaultValue("now()");
|
||||
if (name.contains("create") || name.contains("modified")) {
|
||||
vef.setEdit(false);
|
||||
vef.setCreate(false);
|
||||
}
|
||||
if (name.contains("update")) {
|
||||
vef.setCreate(false);
|
||||
}
|
||||
}
|
||||
|
||||
ve.addVascEntryField(vef);
|
||||
if (ve.getDisplayNameFieldId()==null && c.getName().equals(ve.getPrimaryKeyFieldId())==false && c.getType().getJavaEquivalentClass()==String.class) {
|
||||
ve.setDisplayNameFieldId(c.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// Disable lists when id contains;
|
||||
for (VascEntryField vef:ve.getVascEntryFields()) {
|
||||
String id = vef.getId().toLowerCase();
|
||||
if (ve.getDisplayNameFieldId()!=null && ve.getDisplayNameFieldId().equals(vef.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (ve.getPrimaryKeyFieldId()!=null && ve.getPrimaryKeyFieldId().equals(vef.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (vef.getList()!=null && vef.getList()==false) {
|
||||
continue;
|
||||
}
|
||||
if ( id.contains("email") |
|
||||
id.contains("phone") |
|
||||
id.contains("data") |
|
||||
id.contains("value") |
|
||||
id.contains("create") |
|
||||
id.contains("update") |
|
||||
id.contains("delete") |
|
||||
id.contains("classname") |
|
||||
id.contains("description")
|
||||
) {
|
||||
vef.setList(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Some auto detection on fields so default imported list view looks oke on 8++ columns.
|
||||
if (ve.getVascEntryFields().size()>10) {
|
||||
List<String> vefListIds = new ArrayList<String>(20);
|
||||
int max = 0;
|
||||
for (VascEntryField vef:ve.getVascEntryFields()) {
|
||||
if (ve.getDisplayNameFieldId()!=null && ve.getDisplayNameFieldId().equals(vef.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (ve.getPrimaryKeyFieldId()!=null && ve.getPrimaryKeyFieldId().equals(vef.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (vef.getList()!=null && vef.getList()==false) {
|
||||
continue;
|
||||
}
|
||||
vefListIds.add(vef.getId());
|
||||
max++;
|
||||
if (max>8) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (String key:vefListIds) {
|
||||
VascEntryField vef = ve.getVascEntryFieldById(key);
|
||||
vef.setList(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataContextProvider
|
||||
*/
|
||||
public MetaModelDataContextProvider getDataContextProvider() {
|
||||
return dataContextProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataContextProvider the dataContextProvider to set
|
||||
*/
|
||||
public void setDataContextProvider(MetaModelDataContextProvider dataContextProvider) {
|
||||
this.dataContextProvider = dataContextProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tableInclude
|
||||
*/
|
||||
public String getTableInclude() {
|
||||
return tableInclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tableInclude the tableInclude to set
|
||||
*/
|
||||
public void setTableInclude(String tableInclude) {
|
||||
this.tableInclude = tableInclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tableExclude
|
||||
*/
|
||||
public String getTableExclude() {
|
||||
return tableExclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tableExclude the tableExclude to set
|
||||
*/
|
||||
public void setTableExclude(String tableExclude) {
|
||||
this.tableExclude = tableExclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the entryPrefix
|
||||
*/
|
||||
public String getEntryPrefix() {
|
||||
return entryPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entryPrefix the entryPrefix to set
|
||||
*/
|
||||
public void setEntryPrefix(String entryPrefix) {
|
||||
this.entryPrefix = entryPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the vascGroupId
|
||||
*/
|
||||
public String getVascGroupId() {
|
||||
return vascGroupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param vascGroupId the vascGroupId to set
|
||||
*/
|
||||
public void setVascGroupId(String vascGroupId) {
|
||||
this.vascGroupId = vascGroupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resultEntries
|
||||
*/
|
||||
public List<VascEntryLocal> getResultEntries() {
|
||||
List<VascEntryLocal> result = new ArrayList<VascEntryLocal>(resultEntries.values());
|
||||
Collections.sort(result, new Comparator<VascEntryLocal>() {
|
||||
@Override
|
||||
public int compare(VascEntryLocal o1, VascEntryLocal o2) {
|
||||
return o1.getId().compareTo(o2.getId());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resultEntryGroups
|
||||
*/
|
||||
public List<VascEntryGroupLocal> getResultEntryGroups() {
|
||||
List<VascEntryGroupLocal> result = new ArrayList<VascEntryGroupLocal>(resultEntryGroups.values());
|
||||
Collections.sort(result, new Comparator<VascEntryGroupLocal>() {
|
||||
@Override
|
||||
public int compare(VascEntryGroupLocal o1, VascEntryGroupLocal o2) {
|
||||
return o1.getId().compareTo(o2.getId());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resultBackends
|
||||
*/
|
||||
public List<MetaModelVascBackend> getResultBackends() {
|
||||
List<MetaModelVascBackend> result = new ArrayList<MetaModelVascBackend>(resultBackends.values());
|
||||
Collections.sort(result, new Comparator<MetaModelVascBackend>() {
|
||||
@Override
|
||||
public int compare(MetaModelVascBackend o1, MetaModelVascBackend o2) {
|
||||
return o1.getId().compareTo(o2.getId());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tables
|
||||
*/
|
||||
public List<String> getTables() {
|
||||
return tables;
|
||||
}
|
||||
|
||||
public void addTable(String table) {
|
||||
tables.add(table);
|
||||
}
|
||||
public void removeTable(String table) {
|
||||
tables.remove(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the veLinkPostfix
|
||||
*/
|
||||
public String getVeLinkPostfix() {
|
||||
return veLinkPostfix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param veLinkPostfix the veLinkPostfix to set
|
||||
*/
|
||||
public void setVeLinkPostfix(String veLinkPostfix) {
|
||||
this.veLinkPostfix = veLinkPostfix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the veListPostfix
|
||||
*/
|
||||
public String getVeListPostfix() {
|
||||
return veListPostfix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param veListPostfix the veListPostfix to set
|
||||
*/
|
||||
public void setVeListPostfix(String veListPostfix) {
|
||||
this.veListPostfix = veListPostfix;
|
||||
}
|
||||
}
|
||||
|
|
@ -43,16 +43,14 @@ import org.eobjects.metamodel.schema.Schema;
|
|||
import org.eobjects.metamodel.schema.Table;
|
||||
|
||||
import net.forwardfire.vasc.backend.AbstractVascBackend;
|
||||
import net.forwardfire.vasc.backend.VascBackendException;
|
||||
import net.forwardfire.vasc.backend.VascBackendState;
|
||||
import net.forwardfire.vasc.backend.VascEntryFieldValue;
|
||||
import net.forwardfire.vasc.backend.VascEntryRecordCreator;
|
||||
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;
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
|
||||
/**
|
||||
* MetaModelVascBackend provides vasc backend for metamodel.
|
||||
|
|
@ -212,11 +210,11 @@ public class MetaModelVascBackend extends AbstractVascBackend {
|
|||
return q;
|
||||
}
|
||||
|
||||
public List<Object> execute(VascBackendState state) throws VascException {
|
||||
public List<Object> execute(VascBackendState state) throws VascBackendException {
|
||||
Schema schema = dataContext.getDefaultSchema();
|
||||
Table t = schema.getTableByName(table);
|
||||
if (t==null) {
|
||||
throw new VascException("Could not get meta table for: '"+table+"'.");
|
||||
throw new VascBackendException("Could not get meta table for: '"+table+"'.");
|
||||
}
|
||||
Query q = createFilterQuery(state,t,false);
|
||||
if (isSortable() && state.getSortField() != null) {
|
||||
|
|
@ -265,32 +263,32 @@ public class MetaModelVascBackend extends AbstractVascBackend {
|
|||
return result;
|
||||
}
|
||||
|
||||
public void persist(Object object) throws VascException {
|
||||
public void persist(Object object) throws VascBackendException {
|
||||
if (crudDataContext==null) {
|
||||
return;
|
||||
}
|
||||
crudDataContext.persist((UpdateableRow) object);
|
||||
}
|
||||
|
||||
public Object merge(Object object) throws VascException {
|
||||
public Object merge(Object object) throws VascBackendException {
|
||||
if (crudDataContext==null) {
|
||||
return object;
|
||||
}
|
||||
return crudDataContext.merge((UpdateableRow) object);
|
||||
}
|
||||
|
||||
public void delete(Object object) throws VascException {
|
||||
public void delete(Object object) throws VascBackendException {
|
||||
if (crudDataContext==null) {
|
||||
return;
|
||||
}
|
||||
crudDataContext.delete((UpdateableRow) object);
|
||||
}
|
||||
|
||||
public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) {
|
||||
public VascEntryFieldValue provideVascEntryFieldValue() {
|
||||
return new RowVascEntryFieldValue();
|
||||
}
|
||||
|
||||
public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) {
|
||||
public VascEntryRecordCreator provideVascEntryRecordCreator() {
|
||||
return new RowVascEntryRecordCreator(crudDataContext,crudDataContext.getDefaultSchema().getTableByName(table));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,34 +3,30 @@ package net.forwardfire.vasc.backend.metamodel;
|
|||
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.metamodel.crud.UpdateableRow;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
|
||||
public class RowVascEntryFieldValue implements VascEntryFieldValue {
|
||||
|
||||
private static final long serialVersionUID = -806674640688182132L;
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.entry.VascEntryFieldValue#getValue(net.forwardfire.vasc.core.VascEntryField, java.lang.Object)
|
||||
* @see net.forwardfire.vasc.backend.VascEntryFieldValue#getValue(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public Object getValue(VascEntryField field, Object record) throws VascException {
|
||||
if (field==null) {
|
||||
throw new NullPointerException("Can't get value of null field.");
|
||||
}
|
||||
if (field.getBackendName()==null) {
|
||||
throw new NullPointerException("Can't get value of null backendName field.");
|
||||
public Object getValue(String backendName, Object record) throws VascBackendException {
|
||||
if (backendName==null) {
|
||||
throw new NullPointerException("Can't get value of null backendName.");
|
||||
}
|
||||
if (record==null) {
|
||||
throw new NullPointerException("Can't get value of null object.");
|
||||
}
|
||||
if (record instanceof UpdateableRow) {
|
||||
UpdateableRow row = (UpdateableRow)record;
|
||||
return row.getValue(field.getBackendName());
|
||||
return row.getValue(backendName);
|
||||
}
|
||||
Row row = (Row)record;
|
||||
Object fieldValue = row.getValue(indexOf(field.getBackendName(),row));
|
||||
Object fieldValue = row.getValue(indexOf(backendName,row));
|
||||
return fieldValue;
|
||||
}
|
||||
|
||||
|
|
@ -49,10 +45,10 @@ public class RowVascEntryFieldValue implements VascEntryFieldValue {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.entry.VascEntryFieldValue#getDisplayValue(net.forwardfire.vasc.core.VascEntryField, java.lang.Object)
|
||||
* @see net.forwardfire.vasc.backend.VascEntryFieldValue#getDisplayValue(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public String getDisplayValue(VascEntryField field, Object record) throws VascException {
|
||||
Object fieldValue = getValue(field,record);
|
||||
public String getDisplayValue(String backendName, Object record) throws VascBackendException {
|
||||
Object fieldValue = getValue(backendName,record);
|
||||
if (fieldValue==null) {
|
||||
fieldValue = "";
|
||||
}
|
||||
|
|
@ -60,12 +56,12 @@ public class RowVascEntryFieldValue implements VascEntryFieldValue {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see net.forwardfire.vasc.core.entry.VascEntryFieldValue#setValue(net.forwardfire.vasc.core.VascEntryField, java.lang.Object, java.lang.Object)
|
||||
* @see net.forwardfire.vasc.backend.VascEntryFieldValue#setValue(java.lang.String, java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
public void setValue(VascEntryField field, Object record,Object value) throws VascException {
|
||||
public void setValue(String backendName, Object record,Object value) throws VascBackendException {
|
||||
if (record instanceof UpdateableRow) {
|
||||
UpdateableRow row = (UpdateableRow)record;
|
||||
row.setValue(field.getBackendName(), value);
|
||||
row.setValue(backendName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,11 +2,10 @@ package net.forwardfire.vasc.backend.metamodel;
|
|||
|
||||
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;
|
||||
import net.forwardfire.vasc.backend.metamodel.crud.UpdateableRow;
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
|
||||
public class RowVascEntryRecordCreator implements VascEntryRecordCreator {
|
||||
|
||||
|
|
@ -23,7 +22,7 @@ public class RowVascEntryRecordCreator implements VascEntryRecordCreator {
|
|||
return UpdateableRow.class;
|
||||
}
|
||||
|
||||
public Object newRecord(VascEntry entry) throws VascException {
|
||||
public Object newRecord() throws VascBackendException {
|
||||
return dataContext.createRow(table);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +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.metamodel.x4o;
|
||||
|
||||
import net.forwardfire.vasc.backend.metamodel.MetaModelSchemaAutoEntry;
|
||||
import net.forwardfire.vasc.core.VascController;
|
||||
import net.forwardfire.vasc.impl.x4o.VascDriver;
|
||||
|
||||
import org.x4o.xml.element.AbstractElementConfigurator;
|
||||
import org.x4o.xml.element.Element;
|
||||
import org.x4o.xml.element.ElementConfiguratorException;
|
||||
|
||||
/**
|
||||
* SchemaAutoEntryElementConfigurator runs the autoCreateEntries method the MetaModelSchemaAutoEntry bean.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 12, 2012
|
||||
*/
|
||||
public class SchemaAutoEntryElementConfigurator extends AbstractElementConfigurator {
|
||||
|
||||
/**
|
||||
* @see org.x4o.xml.element.AbstractElementConfigurator#doConfigEndTag(org.x4o.xml.element.Element)
|
||||
*/
|
||||
public void doConfigElement(Element element) throws ElementConfiguratorException {
|
||||
|
||||
if (element.getElementObject()==null) {
|
||||
throw new ElementConfiguratorException(this,"ElementObject is null");
|
||||
}
|
||||
if ((element.getElementObject() instanceof MetaModelSchemaAutoEntry)==false) {
|
||||
throw new ElementConfiguratorException(this,"ElementObject is not MetaModelSchemaAutoEntry object.");
|
||||
}
|
||||
MetaModelSchemaAutoEntry autoEntry = (MetaModelSchemaAutoEntry)element.getElementObject();
|
||||
VascController vascController = VascDriver.getVascController(element.getLanguageSession());
|
||||
autoEntry.autoFillResult(vascController);
|
||||
autoEntry.autoAddResultToController();
|
||||
}
|
||||
}
|
||||
|
|
@ -30,10 +30,5 @@
|
|||
<element tag="xmlDomDataContext" objectClass="net.forwardfire.vasc.backend.metamodel.MetaModelDataContextXmlDom"/>
|
||||
|
||||
<element tag="jndiDataContext" objectClass="net.forwardfire.vasc.backend.metamodel.MetaModelDataContextJndiDataContext"/>
|
||||
|
||||
<element tag="schemaAutoEntry" objectClass="net.forwardfire.vasc.backend.metamodel.MetaModelSchemaAutoEntry">
|
||||
<configurator id="schemaAutoEntry-SchemaAutoEntryElementConfigurator" bean.class="net.forwardfire.vasc.backend.metamodel.x4o.SchemaAutoEntryElementConfigurator" configAction="true"/>
|
||||
</element>
|
||||
|
||||
</namespace>
|
||||
</root:module>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue