Search in sources :

Example 16 with RowMapper

use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.

the class IDEF0ConnectionPlugin method getStreams.

private Rows getStreams(Data data, String name) {
    final RowSet rowSet = IDEF0Buffer.getStreamsRowSet(data);
    final Rows rows = new Rows(rowSet, data, false);
    rows.setQualifierName(name);
    data.getTemplate().queryWithoutResults("SELECT DISTINCT ramus_attribute_any_to_any_elements.element_id,\n" + "(SELECT element_id FROM ramus_elements WHERE ramus_attribute_any_to_any_elements.other_element= ramus_elements.element_id) as oelement_id,\n" + "ramus_elements.element_name\n" + "FROM ramus_attribute_any_to_any_elements, ramus_elements, ramus_attribute_sector_borders, ramus_attribute_other_elements\n" + "WHERE ramus_attribute_any_to_any_elements.element_id= ramus_elements.element_id\n" + "AND ramus_attribute_sector_borders.function_type>=0\n" + "AND ramus_attribute_sector_borders.element_id = ramus_attribute_other_elements.element_id\n" + "AND ramus_attribute_other_elements.other_element = ramus_elements.element_id\n", new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            if ((rs.getString(3).length() > 0) || (rs.getObject(2) != null)) {
                rows.add((Row) rowSet.findRow(rs.getLong(1)));
            }
            return null;
        }
    }, true);
    return rows;
}
Also used : SQLException(java.sql.SQLException) RowSet(com.ramussoft.report.data.RowSet) ResultSet(java.sql.ResultSet) Row(com.ramussoft.report.data.Row) Rows(com.ramussoft.report.data.Rows) RowMapper(com.ramussoft.jdbc.RowMapper)

Example 17 with RowMapper

use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.

the class HTTPParser method printRowAttributes.

private void printRowAttributes(final Row row) throws IOException {
    Element element = row.getElement();
    Qualifier qualifier = dataPlugin.getEngine().getQualifier(element.getQualifierId());
    List<Attribute> attributes = qualifier.getAttributes();
    for (Attribute attr : attributes) {
        if (attr.getId() != qualifier.getAttributeForName()) {
            factory.printAttribute(htmlStream, dataPlugin, element, this, attr);
        }
    }
    IEngine deligate = dataPlugin.getEngine().getDeligate();
    if (deligate instanceof IEngineImpl) {
        final IEngineImpl impl = (IEngineImpl) deligate;
        String prefix = impl.getPrefix();
        JDBCTemplate template = impl.getTemplate();
        List<OtherElementMetadata> list = template.query("SELECT * FROM " + prefix + "attribute_other_elements a WHERE other_element=? AND value_branch_id IN (SELECT branch_id FROM " + prefix + "attributes_data_metadata WHERE attribute_id=a.attribute_id AND element_id=a.element_id)", new RowMapper() {

            private Hashtable<Long, Attribute> attrs = new Hashtable<Long, Attribute>();

            private Hashtable<Long, Qualifier> qualifiers = new Hashtable<Long, Qualifier>();

            @Override
            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                OtherElementMetadata metadata = new OtherElementMetadata();
                Element element = impl.getElement(rs.getLong("element_id"));
                if (element == null)
                    return null;
                metadata.element = element;
                metadata.qualifier = getQualifier(element.getQualifierId());
                metadata.attribute = getAttribute(rs.getLong("attribute_id"));
                return metadata;
            }

            private Attribute getAttribute(Long id) {
                Attribute attribute = attrs.get(id);
                if (attribute == null) {
                    attribute = dataPlugin.getEngine().getAttribute(id);
                    attrs.put(id, attribute);
                }
                return attribute;
            }

            private Qualifier getQualifier(Long id) {
                Qualifier qualifier = qualifiers.get(id);
                if (qualifier == null) {
                    qualifier = dataPlugin.getEngine().getQualifier(id);
                    qualifiers.put(id, qualifier);
                }
                return qualifier;
            }
        }, new Object[] { row.getElement().getId() }, true);
        boolean print = false;
        for (OtherElementMetadata data : list) if (data.isNotSystem()) {
            print = true;
            break;
        }
        if (print) {
            Collections.sort(list);
            htmlStream.println("<table border=1>");
            htmlStream.println("<tr>");
            htmlStream.print("<td><b>");
            htmlStream.print(RES.getString("clasificator"));
            htmlStream.print("</b></td>");
            htmlStream.print("<td><b>");
            htmlStream.print(RES.getString("rowAttribute"));
            htmlStream.print("</b></td>");
            htmlStream.print("<td><b>");
            htmlStream.print(RES.getString("element"));
            htmlStream.print("</b></td>");
            htmlStream.println("</tr>");
            Hashtable<Qualifier, Element> hash = new Hashtable<Qualifier, Element>();
            for (OtherElementMetadata data : list) if (data.isNotSystem()) {
                Element element2 = hash.get(data.qualifier);
                if (element2 == null) {
                    element2 = StandardAttributesPlugin.getElement(dataPlugin.getEngine(), data.qualifier.getId());
                    hash.put(data.qualifier, element2);
                }
                htmlStream.println("<tr>");
                htmlStream.print("<td>");
                printStartATeg("rows/index.html?id=" + element2.getId());
                htmlStream.print(data.qualifier.getName());
                printEndATeg();
                htmlStream.print("</td>");
                htmlStream.print("<td>");
                htmlStream.print(data.attribute.getName());
                htmlStream.print("</td>");
                htmlStream.print("<td>");
                printStartATeg("rows/index.html?id=" + data.element.getId());
                htmlStream.print(data.element.getName());
                printEndATeg();
                htmlStream.print("</td>");
                htmlStream.println("</tr>");
            }
            htmlStream.println("</table><br>");
        }
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) SQLException(java.sql.SQLException) Hashtable(java.util.Hashtable) Element(com.ramussoft.common.Element) IEngine(com.ramussoft.common.IEngine) IEngineImpl(com.ramussoft.core.impl.IEngineImpl) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) ResultSet(java.sql.ResultSet) Qualifier(com.ramussoft.common.Qualifier) RowMapper(com.ramussoft.jdbc.RowMapper)

Example 18 with RowMapper

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

Example 19 with RowMapper

use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.

the class ElementListPlugin method getElementsDeleteStatus.

@SuppressWarnings("unchecked")
@Override
public DeleteStatus getElementsDeleteStatus(long[] elementIds, IEngine aEngine) {
    IEngineImpl engine = (IEngineImpl) aEngine;
    JDBCTemplate template = engine.getTemplate();
    String prefix = engine.getPrefix();
    String sql = "SELECT element_name, qualifier_name, attribute_name " + "FROM {0}attribute_element_lists a, {0}attributes b, {0}qualifiers c, {0}elements d " + "WHERE element2_id in(" + JDBCTemplate.toSqlArray(elementIds) + ") AND a.attribute_id=b.attribute_id AND d.element_id=a.element1_id " + "AND d.qualifier_id=c.qualifier_id AND b.attribute_system=false " + "ORDER BY qualifier_name, attribute_name, element_name";
    List<String> list = template.query(MessageFormat.format(sql, prefix), new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            return "<tr><td>" + rs.getString(1) + "</td><td> " + rs.getString(2) + "</td><td> " + rs.getString(3) + "</td></tr>";
        }
    });
    sql = "SELECT element_name, qualifier_name, attribute_name " + "FROM {0}attribute_element_lists a, {0}attributes b, {0}qualifiers c, {0}elements d " + "WHERE element1_id in(" + JDBCTemplate.toSqlArray(elementIds) + ") AND a.attribute_id=b.attribute_id AND d.element_id=a.element2_id " + "AND d.qualifier_id=c.qualifier_id AND b.attribute_system=false " + "ORDER BY qualifier_name, attribute_name, element_name";
    List<String> list1 = template.query(MessageFormat.format(sql, prefix), new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            return "<tr><td>" + rs.getString(1) + "</td><td> " + rs.getString(2) + "</td><td> " + rs.getString(3) + "</td></tr>";
        }
    });
    list.addAll(list1);
    if (list.size() == 0)
        return null;
    DeleteStatus status = new DeleteStatus();
    status.setPluginName("Core");
    StringBuffer sb = new StringBuffer();
    sb.append("<br>");
    sb.append("<table>");
    sb.append("<tr><td><b>{AttributeType.Core.OtherElement}</b></td><td><b>{OtherElement.Qualifier}</b></td><td><b>{OtherElement.Attribute}</b></td></tr>");
    for (String s : list) {
        sb.append(s);
    }
    sb.append("</table>");
    status.setPluginAnswer("{Warning.ElementsUsedAtOtherElements}" + sb.toString());
    return status;
}
Also used : IEngineImpl(com.ramussoft.core.impl.IEngineImpl) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DeleteStatus(com.ramussoft.common.DeleteStatus) RowMapper(com.ramussoft.jdbc.RowMapper)

Example 20 with RowMapper

use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.

the class RolesConnection method getConnected.

@Override
public Rows getConnected(final Data data, Row row) {
    Integer type = (Integer) row.getAttribute(IDEF0Plugin.getFunctionTypeAttribute(row.getEngine()));
    if (type != null && type.intValue() == 1003) {
        Long id = (Long) row.getAttribute(IDEF0Plugin.getLinkAttribute(row.getEngine()));
        Rows rows = new Rows(row.getRowSet(), data, false);
        if (id != null) {
            Row row2 = data.findRow(id);
            if (row2 != null) {
                List<AnyToAnyPersistent> list = (List) row2.getAttribute(IDEF0Plugin.getStreamAddedAttribute(row2.getEngine()));
                for (AnyToAnyPersistent anyPersistent : list) {
                    Row row3 = data.findRow(anyPersistent.getOtherElement());
                    row3.setElementStatus(anyPersistent.getElementStatus());
                    rows.add(row3);
                }
            }
        }
        return rows;
    }
    RolesConnection connection = (RolesConnection) data.get("RolesConnection");
    if (connection != null)
        return connection.getRoles(data, row);
    final Engine engine = data.getEngine();
    ArrayList<Long> ounerQualifierIds = loadOunerIDs(engine);
    roles = new Hashtable<Row, List<Row>>();
    final Hashtable<Row, List<Row>> mech = new Hashtable<Row, List<Row>>();
    RowMapper mapper = new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            RowSet rowSet = data.getRowSet(rs.getLong(1));
            Row row = (Row) rowSet.findRow(rs.getLong(2));
            RowSet ounerRowSet = data.getRowSet(rs.getLong(3));
            Row role = (Row) ounerRowSet.findRow(rs.getLong(4));
            if (row == null || role == null)
                return null;
            List<Row> rows = mech.get(row);
            if (rows == null) {
                rows = new ArrayList<Row>(5);
                mech.put(row, rows);
            }
            if (!rows.contains(role))
                rows.add(role);
            return null;
        }
    };
    if (ounerQualifierIds.size() > 0) {
        data.getTemplate().queryWithoutResults("SELECT b.qualifier_id, function, ramus_elements.qualifier_id, ramus_elements.element_id FROM\n" + "ramus_attribute_sector_borders, ramus_attribute_other_elements, ramus_attribute_any_to_any_elements, ramus_elements, ramus_elements b\n" + "WHERE ramus_attribute_any_to_any_elements.element_id=ramus_attribute_other_elements.other_element\n" + "AND ramus_elements.element_id=ramus_attribute_any_to_any_elements.other_element\n" + "AND ramus_attribute_sector_borders.element_id = ramus_attribute_other_elements.element_id\n" + "AND function_type=1 AND ramus_attribute_sector_borders.attribute_id in\n" + "(SELECT attribute_id FROM ramus_attributes WHERE attribute_system=true AND attribute_name='F_SECTOR_BORDER_END')\n" + "AND b.element_id=function\n" + "AND ramus_elements.qualifier_id in " + toIns(ounerQualifierIds), mapper, true);
    }
    data.getTemplate().queryWithoutResults("SELECT (SELECT qualifier_id FROM ramus_elements WHERE element_id=ouner_id) as function_qualifier_id, " + "ouner_id AS function,  " + "(SELECT qualifier_id FROM ramus_elements WHERE element_id=other_element) as ouner_qualifier_id, " + "other_element as ouner_id FROM ramus_attribute_any_to_any_elements, ramus_attribute_function_ouners " + "WHERE ramus_attribute_any_to_any_elements.element_id IN " + "(SELECT value FROM ramus_attribute_longs WHERE ramus_attribute_longs.element_id=ramus_attribute_function_ouners.element_id)", mapper, true);
    data.getTemplate().queryWithoutResults("SELECT ramus_attribute_function_ouners.element_id,\n" + "(SELECT MAX(ramus_elements.qualifier_id) FROM ramus_elements WHERE ramus_elements.element_id=ramus_attribute_function_ouners.element_id),\n" + "ramus_elements.qualifier_id,\n" + " ouner_id FROM ramus_elements, ramus_attribute_function_ouners WHERE ramus_elements.element_id=ouner_id " + "AND ramus_attribute_function_ouners.ouner_id IN (SELECT element_id FROM ramus_attribute_function_types WHERE type<1001)", new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            RowSet rowSet = data.getRowSet(rs.getLong(2));
            Row row = (Row) rowSet.findRow(rs.getLong(1));
            RowSet ounerRowSet = data.getRowSet(rs.getLong(3));
            Row ouner = (Row) ounerRowSet.findRow(rs.getLong(4));
            if (ouner != null && row != null) {
                List<Row> rows = roles.get(row);
                if (rows == null) {
                    rows = new ArrayList<Row>();
                    roles.put(row, rows);
                }
                if (!rows.contains(ouner))
                    rows.add(ouner);
            }
            return null;
        }
    }, true);
    RowSet rowSet = data.getRowSet(row.getQualifier());
    setRecOuners(rowSet.getRoot(), mech, null);
    data.put("RolesConnection", this);
    return getRoles(data, row);
}
Also used : SQLException(java.sql.SQLException) Hashtable(java.util.Hashtable) RowSet(com.ramussoft.report.data.RowSet) ArrayList(java.util.ArrayList) AnyToAnyPersistent(com.ramussoft.idef0.attribute.AnyToAnyPersistent) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Row(com.ramussoft.report.data.Row) Engine(com.ramussoft.common.Engine) Rows(com.ramussoft.report.data.Rows) RowMapper(com.ramussoft.jdbc.RowMapper)

Aggregations

RowMapper (com.ramussoft.jdbc.RowMapper)30 ResultSet (java.sql.ResultSet)30 SQLException (java.sql.SQLException)22 FindObject (com.ramussoft.common.attribute.FindObject)14 ArrayList (java.util.ArrayList)14 Attribute (com.ramussoft.common.Attribute)11 List (java.util.List)11 Qualifier (com.ramussoft.common.Qualifier)7 JDBCTemplate (com.ramussoft.jdbc.JDBCTemplate)7 Element (com.ramussoft.common.Element)6 PersistentRow (com.ramussoft.common.persistent.PersistentRow)6 IEngineImpl (com.ramussoft.core.impl.IEngineImpl)6 Hashtable (java.util.Hashtable)6 Engine (com.ramussoft.common.Engine)5 AttributePlugin (com.ramussoft.common.attribute.AttributePlugin)5 Persistent (com.ramussoft.common.persistent.Persistent)5 PersistentField (com.ramussoft.common.persistent.PersistentField)5 PersistentWrapper (com.ramussoft.common.persistent.PersistentWrapper)4 DeleteStatus (com.ramussoft.common.DeleteStatus)3 IEngine (com.ramussoft.common.IEngine)3