Search in sources :

Example 11 with Qualifier

use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.

the class Data method findRow.

public Row findRow(long eleemntId) {
    long id = engine.getQualifierIdForElement(eleemntId);
    Qualifier qualifier = getQualifier(id);
    if (qualifier == null)
        return null;
    return (Row) getRowSet(id).findRow(eleemntId);
}
Also used : Qualifier(com.ramussoft.common.Qualifier)

Example 12 with Qualifier

use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.

the class Data method getQualifier.

public Qualifier getQualifier(long qualifierId) {
    Qualifier qualifier = qualifierByIds.get(qualifierId);
    if (qualifier == null) {
        qualifier = engine.getQualifier(qualifierId);
        if (qualifier == null)
            return null;
        qualifierByIds.put(qualifierId, qualifier);
    }
    return qualifier;
}
Also used : Qualifier(com.ramussoft.common.Qualifier)

Example 13 with Qualifier

use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.

the class ServerAccessRules method canDeleteQualifier.

@Override
public boolean canDeleteQualifier(long qualifierId) {
    boolean admin = isAdmin();
    if (admin)
        return true;
    Qualifier q = engine.getQualifier(qualifierId);
    if (q == null)
        return false;
    if (q.isSystem())
        return true;
    return admin;
}
Also used : Qualifier(com.ramussoft.common.Qualifier)

Example 14 with Qualifier

use of com.ramussoft.common.Qualifier 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;
        }
    });
}
Also used : Attribute(com.ramussoft.common.Attribute) JDBCCallback(com.ramussoft.jdbc.JDBCCallback) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Qualifier(com.ramussoft.common.Qualifier) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 15 with Qualifier

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

Aggregations

Qualifier (com.ramussoft.common.Qualifier)157 Attribute (com.ramussoft.common.Attribute)72 Element (com.ramussoft.common.Element)59 ArrayList (java.util.ArrayList)45 Engine (com.ramussoft.common.Engine)22 Row (com.ramussoft.database.common.Row)17 Row (com.ramussoft.pb.Row)14 List (java.util.List)12 Hashtable (java.util.Hashtable)11 QualifierEvent (com.ramussoft.common.event.QualifierEvent)10 ResultSet (java.sql.ResultSet)9 SQLException (java.sql.SQLException)9 AttributeType (com.ramussoft.common.AttributeType)8 RowSet (com.ramussoft.database.common.RowSet)8 DataPlugin (com.ramussoft.pb.DataPlugin)8 NFunction (com.ramussoft.pb.data.negine.NFunction)8 AttributeEvent (com.ramussoft.common.event.AttributeEvent)7 Journaled (com.ramussoft.common.journal.Journaled)7 RowMapper (com.ramussoft.jdbc.RowMapper)7 IEngine (com.ramussoft.common.IEngine)6