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