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