Search in sources :

Example 6 with Transaction

use of com.ramussoft.common.persistent.Transaction 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 Transaction

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

the class JournaledEngine method deleteElement.

@Override
public void deleteElement(long id) {
    qualifirsForElements.remove(id);
    Element element = getElement(id);
    long qualifierId = getQualifierIdForElement(id);
    Transaction[] data = getAttributeWhatWillBeDeleted(id);
    ElementEvent event = new ElementEvent(this, element, null, qualifierId);
    try {
        beforeElementDeleted(event);
    } catch (Exception e) {
        e.printStackTrace();
    }
    deligate.deleteElement(id);
    synchronized (swithJournalLock) {
        journal.store(new DeleteElementCommand(this, qualifierId, id, data));
    }
    elementDeleted(event);
}
Also used : DeleteElementCommand(com.ramussoft.common.journal.command.DeleteElementCommand) Transaction(com.ramussoft.common.persistent.Transaction) Element(com.ramussoft.common.Element) ElementEvent(com.ramussoft.common.event.ElementEvent)

Example 8 with Transaction

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

the class SetElementQualifierCommand method readBody.

@Override
public void readBody(BinaryDataInput input) throws IOException {
    oldQualifierId = input.readLong();
    newQualifierId = input.readLong();
    elementId = input.readLong();
    int size = input.readInt();
    data = new Transaction[size];
    for (int i = 0; i < size; i++) {
        Transaction transaction = new Transaction();
        data[i] = transaction;
        int size2 = input.readInt();
        for (int j = 0; j < size2; j++) {
            try {
                transaction.getSave().add(TransactionStorageCommand.loadPersistent(engine, input));
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : Transaction(com.ramussoft.common.persistent.Transaction)

Example 9 with Transaction

use of com.ramussoft.common.persistent.Transaction 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)

Example 10 with Transaction

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

the class TransactionStorageCommand method redo.

@Override
public void redo(IEngine iEngine) {
    Transaction transaction = new Transaction();
    copy(delete, transaction.getDelete());
    copy(save, transaction.getSave());
    copy(updateNew, transaction.getUpdate());
    setAttribute(transaction, iEngine);
}
Also used : Transaction(com.ramussoft.common.persistent.Transaction)

Aggregations

Transaction (com.ramussoft.common.persistent.Transaction)21 Attribute (com.ramussoft.common.Attribute)9 Persistent (com.ramussoft.common.persistent.Persistent)6 ArrayList (java.util.ArrayList)6 Element (com.ramussoft.common.Element)5 FindObject (com.ramussoft.common.attribute.FindObject)5 SQLException (java.sql.SQLException)5 JDBCCallback (com.ramussoft.jdbc.JDBCCallback)4 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 Qualifier (com.ramussoft.common.Qualifier)3 Hashtable (java.util.Hashtable)3 ElementEvent (com.ramussoft.common.event.ElementEvent)2 PersistentField (com.ramussoft.common.persistent.PersistentField)2 PersistentRow (com.ramussoft.common.persistent.PersistentRow)2 PersistentWrapper (com.ramussoft.common.persistent.PersistentWrapper)2 List (java.util.List)2 Engine (com.ramussoft.common.Engine)1 IEngine (com.ramussoft.common.IEngine)1 AbstractAttributeConverter (com.ramussoft.common.attribute.AbstractAttributeConverter)1