Search in sources :

Example 6 with Persistent

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

the class VariantPlugin 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) {
                List list = persistents[0];
                if (list != null)
                    Collections.sort(list);
                return persistents[0];
            } else {
                List<Persistent> list = persistents[0];
                if (list.size() != 1)
                    return null;
                List<Persistent> ps = engine.getBinaryAttribute(-1, attributeId)[0];
                VariantPersistent vp = (VariantPersistent) list.get(0);
                for (Persistent p : ps) {
                    VariantPropertyPersistent pp = (VariantPropertyPersistent) p;
                    if (pp.getVariantId() == vp.getVariantId())
                        return pp.getValue();
                }
                return "WARNING: Unknown variant with variant id: " + vp.getVariantId();
            }
        }

        @SuppressWarnings("unchecked")
        @Override
        public List<Persistent>[] toPersistens(Object object, long elementId, long attributeId, IEngine engine) {
            if (elementId < 0) {
                List<VariantPropertyPersistent> list = (List) object;
                for (int i = 0; i < list.size(); i++) list.get(i).setPosition(i);
                return new List[] { list };
            } else {
                if (object == null) {
                    return new List[] { new ArrayList(0) };
                }
                List<Persistent> ps = engine.getBinaryAttribute(-1, attributeId)[0];
                VariantPersistent vp = new VariantPersistent();
                long maxId = -1;
                for (Persistent p : ps) {
                    VariantPropertyPersistent pp = (VariantPropertyPersistent) p;
                    if (pp.getValue().equals(object)) {
                        vp.setVariantId(pp.getVariantId());
                        List<Persistent> list = new ArrayList<Persistent>(1);
                        list.add(vp);
                        return new List[] { list };
                    }
                    if (maxId < pp.getVariantId())
                        maxId = pp.getVariantId();
                }
                VariantPropertyPersistent pp = new VariantPropertyPersistent();
                pp.setValue((String) object);
                pp.setVariantId(maxId + 1l);
                pp.setAttribute(attributeId);
                pp.setPosition(ps.size());
                vp.setVariantId(pp.getVariantId());
                if (engine instanceof Engine) {
                    ps.add(pp);
                    ((Engine) engine).setAttribute(null, engine.getAttribute(attributeId), ps);
                } else {
                    Transaction transaction = new Transaction();
                    transaction.getSave().add(pp);
                    engine.setBinaryAttribute(-1, attributeId, transaction);
                }
                List<Persistent> list = new ArrayList<Persistent>(1);
                list.add(vp);
                return new List[] { list };
            }
        }
    };
}
Also used : IEngine(com.ramussoft.common.IEngine) ArrayList(java.util.ArrayList) Persistent(com.ramussoft.common.persistent.Persistent) Transaction(com.ramussoft.common.persistent.Transaction) List(java.util.List) ArrayList(java.util.ArrayList) AbstractAttributeConverter(com.ramussoft.common.attribute.AbstractAttributeConverter) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine)

Example 7 with Persistent

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

the class StatusPlugin method getAttributeConverter.

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

        @Override
        protected Object toObject(Persistent persistent) {
            StatusPersistent p = (StatusPersistent) persistent;
            return new Status(p.getType(), p.getOtherName());
        }

        @Override
        protected Persistent toPersistent(Object value) {
            StatusPersistent p = new StatusPersistent();
            Status s = (Status) value;
            p.setOtherName(s.getAtherName());
            p.setType(s.getType());
            return p;
        }
    };
}
Also used : Status(com.dsoft.pb.idef.elements.Status) Persistent(com.ramussoft.common.persistent.Persistent) SimpleAttributeConverter(com.ramussoft.core.attribute.simple.SimpleAttributeConverter)

Example 8 with Persistent

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

the class ProjectPreferencesPlugin method getAttributeConverter.

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

        @Override
        public Object toObject(List<Persistent>[] persistents, long elementId, long attributeId, IEngine engine) {
            ProjectOptions result;
            if (persistents[0].size() == 0)
                return null;
            else
                result = new ProjectOptions((IDEF0ModelPreferencesPersistent) persistents[0].get(0));
            for (Persistent p : persistents[1]) result.getReadedModel().addReaded().setDeligate((ReaderPersistent) p);
            return result;
        }

        @SuppressWarnings("unchecked")
        @Override
        public List<Persistent>[] toPersistens(Object object, long elementId, long attributeId, IEngine engine) {
            ProjectOptions po = (ProjectOptions) object;
            List<Persistent>[] res = new List[2];
            List<Persistent> f = new ArrayList<Persistent>();
            f.add(po.getDeligate());
            res[0] = f;
            List<Persistent> s = new ArrayList<Persistent>();
            for (Readed r : po.getReadedModel().getAllReaded()) {
                s.add(r.getDeligate());
            }
            res[1] = s;
            return res;
        }
    };
}
Also used : IEngine(com.ramussoft.common.IEngine) ArrayList(java.util.ArrayList) Persistent(com.ramussoft.common.persistent.Persistent) List(java.util.List) ArrayList(java.util.ArrayList) AbstractAttributeConverter(com.ramussoft.common.attribute.AbstractAttributeConverter) ProjectOptions(com.dsoft.pb.idef.elements.ProjectOptions) Readed(com.dsoft.pb.idef.elements.Readed)

Example 9 with Persistent

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

the class SectorPointPlugin method getAttributeConverter.

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

        @Override
        public Object toObject(List<Persistent>[] persistents, long elementId, long attributeId, IEngine engine) {
            List list = (List) persistents[0];
            Collections.sort(list);
            return persistents[0];
        }

        @Override
        public List<Persistent>[] toPersistens(Object object, long elementId, long attributeId, IEngine engine) {
            List<SectorPointPersistent> list = (List) object;
            for (int i = 0; i < list.size(); i++) list.get(i).setPosition(i);
            return new List[] { list };
        }
    };
}
Also used : IEngine(com.ramussoft.common.IEngine) Persistent(com.ramussoft.common.persistent.Persistent) List(java.util.List) AbstractAttributeConverter(com.ramussoft.common.attribute.AbstractAttributeConverter)

Example 10 with Persistent

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

the class DeleteElementCommand method writeBody.

@Override
public void writeBody(BinaryDataOutput output) throws IOException {
    output.writeLong(qualifierId);
    output.writeLong(elementId);
    output.writeInt(data.length);
    for (Transaction transaction : data) {
        output.writeBoolean(transaction.isRemoveBranchInfo());
        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)

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