Search in sources :

Example 1 with VRLSyntaxException

use of nl.uva.vlet.exception.VRLSyntaxException in project lobcder by skoulouzis.

the class JDBCatalogue method setLocationPreferences.

public void setLocationPreferences(Connection connection, Long uid, List<String> locationPreferences, Boolean includePrivate) throws SQLException {
    if (locationPreferences != null && !locationPreferences.isEmpty()) {
        String storageSitesQuery = "select storageSiteId,resourceUri,private from storage_site_table " + // use =
        "WHERE resourceUri LIKE ";
        for (String site : locationPreferences) {
            try {
                new VRL(site);
                storageSitesQuery += "'" + site + "' OR resourceUri LIKE ";
            } catch (VRLSyntaxException ex) {
                Logger.getLogger(JDBCatalogue.class.getName()).log(Level.WARNING, "Wrong VRL", ex);
            }
        }
        if (storageSitesQuery.endsWith(" OR resourceUri LIKE ")) {
            storageSitesQuery = storageSitesQuery.substring(0, storageSitesQuery.lastIndexOf("OR")) + "";
        }
        storageSitesQuery += " AND isCache = false";
        List<Long> ids = new ArrayList<>();
        try (Statement s = connection.createStatement()) {
            try (ResultSet rs = s.executeQuery(storageSitesQuery)) {
                while (rs.next()) {
                    if (rs.getBoolean(3) && includePrivate) {
                        ids.add(rs.getLong(1));
                    } else if (!rs.getBoolean(3)) {
                        ids.add(rs.getLong(1));
                    }
                }
            }
            if (!ids.isEmpty()) {
                try (PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM pref_table WHERE ld_uid = ?")) {
                    preparedStatement.setLong(1, uid);
                    preparedStatement.executeUpdate();
                }
                // connection.commit();
                try (PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO pref_table (ld_uid, storageSiteRef) VALUES(?,?)")) {
                    for (Long id : ids) {
                        preparedStatement.setLong(1, uid);
                        preparedStatement.setLong(2, id);
                        preparedStatement.addBatch();
                    // preparedStatement.executeUpdate();
                    }
                    preparedStatement.executeBatch();
                }
                Collection<LogicalData> children = getChildrenByParentRef(uid);
                for (LogicalData child : children) {
                    if (!child.isFolder()) {
                        setLocationPreferences(connection, child.getUid(), locationPreferences, includePrivate);
                    }
                }
                setNeedsCheck(uid, connection);
            }
        }
    }
    connection.commit();
// return locationPreferences;//getDataLocationPreferace(connection, uid);
}
Also used : VRL(nl.uva.vlet.vrl.VRL) LogicalData(nl.uva.cs.lobcder.resources.LogicalData) VRLSyntaxException(nl.uva.vlet.exception.VRLSyntaxException)

Aggregations

LogicalData (nl.uva.cs.lobcder.resources.LogicalData)1 VRLSyntaxException (nl.uva.vlet.exception.VRLSyntaxException)1 VRL (nl.uva.vlet.vrl.VRL)1