Search in sources :

Example 11 with LogicalData

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

the class DBMapPredictor method getLogicalDataByUid.

public LogicalData getLogicalDataByUid(Long UID, @Nonnull Connection connection) throws SQLException {
    LogicalData res = null;
    if (res != null) {
        return res;
    }
    try (PreparedStatement ps = connection.prepareStatement("SELECT parentRef, ownerId, datatype, ldName, " + "createDate, modifiedDate, ldLength, contentTypesStr, pdriGroupRef, " + "isSupervised, checksum, lastValidationDate, lockTokenID, lockScope, " + "lockType, lockedByUser, lockDepth, lockTimeout, description, locationPreference, status " + "FROM ldata_table WHERE ldata_table.uid = ?")) {
        ps.setLong(1, UID);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            res = new LogicalData();
            res.setUid(UID);
            res.setParentRef(rs.getLong(1));
            res.setOwner(rs.getString(2));
            res.setType(rs.getString(3));
            res.setName(rs.getString(4));
            res.setCreateDate(rs.getTimestamp(5).getTime());
            res.setModifiedDate(rs.getTimestamp(6).getTime());
            res.setLength(rs.getLong(7));
            res.setContentTypesAsString(rs.getString(8));
            res.setPdriGroupId(rs.getLong(9));
            res.setSupervised(rs.getBoolean(10));
            res.setChecksum(rs.getString(11));
            res.setLastValidationDate(rs.getLong(12));
            res.setLockTokenID(rs.getString(13));
            res.setLockScope(rs.getString(14));
            res.setLockType(rs.getString(15));
            res.setLockedByUser(rs.getString(16));
            res.setLockDepth(rs.getString(17));
            res.setLockTimeout(rs.getLong(18));
            res.setDescription(rs.getString(19));
            // res.setDataLocationPreference(rs.getString(20));
            res.setStatus(rs.getString(21));
            return res;
        } else {
            return null;
        }
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 12 with LogicalData

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

the class DBMapPredictor method getLogicalDataByPath.

public LogicalData getLogicalDataByPath(Path logicalResourceName, @Nonnull Connection connection) throws SQLException {
    LogicalData res = null;
    if (res != null) {
        return res;
    }
    try (PreparedStatement preparedStatement = connection.prepareStatement("SELECT uid FROM ldata_table WHERE ldata_table.parentRef = ? AND ldata_table.ldName = ?")) {
        long parent = 1;
        String[] parts = logicalResourceName.getParts();
        if (parts.length == 0) {
            parts = new String[] { "" };
        }
        for (int i = 0; i != parts.length; ++i) {
            String p = parts[i];
            if (i == (parts.length - 1)) {
                try (PreparedStatement preparedStatement1 = connection.prepareStatement("SELECT uid, ownerId, datatype, createDate, modifiedDate, ldLength, " + "contentTypesStr, pdriGroupRef, isSupervised, checksum, lastValidationDate, " + "lockTokenID, lockScope, lockType, lockedByUser, lockDepth, lockTimeout, " + "description, locationPreference, status " + "FROM ldata_table WHERE ldata_table.parentRef = ? AND ldata_table.ldName = ?")) {
                    preparedStatement1.setLong(1, parent);
                    preparedStatement1.setString(2, p);
                    ResultSet rs = preparedStatement1.executeQuery();
                    if (rs.next()) {
                        res = new LogicalData();
                        res.setUid(rs.getLong(1));
                        res.setParentRef(parent);
                        res.setOwner(rs.getString(2));
                        res.setType(rs.getString(3));
                        res.setName(p);
                        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));
                        res.setStatus(rs.getString(20));
                        return res;
                    } else {
                        return null;
                    }
                }
            } else {
                preparedStatement.setLong(1, parent);
                preparedStatement.setString(2, p);
                ResultSet rs = preparedStatement.executeQuery();
                if (rs.next()) {
                    parent = rs.getLong(1);
                } else {
                    return null;
                }
            }
        }
        return null;
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 13 with LogicalData

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

the class RandomPredictor method getRandomLogicalData.

private LogicalData getRandomLogicalData(@Nonnull Connection connection) throws SQLException {
    LogicalData res = null;
    if (res != null) {
        return res;
    }
    try (PreparedStatement ps = connection.prepareStatement("SELECT uid,parentRef, ownerId, datatype, ldName, " + "createDate, modifiedDate, ldLength, contentTypesStr, pdriGroupRef, " + "isSupervised, checksum, lastValidationDate, lockTokenID, lockScope, " + "lockType, lockedByUser, lockDepth, lockTimeout, description, locationPreference, status " + "FROM ldata_table ORDER BY RAND() LIMIT 1")) {
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            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.setDataLocationPreference(rs.getString(21));
            res.setStatus(rs.getString(22));
            return res;
        } else {
            return null;
        }
    }
}
Also used : LogicalData(nl.uva.cs.lobcder.resources.LogicalData) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 14 with LogicalData

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

the class JDBCatalogue method setLockScope.

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

Example 15 with LogicalData

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

the class JDBCatalogue method setFileChecksum.

public void setFileChecksum(@Nonnull Long uid, @Nonnull String checksum, @Nonnull Connection connection) throws SQLException {
    try (PreparedStatement ps = connection.prepareStatement("UPDATE ldata_table SET checksum = ? WHERE uid = ?")) {
        ps.setString(1, checksum);
        ps.setLong(2, uid);
        ps.executeUpdate();
    }
    LogicalData cached = getFromLDataCache(uid, null);
    if (cached != null) {
        cached.setChecksum(checksum);
        putToLDataCache(cached, null);
    }
}
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