Skip to content
Snippets Groups Projects

Immutable

Merged Nicola Fulvio Calabria requested to merge immutable into master
8 files
+ 359
268
Compare changes
  • Side-by-side
  • Inline
Files
8
@@ -256,7 +256,8 @@ public class NodeDAO {
+ "((SELECT COUNT(*) FROM (SELECT UNNEST(?) INTERSECT SELECT UNNEST(n.group_write)) AS allowed_groups ) = 0 AND\n"
+ "n.creator_id <> ?) AS is_permission_denied,\n"
+ "n.type = 'container' AS is_container,\n"
+ "n.job_id IS NOT NULL AS busy_state\n"
+ "n.job_id IS NOT NULL AS busy_state,\n"
+ "n.immutable AS is_immutable\n"
+ "FROM node n \n"
+ "LEFT JOIN location loc ON loc.location_id = n.location_id\n"
+ "WHERE n.node_id = id_from_vos_path(?)\n";
@@ -286,8 +287,9 @@ public class NodeDAO {
Boolean isBusy = rs.getBoolean("busy_state");
Boolean isPermissionDenied = rs.getBoolean("is_permission_denied");
Boolean isSticky = rs.getBoolean("is_sticky");
Boolean isImmutable = rs.getBoolean("is_immutable");
ShortNodeDescriptor result = new ShortNodeDescriptor(nodePath, isContainer, isWritable, isBusy, isPermissionDenied, isSticky);
ShortNodeDescriptor result = new ShortNodeDescriptor(nodePath, isContainer, isWritable, isBusy, isPermissionDenied, isSticky, isImmutable);
return Optional.of(result);
});
@@ -403,6 +405,30 @@ public class NodeDAO {
return ps;
});
}
public void setBranchImmutable(Long rootNodeId, boolean setImmutable) {
String sql = "UPDATE node c SET immutable = ? "
+ "FROM node r "
+ "WHERE r.node_id = ? "
+ "AND r.path @> c.path";
jdbcTemplate.update(conn -> {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setBoolean(1, setImmutable);
ps.setLong(2, rootNodeId);
return ps;
});
}
public boolean isBranchImmutable(long parentNodeId) {
String sql = "SELECT COUNT(c.node_id) > 0 "
+ "FROM node n "
+ "JOIN node c ON c.path <@ n.path "
+ "WHERE n.node_id = ? AND c.immutable IS TRUE";
return jdbcTemplate.queryForObject(sql, new Object[]{parentNodeId}, new int[]{Types.BIGINT}, Boolean.class);
}
public void releaseBusyNodesByJobId(String jobId) {
String sql = "UPDATE node SET job_id = NULL WHERE job_id = ?";
@@ -742,14 +768,16 @@ public class NodeDAO {
private final boolean busy;
private final boolean permissionDenied;
private final boolean sticky;
private final boolean immutable;
public ShortNodeDescriptor(String nodeLtreePath, boolean container, boolean writable, boolean busy, boolean permissionDenied, boolean sticky) {
public ShortNodeDescriptor(String nodeLtreePath, boolean container, boolean writable, boolean busy, boolean permissionDenied, boolean sticky, boolean immutable) {
this.nodeLtreePath = nodeLtreePath;
this.container = container;
this.writable = writable;
this.busy = busy;
this.permissionDenied = permissionDenied;
this.sticky = sticky;
this.immutable = immutable;
}
public String getDestinationNodeLtreePath() {
@@ -760,6 +788,10 @@ public class NodeDAO {
return container;
}
public boolean isImmutable() {
return immutable;
}
public boolean isWritable() {
return writable;
}
Loading