use of com.ramussoft.common.persistent.Persistent in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method setElistFix.
private void setElistFix(Transaction transaction) {
long branchId = getActiveBranchId();
String delete = "DELETE FROM " + prefix + "attribute_element_lists WHERE attribute_id=? AND element1_id=? AND element2_id = ? AND value_branch_id=?";
String remove = "UPDATE " + prefix + "attribute_element_lists SET connection_type=?, removed_branch_id=? WHERE attribute_id=? AND element1_id=? AND element2_id = ? AND value_branch_id=?";
String insert = "INSERT INTO " + prefix + "attribute_element_lists (connection_type, attribute_id, element1_id, element2_id, value_branch_id) VALUES (?, ?, ?, ?, ?)";
for (Persistent p : transaction.getDelete()) {
Class<? extends Persistent> clazz = p.getClass();
PersistentWrapper wrapper = wrappers.get(clazz);
long bId = (Long) wrapper.getField(p, "valueBranchId");
long aId = (Long) wrapper.getField(p, "attributeId");
long e1Id = (Long) wrapper.getField(p, "element1Id");
long e2Id = (Long) wrapper.getField(p, "element2Id");
String connectionType = (String) wrapper.getField(p, "connectionType");
if (bId == branchId) {
template.update(delete, new Object[] { aId, e1Id, e2Id, bId }, false);
} else {
template.update(remove, new Object[] { connectionType, branchId, aId, e1Id, e2Id, bId }, false);
}
}
for (Persistent p : transaction.getSave()) {
Class<? extends Persistent> clazz = p.getClass();
PersistentWrapper wrapper = wrappers.get(clazz);
long aId = (Long) wrapper.getField(p, "attributeId");
long e1Id = (Long) wrapper.getField(p, "element1Id");
long e2Id = (Long) wrapper.getField(p, "element2Id");
String connectionType = (String) wrapper.getField(p, "connectionType");
template.update(insert, new Object[] { connectionType, aId, e1Id, e2Id, branchId }, false);
}
}
use of com.ramussoft.common.persistent.Persistent in project ramus by Vitaliy-Yakovchuk.
the class CurrencyPlugin method getAttributeConverter.
@Override
public AttributeConverter getAttributeConverter() {
return new SimpleAttributeConverter() {
@SuppressWarnings("unchecked")
@Override
public List<Persistent>[] toPersistens(Object object, long elementId, long attributeId, IEngine engine) {
if (elementId < 0) {
if (object == null)
return new List[] { new ArrayList(0) };
else {
List list = new ArrayList(1);
list.add(object);
return new List[] { list };
}
}
return super.toPersistens(object, elementId, attributeId, engine);
}
public Object toObject(java.util.List<Persistent>[] persistents, long elementId, long attributeId, IEngine engine) {
if (elementId < 0) {
List<Persistent> list = persistents[0];
if (list.size() == 0)
return null;
else
return list.get(0);
}
return super.toObject(persistents, elementId, attributeId, engine);
}
@Override
protected Persistent toPersistent(Object value) {
CurrencyPersistent cp = new CurrencyPersistent();
cp.setValue(((Number) value).doubleValue());
return cp;
}
@Override
protected Object toObject(Persistent persistent) {
return ((CurrencyPersistent) persistent).getValue();
}
};
}
Aggregations