Commit fb5a87c6 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

added immutable node dao methods

parent 6622ea34
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -404,6 +404,30 @@ public class NodeDAO {
        });
    }
    
    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 = ?";

+21 −1
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ public class NodeDAOTest {
        ReflectionTestUtils.setField(dao, "authority", AUTHORITY);
    }


    @Test
    public void testCreateNode() {
        DataNode dataNode = new DataNode();
@@ -275,6 +274,27 @@ public class NodeDAOTest {

    }

    @Test
    public void testSetImmutable() {
        Optional<Long> optId = dao.getNodeId("/test3/m1");
        assertTrue(optId.isPresent());

        assertFalse(dao.isBranchImmutable(optId.get()));

        dao.setBranchImmutable(optId.get(), true);

        assertTrue(dao.isBranchImmutable(optId.get()));

        Optional<Long> childId = dao.getNodeId("/test3/m1/m2");
        assertTrue(childId.isPresent());

        assertTrue(dao.isBranchImmutable(childId.get()));

        dao.setBranchImmutable(optId.get(), false);

        assertFalse(dao.isBranchBusy(optId.get()));
        assertFalse(dao.isBranchBusy((childId.get())));
    }

    @Test
    public void testMoveNodeBranch() {