--
Ticket URL: <http://eobjects.org/trac/ticket/858>
eobjects <http://eobjects.org/trac>
The eobjects project management system, based on the trac system.
Comment (by kasper):
I am affraid I dont think this is a viable design. There is no possibility
to demarcate transactions or to even ensure synchronization and race-
conditions when doing multiple disparate updates like this. I believe that
our current approach with the UpdateScript handles this much better.
While designing the executeUpdate(...) method this was actually something
that was thought quite a lot about. See http://kasper.eobjects.org/2011/07
/proposal-for-writing-data-in-metamodel.html
But one compromise might be that we created a few simple out-of-the-box
UpdateScript implementations that you could easily use in case you just
wanted to eg. insert a single record:
For instance, this naive implementation:
{{{
public class InsertRow implements UpdateScript {
private final Row _row;
public InsertRow(Row row) {
_row = row;
}
@Override
public void run(UpdateCallback callback) {
callback.insertInto(row.getValue(0).getColumn().getTable()).like(_row).execute();
}
}
}}}
... and this consuming code:
{{{
UpdateableDataContext dc = ...
Row row = ...
dc.executeUpdate(new InsertRow(row));
}}}
--
Ticket URL: <http://eobjects.org/trac/ticket/858#comment:1>
Comment (by w.cazander):
Please note that this design is also working implementation where all crud
functions are
delegated to an UpdateScript. So all sync stuff is done by
UpdateableDataContext impl.
Refactored a bit more so integration with current DataContexts should be
easy.
Auto crud support limitations:
- needs query with one FromItem,else falls back to DataSet<Row> result.
- needs table with one or more primary keys, else throws exception.
MM Todos;
- redo AbstractCrudDataContext.queryWhereBuilder* methods to cleaner code
- use correct api to detect selectCount in
AbstractCrudDataContext.executeQueryWrapDataSet
- Add slf4j loggers
- Update Row interface see UpdateableRow and AbstractUpdateableRow.
- Fix table.getPrimaryKeys() see
CrudDataContextImpl.getPrimaryKeysForTable
Also added working unit test to the code to see it in action.
--
Ticket URL: <http://eobjects.org/trac/ticket/858#comment:2>
Comment (by w.cazander):
Examples;
// Level 1 integration let the crud impl do all work on
UpdateableDataContext
{{{
UpdateableDataContext dataContext = new CsvDataContext(testFile);
CrudDataContext crudDataContext = new CrudDataContextImpl(dataContext);
}}}
// Level 2 integration no wrapping of DataSet
{{{
class CrudCsvDataContextNoWrap extends CsvDataContext implements
UpdateableRowDataContext {
public DataSet crudExecuteQuery(CrudDataContext
crudDataContext,Query query);
...
// Pass over CrudDataContext until somewhere;
return new CrudCsvDataSet( ... , crudDataContext);
}
public InitFromBuilder crudCreateQuery(CrudDataContext
crudDataContext) {
return new InitFromBuilderImpl(crudDataContext);
}
}
class CrudCsvDataSet extends CsvDataSet {
private CrudDataContext cdc = null;
public CrudCsvDataSet( ... , CrudDataContext cdc) {
super ( ... );
this.cdc = cdc;
}
private boolean nextInternal() {
...
_row = cdc.createRow(table); // Was new
DefaultRow(_selectItems, rowValues);
_row.setValue(...);
...
return true;
}
}
}}}
// Level 3 integration full crud support by DataContext
{{{
class CrudCsvDataContextFull /* extends CsvDataContext */ implements
CrudDataContext {
CrudDataContext crudDataContext = null;
public CrudCsvDataContextFull() {
crudDataContext = new CrudDataContextImpl(this);
}
public DataSet executeQuery(Query query);
return new SomeDataSetImpl<UpdateableRow>(query);
}
public InitFromBuilder createQuery() {
return new InitFromBuilderImpl(crudDataContext);
}
public UpdateableRow createRow(Table table) {
crudDataContext.createRow(table); }
public void persist(UpdateableRow row) {
crudDataContext.persist(row); }
public Object merge(UpdateableRow row) { return
crudDataContext.merge(row); }
public void delete(UpdateableRow row) {
crudDataContext.delete(row); }
}
}}}
// Level 4 integration do it yourself crud
{{{
class JpaCrudDataContext implements CrudDataContext,UpdateableDataContext
{
// Map CrudDataContext crud of JPA
// Map UpdateableDataContext to JPA
}
}}}
--
Ticket URL: <http://eobjects.org/trac/ticket/858#comment:3>
* milestone: MetaModel 3.0 => MetaModel X.0
Comment:
Batch moving issues to version X.0 for further release planning.
--
Ticket URL: <http://eobjects.org/trac/ticket/858#comment:4>