Search in sources :

Example 51 with LogicalData

use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.

the class JDBCatalogue method updateOwner.

public void updateOwner(@Nonnull Long uid, @Nonnull String owner, @Nonnull Connection connection) throws SQLException {
    try (PreparedStatement ps = connection.prepareStatement("UPDATE ldata_table SET ownerId = ? WHERE uid = ?")) {
        ps.setString(1, owner);
        ps.setLong(2, uid);
        ps.executeUpdate();
    }
    LogicalData cached = getFromLDataCache(uid, null);
    if (cached != null) {
        cached.setOwner(owner);
        putToLDataCache(cached, null);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData)

Example 52 with LogicalData

use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.

the class JDBCatalogue method setLastValidationDate.

public void setLastValidationDate(@Nonnull Long uid, @Nonnull Long lastValidationDate, @Nonnull Connection connection) throws SQLException {
    try (PreparedStatement ps = connection.prepareStatement("UPDATE ldata_table SET lastValidationDate = ? WHERE uid = ?")) {
        ps.setLong(1, lastValidationDate);
        ps.setLong(2, uid);
        ps.executeUpdate();
    }
    LogicalData cached = getFromLDataCache(uid, null);
    if (cached != null) {
        cached.setLastValidationDate(lastValidationDate);
        putToLDataCache(cached, null);
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData)

Example 53 with LogicalData

use of nl.uva.cs.lobcder.resources.LogicalData 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)

Example 54 with LogicalData

use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.

the class JDBCatalogue method getLogicalDataByParentRefAndName.

public LogicalData getLogicalDataByParentRefAndName(Long parentRef, String name, @Nonnull Connection connection) throws SQLException {
    try (PreparedStatement preparedStatement = connection.prepareStatement("SELECT uid, ownerId, datatype, createDate, modifiedDate, ldLength, " + "contentTypesStr, pdriGroupRef, isSupervised, checksum, lastValidationDate, " + "lockTokenId, lockScope, lockType, lockedByUser, lockDepth, lockTimeout, " + "description, accessDate, ttlSec " + // + ", resourceUri "
    "FROM ldata_table " + // + "JOIN storage_site_table ON storageSiteId = storageSiteRef"
    "WHERE ldata_table.parentRef = " + parentRef + " AND ldata_table.ldName like '" + name + "'")) {
        // preparedStatement.setLong(1, parentRef);
        // preparedStatement.setString(2, name);
        ResultSet rs = preparedStatement.executeQuery();
        if (rs.next()) {
            LogicalData res = new LogicalData();
            res.setUid(rs.getLong(1));
            res.setParentRef(parentRef);
            res.setOwner(rs.getString(2));
            res.setType(rs.getString(3));
            res.setName(name);
            res.setCreateDate(rs.getTimestamp(4).getTime());
            res.setModifiedDate(rs.getTimestamp(5).getTime());
            res.setLength(rs.getLong(6));
            res.setContentTypesAsString(rs.getString(7));
            res.setPdriGroupId(rs.getLong(8));
            res.setSupervised(rs.getBoolean(9));
            res.setChecksum(rs.getString(10));
            res.setLastValidationDate(rs.getLong(11));
            res.setLockTokenID(rs.getString(12));
            res.setLockScope(rs.getString(13));
            res.setLockType(rs.getString(14));
            res.setLockedByUser(rs.getString(15));
            res.setLockDepth(rs.getString(16));
            res.setLockTimeout(rs.getLong(17));
            res.setDescription(rs.getString(18));
            // res.setDataLocationPreference(rs.getString(19));
            Timestamp ts = rs.getTimestamp(19);
            res.setLastAccessDate(ts != null ? ts.getTime() : null);
            int ttl = rs.getInt(20);
            res.setTtlSec(rs.wasNull() ? null : ttl);
            return res;
        } else {
            return null;
        }
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData)

Example 55 with LogicalData

use of nl.uva.cs.lobcder.resources.LogicalData in project lobcder by skoulouzis.

the class JDBCatalogue method getReplicationQueue.

public List<LogicalData> getReplicationQueue(Connection connection) throws SQLException {
    List<LogicalData> list = new ArrayList<>();
    try (PreparedStatement ps = connection.prepareStatement("SELECT uid, parentRef, " + "ownerId, datatype, ldName, createDate, modifiedDate, ldLength, " + "contentTypesStr, pdri_table.pdriGroupRef, isSupervised, checksum, " + "lastValidationDate, lockTokenID, lockScope, lockType, lockedByUser, " + "lockDepth, lockTimeout, description, locationPreference, status, accessDate, ttlSec " + "FROM pdri_table " + "JOIN ldata_table ON pdri_table.pdriGroupRef = ldata_table.pdriGroupRef " + "JOIN storage_site_table ON storage_site_table.storageSiteId = pdri_table.storageSiteRef " + "WHERE isCache = true")) {
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            LogicalData res = new LogicalData();
            res.setUid(rs.getLong(1));
            res.setParentRef(rs.getLong(2));
            res.setOwner(rs.getString(3));
            res.setType(rs.getString(4));
            res.setName(rs.getString(5));
            res.setCreateDate(rs.getTimestamp(6).getTime());
            res.setModifiedDate(rs.getTimestamp(7).getTime());
            res.setLength(rs.getLong(8));
            res.setContentTypesAsString(rs.getString(9));
            res.setPdriGroupId(rs.getLong(10));
            res.setSupervised(rs.getBoolean(11));
            res.setChecksum(rs.getString(12));
            res.setLastValidationDate(rs.getLong(13));
            res.setLockTokenID(rs.getString(14));
            res.setLockScope(rs.getString(15));
            res.setLockType(rs.getString(16));
            res.setLockedByUser(rs.getString(17));
            res.setLockDepth(rs.getString(18));
            res.setLockTimeout(rs.getLong(19));
            res.setDescription(rs.getString(20));
            res.setStatus(rs.getString(21));
            res.setLastAccessDate(rs.getTimestamp(22) != null ? rs.getTimestamp(22).getTime() : null);
            int ttl = rs.getInt(23);
            res.setTtlSec(rs.wasNull() ? null : ttl);
            list.add(res);
        }
    }
    return list;
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData)

Aggregations

LogicalData (nl.uva.cs.lobcder.resources.LogicalData)71 Connection (java.sql.Connection)29 SQLException (java.sql.SQLException)29 Permissions (nl.uva.cs.lobcder.auth.Permissions)29 MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)20 PreparedStatement (java.sql.PreparedStatement)11 ResultSet (java.sql.ResultSet)10 Path (io.milton.common.Path)7 ArrayList (java.util.ArrayList)7 BadRequestException (io.milton.http.exceptions.BadRequestException)6 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)5 PDRIDescr (nl.uva.cs.lobcder.resources.PDRIDescr)5 ConflictException (io.milton.http.exceptions.ConflictException)4 URISyntaxException (java.net.URISyntaxException)4 Stack (java.util.Stack)4 Path (javax.ws.rs.Path)4 LogicalDataWrapped (nl.uva.cs.lobcder.rest.wrappers.LogicalDataWrapped)4 VRL (nl.uva.vlet.vrl.VRL)4 PreConditionFailedException (io.milton.http.exceptions.PreConditionFailedException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3