2
0
Fork 0

Upgraded backend api with generics.

This commit is contained in:
Willem Cazander 2014-05-28 14:16:03 +02:00
parent 9a6227be5b
commit 1b3e65fa83
53 changed files with 282 additions and 256 deletions

View file

@ -58,7 +58,7 @@ import net.forwardfire.vasc.backend.metamodel.crud.UpdateableRowMapImpl;
* @author Willem Cazander
* @version 1.0 Dec 31, 2011
*/
public class MetaModelVascBackend extends AbstractVascBackend {
public class MetaModelVascBackend extends AbstractVascBackend<Row> {
private Logger logger = Logger.getLogger(MetaModelVascBackend.class.getName());
private MetaModelDataContextProvider dataContextProvider = null;
@ -210,7 +210,7 @@ public class MetaModelVascBackend extends AbstractVascBackend {
return q;
}
public List<Object> execute(VascBackendState state) throws VascBackendException {
public List<Row> execute(VascBackendState state) throws VascBackendException {
Schema schema = dataContext.getDefaultSchema();
Table t = schema.getTableByName(table);
if (t==null) {
@ -236,16 +236,15 @@ public class MetaModelVascBackend extends AbstractVascBackend {
}
q.setMaxRows(state.getPageSize());
}
List<Row> result = new ArrayList<Row>(50);
if (crudDataContext!=null) {
DataSet ds = crudDataContext.executeQuery(q);
List<Object> result = new ArrayList<Object>(50);
result.addAll(ds.toRows());
ds.close();
return result;
}
DataSet ds = dataContext.executeQuery(q);
List<Object> result = new ArrayList<Object>(50);
while (ds.next()) {
Row row = ds.getRow();
SelectItem[] cols = row.getSelectItems();
@ -263,21 +262,21 @@ public class MetaModelVascBackend extends AbstractVascBackend {
return result;
}
public void persist(Object object) throws VascBackendException {
public void persist(Row object) throws VascBackendException {
if (crudDataContext==null) {
return;
}
crudDataContext.persist((UpdateableRow) object);
}
public Object merge(Object object) throws VascBackendException {
public Row merge(Row object) throws VascBackendException {
if (crudDataContext==null) {
return object;
}
return crudDataContext.merge((UpdateableRow) object);
}
public void delete(Object object) throws VascBackendException {
public void delete(Row object) throws VascBackendException {
if (crudDataContext==null) {
return;
}
@ -288,7 +287,7 @@ public class MetaModelVascBackend extends AbstractVascBackend {
return new RowVascEntryFieldValue();
}
public VascEntryRecordCreator provideVascEntryRecordCreator() {
public VascEntryRecordCreator<Row> provideVascEntryRecordCreator() {
return new RowVascEntryRecordCreator(crudDataContext,crudDataContext.getDefaultSchema().getTableByName(table));
}

View file

@ -1,13 +1,13 @@
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;
import net.forwardfire.vasc.backend.metamodel.crud.UpdateableRow;
public class RowVascEntryRecordCreator implements VascEntryRecordCreator {
public class RowVascEntryRecordCreator implements VascEntryRecordCreator<Row> {
private static final long serialVersionUID = -1182678362367989090L;
private CrudDataContext dataContext = null;
@ -17,12 +17,8 @@ public class RowVascEntryRecordCreator implements VascEntryRecordCreator {
this.dataContext=dataContext;
this.table=table;
}
public Class<?> getObjectClass() {
return UpdateableRow.class;
}
public Object newRecord() throws VascBackendException {
public Row newRecord() throws VascBackendException {
return dataContext.createRow(table);
}
}

View file

@ -48,6 +48,9 @@ abstract public class AbstractCrudDataContext implements CrudDataContext {
RowInsertionBuilder query = backendImpl.insertInto(row.getTable());
for (int i=0;i<row.size();i++) {
SelectItem si = row.getSelectItem(i);
if (si.getColumn().isPrimaryKey()) {
continue; // insert null will only work with correct default sequence attacted to column.
}
Object value = row.getValue(i);
query.value(si.getColumn(), value);
}
@ -56,7 +59,7 @@ abstract public class AbstractCrudDataContext implements CrudDataContext {
});
}
public Object merge(final UpdateableRow row) {
public UpdateableRow merge(final UpdateableRow row) {
for (String column:row.getPrimaryKeys()) {
if (row.getValue(column)==null) {
throw new IllegalStateException("Can't update row where primary key: "+column+" value is null.");

View file

@ -26,7 +26,7 @@ public interface CrudDataContext extends UpdateableDataContext {
/**
* Merges row with table.
*/
public Object merge(UpdateableRow row);
public UpdateableRow merge(UpdateableRow row);
/**
* Deletes row from table.