Search in sources :

Example 1 with JDBCCallback

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

Example 2 with JDBCCallback

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;
        }
    });
}
Also used : User(com.ramussoft.net.common.User) JDBCCallback(com.ramussoft.jdbc.JDBCCallback) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 3 with JDBCCallback

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

Example 4 with JDBCCallback

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;
        }
    });
}
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 5 with JDBCCallback

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;
        }
    });
}
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

JDBCCallback (com.ramussoft.jdbc.JDBCCallback)14 Connection (java.sql.Connection)14 PreparedStatement (java.sql.PreparedStatement)12 SQLException (java.sql.SQLException)10 FindObject (com.ramussoft.common.attribute.FindObject)5 ResultSet (java.sql.ResultSet)5 Statement (java.sql.Statement)5 Transaction (com.ramussoft.common.persistent.Transaction)4 ArrayList (java.util.ArrayList)4 Attribute (com.ramussoft.common.Attribute)3 Qualifier (com.ramussoft.common.Qualifier)2 PersistentField (com.ramussoft.common.persistent.PersistentField)2 PersistentRow (com.ramussoft.common.persistent.PersistentRow)2 User (com.ramussoft.net.common.User)2 ResultSetMetaData (java.sql.ResultSetMetaData)2 Hashtable (java.util.Hashtable)2 Element (com.ramussoft.common.Element)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1