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);
}
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);
}
}
}
}
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);
}
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);
}
}
}
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;
}
};
}
Aggregations