code: protected void internalCleanup(CmsDbContext dbc, I_CmsHistoryResource resource) throws CmsDataAccessException {
  
          Connection conn = null;
          PreparedStatement stmt = null;
          ResultSet res = null;
          Map<CmsUUID, Integer> tmpSubResources = new HashMap<CmsUUID, Integer>();
  
          // if is folder and if no versions left
          boolean isFolderAndNoVersionLeft = resource.getRootPath().endsWith("/")
              && (readLastVersion(dbc, resource.getStructureId()) == 0);
  
          // if the resource is a folder
          if (isFolderAndNoVersionLeft) {
              try {
                  conn = m_sqlManager.getConnection(dbc);
                  // get all direct subresources
                  stmt = m_sqlManager.getPreparedStatement(conn, "C_STRUCTURE_HISTORY_READ_SUBRESOURCES");
                  stmt.setString(1, resource.getStructureId().toString());
                  res = stmt.executeQuery();
                  while (res.next()) {
                      CmsUUID structureId = new CmsUUID(res.getString(1));
                      int version = res.getInt(2);
                      tmpSubResources.put(structureId, Integer.valueOf(version));
                  }
              } 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, res);
              }
          }
          // delete all subresource versions
          for (Map.Entry<CmsUUID, Integer> entry : tmpSubResources.entrySet()) {
              I_CmsHistoryResource histResource = readResource(dbc, entry.getKey(), entry.getValue().intValue());
              deleteEntries(dbc, histResource, 0, -1);
          }
      }
docs: Deletes all historical entries of subresources of a folder without any historical netry left.<p>
  
  @param dbc the current database context
  @param resource the resource to check
  
  @throws CmsDataAccessException if something goes wrong