Search in sources :

Example 11 with Persistent

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

the class ElementListPlugin method init.

@Override
public void init(Engine engine, AccessRules accessor) {
    super.init(engine, accessor);
    if (!StandardAttributesPlugin.isDisableAutoupdate(engine))
        engine.addElementListener(null, new ElementAdapter() {

            @Override
            public void beforeElementDeleted(ElementEvent event) {
                if (event.isJournaled())
                    return;
                long id = event.getQualifierId();
                Qualifier q = event.getEngine().getQualifier(id);
                cleanAttribute(q.getAttributes(), event);
                cleanAttribute(q.getSystemAttributes(), event);
                super.beforeElementDeleted(event);
            }

            private void cleanAttribute(List<Attribute> attributes, ElementEvent event) {
                for (Attribute a : attributes) {
                    if (isMyType(a)) {
                        event.getEngine().setAttribute(event.getOldElement(), a, new ArrayList<Persistent>(0));
                    }
                }
            }
        });
}
Also used : ElementAdapter(com.ramussoft.common.event.ElementAdapter) Attribute(com.ramussoft.common.Attribute) Qualifier(com.ramussoft.common.Qualifier) ArrayList(java.util.ArrayList) List(java.util.List) Persistent(com.ramussoft.common.persistent.Persistent) ElementEvent(com.ramussoft.common.event.ElementEvent)

Example 12 with Persistent

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

the class AnyToAnyPlugin method getElementName.

private String getElementName(final IEngine engine, final HashMap<Long, Attribute> attributesCache, final HashMap<Long, Qualifier> qualifiersCache, ResultSet rs) throws SQLException {
    Element element = engine.getElement(rs.getLong("element_id"));
    if (element == null)
        return "";
    Qualifier qualifier;
    if (!qualifiersCache.containsKey(element.getQualifierId())) {
        qualifier = engine.getQualifier(element.getQualifierId());
        qualifiersCache.put(element.getQualifierId(), qualifier);
    } else
        qualifier = qualifiersCache.get(element.getQualifierId());
    if (qualifier == null || qualifier.getAttributeForName() < 0l)
        return "";
    Attribute attribute;
    if (!attributesCache.containsKey(qualifier.getAttributeForName())) {
        attribute = engine.getAttribute(qualifier.getAttributeForName());
        attributesCache.put(qualifier.getAttributeForName(), attribute);
    } else
        attribute = attributesCache.get(qualifier.getAttributeForName());
    if (attribute == null)
        return "";
    List<Persistent>[] bAttribute = engine.getBinaryAttribute(element.getId(), attribute.getId());
    if (bAttribute.length == 0)
        return "";
    List<Persistent> list = bAttribute[0];
    if (list.size() == 0)
        return "";
    if (list.get(0) instanceof TextPersistent)
        return String.valueOf(((TextPersistent) list.get(0)).getValue());
    else if (list.get(0) instanceof DFDSName)
        return String.valueOf(((DFDSName) list.get(0)).getShortName());
    return "";
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) Qualifier(com.ramussoft.common.Qualifier) ArrayList(java.util.ArrayList) List(java.util.List) TextPersistent(com.ramussoft.core.attribute.simple.TextPersistent) Persistent(com.ramussoft.common.persistent.Persistent) TextPersistent(com.ramussoft.core.attribute.simple.TextPersistent)

Example 13 with Persistent

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

the class FRectanglePlugin method getAttributeConverter.

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

        @Override
        protected Object toObject(Persistent persistent) {
            FRectanglePersistent fp = (FRectanglePersistent) persistent;
            return new FRectangle(fp.getX(), fp.getY(), fp.getWidth(), fp.getHeight());
        }

        @Override
        protected Persistent toPersistent(Object value) {
            FRectanglePersistent e = new FRectanglePersistent();
            FRectangle rect = (FRectangle) value;
            e.setX(rect.getX());
            e.setY(rect.getY());
            e.setWidth(rect.getWidth());
            e.setHeight(rect.getHeight());
            return e;
        }
    };
}
Also used : FRectangle(com.dsoft.pb.types.FRectangle) Persistent(com.ramussoft.common.persistent.Persistent) SimpleAttributeConverter(com.ramussoft.core.attribute.simple.SimpleAttributeConverter)

Example 14 with Persistent

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

the class FontPlugin method getAttributeConverter.

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

        @Override
        protected Object toObject(Persistent persistent) {
            FontPersistent p = (FontPersistent) persistent;
            return new Font(p.getName(), p.getStyle(), p.getSize());
        }

        @Override
        protected Persistent toPersistent(Object value) {
            Font f = (Font) value;
            FontPersistent p = new FontPersistent();
            p.setName(f.getName());
            p.setStyle(f.getStyle());
            p.setSize(f.getSize());
            return p;
        }
    };
}
Also used : Persistent(com.ramussoft.common.persistent.Persistent) Font(java.awt.Font) SimpleAttributeConverter(com.ramussoft.core.attribute.simple.SimpleAttributeConverter)

Example 15 with Persistent

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

the class TransactionStorageCommand method loadPersistent.

static Persistent loadPersistent(JournaledEngine engine, BinaryDataInput input) throws IOException, InstantiationException, IllegalAccessException {
    Class<? extends Persistent> key = engine.getPersistentClassById(input.read());
    PersistentRow row = engine.getPersistentMetadata(key);
    Persistent persistent = key.newInstance();
    int size = input.read();
    for (int i = 0; i < size; i++) {
        int fieldId = input.read();
        PersistentField field = row.getFieldById(fieldId);
        String fieldName = field.getName();
        PersistentWrapper wrapper = engine.getWrapper(key);
        if (input.read() == 1)
            switch(field.getType()) {
                case ATTRIBUTE:
                case ELEMENT:
                case QUALIFIER:
                case ID:
                case LONG:
                    wrapper.setField(persistent, fieldName, input.readLong());
                    break;
                case TEXT:
                    wrapper.setField(persistent, fieldName, input.readSwimedString());
                    break;
                case DATE:
                    wrapper.setField(persistent, fieldName, new Timestamp(input.readLong()));
                    break;
                case DOUBLE:
                    wrapper.setField(persistent, fieldName, input.readDouble());
                    break;
                case BINARY:
                    wrapper.setField(persistent, fieldName, input.readBinary());
                    break;
                case INTEGER:
                    wrapper.setField(persistent, fieldName, input.readInt());
                    break;
                default:
                    throw new RuntimeException("Unknown field type: " + field.getType());
            }
    }
    persistent.setValueBranchId(input.readLong());
    return persistent;
}
Also used : PersistentField(com.ramussoft.common.persistent.PersistentField) PersistentRow(com.ramussoft.common.persistent.PersistentRow) Persistent(com.ramussoft.common.persistent.Persistent) PersistentWrapper(com.ramussoft.common.persistent.PersistentWrapper) Timestamp(java.sql.Timestamp)

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