Search in sources :

Example 6 with AnyToAnyPersistent

use of com.ramussoft.idef0.attribute.AnyToAnyPersistent in project ramus by Vitaliy-Yakovchuk.

the class FastIdef0Connection method createBuffers.

private IDEF0Buffer[] createBuffers(final Key key, final Data data) {
    final IDEF0Buffer[] buffers = new IDEF0Buffer[4];
    for (int i = 0; i < 4; i++) buffers[i] = new IDEF0Buffer(data, key.model);
    RowSet model = data.getRowSet(key.model);
    RowSet base = data.getRowSet(IDEF0Plugin.getBaseFunctions(data.getEngine()));
    end = IDEF0Plugin.getSectorBorderEndAttribute(data.getEngine());
    start = IDEF0Plugin.getSectorBorderStartAttribute(data.getEngine());
    Attribute fun = IDEF0Plugin.getSectorFunctionAttribute(data.getEngine());
    Attribute st = IDEF0Plugin.getSectorStreamAttribute(data.getEngine());
    Attribute dType = IDEF0Plugin.getDecompositionTypeAttribute(data.getEngine());
    RowSet sectors = data.getRowSet(IDEF0Plugin.getBaseSectorQualifier(data.getEngine()));
    RowSet streams = data.getRowSet(IDEF0Plugin.getBaseStreamQualifier(data.getEngine()));
    Attribute anyToAnyAttribute = IDEF0Plugin.getStreamAddedAttribute(data.getEngine());
    for (com.ramussoft.database.common.Row sector : sectors.getAllRows()) {
        Long f = (Long) sector.getAttribute(fun);
        Long s = (Long) sector.getAttribute(st);
        if (f != null && s != null) {
            com.ramussoft.database.common.Row parentFunction = model.findRow(f);
            com.ramussoft.database.common.Row pFunction = null;
            if (parentFunction == null) {
                Qualifier q1 = base.getEngine().getQualifier(f);
                if (q1 != null)
                    System.out.println(q1);
                pFunction = base.findRow(f);
                if (pFunction != null && pFunction.getAttribute(IDEF0Plugin.getBaseFunctionQualifierId(data.getEngine())).equals(model.getQualifier().getId()))
                    parentFunction = pFunction;
            }
            Row stream = (Row) streams.findRow(s);
            if (parentFunction != null && stream != null) {
                Integer decompositionType = (Integer) parentFunction.getAttribute(dType);
                if (pFunction != null)
                    parentFunction = null;
                else if (parentFunction.getChildCount() == 0)
                    continue;
                List<AnyToAnyPersistent> list = (List) stream.getAttribute(anyToAnyAttribute);
                if (list == null)
                    list = Collections.emptyList();
                SectorBorderPersistent sb = (SectorBorderPersistent) sector.getAttribute(start);
                int type;
                if (sb != null && (type = sb.getFunctionType()) >= 0) {
                    if (decompositionType != null && decompositionType == 2) {
                        // DFDS
                        type = 0;
                    }
                    IDEF0Buffer buffer = buffers[type];
                    Row function = buffer.addFunctionStream(sb.getFunction(), stream.getElementId(), parentFunction);
                    for (AnyToAnyPersistent p : list) if (p != null) {
                        buffer.addRowFunction(p.getOtherElement(), sb.getFunction(), p.getElementStatus(), parentFunction);
                        if (sb.getTunnelSoft() == 1 && function != null && function.getChildCount() > 0) {
                            addAll(function, buffer);
                        }
                    }
                }
                sb = (SectorBorderPersistent) sector.getAttribute(end);
                if (sb != null && (type = sb.getFunctionType()) >= 0) {
                    if (decompositionType != null && decompositionType == 2) {
                        // DFDS
                        type = 2;
                    }
                    IDEF0Buffer buffer = buffers[type];
                    Row function = buffer.addFunctionStream(sb.getFunction(), stream.getElementId(), parentFunction);
                    for (AnyToAnyPersistent p : list) if (p != null) {
                        buffer.addRowFunction(p.getOtherElement(), sb.getFunction(), p.getElementStatus(), parentFunction);
                        if (sb.getTunnelSoft() == 1 && function != null && function.getChildCount() > 0) {
                            addAll(function, buffer);
                        }
                    }
                }
            }
        }
    }
    for (IDEF0Buffer buffer : buffers) buffer.commit(all);
    return buffers;
}
Also used : Attribute(com.ramussoft.common.Attribute) RowSet(com.ramussoft.report.data.RowSet) SectorBorderPersistent(com.ramussoft.idef0.attribute.SectorBorderPersistent) AnyToAnyPersistent(com.ramussoft.idef0.attribute.AnyToAnyPersistent) Qualifier(com.ramussoft.common.Qualifier) ArrayList(java.util.ArrayList) List(java.util.List) Row(com.ramussoft.report.data.Row)

Example 7 with AnyToAnyPersistent

use of com.ramussoft.idef0.attribute.AnyToAnyPersistent in project ramus by Vitaliy-Yakovchuk.

the class NStream method setIdProperties.

@Override
public void setIdProperties() {
    List<AnyToAnyPersistent> list = (List<AnyToAnyPersistent>) this.getAttribute(((NDataPlugin) dataPlugin).addedRows);
    if (list == null)
        return;
    rows = new Row[list.size()];
    rowStatuses = new String[list.size()];
    for (int i = 0; i < rows.length; i++) {
        Row row = ((NDataPlugin) dataPlugin).findRowByGlobalId(list.get(i).getOtherElement());
        getARows()[i] = row;
        rowStatuses[i] = list.get(i).getElementStatus();
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Row(com.ramussoft.pb.Row) AnyToAnyPersistent(com.ramussoft.idef0.attribute.AnyToAnyPersistent)

Example 8 with AnyToAnyPersistent

use of com.ramussoft.idef0.attribute.AnyToAnyPersistent 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

AnyToAnyPersistent (com.ramussoft.idef0.attribute.AnyToAnyPersistent)8 List (java.util.List)7 Row (com.ramussoft.report.data.Row)6 ArrayList (java.util.ArrayList)6 Engine (com.ramussoft.common.Engine)4 RowSet (com.ramussoft.report.data.RowSet)4 Rows (com.ramussoft.report.data.Rows)4 Attribute (com.ramussoft.common.Attribute)3 Qualifier (com.ramussoft.common.Qualifier)2 RowMapper (com.ramussoft.jdbc.RowMapper)2 Row (com.ramussoft.pb.Row)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Hashtable (java.util.Hashtable)2 Element (com.ramussoft.common.Element)1 SectorBorderPersistent (com.ramussoft.idef0.attribute.SectorBorderPersistent)1 XMLReportEngine (com.ramussoft.report.XMLReportEngine)1 DataException (com.ramussoft.report.data.DataException)1 IOException (java.io.IOException)1 InvalidPropertiesFormatException (java.util.InvalidPropertiesFormatException)1