use of com.ramussoft.jdbc.JDBCCallback in project ramus by Vitaliy-Yakovchuk.
the class UserFactoryImpl method getUsers.
@SuppressWarnings("unchecked")
@Override
public List<User> getUsers() {
return (List<User>) template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
List<User> result = new ArrayList<User>();
Statement st = connection.createStatement();
PreparedStatement groups = connection.prepareStatement("SELECT * FROM users_groups WHERE \"login\"=? ORDER BY group_name");
ResultSet rs = st.executeQuery("SELECT * FROM users ORDER BY \"login\"");
PreparedStatement groupQualifiers = template.getConnection().prepareStatement("SELECT qualifier_id FROM group_qualifier_access WHERE group_name=? ORDER BY qualifier_id");
while (rs.next()) {
User user = createUser(groups, rs, groupQualifiers);
result.add(user);
}
groupQualifiers.close();
groups.close();
rs.close();
st.close();
return result;
}
});
}
use of com.ramussoft.jdbc.JDBCCallback in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method deleteAttribute.
@Override
public void deleteAttribute(final long id) {
throwExaptionIfNotCan(getAccessor().canDeleteAttribute(id), "Can not delete attribute.");
template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
Transaction transaction = getAttributePropertyWhatWillBeDeleted(id);
executeTransaction(transaction, connection);
long branch = getActiveBranchId();
PreparedStatement ps = connection.prepareStatement("UPDATE " + prefix + "attributes SET removed_branch_id=? WHERE ATTRIBUTE_ID=?");
ps.setLong(1, branch);
ps.setLong(2, id);
ps.execute();
ps.close();
return null;
}
});
}
use of com.ramussoft.jdbc.JDBCCallback in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method updateAttributes.
private void updateAttributes(List<Attribute> attributes, final boolean system, final long qualifierId, final long branch) {
List<Attribute> olds = new ArrayList<Attribute>();
loadAttributes(olds, system, qualifierId, branch);
for (final Attribute old : olds) {
if (attributes.indexOf(old) < 0) {
template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
Hashtable<Element, Transaction> hash = getAttributeWhatWillBeDeleted(qualifierId, old.getId());
for (Transaction transaction : hash.values()) {
executeTransaction(transaction, connection);
}
PreparedStatement ps;
ps = connection.prepareStatement("DELETE FROM " + prefix + "formula_dependences WHERE source_attribute_id=? AND source_element_id IN (SELECT element_id FROM " + prefix + "elements WHERE qualifier_id=?)");
ps.setLong(1, old.getId());
ps.setLong(2, qualifierId);
ps.execute();
ps.close();
ps = connection.prepareStatement("DELETE FROM " + prefix + "formulas WHERE attribute_id=? AND element_id IN (SELECT element_id FROM " + prefix + "elements WHERE qualifier_id=?)");
ps.setLong(1, old.getId());
ps.setLong(2, qualifierId);
ps.execute();
ps.close();
return null;
}
});
}
}
long position = 0;
template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement("DELETE FROM " + prefix + "qualifiers_attributes WHERE QUALIFIER_ID=? AND ATTRIBUTE_SYSTEM=? AND created_branch_id=?");
ps.setLong(1, qualifierId);
ps.setBoolean(2, system);
ps.setLong(3, branch);
ps.execute();
ps.close();
return null;
}
});
for (Attribute a : attributes) {
// if (olds.indexOf(a) < 0) {
template.update("INSERT INTO " + prefix + "qualifiers_attributes(QUALIFIER_ID, ATTRIBUTE_ID, ATTRIBUTE_SYSTEM, ATTRIBUTE_POSITION, created_branch_id) " + "VALUES(?, ?, ?, ?, ?)", new Object[] { qualifierId, a.getId(), system, position, branch }, true);
/*
* } else { template.update( "UPDATE " + prefix +
* "qualifiers_attributes SET ATTRIBUTE_POSITION=? WHERE QUALIFIER_ID=? AND ATTRIBUTE_ID=? AND created_branch_id=?"
* , new Object[] { position, qualifierId, a.getId(), branch },
* true); }
*/
position++;
}
}
use of com.ramussoft.jdbc.JDBCCallback in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method deleteQualifier.
@Override
public void deleteQualifier(final long id) {
throwExaptionIfNotCan(getAccessor().canDeleteQualifier(id), "Can not delete qualifier.");
template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
long branch = getActiveBranchId();
PreparedStatement ps = connection.prepareStatement("UPDATE " + prefix + "qualifiers SET removed_branch_id=? WHERE QUALIFIER_ID=?");
ps.setLong(1, branch);
ps.setLong(2, id);
ps.execute();
ps.close();
return null;
}
});
if (cached)
qualifeirsCache.remove(id);
}
Aggregations