public void removeFile(CmsDbContext dbc, CmsUUID projectId, CmsResource resource) throws CmsDataAccessException {

        PreparedStatement stmt = null;
        Connection conn = null;
        int siblingCount = 0;

        try {
            conn = m_sqlManager.getConnection(dbc);

            // delete the structure record
            stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_STRUCTURE_DELETE_BY_STRUCTUREID");
            stmt.setString(1, resource.getStructureId().toString());
            stmt.executeUpdate();

            m_sqlManager.closeAll(dbc, conn, stmt, null);

            // count the references to the resource
            siblingCount = countSiblings(dbc, projectId, resource.getResourceId());

            conn = m_sqlManager.getConnection(dbc);
            if (siblingCount > 0) {
                // update the link Count
                stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_RESOURCES_UPDATE_SIBLING_COUNT");
                stmt.setInt(1, siblingCount);
                stmt.setString(2, resource.getResourceId().toString());
                stmt.executeUpdate();

                m_sqlManager.closeAll(dbc, null, stmt, null);

                // update the resource flags
                stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_RESOURCES_UPDATE_FLAGS");
                stmt.setInt(1, resource.getFlags());
                stmt.setString(2, resource.getResourceId().toString());
                stmt.executeUpdate();

            } else {
                // if not referenced any longer, also delete the resource and the content record
                stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_RESOURCES_DELETE_BY_RESOURCEID");
                stmt.setString(1, resource.getResourceId().toString());
                stmt.executeUpdate();

                m_sqlManager.closeAll(dbc, null, stmt, null);

                boolean dbcHasProjectId = (dbc.getProjectId() != null) && !dbc.getProjectId().isNullUUID();

                // if online we have to keep historical content
                if (projectId.equals(CmsProject.ONLINE_PROJECT_ID)) {
                    // put the online content in the history
                    stmt = m_sqlManager.getPreparedStatement(conn, "C_ONLINE_CONTENTS_HISTORY");
                    stmt.setString(1, resource.getResourceId().toString());
                    stmt.executeUpdate();
                } else if (dbcHasProjectId) {
                    // remove current online version
                    stmt = m_sqlManager.getPreparedStatement(conn, "C_ONLINE_CONTENTS_DELETE");
                    stmt.setString(1, resource.getResourceId().toString());
                    stmt.executeUpdate();
                } else {
                    // delete content records with this resource id
                    stmt = m_sqlManager.getPreparedStatement(conn, projectId, "C_OFFLINE_FILE_CONTENT_DELETE");
                    stmt.setString(1, resource.getResourceId().toString());
                    stmt.executeUpdate();
                }
            }
        } catch (SQLException e) {
            throw new CmsDbSqlException(
                Messages.get().container(Messages.ERR_GENERIC_SQL_1, CmsDbSqlException.getErrorQuery(stmt)),
                e);
        } finally {
            m_sqlManager.closeAll(dbc, conn, stmt, null);
        }
    }
public void removeFile ( CmsDbContext dbc , CmsUUID projectId , CmsResource resource ) throws CmsDataAccessException { PreparedStatement stmt = null ; Connection conn = null ; int siblingCount = 0 ; try { conn = m_sqlManager . getConnection ( dbc ) ; stmt = m_sqlManager . getPreparedStatement ( conn , projectId , "C_STRUCTURE_DELETE_BY_STRUCTUREID" ) ; stmt . setString ( 1 , resource . getStructureId ( ) . toString ( ) ) ; stmt . executeUpdate ( ) ; m_sqlManager . closeAll ( dbc , conn , stmt , null ) ; siblingCount = countSiblings ( dbc , projectId , resource . getResourceId ( ) ) ; conn = m_sqlManager . getConnection ( dbc ) ; if ( siblingCount > 0 ) { stmt = m_sqlManager . getPreparedStatement ( conn , projectId , "C_RESOURCES_UPDATE_SIBLING_COUNT" ) ; stmt . setInt ( 1 , siblingCount ) ; stmt . setString ( 2 , resource . getResourceId ( ) . toString ( ) ) ; stmt . executeUpdate ( ) ; m_sqlManager . closeAll ( dbc , null , stmt , null ) ; stmt = m_sqlManager . getPreparedStatement ( conn , projectId , "C_RESOURCES_UPDATE_FLAGS" ) ; stmt . setInt ( 1 , resource . getFlags ( ) ) ; stmt . setString ( 2 , resource . getResourceId ( ) . toString ( ) ) ; stmt . executeUpdate ( ) ; } else { stmt = m_sqlManager . getPreparedStatement ( conn , projectId , "C_RESOURCES_DELETE_BY_RESOURCEID" ) ; stmt . setString ( 1 , resource . getResourceId ( ) . toString ( ) ) ; stmt . executeUpdate ( ) ; m_sqlManager . closeAll ( dbc , null , stmt , null ) ; boolean dbcHasProjectId = ( dbc . getProjectId ( ) != null ) && ! dbc . getProjectId ( ) . isNullUUID ( ) ; if ( projectId . equals ( CmsProject . ONLINE_PROJECT_ID ) ) { stmt = m_sqlManager . getPreparedStatement ( conn , "C_ONLINE_CONTENTS_HISTORY" ) ; stmt . setString ( 1 , resource . getResourceId ( ) . toString ( ) ) ; stmt . executeUpdate ( ) ; } else if ( dbcHasProjectId ) { stmt = m_sqlManager . getPreparedStatement ( conn , "C_ONLINE_CONTENTS_DELETE" ) ; stmt . setString ( 1 , resource . getResourceId ( ) . toString ( ) ) ; stmt . executeUpdate ( ) ; } else { stmt = m_sqlManager . getPreparedStatement ( conn , projectId , "C_OFFLINE_FILE_CONTENT_DELETE" ) ; stmt . setString ( 1 , resource . getResourceId ( ) . toString ( ) ) ; stmt . executeUpdate ( ) ; } } } catch ( SQLException e ) { throw new CmsDbSqlException ( Messages . get ( ) . container ( Messages . ERR_GENERIC_SQL_1 , CmsDbSqlException . getErrorQuery ( stmt ) ) , e ) ; } finally { m_sqlManager . closeAll ( dbc , conn , stmt , null ) ; } }
@see org.opencms.db.I_CmsVfsDriver#removeFile(org.opencms.db.CmsDbContext, CmsUUID, org.opencms.file.CmsResource)