use of com.ramussoft.core.impl.IEngineImpl in project ramus by Vitaliy-Yakovchuk.
the class AnyToAnyPlugin method getElementsDeleteStatus.
@SuppressWarnings("unchecked")
@Override
public DeleteStatus getElementsDeleteStatus(long[] elementIds, final IEngine engine) {
final HashMap<Long, Attribute> attributesCache = new HashMap<Long, Attribute>();
final HashMap<Long, Qualifier> qualifiersCache = new HashMap<Long, Qualifier>();
JDBCTemplate template = ((IEngineImpl) engine).getTemplate();
String prefix = ((IEngineImpl) engine).getPrefix();
StringBuffer sb = JDBCTemplate.toSqlArray(elementIds);
String sql = "SELECT element_id FROM " + prefix + "attribute_any_to_any_elements WHERE other_element in(" + sb.toString() + ")";
String gSQL;
final List<String> functions = new ArrayList<String>();
gSQL = "SELECT * FROM {0}elements WHERE element_id IN(" + "SELECT other_element FROM {0}attribute_other_elements WHERE element_id in(" + "SELECT element_id FROM {0}attribute_other_elements WHERE other_element in(" + sql + ")) " + "AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true)) ORDER BY element_name";
template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
if (elementName.trim().length() > 0 && !functions.contains(elementName))
functions.add(elementName);
return null;
}
}, new Object[] { IDEF0Plugin.F_SECTOR_FUNCTION }, true);
gSQL = "SELECT * FROM {0}elements WHERE element_id IN(" + "SELECT other_element FROM {0}attribute_other_elements WHERE element_id in(" + "SELECT element_id FROM {0}attribute_other_elements WHERE other_element in(" + sb + ")) " + "AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true)) ORDER BY element_name";
template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
if (elementName.trim().length() > 0 && !functions.contains(elementName))
functions.add(elementName);
return null;
}
}, new Object[] { IDEF0Plugin.F_SECTOR_FUNCTION }, true);
gSQL = "SELECT * FROM {0}elements WHERE element_id IN(SELECT parent_element_id FROM {0}attribute_hierarchicals WHERE element_id IN(" + "SELECT element_id FROM {0}attribute_longs WHERE value in(" + sql + ")AND attribute_id IN (SELECT attribute_id FROM {0}attributes WHERE attribute_name=? AND attribute_system=true) " + ")) ORDER BY element_name";
template.query(MessageFormat.format(gSQL, prefix), new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
String elementName = getElementName(engine, attributesCache, qualifiersCache, rs);
if (elementName.trim().length() > 0 && !functions.contains(elementName))
functions.add(elementName);
return null;
}
}, new Object[] { IDEF0Plugin.F_LINK }, true);
if (functions.size() > 0) {
Collections.sort(functions, new Comparator<String>() {
@Override
public int compare(String arg0, String arg1) {
return StringCollator.compare(arg0, arg1);
}
});
DeleteStatus deleteStatus = new DeleteStatus();
deleteStatus.setPluginName(getName());
StringBuffer buffer = new StringBuffer();
for (String s : functions) if (!s.trim().equals("")) {
buffer.append("<br>");
buffer.append(s);
}
deleteStatus.setPluginAnswer("{Warning.ElementsUsedAtFunctions}" + buffer.toString());
return deleteStatus;
}
return null;
}
use of com.ramussoft.core.impl.IEngineImpl in project ramus by Vitaliy-Yakovchuk.
the class HTTPParser method getReportHTMLText.
protected Source getReportHTMLText(Engine engine, Element report, Query query) {
String page = null;
try {
HashMap<String, Object> map = new HashMap<String, Object>();
ReportQuery impl;
if (dataPlugin.getEngine().getDeligate() instanceof IEngineImpl)
impl = new ReportQueryImpl(engine) {
@Override
protected Out createOut(OutputStream stream) {
try {
return new Out(stream) {
@Override
public void print(Object object) {
if (!printVersion) {
if (object instanceof Qualifier) {
Engine engine = dataPlugin.getEngine();
Element element = StandardAttributesPlugin.getElement(engine, ((Qualifier) object).getId());
if (element == null) {
print(object.toString());
} else {
String href = "rows/index.html?id=" + element.getId();
print(getStartATeg(href, false, true));
print(object.toString());
print(getEndATeg());
}
} else if (object instanceof Code) {
String href = "rows/index.html?id=" + ((Code) object).getElement().getId();
print(getStartATeg(href, false, true));
print(object.toString());
print(getEndATeg());
} else if (object instanceof com.ramussoft.database.common.Row) {
String href = "rows/index.html?id=" + ((com.ramussoft.database.common.Row) object).getElementId();
print(getStartATeg(href, false, true));
print(object.toString());
print(getEndATeg());
} else
super.print(object);
} else
super.print(object);
}
};
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
};
else
impl = (ReportQuery) dataPlugin.getEngine();
if (query != null)
map.put("query", query);
page = impl.getHTMLReport(report, map);
} catch (Exception e1) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
java.io.PrintStream s = null;
try {
s = new java.io.PrintStream(stream, true, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (e1 instanceof DataException)
s.println(((DataException) e1).getMessage(new MessageFormatter() {
@Override
public String getString(String key, Object[] arguments) {
return MessageFormat.format(ReportResourceManager.getString(key), arguments);
}
}));
else {
s.println("<pre>");
e1.printStackTrace(s);
s.println("</pre>");
}
s.flush();
try {
page = new String(stream.toByteArray(), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
htmlStream.println(page);
return null;
}
if (!printVersion) {
htmlStream.println("<H4>" + report.getName() + "</H4>");
}
Source source = new Source(page);
source.fullSequentialParse();
htmlStream.println(source);
return source;
}
use of com.ramussoft.core.impl.IEngineImpl in project ramus by Vitaliy-Yakovchuk.
the class InternetServer method run.
private void run(String[] args) throws IOException {
new File(tmpPath).mkdirs();
engineFactory = new EngineFactory() {
};
final ServerSocket ss = new ServerSocket();
ss.bind(new InetSocketAddress("0.0.0.0", Metadata.INTERNET_PORT));
userFactory = new UserFactoryImpl(engineFactory.getTemplate());
serverAccessRules = new ServerAccessRules(engineFactory.getEngine(), userFactory) {
@Override
protected String getLogin() {
return logins.get(Thread.currentThread());
}
};
Thread acceptionThread = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Ramus Interner Server ready");
while (true) {
try {
final Thread thread;
final Socket socket = ss.accept();
CheckableUserFactory userFactoryClient = new CheckableUserFactory(userFactory);
IntegrityAccessorSuit suit = new IntegrityAccessorSuit();
suit.addAccessRules(serverAccessRules);
suit.addAccessRules(((IEngineImpl) getEngine().getDeligate()).getAccessor());
final ClientServiceImpl service = new ClientServiceImpl(InternetServer.this, userFactory, userFactoryClient);
SuperInvoker invoker = new SuperInvoker(new Object[] { service, suit, userFactoryClient, service }, new Class[] { ClientService.class, AccessRules.class, UserFactory.class, UserProvider.class });
final TcpServerConnection connection = new TcpServerConnection(socket, new String[] { ClientService.class.getName(), AccessRules.class.getName(), UserFactory.class.getName(), UserProvider.class.getName() }, invoker.createProxy()) {
public void close() throws IOException {
synchronized (servicesLock) {
services.remove(service);
}
service.close();
super.close();
}
};
synchronized (servicesLock) {
services.add(service);
}
thread = new Thread(new Runnable() {
@Override
public void run() {
connection.run();
}
}, "server-client");
service.setConnection(connection);
thread.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}, "inet-server-main");
acceptionThread.start();
}
use of com.ramussoft.core.impl.IEngineImpl in project ramus by Vitaliy-Yakovchuk.
the class InternetClient method load.
private void load(String dump, PluginFactory factory) throws Exception, FileNotFoundException, IOException, ZipException, InvalidPropertiesFormatException {
new // to create all tables
IEngineImpl(// to create all tables
0, // to create all tables
template, // to create all tables
"ramus_", // to create all tables
factory) {
@Override
protected void writeStream(String path, byte[] bytes) {
}
@Override
public byte[] getStream(String path) {
return null;
}
@Override
protected boolean deleteStreamBytes(String path) {
return false;
}
};
template.execute("DELETE FROM {0}persistent_fields", "ramus_");
template.execute("DELETE FROM {0}persistents", "ramus_");
byte[] bs = (byte[]) connection.invoke("loadAllData", new Object[] {});
File file = new File(dump);
FileOutputStream fos = new FileOutputStream(file);
fos.write(bs);
fos.close();
bs = null;
prefix = "ramus_";
zFile = new ZipFile(file);
ZipEntry entry = new ZipEntry(FileIEngineImpl.SEQUENCES);
InputStream is = zFile.getInputStream(entry);
Connection c = template.getConnection();
try {
if (is != null) {
Properties ps = new Properties();
ps.loadFromXML(is);
Statement st = c.createStatement();
Enumeration<Object> keys = ps.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
try {
st.execute("DROP SEQUENCE " + prefix + key + ";");
} catch (SQLException e) {
}
st.execute("CREATE SEQUENCE " + prefix + key + " START " + ps.getProperty(key) + ";");
}
st.close();
is.close();
}
c.commit();
} catch (SQLException e) {
throw new RuntimeException(e);
}
loadTable("", "qualifiers");
loadTable("", "attributes");
loadTable("", "qualifiers_attributes");
loadTable("", "elements");
loadTable("", "persistents");
loadTable("", "persistent_fields");
loadTable("", "application_preferencies");
loadTable("", "streams");
loadTable("", "formulas");
loadTable("", "formula_dependences");
openPersistentTables();
zFile.close();
zFile = null;
}
use of com.ramussoft.core.impl.IEngineImpl in project ramus by Vitaliy-Yakovchuk.
the class DemoChecker method elementCreated.
@Override
public void elementCreated(ElementEvent event) {
IEngineImpl impl = (IEngineImpl) event.getEngine().getDeligate();
String prefix = impl.getPrefix();
long elementCount = getElementCount(impl, prefix);
if (elementCount > 100) {
framework.propertyChanged("DisableSaveActions");
}
if ((elementCount == 101) && (framework.get("FilePlugin") != null)) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(framework.getMainFrame(), MessageFormat.format(GlobalResourcesManager.getString("DemoVersionElementCountLimit"), 100));
}
});
}
}
Aggregations