Search in sources :

Example 16 with Persistent

use of com.ramussoft.common.persistent.Persistent in project ramus by Vitaliy-Yakovchuk.

the class TransactionStorageCommand method write.

private void write(List<Persistent> list, BinaryDataOutput output) throws IOException {
    for (Persistent p : list) {
        output.writeByte(1);
        storePersistent(output, p);
    }
    output.writeByte(0);
}
Also used : Persistent(com.ramussoft.common.persistent.Persistent)

Example 17 with Persistent

use of com.ramussoft.common.persistent.Persistent in project ramus by Vitaliy-Yakovchuk.

the class UpdateQualifierCommand method writeBody.

@Override
public void writeBody(BinaryDataOutput output) throws IOException {
    storeQualifier(output, oldQualifier);
    storeQualifier(output, newQualifier);
    for (Attribute attribute : deletedAttributes) {
        Hashtable<Long, Transaction> hash = hashtable.get(attribute.getId());
        output.writeInt(hash.size());
        for (Entry<Long, Transaction> entry : hash.entrySet()) {
            output.writeLong(entry.getKey());
            output.writeInt(entry.getValue().getDelete().size());
            for (Persistent p : entry.getValue().getDelete()) {
                TransactionStorageCommand.storePersistent(engine, output, p);
            }
        }
    }
}
Also used : Transaction(com.ramussoft.common.persistent.Transaction) Attribute(com.ramussoft.common.Attribute) Persistent(com.ramussoft.common.persistent.Persistent)

Example 18 with Persistent

use of com.ramussoft.common.persistent.Persistent in project ramus by Vitaliy-Yakovchuk.

the class DeleteAttributeCommand method writeBody.

@Override
public void writeBody(BinaryDataOutput output) throws IOException {
    output.writeInt(properties.getDelete().size());
    for (Persistent persistent : properties.getDelete()) {
        TransactionStorageCommand.storePersistent(engine, output, persistent);
    }
    storeAttribute(output, attribute);
}
Also used : Persistent(com.ramussoft.common.persistent.Persistent)

Example 19 with Persistent

use of com.ramussoft.common.persistent.Persistent in project ramus by Vitaliy-Yakovchuk.

the class SetElementQualifierCommand method writeBody.

@Override
public void writeBody(BinaryDataOutput output) throws IOException {
    output.writeLong(oldQualifierId);
    output.writeLong(newQualifierId);
    output.writeLong(elementId);
    output.writeInt(data.length);
    for (Transaction transaction : data) {
        output.writeInt(transaction.getDelete().size());
        for (Persistent persistent : transaction.getDelete()) {
            TransactionStorageCommand.storePersistent(engine, output, persistent);
        }
    }
}
Also used : Transaction(com.ramussoft.common.persistent.Transaction) Persistent(com.ramussoft.common.persistent.Persistent)

Example 20 with Persistent

use of com.ramussoft.common.persistent.Persistent in project ramus by Vitaliy-Yakovchuk.

the class ElementListPlugin method getAttributeConverter.

@Override
public AttributeConverter getAttributeConverter() {
    return new AbstractAttributeConverter() {

        @SuppressWarnings("unchecked")
        public Object toObject(java.util.List<Persistent>[] persistents, long elementId, long attributeId, IEngine engine) {
            if (elementId < 0) {
                return toPropertyObject(persistents);
            } else {
                List res = persistents[0];
                if (res != null)
                    Collections.sort(res);
                return res;
            }
        }

        @SuppressWarnings("unchecked")
        @Override
        public List<Persistent>[] toPersistens(Object object, long elementId, long attributeId, IEngine engine) {
            if (elementId < 0) {
                List<Persistent> list = new ArrayList<Persistent>(1);
                list.add((ElementListPropertyPersistent) object);
                return new List[] { list };
            } else
                return new List[] { new ArrayList<Persistent>(check(object, elementId, attributeId, engine)) };
        }

        @SuppressWarnings("unchecked")
        private List check(Object object, long elementId, long attributeId, IEngine engine) {
            List<ElementListPersistent> list = (List) object;
            ElementListPropertyPersistent p = (ElementListPropertyPersistent) toObject(engine.getBinaryAttribute(-1, attributeId), -1, attributeId, engine);
            if ((p.getQualifier1() == -1) || (p.getQualifier2() == -1))
                throw new RuntimeException("Left or right qualifier not seted.");
            long mq = engine.getQualifierIdForElement(elementId);
            if (mq == p.getQualifier1()) {
                for (int i = list.size() - 1; i >= 0; --i) {
                    ElementListPersistent e = list.get(i);
                    if ((e.getElement1Id() != elementId) || (engine.getQualifierIdForElement(e.getElement2Id())) != p.getQualifier2()) {
                        System.err.println("Element id not correct.");
                        list.remove(i);
                    }
                }
            } else if (mq == p.getQualifier2()) {
                for (int i = list.size() - 1; i >= 0; --i) {
                    ElementListPersistent e = list.get(i);
                    if ((e.getElement2Id() != elementId) || (engine.getQualifierIdForElement(e.getElement1Id())) != p.getQualifier1()) {
                        System.err.println("Element id not correct.");
                        list.remove(i);
                    }
                }
            } else {
                System.err.println("Element not correct.");
                return new ArrayList(0);
            }
            return list;
        }
    };
}
Also used : IEngine(com.ramussoft.common.IEngine) ArrayList(java.util.ArrayList) Persistent(com.ramussoft.common.persistent.Persistent) ArrayList(java.util.ArrayList) List(java.util.List) AbstractAttributeConverter(com.ramussoft.common.attribute.AbstractAttributeConverter)

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