@Override
    public void persist(final String key, final String value) {
        try {
            if (isExisted(key)) {
                update(key, value);
                return;
            }
            String tempPrefix = "";
            String parent = SEPARATOR;
            String[] paths = Arrays.stream(key.split(SEPARATOR)).filter(each -> !Strings.isNullOrEmpty(each)).toArray(String[]::new);
            // Create key level directory recursively.
            for (int i = 0; i < paths.length - 1; i++) {
                String tempKey = tempPrefix + SEPARATOR + paths[i];
                if (!isExisted(tempKey)) {
                    insert(tempKey, "", parent);
                }
                tempPrefix = tempKey;
                parent = tempKey;
            }
            insert(key, value, parent);
        } catch (final SQLException ex) {
            log.error("Persist {} data to key: {} failed", getType(), key, ex);
        }
    }
@Test
    void assertPersistForDirectory() throws SQLException {
        final String key = "/parent/child/test1";
        final String value = "test1_content";
        when(mockJdbcConnection.prepareStatement(repositorySQL.getSelectByKeySQL())).thenReturn(mockPreparedStatement);
        when(mockJdbcConnection.prepareStatement(repositorySQL.getInsertSQL())).thenReturn(mockPreparedStatementForPersist);
        when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
        repository.persist(key, value);
        int depthOfDirectory = (int) key.chars().filter(each -> each == '/').count();
        int beginIndex = 0;
        String parentDirectory = "/";
        for (int i = 0; i < depthOfDirectory; i++) {
            int separatorIndex = key.indexOf('/', beginIndex);
            int nextSeparatorIndex = key.indexOf('/', separatorIndex + 1);
            if (nextSeparatorIndex == -1) {
                nextSeparatorIndex = key.length();
            }
            String directoryPath = key.substring(0, nextSeparatorIndex);
            // Verifying if get operation is called for every directory level
            verify(mockPreparedStatement).setString(1, directoryPath);
            // Verifying that during insert operation, setString at index 2 is called for every directory level
            verify(mockPreparedStatementForPersist).setString(2, directoryPath);
            // Verifying that during insert operation, setString at index 4 is called for every parent directory
            verify(mockPreparedStatementForPersist).setString(4, parentDirectory);
            beginIndex = nextSeparatorIndex;
            parentDirectory = directoryPath;
        }
        // Verifying that during insert operation, setString at index 3 is called with "" for all the parent directories
        verify(mockPreparedStatementForPersist, times(depthOfDirectory - 1)).setString(3, "");
        // Verifying that during insert operation, setString at index 3 is called with the leaf node once
        verify(mockPreparedStatementForPersist).setString(3, "test1_content");
        // Verifying that during insert operation, setString at index 1 is called with a UUID
        verify(mockPreparedStatementForPersist, times(depthOfDirectory)).setString(eq(1), anyString());
        // Verifying that executeOperation in insert is called for all the directory levels
        verify(mockPreparedStatementForPersist, times(depthOfDirectory)).executeUpdate();
    }