use of com.ramussoft.report.data.RowSet in project ramus by Vitaliy-Yakovchuk.
the class OwnersConnection 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;
}
OwnersConnection connection = (OwnersConnection) data.get("OunersConnection");
if (connection != null)
return connection.getOuners(data, row);
final Engine engine = data.getEngine();
ArrayList<Long> ounerQualifierIds = loadOunerIDs(engine);
owners = new Hashtable<Row, List<Row>>();
final Attribute ounerAttribute = IDEF0Plugin.getFunctionOunerAttribute(engine);
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));
if (row == null)
return null;
Long o = (Long) row.getAttribute(ounerAttribute);
if (o != null) {
Element element = engine.getElement(o);
if (element != null) {
RowSet ounerRowSet = data.getRowSet(element.getQualifierId());
Row owner = (Row) ounerRowSet.findRow(o);
if (row == null || owner == null)
return null;
mech.put(row, Arrays.asList(owner));
}
return null;
}
RowSet ounerRowSet = data.getRowSet(rs.getLong(3));
Row ouner = (Row) ounerRowSet.findRow(rs.getLong(4));
if (row == null || ouner == null)
return null;
List<Row> l = mech.get(row);
if (l == null) {
l = new ArrayList<Row>(2);
mech.put(row, l);
}
if (!l.contains(ouner))
l.add(ouner);
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);
}
try {
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);
} catch (Exception e) {
e.printStackTrace();
}
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> l = mech.get(row);
if (l == null) {
l = new ArrayList<Row>(2);
mech.put(row, l);
}
if (!l.contains(ouner))
l.add(ouner);
}
return null;
}
}, true);
RowSet rowSet = data.getRowSet(row.getQualifier());
setRecOuners(rowSet.getRoot(), mech, null);
data.put("OunersConnection", this);
return getOuners(data, row);
}
use of com.ramussoft.report.data.RowSet in project ramus by Vitaliy-Yakovchuk.
the class IDEF0Buffer method getStreamsRowSet.
public static RowSet getStreamsRowSet(final Data data) {
RowSet rowSet = (RowSet) data.get("Streams");
if (rowSet != null)
return rowSet;
com.ramussoft.database.common.RowSet.RowCreater rowCreater = new com.ramussoft.database.common.RowSet.RowCreater() {
@Override
public com.ramussoft.database.common.Row createRow(Element aElement, com.ramussoft.database.common.RowSet rowSet, Attribute[] attributes, Object[] objects) {
return new Stream(aElement, (RowSet) rowSet, attributes, objects, data);
}
};
Engine engine = data.getEngine();
rowSet = new RowSet(engine, IDEF0Plugin.getBaseStreamQualifier(engine), data, rowCreater);
data.put("Streams", rowSet);
return rowSet;
}
use of com.ramussoft.report.data.RowSet 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;
}
use of com.ramussoft.report.data.RowSet in project ramus by Vitaliy-Yakovchuk.
the class QualifiersConnection method getConnected.
@SuppressWarnings("unchecked")
@Override
public Rows getConnected(Data data, Row row) {
if (!(row.getQualifier().equals(IDEF0Plugin.getBaseStreamQualifier(data.getEngine()))))
return new Rows(null, data, false);
List<AnyToAnyPersistent> list = (List) row.getAttribute(IDEF0Plugin.getStreamAddedAttribute(data.getEngine()));
final Engine engine = data.getEngine();
Rows rows = new Rows(null, data, false) {
/**
*/
private static final long serialVersionUID = -284240974188065028L;
@Override
public RowSet getRowSet() {
Row current = getCurrent();
if (current == null)
return null;
return current.getRowSet();
}
@Override
public Row addRow(long elementId) {
long qId = engine.getQualifierIdForElement(elementId);
if (qId >= 0l) {
Qualifier qualifier = this.data.getQualifier(qId);
if (qualifier != null) {
RowSet rowSet = this.data.getRowSet(qualifier);
Row row = (Row) rowSet.findRow(elementId);
if (row != null) {
add(row);
return row;
}
}
}
return null;
}
};
for (AnyToAnyPersistent p : list) {
Row row2 = rows.addRow(p.getOtherElement());
if (row2 != null)
row2.setElementStatus(p.getElementStatus());
}
return rows;
}
use of com.ramussoft.report.data.RowSet in project ramus by Vitaliy-Yakovchuk.
the class FastIdef0Connection method getQualifiers.
public List<Qualifier> getQualifiers(Data data, String modelName) {
Engine engine = data.getEngine();
List<Qualifier> qualifiers = new ArrayList<Qualifier>();
if ("[ALL MODELS]".equals(modelName)) {
for (Qualifier qualifier : engine.getQualifiers()) if (IDEF0Plugin.isFunction(qualifier))
qualifiers.add(qualifier);
} else {
com.ramussoft.database.common.RowSet rowSet = new com.ramussoft.database.common.RowSet(engine, IDEF0Plugin.getModelTree(engine), new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine) }, null, true);
StringTokenizer st = new StringTokenizer(modelName, Data.QUALIFIER_DELIMETER);
while (st.hasMoreElements()) {
com.ramussoft.database.common.Row row = rowSet.findRow(st.nextToken());
if (row != null)
addQualifiers(data.getEngine(), qualifiers, row);
}
Qualifier qualifier = engine.getQualifierByName(modelName);
if (qualifier != null && !qualifiers.contains(qualifier))
qualifiers.add(qualifier);
}
return qualifiers;
}
Aggregations