Search in sources :

Example 26 with Persistent

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);
    }
}
Also used : Persistent(com.ramussoft.common.persistent.Persistent) PersistentWrapper(com.ramussoft.common.persistent.PersistentWrapper)

Example 27 with Persistent

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();
        }
    };
}
Also used : IEngine(com.ramussoft.common.IEngine) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Persistent(com.ramussoft.common.persistent.Persistent)

Aggregations

Persistent (com.ramussoft.common.persistent.Persistent)27 ArrayList (java.util.ArrayList)15 List (java.util.List)13 PersistentField (com.ramussoft.common.persistent.PersistentField)9 PersistentWrapper (com.ramussoft.common.persistent.PersistentWrapper)9 PersistentRow (com.ramussoft.common.persistent.PersistentRow)8 Attribute (com.ramussoft.common.Attribute)6 IEngine (com.ramussoft.common.IEngine)6 FindObject (com.ramussoft.common.attribute.FindObject)6 Transaction (com.ramussoft.common.persistent.Transaction)6 AbstractAttributeConverter (com.ramussoft.common.attribute.AbstractAttributeConverter)5 RowMapper (com.ramussoft.jdbc.RowMapper)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 AttributePlugin (com.ramussoft.common.attribute.AttributePlugin)4 SimpleAttributeConverter (com.ramussoft.core.attribute.simple.SimpleAttributeConverter)3 Element (com.ramussoft.common.Element)2 Qualifier (com.ramussoft.common.Qualifier)2 ProjectOptions (com.dsoft.pb.idef.elements.ProjectOptions)1 Readed (com.dsoft.pb.idef.elements.Readed)1