use of com.ramussoft.common.AccessRules 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.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class FileNavigator method tryLoadFile.
private void tryLoadFile() {
File file = new File(fileName);
if (file.lastModified() > lastModified) {
closeModel();
try {
tmpFile = File.createTempFile("navigator-file-copy", null);
FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(tmpFile);
copyStream(fis, fos);
fis.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
MemoryDatabase database = new MemoryDatabase() {
@Override
protected File getFile() {
return tmpFile;
}
};
Engine engine = database.getEngine(null);
AccessRules rules = database.getAccessRules(null);
dataPlugin = NDataPluginFactory.getDataPlugin(null, engine, rules);
lastModified = file.lastModified();
}
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class Runner method recoverySession.
public boolean recoverySession(final String sessionPath, final File sourceFile) {
Window rFrame = new Window(null);
String recovering = GlobalResourcesManager.getString("File.Recovering");
rFrame.add(new Label(MessageFormat.format(recovering, ((sourceFile == null) ? GlobalResourcesManager.getString("Session.NoName") : sourceFile.getName()))));
rFrame.pack();
rFrame.setLocationRelativeTo(null);
rFrame.setVisible(true);
final String s = sessionPath + File.separator + "source.rms";
MemoryDatabase database = new MemoryDatabase() {
@Override
protected Collection<? extends PluginProvider> getAdditionalSuits() {
ArrayList<PluginProvider> ps = new ArrayList<PluginProvider>(1);
initAdditionalPluginSuits(ps);
return ps;
}
@Override
protected File getFile() {
File file = new File(s);
if (file.exists())
return file;
return null;
}
protected FileIEngineImpl createFileIEngine(PluginFactory factory) throws ClassNotFoundException, ZipException, IOException {
return new FileIEngineImpl(0, template, factory, sessionPath);
}
};
final Engine engine = database.getEngine(null);
DirectoryJournalFactory factory = database.getJournalFactory();
Journal[] journals = factory.loadJournals(database.getJournaledEngine());
if (journals.length == 0)
return false;
boolean exist = false;
Journal.RedoCallback redoCallback = new Journal.RedoCallback() {
boolean hadStartUserTransaction;
@Override
public boolean execute(Command command) {
if (command instanceof StartUserTransactionCommand) {
hadStartUserTransaction = true;
}
return hadStartUserTransaction;
}
};
for (Journal journal : journals) {
try {
Command command = null;
while (journal.canRedo()) {
command = journal.redo(redoCallback);
}
if ((journal.getPointer() == 0l) || (command instanceof StopUndoPointCommand)) {
rFrame.setVisible(false);
continue;
} else
exist = true;
if (!(command instanceof EndUserTransactionCommand))
throw new Exception();
} catch (Exception e) {
e.printStackTrace();
while (journal.canUndo()) {
if (journal.undo() instanceof StartUserTransactionCommand)
break;
}
}
}
if (!exist) {
try {
((FileIEngineImpl) engine.getDeligate()).close();
for (Journal journal : journals) journal.close();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
((FileIEngineImpl) engine.getDeligate()).recoveryStreams();
engine.setPluginProperty(CORE, "Changed", Boolean.TRUE);
engine.setActiveBranch(-1l);
final AccessRules accessor = database.getAccessRules(null);
rFrame.setVisible(false);
Runnable runnable = new Runnable() {
@Override
public void run() {
SplashScreen screen = new SplashScreen() {
/**
*/
private static final long serialVersionUID = -2727237354089088151L;
@Override
protected String getImageName() {
return Runner.this.getSplashImageName();
}
};
screen.setLocationRelativeTo(null);
screen.setVisible(true);
final JFrame frame = openInNewWindows(engine, accessor, sourceFile, true);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
String recovered = GlobalResourcesManager.getString("File.Recovered");
frame.setTitle(frame.getTitle() + " " + recovered);
}
});
screen.setVisible(false);
}
};
recoveredCount++;
Thread thread = new Thread(runnable);
thread.start();
return true;
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class Runner method openFile.
private void openFile(File file) {
saveFileToHistory(file);
MemoryDatabase database = createDatabase(file);
Engine engine = database.getEngine(null);
AccessRules accessor = database.getAccessRules(null);
openInNewWindows(engine, accessor, file, false);
}
use of com.ramussoft.common.AccessRules in project ramus by Vitaliy-Yakovchuk.
the class TableChartAttributePlugin method getAttributePreferenciesEditor.
@Override
public AttributePreferenciesEditor getAttributePreferenciesEditor() {
return new AttributePreferenciesEditor() {
private RowTreeTableComponent component;
@Override
public JComponent createComponent(Attribute attribute, Engine engine, AccessRules accessRules) {
component = new RowTreeTableComponent(engine, ChartPlugin.getCharts(engine), accessRules, new RowRootCreater(), new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine) }, framework);
component.setSelectType(SelectType.RADIO);
return component;
}
@Override
public boolean canApply() {
return component.getModel().getSelectedRows().size() > 0;
}
@Override
public void apply(Attribute attribute, Engine engine, AccessRules accessRules) {
Row row = component.getModel().getSelectedRows().get(0);
TableChartPersistent tcp = new TableChartPersistent();
tcp.setOtherElementId(row.getElementId());
engine.setAttribute(null, attribute, tcp);
}
};
}
Aggregations