use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class BaseImporter method main.
/**
* @param args
*/
public static void main(final String[] args) {
if (args.length == 0) {
System.err.println("Enter input file as parameter");
return;
}
MemoryDatabase database = new MemoryDatabase() {
@Override
protected Collection<? extends PluginProvider> getAdditionalSuits() {
ArrayList<PluginProvider> ps = new ArrayList<PluginProvider>(1);
ps.add(new IDEF0PluginProvider());
return ps;
}
@Override
protected File getFile() {
return new File(args[0]);
}
@Override
public Connection createConnection() throws SQLException {
return EngineFactory.createNewConnection();
}
@Override
protected String getJournalDirectoryName(String tmp) {
return null;
}
};
EngineFactory factory = new EngineFactory();
Engine s = database.getEngine(null);
IEngine d = factory.getEngine();
for (String streamName : s.getStreamNames()) {
byte[] bs = s.getStream(streamName);
if (bs == null) {
System.err.println("WARNING: stream " + streamName + " not found in the source");
} else
d.setStream(streamName, bs);
}
try {
((FileIEngineImpl) (database.getEngine(null).getDeligate())).close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class ClientServiceImpl method replaceElements.
@Override
public byte[] replaceElements(Element[] oldElements, Element newElement) {
Journal journal;
Engine engine = server.getEngine();
if (engine instanceof JournaledEngine) {
journal = ((JournaledEngine) engine).getJournal();
} else {
journal = ((JournaledEngine) ((CachedEngine) engine).getSource()).getJournal();
}
synchronized (server) {
try {
journal.startUserTransaction();
server.getEngine().replaceElements(oldElements, newElement);
journal.commitUserTransaction();
byte[] remove = server.getCalls().remove(Thread.currentThread());
journal.undoUserTransaction();
return remove;
} catch (Exception e) {
server.getCalls().remove(Thread.currentThread());
journal.rollbackUserTransaction();
throw new RuntimeException(e);
}
}
}
use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class StartCommand method main.
/**
* @param args
*/
public static void main(String[] args) {
try {
System.setProperty("catalina.base", args[0]);
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
Properties ps = EngineFactory.getPropeties();
String command = args[1];
String fileName = (String) ps.get(command);
EngineFactory engineFactory = new EngineFactory();
engineFactory.createJournaledEngine(new DirectoryJournalFactory(null));
final Engine engine1 = (Engine) SuperEngineFactory.createTransactionalEngine(engineFactory.journaledEngine, ((JournaledEngine) ((CachedEngine) engineFactory.journaledEngine).getSource()).getJournal());
engine.getContext().setAttribute("engine", engine1, ScriptContext.ENGINE_SCOPE);
engine.eval(new InputStreamReader(new FileInputStream(fileName), "UTF-8"));
System.exit(0);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ScriptException e) {
e.printStackTrace();
}
System.exit(1);
}
use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class InternetServer method loadAllData.
public byte[] loadAllData() {
synchronized (saveLock) {
MemoryDatabase database = new MemoryDatabase() {
@Override
protected void loadSuits(List<PluginProvider> suits) {
suits.addAll(engineFactory.getSuits());
}
@Override
protected File getFile() {
return null;
}
@Override
public Connection createConnection() throws SQLException {
return engineFactory.createConnection();
}
@Override
protected String getJournalDirectoryName(String tmp) {
return null;
}
@Override
protected FileIEngineImpl createFileIEngine(PluginFactory factory) throws ClassNotFoundException, ZipException, IOException {
return new FileIEngineImpl(0, template, factory, null);
}
};
Engine s = database.getEngine(null);
FileIEngineImpl impl = (FileIEngineImpl) s.getDeligate();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ZipOutputStream out;
try {
out = impl.writeToStream(stream);
out.close();
return stream.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class GroupRootCreater method createChildren.
private Vector<TreeTableNode> createChildren(int i, GroupNode parent) {
List<Row> rows = parent.getRows();
Vector<TreeTableNode> res = new Vector<TreeTableNode>();
if (i >= attrs.length) {
for (Row row : rows) {
if (hierarchy.isShowBaseHierarchy()) {
RowNode rowNode = new RowNode(createRowChildren(row), row);
rowNode.setParent();
res.add(rowNode);
} else {
RowNode rowNode = new RowNode(new Vector<TreeTableNode>(), row);
rowNode.setParent();
res.add(rowNode);
}
}
} else {
if (attrs[i].getAttributeType().toString().equals("Core.ElementList")) {
Hashtable<Long, Element> hash = new Hashtable<Long, Element>();
for (Row row : rows) {
Engine engine = row.getEngine();
long[] ids = ElementListPlugin.getElements(engine, attrs[i], row.getElement());
if (ids.length == 0) {
Object value = null;
GroupNode groupNode = new GroupNode(this, attrs[i], value);
int index;
if ((index = res.indexOf(groupNode)) >= 0) {
((GroupNode) res.get(index)).getRows().add(row);
} else {
groupNode.createRowsList();
groupNode.getRows().add(row);
res.add(groupNode);
}
}
for (long id : ids) {
Object value = getElement(hash, id, engine);
GroupNode groupNode = new GroupNode(this, attrs[i], value);
int index;
if ((index = res.indexOf(groupNode)) >= 0) {
((GroupNode) res.get(index)).getRows().add(row);
} else {
groupNode.createRowsList();
groupNode.getRows().add(row);
res.add(groupNode);
}
}
}
} else
for (Row row : rows) {
Object value = row.getAttribute(attrs[i]);
GroupNode groupNode = new GroupNode(this, attrs[i], value);
int index;
if ((index = res.indexOf(groupNode)) >= 0) {
((GroupNode) res.get(index)).getRows().add(row);
} else {
groupNode.createRowsList();
groupNode.getRows().add(row);
res.add(groupNode);
}
}
Object[] objects = res.toArray();
Arrays.sort(objects);
for (int j = 0; j < objects.length; j++) {
res.set(j, (TreeTableNode) objects[j]);
}
for (TreeTableNode node : res) {
GroupNode groupNode = (GroupNode) node;
Vector<TreeTableNode> children = createChildren(i + 1, groupNode);
groupNode.setChildren(children);
groupNode.setParent();
}
}
return res;
}
Aggregations