use of com.ramussoft.common.Engine 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.Engine in project ramus by Vitaliy-Yakovchuk.
the class ElementEventTableModel method getValueAt.
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Event event = getEvent(rowIndex);
switch(columnIndex) {
case 0:
return getType(event);
case 1:
Long id = (Long) event.getAttribute("attribute_id");
if (id == null)
return null;
Engine engine = getEngine();
Attribute attribute = engine.getAttribute(id);
if (attribute == null)
return null;
return attribute.getName();
case 2:
return event.getOldValue();
case 3:
return event.getNewValue();
case 4:
return event.eventTime;
case 5:
return getUser(event);
default:
break;
}
return null;
}
use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class ElistTableTabView method createComponent.
@Override
public JComponent createComponent() {
pane = new JScrollPane();
left = new ElistTablePanel(framework, q1);
top = new ElistTablePanel(framework, q2);
this.model = createModel();
this.table = new ElistTable() {
/**
*/
private static final long serialVersionUID = 5056893447852539087L;
@Override
protected Engine getEngine() {
return framework.getEngine();
}
@Override
protected Attribute getAttribute() {
return attribute;
}
};
this.table.setModel(model);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tableHeader = new TopTablePanel(top, table);
table.setTableHeader(tableHeader);
table.setRowHeight(CELL_BORDER);
table.setColumnSelectionAllowed(true);
TableColumnModel columnModel = table.getColumnModel();
for (int i = 0; i < columnModel.getColumnCount(); i++) {
TableColumn column = columnModel.getColumn(i);
column.setMaxWidth(CELL_BORDER);
column.setMinWidth(CELL_BORDER);
}
table.getColumnModel().addColumnModelListener(new TableColumnModelListener() {
@Override
public void columnAdded(TableColumnModelEvent e) {
}
@Override
public void columnMarginChanged(ChangeEvent e) {
}
@Override
public void columnMoved(TableColumnModelEvent e) {
}
@Override
public void columnRemoved(TableColumnModelEvent e) {
}
@Override
public void columnSelectionChanged(ListSelectionEvent e) {
int column = table.getSelectedColumn();
if (column >= 0) {
top.setSelectionRow(column);
tableHeader.repaint();
}
}
});
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
int row = table.getSelectedRow();
if (row >= 0) {
left.setSelectionRow(row);
}
}
});
pane.setViewportView(table);
pane.setRowHeaderView(left);
updateHeadders();
pane.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
updateHeadders();
}
});
return pane;
}
use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class ElistTable method updateShowBoolean.
private void updateShowBoolean() {
Engine engine = getEngine();
ElementListPropertyPersistent pp = (ElementListPropertyPersistent) engine.getAttribute(null, getAttribute());
String connectionTypes = pp.getConnectionTypes();
showBoolean = connectionTypes == null || connectionTypes.trim().length() == 0;
cached = getAttribute();
}
use of com.ramussoft.common.Engine in project ramus by Vitaliy-Yakovchuk.
the class RowTreeTableModel method setValueAt.
@Override
public void setValueAt(Object value, Object node, int column) {
if (!saveValues[column])
return;
TreeTableNode row = (TreeTableNode) node;
if (row.getRow() == null)
return;
Attribute a = row.getRow().getRowAttributes()[column + 1];
Engine engine = row.getRow().getRowSet().getEngine();
Qualifier q = engine.getQualifier(row.getRow().getElement().getQualifierId());
if ((q.getAttributeForName() == a.getId()) && (value instanceof String)) {
List<Element> list = engine.findElements(q.getId(), a, value);
for (Element element : list) {
if (element.getId() != row.getRow().getElementId()) {
if (JOptionPane.showConfirmDialog(table, GlobalResourcesManager.getString("Warning.ElementsExists"), GlobalResourcesManager.getString("ConfirmMessage.Title"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
return;
break;
}
}
}
row.getRow().startUserTransaction();
row.getRow().setAttribute(column, value);
row.getRow().endUserTransaction();
}
Aggregations