Search in sources :

Example 6 with IEngine

use of com.ramussoft.common.IEngine 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 7 with IEngine

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

the class Journal method redo.

public Command redo(RedoCallback callback) {
    Command command = null;
    long index = getPointer();
    try {
        command = readNext();
        IEngine engine = command.getEngine().deligate;
        if (callback.execute(command))
            command.redo(engine);
        JournalEvent event = new JournalEvent(this, command, index);
        afterRedo(event);
    } catch (Exception e) {
        try {
            accessFile.seek(index);
        } catch (IOException e1) {
        }
        throw new RuntimeException(e);
    }
    return command;
}
Also used : CreateAttributeCommand(com.ramussoft.common.journal.command.CreateAttributeCommand) UpdateAttributeCommand(com.ramussoft.common.journal.command.UpdateAttributeCommand) DeleteElementCommand(com.ramussoft.common.journal.command.DeleteElementCommand) SetElementQualifierCommand(com.ramussoft.common.journal.command.SetElementQualifierCommand) CreateQualifierCommand(com.ramussoft.common.journal.command.CreateQualifierCommand) DeleteQualifierCommand(com.ramussoft.common.journal.command.DeleteQualifierCommand) TransactionStorageCommand(com.ramussoft.common.journal.command.TransactionStorageCommand) Command(com.ramussoft.common.journal.command.Command) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) DeleteAttributeCommand(com.ramussoft.common.journal.command.DeleteAttributeCommand) FormulaCommand(com.ramussoft.common.journal.command.FormulaCommand) NewBranchCommand(com.ramussoft.common.journal.command.NewBranchCommand) UpdateQualifierCommand(com.ramussoft.common.journal.command.UpdateQualifierCommand) CreateElementCommand(com.ramussoft.common.journal.command.CreateElementCommand) SetStreamCommand(com.ramussoft.common.journal.command.SetStreamCommand) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand) NextCommand(com.ramussoft.common.journal.command.NextCommand) IEngine(com.ramussoft.common.IEngine) JournalEvent(com.ramussoft.common.journal.event.JournalEvent) IOException(java.io.IOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with IEngine

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

the class Journal method undo.

public Command undo() {
    long index = getPointer();
    Command command = null;
    try {
        command = readPrev();
        IEngine engine = command.getEngine().deligate;
        command.undo(engine);
        JournalEvent event = new JournalEvent(this, command, getPointer());
        afterUndo(event);
    } catch (Exception e) {
        try {
            accessFile.seek(index);
        } catch (IOException e1) {
        }
        throw new RuntimeException(e);
    }
    return command;
}
Also used : CreateAttributeCommand(com.ramussoft.common.journal.command.CreateAttributeCommand) UpdateAttributeCommand(com.ramussoft.common.journal.command.UpdateAttributeCommand) DeleteElementCommand(com.ramussoft.common.journal.command.DeleteElementCommand) SetElementQualifierCommand(com.ramussoft.common.journal.command.SetElementQualifierCommand) CreateQualifierCommand(com.ramussoft.common.journal.command.CreateQualifierCommand) DeleteQualifierCommand(com.ramussoft.common.journal.command.DeleteQualifierCommand) TransactionStorageCommand(com.ramussoft.common.journal.command.TransactionStorageCommand) Command(com.ramussoft.common.journal.command.Command) StartUserTransactionCommand(com.ramussoft.common.journal.command.StartUserTransactionCommand) DeleteAttributeCommand(com.ramussoft.common.journal.command.DeleteAttributeCommand) FormulaCommand(com.ramussoft.common.journal.command.FormulaCommand) NewBranchCommand(com.ramussoft.common.journal.command.NewBranchCommand) UpdateQualifierCommand(com.ramussoft.common.journal.command.UpdateQualifierCommand) CreateElementCommand(com.ramussoft.common.journal.command.CreateElementCommand) SetStreamCommand(com.ramussoft.common.journal.command.SetStreamCommand) EndUserTransactionCommand(com.ramussoft.common.journal.command.EndUserTransactionCommand) NextCommand(com.ramussoft.common.journal.command.NextCommand) IEngine(com.ramussoft.common.IEngine) JournalEvent(com.ramussoft.common.journal.event.JournalEvent) IOException(java.io.IOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with IEngine

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

Example 10 with IEngine

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

the class BooleanPlugin method getAttributeConverter.

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

        @SuppressWarnings("unchecked")
        @Override
        public List<Persistent>[] toPersistens(Object object, long elementId, long attributeId, IEngine engine) {
            if (object == null)
                return new List[] { new ArrayList<Persistent>(0) };
            ArrayList<Persistent> l = new ArrayList<Persistent>(1);
            l.add(new BooleanPersistent(((Boolean) object) ? 1 : 0));
            return new List[] { l };
        }

        @SuppressWarnings("unchecked")
        @Override
        public Object toObject(List<Persistent>[] persistents, long elementId, long attributeId, IEngine engine) {
            List l = persistents[0];
            if (l.size() == 0)
                return null;
            BooleanPersistent p = (BooleanPersistent) l.get(0);
            return p.getValue() != 0;
        }
    };
}
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) AbstractAttributeConverter(com.ramussoft.common.attribute.AbstractAttributeConverter)

Aggregations

IEngine (com.ramussoft.common.IEngine)15 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Engine (com.ramussoft.common.Engine)6 Persistent (com.ramussoft.common.persistent.Persistent)6 AbstractAttributeConverter (com.ramussoft.common.attribute.AbstractAttributeConverter)5 IOException (java.io.IOException)4 PluginProvider (com.ramussoft.common.PluginProvider)3 IEngineImpl (com.ramussoft.core.impl.IEngineImpl)3 SQLException (java.sql.SQLException)3 Attribute (com.ramussoft.common.Attribute)2 Element (com.ramussoft.common.Element)2 PluginFactory (com.ramussoft.common.PluginFactory)2 Qualifier (com.ramussoft.common.Qualifier)2 CachedEngine (com.ramussoft.common.cached.CachedEngine)2 Command (com.ramussoft.common.journal.command.Command)2 CreateAttributeCommand (com.ramussoft.common.journal.command.CreateAttributeCommand)2 CreateElementCommand (com.ramussoft.common.journal.command.CreateElementCommand)2 CreateQualifierCommand (com.ramussoft.common.journal.command.CreateQualifierCommand)2 DeleteAttributeCommand (com.ramussoft.common.journal.command.DeleteAttributeCommand)2