Project

General

Profile

« Previous | Next » 

Revision 634

Added by berkley almost 24 years ago

updating a package file now updates the relations that are created from it. Also, if you delete a package file, it will delete the relations associated with it.

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
799 799
                              String group, int serverCode, boolean override)
800 800
                throws Exception
801 801
  {
802
    if(action.equals("UPDATE"))
803
    {
804
      RelationHandler.deleteRelations(docid);
805
    }
806
    
802 807
    int updaterev;
803 808
    MetaCatUtil util = new MetaCatUtil();
804 809
        // Determine if the docid is OK for INSERT or UPDATE
......
981 986
    stmt.close();
982 987
    conn.commit();
983 988
    conn.setAutoCommit(true);
984
    
989
    //IF this is a package document:
990
    //delete all of the relations that this document created.
991
    //if the deleted document is a package document its relations should 
992
    //no longer be active if it has been deleted from the system.
993
    RelationHandler.deleteRelations(docid);
985 994
  }
986 995
  
987 996
  /** 
src/edu/ucsb/nceas/metacat/RelationHandler.java
105 105
          if(object.equals(currentObj))
106 106
          {//there is a transitive relation so add a new relation to the table
107 107
            StringBuffer insertTransRelation = new StringBuffer();
108
            insertTransRelation.append("insert into xml_relation (subject, ");
108
            insertTransRelation.append("insert into xml_relation (docid, ");
109
            insertTransRelation.append(" subject, ");
109 110
            insertTransRelation.append("subdoctype, relationship, object, ");
110 111
            insertTransRelation.append("objdoctype) values ('");
112
            insertTransRelation.append(docid).append("', '");
111 113
            insertTransRelation.append(currentSub).append("', '");
112 114
            insertTransRelation.append(currentSubDoctype).append("', ");
113 115
            insertTransRelation.append("'hasTransitiveRelationTo', '");
114 116
            insertTransRelation.append(subject).append("', '");
115 117
            insertTransRelation.append(subjectDoctype).append("')");
118
            //System.out.println("sql1: " + insertTransRelation.toString());
116 119
            pstmt = conn.prepareStatement(insertTransRelation.toString());
117 120
            pstmt.execute(); 
118 121
            
119 122
            insertTransRelation = new StringBuffer();
120 123
            //put the same relation in with the subject and object switched
121
            insertTransRelation.append("insert into xml_relation (subject, ");
124
            insertTransRelation.append("insert into xml_relation (docid, ");
125
            insertTransRelation.append(" subject, ");
122 126
            insertTransRelation.append("subdoctype, relationship, object, ");
123 127
            insertTransRelation.append("objdoctype) values ('");
128
            insertTransRelation.append(docid).append("', '");
124 129
            insertTransRelation.append(subject).append("', '");
125 130
            insertTransRelation.append(subjectDoctype).append("', ");
126 131
            insertTransRelation.append("'hasTransitiveRelationTo', '");
127 132
            insertTransRelation.append(currentSub).append("', '");
128 133
            insertTransRelation.append(currentSubDoctype).append("')");
134
            //System.out.println("sql2: " + insertTransRelation.toString());
129 135
            pstmt = conn.prepareStatement(insertTransRelation.toString());
130 136
            pstmt.execute();
131 137
          }
......
151 157
        //now that the comparisons are done, the new relation can be put
152 158
        //into xml_relation
153 159
        StringBuffer insertStmt = new StringBuffer();
154
        insertStmt.append("insert into xml_relation (subject, subdoctype, ");
160
        insertStmt.append("insert into xml_relation (docid, subject, ");
161
        insertStmt.append("subdoctype, ");
155 162
        insertStmt.append("relationship, object, objdoctype) values ('");
163
        insertStmt.append(docid).append("', '");
156 164
        insertStmt.append(subject).append("', '");
157 165
        insertStmt.append(subDoctype).append("', '");
158 166
        insertStmt.append(relationship).append("', '");
......
182 190
      btThread = null;
183 191
    }
184 192
  }
193
  
194
  /**
195
   * Deletes all of the relations with a docid of 'docid'.
196
   * @param docid the docid to delete.
197
   */
198
  public static void deleteRelations(String docid)
199
  {
200
    try
201
    {
202
      MetaCatUtil util2 = new MetaCatUtil();
203
      Connection conn = util2.openDBConnection();
204
      PreparedStatement pstmt = conn.prepareStatement("delete from " +
205
                             "xml_relation where docid like '" + docid + "'");
206
      pstmt.execute();
207
    }
208
    catch(Exception e)
209
    {
210
      System.out.println("error in deleteRelations(): " + e.getMessage());
211
      e.printStackTrace(System.out);
212
    }
213
    
214
  }
185 215
}

Also available in: Unified diff