Search in sources :

Example 16 with Transaction

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);
            }
        }
    }
}
Also used : Transaction(com.ramussoft.common.persistent.Transaction) Attribute(com.ramussoft.common.Attribute) Persistent(com.ramussoft.common.persistent.Persistent)

Example 17 with Transaction

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);
}
Also used : Transaction(com.ramussoft.common.persistent.Transaction) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) QualifierEvent(com.ramussoft.common.event.QualifierEvent) AttributeEvent(com.ramussoft.common.event.AttributeEvent)

Example 18 with Transaction

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);
        }
    }
}
Also used : Transaction(com.ramussoft.common.persistent.Transaction) Persistent(com.ramussoft.common.persistent.Persistent)

Example 19 with Transaction

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;
        }
    });
}
Also used : Transaction(com.ramussoft.common.persistent.Transaction) SQLException(java.sql.SQLException) JDBCCallback(com.ramussoft.jdbc.JDBCCallback) Connection(java.sql.Connection) FindObject(com.ramussoft.common.attribute.FindObject) PreparedStatement(java.sql.PreparedStatement)

Example 20 with Transaction

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++;
    }
}
Also used : Transaction(com.ramussoft.common.persistent.Transaction) Attribute(com.ramussoft.common.Attribute) SQLException(java.sql.SQLException) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) JDBCCallback(com.ramussoft.jdbc.JDBCCallback) Connection(java.sql.Connection) FindObject(com.ramussoft.common.attribute.FindObject) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Transaction (com.ramussoft.common.persistent.Transaction)21 Attribute (com.ramussoft.common.Attribute)9 Persistent (com.ramussoft.common.persistent.Persistent)6 ArrayList (java.util.ArrayList)6 Element (com.ramussoft.common.Element)5 FindObject (com.ramussoft.common.attribute.FindObject)5 SQLException (java.sql.SQLException)5 JDBCCallback (com.ramussoft.jdbc.JDBCCallback)4 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 Qualifier (com.ramussoft.common.Qualifier)3 Hashtable (java.util.Hashtable)3 ElementEvent (com.ramussoft.common.event.ElementEvent)2 PersistentField (com.ramussoft.common.persistent.PersistentField)2 PersistentRow (com.ramussoft.common.persistent.PersistentRow)2 PersistentWrapper (com.ramussoft.common.persistent.PersistentWrapper)2 List (java.util.List)2 Engine (com.ramussoft.common.Engine)1 IEngine (com.ramussoft.common.IEngine)1 AbstractAttributeConverter (com.ramussoft.common.attribute.AbstractAttributeConverter)1