use of com.ramussoft.database.MemoryDatabase in project ramus by Vitaliy-Yakovchuk.
the class BaseExporter method export.
/**
* @param args
* @throws IOException
*/
public void export(final File file) throws IOException {
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 null;
}
@Override
public Connection createConnection() throws SQLException {
return EngineFactory.createNewConnection();
}
@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();
EngineFactory factory = new EngineFactory();
IEngine d = factory.getEngine();
ZipOutputStream out = impl.saveToFileNotCloseFile(file);
for (String streamName : d.getStreamNames()) {
byte[] bs = d.getStream(streamName);
if (bs == null) {
} else {
if (streamName.startsWith("/"))
streamName = streamName.substring(1);
out.putNextEntry(new ZipEntry(streamName));
out.write(bs);
}
}
out.close();
try {
factory.getTemplate().getConnection().close();
impl.getConnection().close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.ramussoft.database.MemoryDatabase 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.database.MemoryDatabase 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.database.MemoryDatabase in project ramus by Vitaliy-Yakovchuk.
the class Runner method createDatabase.
public MemoryDatabase createDatabase(final File file) {
MemoryDatabase database = new MemoryDatabase(true) {
@Override
protected Collection<? extends PluginProvider> getAdditionalSuits() {
ArrayList<PluginProvider> ps = new ArrayList<PluginProvider>(1);
initAdditionalPluginSuits(ps);
return ps;
}
@Override
protected File getFile() {
return file;
}
};
return database;
}
use of com.ramussoft.database.MemoryDatabase 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);
}
Aggregations