use of com.ramussoft.common.persistent.Transaction in project ramus by Vitaliy-Yakovchuk.
the class UpdateQualifierCommand method writeBody.
@Override
public void writeBody(BinaryDataOutput output) throws IOException {
storeQualifier(output, oldQualifier);
storeQualifier(output, newQualifier);
for (Attribute attribute : deletedAttributes) {
Hashtable<Long, Transaction> hash = hashtable.get(attribute.getId());
output.writeInt(hash.size());
for (Entry<Long, Transaction> entry : hash.entrySet()) {
output.writeLong(entry.getKey());
output.writeInt(entry.getValue().getDelete().size());
for (Persistent p : entry.getValue().getDelete()) {
TransactionStorageCommand.storePersistent(engine, output, p);
}
}
}
}
use of com.ramussoft.common.persistent.Transaction in project ramus by Vitaliy-Yakovchuk.
the class UpdateQualifierCommand method undo.
@Override
public void undo(IEngine iEngine) {
iEngine.updateQualifier(oldQualifier);
QualifierEvent event = new QualifierEvent(engine, newQualifier, oldQualifier, true);
for (Attribute attribute : deletedAttributes) {
for (Entry<Long, Transaction> entry : hashtable.get(attribute.getId()).entrySet()) {
iEngine.setBinaryAttribute(entry.getKey(), attribute.getId(), entry.getValue());
Element element = iEngine.getElement(entry.getKey());
AttributeEvent event2 = new AttributeEvent(engine, element, attribute, null, engine.getAttribute(element, attribute), true);
engine.attributeChanged(event2);
}
}
if (oldQualifier.getAttributeForName() != newQualifier.getAttributeForName())
getEngine().updateElementNames(newQualifier, oldQualifier);
engine.qualifierUpdated(event);
}
use of com.ramussoft.common.persistent.Transaction in project ramus by Vitaliy-Yakovchuk.
the class SetElementQualifierCommand method writeBody.
@Override
public void writeBody(BinaryDataOutput output) throws IOException {
output.writeLong(oldQualifierId);
output.writeLong(newQualifierId);
output.writeLong(elementId);
output.writeInt(data.length);
for (Transaction transaction : data) {
output.writeInt(transaction.getDelete().size());
for (Persistent persistent : transaction.getDelete()) {
TransactionStorageCommand.storePersistent(engine, output, persistent);
}
}
}
use of com.ramussoft.common.persistent.Transaction 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.common.persistent.Transaction 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++;
}
}
Aggregations