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