Search in sources :

Example 1 with ExecutionCallback

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);
    }
}
Also used : SQLException(java.sql.SQLException) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) ResultSet(java.sql.ResultSet) Qualifier(com.ramussoft.common.Qualifier) ExecutionCallback(com.ramussoft.jdbc.ExecutionCallback)

Aggregations

Attribute (com.ramussoft.common.Attribute)1 Element (com.ramussoft.common.Element)1 Qualifier (com.ramussoft.common.Qualifier)1 IEngineImpl (com.ramussoft.core.impl.IEngineImpl)1 ExecutionCallback (com.ramussoft.jdbc.ExecutionCallback)1 JDBCTemplate (com.ramussoft.jdbc.JDBCTemplate)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1