use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method getBinaryAttribute.
@Override
@SuppressWarnings("unchecked")
public List<Persistent>[] getBinaryAttribute(long elementId, long attributeId) {
throwExaptionIfNotCan(getAccessor().canReadElement(elementId, attributeId), "Can not get attribute.");
Attribute attribute = getAttribute(attributeId);
AttributePlugin plugin = factory.getAttributePlugin(attribute.getAttributeType());
final Class<? extends Persistent>[] classes;
if (elementId >= 0)
classes = plugin.getAttributePersistents();
else
classes = plugin.getAttributePropertyPersistents();
List<Persistent>[] lists = new List[classes.length];
for (int i = 0; i < lists.length; i++) {
final Class<? extends Persistent> clazz = classes[i];
final PersistentRow row = metadata.get(clazz);
final PersistentWrapper wrapper = wrappers.get(clazz);
ArrayList<Object> params = new ArrayList<Object>(2);
ArrayList<String> paramFields = new ArrayList<String>(2);
plugin.fillAttributeQuery(row, attributeId, elementId, params, paramFields, this);
if (elementId >= 0l && attribute.getAttributeType().getTypeName().equals("ElementList") && attribute.getAttributeType().getPluginName().equals("Core")) {
return getEListFixed(row, clazz, wrapper, paramFields, params, getActiveBranchId());
}
long branchId = 0l;
try {
branchId = getBranch(prefix + "attributes_data_metadata", new Object[] { "element_id", "attribute_id" }, new Object[] { elementId, attributeId }, getActiveBranchId());
} catch (SQLException e1) {
e1.printStackTrace();
throw new RuntimeException(e1);
}
params.add(branchId);
paramFields.add("value_branch_id");
StringBuffer sb = new StringBuffer("SELECT * FROM " + row.getTableName());
if (params.size() > 0) {
sb.append(" WHERE ");
}
boolean first = true;
for (int j = 0; j < params.size(); j++) {
if (first) {
first = false;
} else {
sb.append(" AND ");
}
sb.append(paramFields.get(j));
sb.append("=?");
}
List<Persistent> list = template.query(sb.toString(), new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
try {
Persistent persistent = clazz.newInstance();
for (PersistentField field : row.getFields()) {
wrapper.setDatabaseField(persistent, field, rs);
}
return persistent;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
throw new RuntimeException();
}
}, params.toArray(new Object[params.size()]), true);
lists[i] = list;
}
return lists;
}
use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.
the class PersistentFactory method load.
@SuppressWarnings("unchecked")
protected void load() throws SQLException {
List list = template.query("SELECT * FROM " + prefix + "persistents", 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.setExists(rs.getBoolean("PERSISTENT_EXISTS"));
row.setId((int) rs.getLong("PERSISTENT_ID"));
row.setTableName(rs.getString("TABLE_NAME").trim());
row.setTableType(rs.getInt("TABLE_TYPE"));
row.setPluginName(rs.getString("PLUGIN_NAME").trim());
row.setTypeName(rs.getString("TYPE_NAME").trim());
row.setFields(c(loadFields(row.getId())));
return row;
}
});
rows = list;
}
use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method createQualifier.
@Override
protected Qualifier createQualifier(long qualifierId, boolean system) {
if (!system)
throwExaptionIfNotCan(getAccessor().canCreateQualifier(), "Can not create qualifier.");
if (qualifierId == -1) {
qualifierId = nextValue("qualifiers_sequence");
long id = template.queryForLong("SELECT MAX(QUALIFIER_ID) FROM " + prefix + "qualifiers;");
while (id >= qualifierId) {
qualifierId = template.nextVal(prefix + "qualifiers_sequence");
}
}
Qualifier qualifier = new Qualifier();
qualifier.setId(qualifierId);
qualifier.setSystem(system);
long branchId = getActiveBranchId();
Long l = (Long) template.queryForObjects("SELECT COUNT(*) FROM " + prefix + "qualifiers WHERE qualifier_id=? AND removed_branch_id=?", new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getLong(1);
}
}, new Object[] { qualifierId, branchId }, false);
if (l.longValue() == 0l)
template.update("INSERT INTO " + prefix + "qualifiers(QUALIFIER_ID, QUALIFIER_NAME, QUALIFIER_SYSTEM, created_branch_id) VALUES(?, ?, ?, ?)", new Object[] { qualifierId, qualifier.getName(), system, branchId }, true);
else
template.update("UPDATE " + prefix + "qualifiers SET removed_branch_id=? WHERE QUALIFIER_ID=? AND removed_branch_id=?", new Object[] { Integer.MAX_VALUE, qualifierId, branchId }, false);
return qualifier;
}
use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method loadBranches.
@SuppressWarnings({ "cast" })
protected List<Branch> loadBranches() {
List<Branch> data = (List<Branch>) template.query("SELECT branch_id, reason, branch_type, creation_user, module_name, creation_time FROM " + prefix + "branches a ", new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
Branch branch = new Branch();
branch.setBranchId(rs.getLong("branch_id"));
branch.setReason(rs.getString("reason"));
branch.setType(rs.getInt("branch_type"));
branch.setUser(rs.getString("creation_user"));
branch.setModule(rs.getString("module_name"));
Timestamp ts = rs.getTimestamp("creation_time");
branch.setCreationTime(new Date(ts.getTime()));
return branch;
}
});
return data;
}
use of com.ramussoft.jdbc.RowMapper in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method getQualifierByName.
@Override
public Qualifier getQualifierByName(String qualifierName) {
long branch = getActiveBranchId();
Qualifier qualifier = (Qualifier) template.queryForObjects("SELECT * FROM " + prefix + "qualifiers WHERE QUALIFIER_NAME=? AND qualifier_system=FALSE AND removed_branch_id>? " + "AND created_branch_id <=?", new QualifierRowMapper(branch), new Object[] { qualifierName, branch, branch }, true);
if (qualifier != null) {
Qualifier q = getQualifier(qualifier.getId());
if (!q.getName().equals(qualifierName))
qualifier = null;
}
if (branch > 0l) {
Long l = (Long) template.queryForObjects("SELECT QUALIFIER_ID FROM " + prefix + "qualifiers_history qh WHERE QUALIFIER_NAME=? AND created_branch_id IN (" + "SELECT MAX(created_branch_id) FROM " + prefix + "qualifiers_history WHERE QUALIFIER_NAME=qh.QUALIFIER_NAME AND created_branch_id <=? )", new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getLong(1);
}
}, new Object[] { qualifierName, branch }, false);
if (l != null)
return getQualifier(l);
}
if (qualifier == null)
return null;
throwExaptionIfNotCan(getAccessor().canReadQualifier(qualifier.getId()), "Can not get qualifier.");
return qualifier;
}
Aggregations