public void setValue(RecT rec, ValueT value) throws SQLException { doSetValue(rec, value); Flow<ValueT> f = rec.getFlow(this); if (f != null) { f.setValue(value); } }
public void genDirtyFieldDescriptions(RecT rec, Set<String> out) throws SQLException { for (Col<RecT, ?> c : cols()) { if (c.isVisible() && c.field().isDirty(rec)) { String n = String.format("%s.%s", name(), c.name()); out.add( String.format( "%s: %s (%s)", rec.cx().t8(n), c.formatValue(rec), c.formatStoredValue(rec))); } } for (Table<RecT>.Ref<?> r : refs()) { CoreTable<?> t = (CoreTable<?>) r.refTable(); if (!t.createEvents(rec.cx())) { ((Ref<?>) r).genDirtyFieldDescriptions(rec, out); } } }
public Flow<ValueT> valueFlow(final RecT rec) { Flow<ValueT> f = rec.getFlow(this); if (f == null) { f = new Flow<ValueT>() { @Override public void setValue(ValueT value, Set<Node> blacklist) { try { Map<Col<RecT, ?>, Object> valueMap = new HashMap<>(); for (Col<RecT, ?> c : table.cols()) { if (c != Col.this) { valueMap.put(c, c.getValue(rec)); } } Col.this.setValue(rec, value); for (Map.Entry<Col<RecT, ?>, Object> e : valueMap.entrySet()) { Col<RecT, ?> c = e.getKey(); Flow<?> f = rec.getFlow(c); if (f != null && !c.equalObjects(valueMap.get(c), c.getValue(rec))) { f.pushValue(); } } } catch (SQLException e) { throw new RuntimeException(e); } } @Override public ValueT value() { try { return getValue(rec); } catch (SQLException e) { throw new RuntimeException(e); } } }; rec.addFlow(this, f); } return f; }
public String genStoreEventDescription(RecT rec) throws SQLException { boolean isStored = recIsStored(rec); StringBuilder res = new StringBuilder(); res.append( String.format( "%s %s.", rec.caption(), isStored ? rec.cx().t8(updated()) : rec.cx().t8(created()))); if (isStored) { Set<String> fieldDescriptions = new TreeSet<>(); genDirtyFieldDescriptions(rec, fieldDescriptions); if (fieldDescriptions.isEmpty()) { return null; } res.append(' '); String sep = ""; for (String s : fieldDescriptions) { res.append(sep).append(s); sep = ", "; } res.append('.'); } return res.toString(); }
@Override public void deleteRec(final RecT rec) throws SQLException { if (createEvents(rec.cx())) { rec.cx() .execEvent( new Event.Procedure<Object>(rec.cx()) { @Override protected Object onExec() throws SQLException { description = genDeleteEventDescription(rec); doDeleteRec(rec); return null; } @Override protected String getDescription() throws SQLException { return description; } private String description; }); } else { doDeleteRec(rec); } }
@Override public RecT storeRec(final RecT rec) throws SQLException { if (!rec.isStoring()) { rec.setStoring(true); try { if (createEvents(rec.cx())) { rec.cx() .execEvent( new Event.Procedure<Object>(rec.cx()) { @Override protected Object onExec() throws SQLException { description = genStoreEventDescription(rec); doStoreRec(rec); return null; } @Override protected String getDescription() throws SQLException { return description; } @Override protected boolean storeEvent() { return description != null; } private String description; }); } else { doStoreRec(rec); } } finally { rec.setStoring(false); } } return rec; }
public void updateValueFlow(RecT rec) { Flow<ValueT> f = rec.getFlow(this); if (f != null) { f.pushValue(); } }
public void loadValue(RecT rec, Query.Result result) throws SQLException { field.setValue(rec, loadValue(rec.cx(), result)); }
public void initRec(RecT rec) { field.initRec(rec, defaultValue(rec.cx())); }
public String formatValue(RecT rec) throws SQLException { return formatValue(rec.cx(), getValue(rec)); }
public String genDeleteEventDescription(RecT rec, String deleted) throws SQLException { return String.format("%s %s.", rec.caption(), rec.cx().t8(deleted)); }