use of com.ramussoft.common.Element in project ramus by Vitaliy-Yakovchuk.
the class InternetClient method getEngine.
@SuppressWarnings("unused")
@Override
protected Engine getEngine(PluginFactory factory, PersistentFactory pf) {
File tmp = new File(System.getProperty("java.io.tmpdir"), "ramus-" + String.valueOf(System.currentTimeMillis()));
String tmpPath = tmp.getAbsolutePath() + Math.round(Math.random() * 1000);
try {
try {
Class.forName("org.h2.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String url = "jdbc:h2:" + tmpPath + File.separator + "client-cache" + ";";
Connection conn = DriverManager.getConnection(url, "sa", "");
template = MemoryDatabase.createStaticTemplate(conn);
String dump = tmpPath + File.separator + "dump.rsf";
new File(tmpPath).mkdirs();
load(dump, factory);
impl = new FileIEngineImpl(0, template, factory, tmpPath) {
@Override
protected boolean deleteStreamBytes(String path) {
try {
return (Boolean) connection.invoke("deleteStream", new Object[] { path });
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public byte[] getStream(String path) {
try {
return (byte[]) connection.invoke("getStream", new Object[] { path });
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
protected void writeStream(String path, byte[] bytes) {
try {
connection.invoke("setStream", new Object[] { path, bytes });
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public long nextValue(String sequence) {
try {
return (Long) connection.invoke("nextValue", new Object[] { sequence });
} catch (Exception e) {
return super.nextValue(sequence);
}
}
};
AccessRules accessor = impl.getAccessor();
String jName = getJournalFileName(impl.getTmpPath() + File.separator);
BinaryAccessFile accessFile = null;
if (jName != null) {
accessFile = new BinaryAccessFile(jName, "rw");
}
final InternetHookJournal journal = new InternetHookJournal(accessFile) {
@Override
public void onUndo(byte[] bs) {
try {
connection.invoke("undo", new Object[] { bs });
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onRedo(byte[] bs) {
try {
connection.invoke("redo", new Object[] { bs });
} catch (Exception e) {
e.printStackTrace();
}
}
};
if (true)
throw new RuntimeException("Not implementated");
InternetEngine internetEngine = new InternetEngine(factory, impl, impl.getPersistentFactory().getRows(), null, accessor) {
@Override
public void replaceElements(Element[] oldElements, Element newElement) {
try {
byte[] bs = (byte[]) connection.invoke("replaceElements", new Object[] { oldElements, newElement });
journal.serverCopy(bs, this);
} catch (Exception e) {
e.printStackTrace();
}
}
};
BinaryAccessFile binaryAccessFile = new BinaryAccessFile(new File(impl.getTmpPath() + File.separator + "hook.tmp"), "rw");
syncJournal = new InternetSyncJournal(binaryAccessFile);
syncJournal.registerEngine(internetEngine);
Engine engine = internetEngine;
if (accessFile != null)
journal.setEnable(true);
engine = (Engine) SuperEngineFactory.createTransactionalEngine(engine, journal);
engine.setPluginProperty("Core", "PluginList", factory.getPlugins());
engine.setPluginProperty("Core", "PluginFactory", factory);
synchronized (startLock) {
for (Object object : runCallbacks) asyncCall(object);
runCallbacks = null;
}
return engine;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.ramussoft.common.Element in project ramus by Vitaliy-Yakovchuk.
the class CachedEngine method loadQualifier.
private CachedQualifier loadQualifier(Long id) {
CachedQualifier q = new CachedQualifier();
q.qualifier = deligate.getQualifier(id);
if (q.qualifier == null)
return null;
List<Attribute> attributes = q.buildAttributes();
q.setAllAttributes(attributes.toArray(new Attribute[attributes.size()]));
Hashtable<Element, Object[]> hashtable = deligate.getElements(q.qualifier, attributes);
List<CachedElement> elements = q.elements;
for (Entry<Element, Object[]> entry : hashtable.entrySet()) {
Element key = entry.getKey();
CachedElement e = new CachedElement(key, entry.getValue(), q);
elements.add(e);
this.elements.put(key.getId(), e);
}
return q;
}
use of com.ramussoft.common.Element in project ramus by Vitaliy-Yakovchuk.
the class EvalQualifierSetupEditor method save.
@Override
public void save(Engine engine, Qualifier qualifier) {
final String e = GlobalResourcesManager.getString("Eval.Element");
Element element = StandardAttributesPlugin.getElement(engine, qualifier.getId());
List<FunctionPersistent> list = new ArrayList<FunctionPersistent>();
Util utils = Util.getUtils(engine);
for (FunctionPersistent fp : functions) if (fp != null) {
String function = fp.getFunction();
Eval eval = new Eval(function);
eval.replaceValueNames(new Replacementable() {
@Override
public String getNewName(String oldName) {
if (e.equals(oldName))
return "ELEMENT";
return oldName;
}
});
fp.setFunction(utils.compile(qualifier, eval.toString()));
list.add(fp);
}
EvalPlugin.setFunctionAttribute(engine, element, list);
}
use of com.ramussoft.common.Element in project ramus by Vitaliy-Yakovchuk.
the class QualifierPreferencesPanel method updateAttributesInOrder.
@SuppressWarnings("unchecked")
private void updateAttributesInOrder(List<Attribute> qAttributes) {
Attribute attributeId = (Attribute) engine.getPluginProperty("Core", StandardAttributesPlugin.ATTRIBUTE_ID);
List<ElementListPersistent> list = (List<ElementListPersistent>) attributeEditor.getValue();
List<Attribute> attributes = new ArrayList<Attribute>(list.size());
for (ElementListPersistent pr : list) {
Element element2 = engine.getElement(pr.getElement2Id());
Long id2 = (Long) engine.getAttribute(element2, attributeId);
Attribute attribute = engine.getAttribute(id2);
attributes.add(attribute);
if (qAttributes.indexOf(attribute) < 0)
qAttributes.add(attribute);
}
List<Attribute> rem = new ArrayList<Attribute>();
for (Attribute a : qAttributes) if (attributes.indexOf(a) < 0)
rem.add(a);
for (Attribute r : rem) qAttributes.remove(r);
}
use of com.ramussoft.common.Element in project ramus by Vitaliy-Yakovchuk.
the class QualifierView method moveElements.
private void moveElements(Row row, long parentElementId, long prevParentId, Qualifier dest) {
long qualifierId = StandardAttributesPlugin.getQualifierId(engine, row.getElement());
framework.propertyChanged("CloseQualifier", qualifierId);
Attribute hAttribute = StandardAttributesPlugin.getHierarchicalAttribute(engine);
List<Element> elements = engine.getElements(qualifierId);
for (Element element : elements) {
engine.setElementQualifier(element.getId(), dest.getId());
element.setQualifierId(dest.getId());
HierarchicalPersistent hp = (HierarchicalPersistent) engine.getAttribute(element, hAttribute);
if ((hp != null) && (hp.getParentElementId() == -1l)) {
hp.setParentElementId(row.getElementId());
engine.setAttribute(element, hAttribute, hp);
}
}
long prevId = -1l;
for (Row row2 : toArray(row.getChildren())) {
moveElements(row2, row.getElementId(), prevId, dest);
prevId = row2.getId();
}
String name = row.getName();
engine.setElementQualifier(row.getElementId(), dest.getId());
HierarchicalPersistent hp = new HierarchicalPersistent();
hp.setPreviousElementId(prevParentId);
hp.setParentElementId(parentElementId);
engine.setAttribute(row.getElement(), hAttribute, hp);
Attribute nameAttribute = engine.getAttribute(dest.getAttributeForName());
if (nameAttribute != null)
engine.setAttribute(row.getElement(), nameAttribute, name);
}
Aggregations