use of com.ramussoft.common.journal.JournaledEngine in project ramus by Vitaliy-Yakovchuk.
the class MemoryDatabase method createJournaledEngine.
private JournaledEngine createJournaledEngine(PluginFactory factory, PersistentFactory persistentFactory) throws ClassNotFoundException {
if (cached) {
JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor) {
@Override
protected void initPlugins(PluginFactory pluginFactory, AccessRules accessor) {
}
};
CachedEngine cachedEngine = new CachedEngine(journaledEngine2);
for (Plugin plugin : factory.getPlugins()) plugin.init(cachedEngine, accessor);
this.engine = cachedEngine;
return journaledEngine2;
} else {
JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor);
this.engine = journaledEngine2;
return journaledEngine2;
}
}
use of com.ramussoft.common.journal.JournaledEngine in project ramus by Vitaliy-Yakovchuk.
the class LightClient method getEngine.
@Override
protected Engine getEngine(PluginFactory factory, PersistentFactory persistentFactory) {
try {
Journal journal = new Journal(null, -1l);
journal.setEnable(false);
final JournaledEngine journaledEngine = new JournaledEngine(factory, impl, persistentFactory.getRows(), new DirectoryJournalFactory(null), accessor);
Engine engine = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Engine.class, Journaled.class }, new InvocationHandler() {
private Journaled journaled = new Journaled() {
boolean started = false;
@Override
public void undoUserTransaction() {
}
@Override
public void startUserTransaction() {
started = true;
}
@Override
public void setNoUndoPoint() {
}
@Override
public void setEnable(boolean b) {
}
@Override
public void rollbackUserTransaction() {
started = false;
}
@Override
public void removeJournalListener(JournalListener listener) {
}
@Override
public void redoUserTransaction() {
}
@Override
public boolean isUserTransactionStarted() {
return started;
}
@Override
public boolean isEnable() {
return false;
}
@Override
public JournalListener[] getJournalListeners() {
return new JournalListener[] {};
}
@Override
public void commitUserTransaction() {
started = false;
}
@Override
public void close() {
}
@Override
public boolean canUndo() {
return false;
}
@Override
public boolean canRedo() {
return false;
}
@Override
public void addJournalListener(JournalListener listener) {
}
@Override
public long getBranch() {
return -1l;
}
};
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getDeclaringClass().equals(Journaled.class))
return method.invoke(journaled, args);
return method.invoke(journaledEngine, args);
}
});
return engine;
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of com.ramussoft.common.journal.JournaledEngine in project ramus by Vitaliy-Yakovchuk.
the class EngineFactory method createJournaledEngine.
public Engine createJournaledEngine(DirectoryJournalFactory journalFactory) {
try {
JDBCTemplate template = new JDBCTemplate(createNewConnectionA());
suits = new ArrayList<PluginProvider>();
suits.add(new SimpleAttributePluginSuit());
suits.add(new IDEF0PluginProvider());
Properties ps = getPropeties();
if (ps != null) {
String suitNames = ps.getProperty("AdditionalSuits");
if (suitNames != null)
PluginFactory.loadAdditionalSuits(suitNames, suits);
canUndoRedo = !"false".equals(ps.getProperty("CanUndoRedo"));
}
suits.addAll(getAdditionalSuits());
createUniversalPersistentFactory(template, (ps == null) ? null : ps.getProperty("PersistentPluginsProvider"));
factory = createPluginFactory(suits);
String prefix = "ramus_";
impl = new ServerIEngineImpl(0, template, prefix, factory);
accessor = impl.getAccessor();
persistentFactory = new PersistentFactory(prefix, factory.getAttributePlugins(), template);
persistentFactory.rebuild();
checkIfGroupsExists();
Engine result;
Journaled journaled;
if (cachedData == null) {
JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor);
result = journaledEngine2;
journaled = journaledEngine2.getJournal();
} else {
JournaledEngine engine = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor) {
@Override
protected void initPlugins(PluginFactory pluginFactory, AccessRules accessor) {
}
};
journaled = engine.getJournal();
CachedEngine cachedEngine = new CachedEngine(engine, cachedData);
for (Plugin plugin : factory.getPlugins()) plugin.init(cachedEngine, accessor);
result = cachedEngine;
}
EngineLogExtension engineLogExtension = new EngineLogExtension(result, journaled);
log = new Log(result, journaled) {
protected Event createEvent(String type, UpdateEventCallback callback) {
String user = "admin";
if (impl.getServerAccessRules() != null)
user = impl.getServerAccessRules().getUser().getLogin();
long id = impl.nextValue("qualifiers_log_seq");
return callback.createEvent(this, id, new Timestamp(System.currentTimeMillis()), type, user, null);
}
};
log.addExtension(engineLogExtension);
log.addExtension(new StorageLogExtension(new JDBCTemplate(createNewConnection()), prefix));
return result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.ramussoft.common.journal.JournaledEngine 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.journal.JournaledEngine 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);
}
Aggregations