use of com.ramussoft.jdbc.ExecutionCallback in project ramus by Vitaliy-Yakovchuk.
the class AnyToAnyPlugin method replaceElements.
@SuppressWarnings("unchecked")
@Override
public void replaceElements(Engine engine, Element[] oldElements, Element newElement) {
if (engine.getDeligate() instanceof IEngineImpl) {
IEngineImpl engineImpl = (IEngineImpl) engine.getDeligate();
JDBCTemplate template = engineImpl.getTemplate();
String prefix = engineImpl.getPrefix();
long[] elementIds = new long[oldElements.length];
for (int i = 0; i < oldElements.length; i++) {
elementIds[i] = oldElements[i].getId();
}
String sql = "SELECT element_id FROM " + prefix + "attribute_any_to_any_elements WHERE other_element IN(" + JDBCTemplate.toSqlArray(elementIds) + ")";
if (!(Boolean) template.query(sql, new ExecutionCallback() {
@Override
public Object execute(PreparedStatement statement) throws SQLException {
ResultSet rs = statement.executeQuery();
boolean has = rs.next();
rs.close();
return has;
}
}, false))
return;
}
Qualifier qualifier = IDEF0Plugin.getBaseStreamQualifier(engine);
Attribute added = IDEF0Plugin.getStreamAddedAttribute(engine);
List<Attribute> attributes = new ArrayList<Attribute>(1);
attributes.add(added);
Hashtable<Element, Object[]> res = engine.getElements(qualifier, attributes);
Enumeration<Element> keys = res.keys();
while (keys.hasMoreElements()) {
Element key = keys.nextElement();
Object[] value = res.get(key);
updateElements(engine, key, (List<AnyToAnyPersistent>) value[0], oldElements, newElement, added);
}
}
Aggregations