use of com.ramussoft.jdbc.JDBCCallback in project ramus by Vitaliy-Yakovchuk.
the class UserFactoryImpl method deleteGroup.
@Override
public void deleteGroup(final String groupName) {
if (!groupName.equals("admin"))
template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
PreparedStatement d1 = connection.prepareStatement("DELETE FROM USERS_GROUPS WHERE GROUP_NAME=?");
d1.setString(1, groupName);
d1.execute();
d1.close();
d1 = connection.prepareStatement("DELETE FROM group_qualifier_access WHERE GROUP_NAME=?");
d1.setString(1, groupName);
d1.execute();
d1.close();
d1 = connection.prepareStatement("DELETE FROM GROUPS WHERE GROUP_NAME=?");
d1.setString(1, groupName);
d1.execute();
d1.close();
return null;
}
});
}
use of com.ramussoft.jdbc.JDBCCallback in project ramus by Vitaliy-Yakovchuk.
the class UserFactoryImpl method getUser.
@Override
public User getUser(final String login) {
return (User) template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
PreparedStatement selUser = connection.prepareStatement("SELECT * FROM USERS WHERE \"login\"=?");
selUser.setString(1, login);
ResultSet rs = selUser.executeQuery();
PreparedStatement groupQualifiers = template.getConnection().prepareStatement("SELECT qualifier_id FROM group_qualifier_access WHERE group_name=? ORDER BY qualifier_id");
if (rs.next()) {
PreparedStatement groups = connection.prepareStatement("SELECT * FROM users_groups WHERE \"login\"=? ORDER BY group_name");
User user = createUser(groups, rs, groupQualifiers);
groups.close();
rs.close();
selUser.close();
return user;
}
rs.close();
groupQualifiers.close();
selUser.close();
return null;
}
});
}
use of com.ramussoft.jdbc.JDBCCallback in project ramus by Vitaliy-Yakovchuk.
the class UserFactoryImpl method deleteUser.
@Override
public void deleteUser(final String login) {
if (!login.equals("admin"))
template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
PreparedStatement d1 = connection.prepareStatement("DELETE FROM USERS_GROUPS WHERE \"login\"=?");
d1.setString(1, login);
d1.execute();
d1.close();
d1 = connection.prepareStatement("DELETE FROM USERS WHERE \"login\"=?");
d1.setString(1, login);
d1.execute();
d1.close();
return null;
}
});
}
use of com.ramussoft.jdbc.JDBCCallback in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method setBinaryAttribute.
// @SuppressWarnings("unused")
@Override
public boolean setBinaryAttribute(final long elementId, final long attributeId, final Transaction transaction) {
if (elementId >= 0) {
long qualifierId = getQualifierIdForElement(elementId);
Qualifier qualifier = getQualifier(qualifierId);
boolean attr = false;
if ((qualifier == null) && (Metadata.DEBUG)) {
System.err.println("WARNING: Can not set attribute for not existing element");
throw new RuntimeException("WARNING: Can not set attribute for not existing element");
}
for (Attribute attribute : qualifier.getAttributes()) {
if (attributeId == attribute.getId()) {
attr = true;
}
}
for (Attribute attribute : qualifier.getSystemAttributes()) {
if (attributeId == attribute.getId()) {
attr = true;
}
}
if (!attr) {
throw new RuntimeException("Attribute with id: " + attributeId + " not found for qualifier: " + qualifier);
}
}
Attribute propertyAttribute = getAttribute(attributeId);
if (elementId < 0l && propertyAttribute != null && propertyAttribute.getAttributeType().toString().equals("Core.Variant")) {
} else if (!getAccessor().canUpdateElement(elementId, attributeId))
return false;
process(transaction.getDelete(), elementId, attributeId);
process(transaction.getUpdate(), elementId, attributeId);
process(transaction.getSave(), elementId, attributeId);
if (elementId >= 0 && propertyAttribute.getAttributeType().getTypeName().equals("ElementList") && propertyAttribute.getAttributeType().getPluginName().equals("Core")) {
try {
setElistFix(transaction);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
return (Boolean) template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
executeTransaction(transaction, connection);
long branch = getActiveBranchId();
Boolean res = Boolean.FALSE;
if (branch > 0l) {
PreparedStatement ps = template.getPreparedStatement("SELECT branch_id FROM " + prefix + "attributes_data_metadata WHERE branch_id=? AND attribute_id=? AND element_id=?", true);
ps.setLong(1, branch);
ps.setLong(2, attributeId);
ps.setLong(3, elementId);
ResultSet rs = ps.executeQuery();
if (!rs.next() && !transaction.isRemoveBranchInfo()) {
rs.close();
ps = template.getPreparedStatement("INSERT INTO " + prefix + "attributes_data_metadata(element_id, attribute_id, branch_id) VALUES(?, ?, ?)", true);
ps.setLong(1, elementId);
ps.setLong(2, attributeId);
ps.setLong(3, branch);
ps.execute();
res = Boolean.TRUE;
} else {
rs.close();
if (transaction.isRemoveBranchInfo()) {
ps = template.getPreparedStatement("DELETE FROM " + prefix + "attributes_data_metadata WHERE branch_id=? AND attribute_id=? AND element_id=?", false);
ps.setLong(1, branch);
ps.setLong(2, attributeId);
ps.setLong(3, elementId);
ps.execute();
ps.close();
}
}
}
return res;
}
});
}
use of com.ramussoft.jdbc.JDBCCallback in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method setElementQualifier.
@Override
public void setElementQualifier(final long elementId, final long qualifierId) {
throwExaptionIfNotCan(getAccessor().canDeleteElements(new long[] { elementId }), "Can not update element's qualifier.");
throwExaptionIfNotCan(getAccessor().canCreateElement(qualifierId), "Can not update element's qualifier.");
Element element = getElement(elementId);
Qualifier current = getQualifier(element.getQualifierId());
Qualifier newQualifier = getQualifier(qualifierId);
final List<Attribute> attrs = new ArrayList<Attribute>();
addNotPresentAttributes(current.getAttributes(), newQualifier.getAttributes(), attrs);
addNotPresentAttributes(current.getSystemAttributes(), newQualifier.getSystemAttributes(), attrs);
template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
Transaction[] transactions = getAttributesWhatWillBeDeleted(elementId, attrs);
for (Transaction transaction : transactions) {
executeTransaction(transaction, connection);
}
PreparedStatement ps = connection.prepareStatement("UPDATE " + prefix + "elements SET QUALIFIER_ID=? WHERE ELEMENT_ID=?");
ps.setLong(1, qualifierId);
ps.setLong(2, elementId);
ps.execute();
ps.close();
return null;
}
});
}
Aggregations