use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method getAttributeByName.
@Override
public Attribute getAttributeByName(String attributeName) {
final long branch = getActiveBranchId();
Attribute attribute = (Attribute) template.queryForObjects("SELECT * FROM " + prefix + "attributes WHERE ATTRIBUTE_NAME=? AND attribute_system=FALSE AND removed_branch_id>?", new AttributeRowMapper(branch), new Object[] { attributeName, branch }, true);
if (attribute != null && !attributeName.equals(getAttribute(attribute.getId()).getName()))
attribute = null;
if (branch > 0l) {
Long l = (Long) template.queryForObjects("SELECT ATTRIBUTE_ID FROM " + prefix + "attributes_history qh WHERE ATTRIBUTE_NAME=? AND created_branch_id IN (" + "SELECT MAX(created_branch_id) FROM " + prefix + "attributes_history WHERE ATTRIBUTE_NAME=qh.ATTRIBUTE_NAME AND created_branch_id<=?)", new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getLong(1);
}
}, new Object[] { attributeName, branch }, false);
if (l != null)
return getAttribute(l);
}
return attribute;
}
use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method getSystemAttribute.
@Override
public Attribute getSystemAttribute(String attributeName) {
Attribute a = (Attribute) template.queryForObjects("SELECT * FROM " + prefix + "attributes WHERE ATTRIBUTE_NAME=? AND attribute_system=TRUE", new AttributeRowMapper(getActiveBranchId()), new Object[] { attributeName }, true);
if (a != null)
return a;
final long branch = getActiveBranchId();
Attribute attribute = (Attribute) template.queryForObjects("SELECT * FROM " + prefix + "attributes WHERE ATTRIBUTE_NAME=? AND attribute_system=TRUE AND removed_branch_id>?", new AttributeRowMapper(branch), new Object[] { attributeName, branch }, true);
if (attribute != null && !attributeName.equals(getAttribute(attribute.getId()).getName()))
attribute = null;
if (branch > 0l) {
Long l = (Long) template.queryForObjects("SELECT ATTRIBUTE_ID FROM " + prefix + "attributes_history qh WHERE ATTRIBUTE_NAME=? AND created_branch_id IN (" + "SELECT MAX(created_branch_id) FROM " + prefix + "attributes_history WHERE ATTRIBUTE_NAME=qh.ATTRIBUTE_NAME AND created_branch_id <=?)", new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getLong(1);
}
}, new Object[] { attributeName, branch }, false);
if (l != null)
return getAttribute(l);
}
return attribute;
}
use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.
the class UniversalPersistentFactory method load.
@Override
protected void load() throws SQLException {
List list = template.query("SELECT * FROM " + getPersistentClassesTableName(), new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
PersistentRow row = new PersistentRow();
row.setStatus(LOADED);
row.setClassName(rs.getString("CLASS_NAME").trim());
row.setTableName(rs.getString("TABLE_NAME").trim());
row.setExists(rs.getBoolean("PERSISTENT_EXISTS"));
row.setFields(c(loadFields(row.getClassName())));
return row;
}
});
rows = list;
}
use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.
the class OtherElementPlugin method getElementsDeleteStatus.
@SuppressWarnings("unchecked")
@Override
public DeleteStatus getElementsDeleteStatus(long[] elementIds, IEngine aEngine) {
if (!(aEngine instanceof IEngineImpl))
return super.getElementsDeleteStatus(elementIds, 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_other_elements a, {0}attributes b, {0}qualifiers c, {0}elements d " + "WHERE other_element in(" + JDBCTemplate.toSqlArray(elementIds) + ") AND a.attribute_id=b.attribute_id AND d.element_id=a.element_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 {
String qName = rs.getString(2);
if (qName.startsWith("TableQualifier_"))
qName = "{AttributeType.Core.Table}";
return "<tr><td>" + rs.getString(1) + "</td><td> " + qName + "</td><td> " + rs.getString(3) + "</td></tr>";
}
});
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;
}
use of com.ramussoft.jdbc.RowMapper 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);
}
Aggregations