Project

General

Profile

« Previous | Next » 

Revision 6375

include obsoletes and obsoletedBy for system metadata
repurpose the "provenance" table as the ORE mapping table for system metadata

View differences:

src/xmltables-oracle.sql
416 416
   size VARCHAR2(256), --the size of the object
417 417
   replication_allowed boolean,	 -- replication allowed
418 418
   number_replicas NUMBER(8), 	-- the number of replicas allowed
419
   obsoletes   VARCHAR2(2000),    -- the identifier of the record that this replaces
420
   obsoleted_by   VARCHAR2(2000),    -- the identifier of the record that replaces this record
419 421
   CONSTRAINT systemMetadata_pk 
420 422
		PRIMARY KEY (guid)
421 423
)
......
423 425
/*
424 426
 * Table used to store system metadata provenance information
425 427
 */
426
CREATE TABLE systemMetadataProvenance (
428
CREATE TABLE systemMetadataMap (
427 429
   guid   		VARCHAR2(2000),          -- the globally unique string identifier of the object that the system metadata describes
428
   relationship	VARCHAR(250),	 -- the provenance relationship defined between objects
429 430
   target_guid	VARCHAR2(2000),          -- the globally unique string identifier of the other object
430
   CONSTRAINT systemMetadataProvenance_fk 
431
   CONSTRAINT systemMetadataMap_fk 
431 432
		FOREIGN KEY (guid) REFERENCES systemMetadata
432 433
);
433 434

  
src/upgrade-db-to-1.10.0-postgres.sql
12 12
	size VARCHAR(256), --the size of the object
13 13
	replication_allowed boolean,	 -- replication allowed
14 14
	number_replicas INT8, 	-- the number of replicas allowed
15
	obsoletes   text,       -- the identifier that this record obsoletes
16
	obsoleted_by   text,     -- the identifier of the record that replaces this record
15 17
	CONSTRAINT systemMetadata_pk PRIMARY KEY (guid)
16 18
);
17 19
/*
18
 * Table used to store system metadata provenance information
20
 * Table used to store system metadata map information
19 21
 */
20
CREATE TABLE systemMetadataProvenance (
22
CREATE TABLE systemMetadataMap (
21 23
   guid   		text,          -- the globally unique string identifier of the object that the system metadata describes
22 24
   relationship	VARCHAR(250),	 -- the provenance relationship defined between objects
23 25
   target_guid	text,          -- the globally unique string identifier of the other object
24
   CONSTRAINT systemMetadataProvenance_fk 
26
   CONSTRAINT systemMetadataMap_fk 
25 27
		FOREIGN KEY (guid) REFERENCES systemMetadata
26 28
);
27 29

  
src/xmltables-postgres.sql
308 308
	size VARCHAR(256), --the size of the object
309 309
	replication_allowed boolean,	 -- replication allowed
310 310
	number_replicas INT8, 	-- the number of replicas allowed
311
	obsoletes   text,       -- the identifier that this record obsoletes
312
	obsoleted_by   text,     -- the identifier of the record that replaces this record
311 313
	CONSTRAINT systemMetadata_pk PRIMARY KEY (guid)
312 314
);
313 315
/*
......
319 321
 */
320 322

  
321 323
/*
322
 * Table used to store system metadata provenance information
324
 * Table used to store system metadata ORE map information
323 325
 */
324
CREATE TABLE systemMetadataProvenance (
326
CREATE TABLE systemMetadataMap (
325 327
   guid   		text,          -- the globally unique string identifier of the object that the system metadata describes
326
   relationship	VARCHAR(250),	 -- the provenance relationship defined between objects
327 328
   target_guid	text,          -- the globally unique string identifier of the other object
328
   CONSTRAINT systemMetadataProvenance_fk 
329
   CONSTRAINT systemMetadataMap_fk 
329 330
		FOREIGN KEY (guid) REFERENCES systemMetadata
330 331
);
331 332

  
src/upgrade-db-to-1.10.0-oracle.sql
12 12
   size VARCHAR2(256), --the size of the object
13 13
   replication_allowed boolean,	 -- replication allowed
14 14
   number_replicas NUMBER(8), 	-- the number of replicas allowed
15
   obsoletes   VARCHAR2(2000),    -- the identifier of the record that this replaces
16
   obsoleted_by   VARCHAR2(2000),    -- the identifier of the record that replaces this record
15 17
   CONSTRAINT systemMetadata_pk 
16 18
		PRIMARY KEY (guid)
17 19
)
18 20

  
19 21
/*
20
 * Table used to store system metadata provenance information
22
 * Table used to store system metadata map information
21 23
 */
22
CREATE TABLE systemMetadataProvenance (
24
CREATE TABLE systemMetadataMap (
23 25
   guid   		VARCHAR2(2000),          -- the globally unique string identifier of the object that the system metadata describes
24 26
   relationship	VARCHAR(250),	 -- the provenance relationship defined between objects
25 27
   target_guid	VARCHAR2(2000),          -- the globally unique string identifier of the other object
26
   CONSTRAINT systemMetadataProvenance_fk 
28
   CONSTRAINT systemMetadataMap_fk 
27 29
		FOREIGN KEY (guid) REFERENCES systemMetadata
28 30
);
29 31

  
src/edu/ucsb/nceas/metacat/IdentifierManager.java
244 244
        
245 245
        SystemMetadata sysMeta = new SystemMetadata();
246 246
        String sql = "select guid, date_uploaded, rights_holder, checksum, checksum_algorithm, " +
247
          "origin_member_node, authoritive_member_node, date_modified, submitter, object_format, size " +
247
          "origin_member_node, authoritive_member_node, date_modified, submitter, object_format, size, " +
248
          "obsoletes, obsoleted_by " +
248 249
          "from systemmetadata where guid = ?";
249 250
        DBConnection dbConn = null;
250 251
        int serialNumber = -1;
......
270 271
                String submitter = rs.getString(9);
271 272
                String fmtidStr = rs.getString(10);
272 273
                long size = new Long(rs.getString(11)).longValue();
274
                String obsoletes = rs.getString(12);
275
                String obsoletedBy = rs.getString(13);
276

  
273 277
                
274 278
                Identifier sysMetaId = new Identifier();
275 279
                sysMetaId.setValue(guid);
......
305 309
                  sysMeta.setObjectFormat(of);
306 310
                }
307 311
                sysMeta.setSize(size);
312
                Identifier obsoletesId = new Identifier();
313
                obsoletesId.setValue(obsoletes);
314
                sysMeta.setObsoletes(obsoletesId);
315
                Identifier obsoletedById = new Identifier();
316
                obsoletedById.setValue(obsoletedBy);
317
                sysMeta.setObsoletedBy(obsoletedById);
308 318
                
309 319
                stmt.close();
310 320
            } 
......
328 338
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
329 339
        }
330 340
        
331
        // look up provenance information
332
        sysMeta.setObsoletes(getSystemMetadataProvenance(sysMeta.getIdentifier().getValue(), "obsoletes").get(0));
333
        sysMeta.setObsoletedBy(getSystemMetadataProvenance(sysMeta.getIdentifier().getValue(), "obsoletedBy").get(0));
341
        // look up mapping information
342
        sysMeta.setResourceMapList((getSystemMetadataMap(sysMeta.getIdentifier().getValue())));
334 343
        
335 344
        // look up replication policy
336 345
        ReplicationPolicy replicationPolicy = new ReplicationPolicy();
......
351 360
        return sysMeta;
352 361
    }
353 362
    
354
    private List<Identifier> getSystemMetadataProvenance(String guid, String relationship)
363
    private List<Identifier> getSystemMetadataMap(String guid)
355 364
    	throws McdbDocNotFoundException {
356 365
    	
357 366
    	List<Identifier> identifiers = new ArrayList<Identifier>();
358
    	String sql = "select guid, relationship, target_guid " +
359
    		"from systemMetadataProvenance where guid = ? and relationship = ?";
367
    	String sql = "select guid, target_guid " +
368
    		"from systemMetadataMap where guid = ?";
360 369
	    DBConnection dbConn = null;
361 370
	    int serialNumber = -1;
362 371
	    try {
363 372
	        // Get a database connection from the pool
364
	        dbConn = DBConnectionPool.getDBConnection("IdentifierManager.getSystemMetadataProvenance");
373
	        dbConn = DBConnectionPool.getDBConnection("IdentifierManager.getSystemMetadataMap");
365 374
	        serialNumber = dbConn.getCheckOutSerialNumber();
366 375
	
367 376
	        // Execute the statement
368 377
	        PreparedStatement stmt = dbConn.prepareStatement(sql);
369 378
	        stmt.setString(1, guid);
370
	        stmt.setString(2, relationship);
371 379
	        ResultSet rs = stmt.executeQuery();
372 380
	        while (rs.next()) 
373 381
	        {
......
381 389
	        
382 390
	    } 
383 391
	    catch (SQLException e) {
384
	        logMetacat.error("Error while getting system metadata provenance for guid " + guid, e);
392
	        logMetacat.error("Error while getting system metadata map for guid " + guid, e);
385 393
	    } 
386 394
	    finally {
387 395
	        // Return database connection to the pool
......
1004 1012
            String checksum, String checksumAlgorithm, String originMemberNode,
1005 1013
            String authoritativeMemberNode, long modifiedDate, String submitter, 
1006 1014
            String guid, String objectFormat, long size, boolean replicationAllowed,
1007
            int numberReplicas)
1015
            int numberReplicas, String obsoletes, String obsoletedBy)
1008 1016
    {
1009 1017
        DBConnection dbConn = null;
1010 1018
        int serialNumber = -1;
......
1019 1027
            String query = "update " + TYPE_SYSTEM_METADATA + 
1020 1028
                " set (date_uploaded, rights_holder, checksum, checksum_algorithm, " +
1021 1029
                "origin_member_node, authoritive_member_node, date_modified, " +
1022
                "submitter, object_format, size, replication_allowed, number_replicas) " +
1023
                "= (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) where guid = ?";
1030
                "submitter, object_format, size, replication_allowed, number_replicas, obsoletes, obsoleted_by) " +
1031
                "= (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) where guid = ?";
1024 1032
            PreparedStatement stmt = dbConn.prepareStatement(query);
1025 1033
            
1026 1034
            //data values
......
1036 1044
            stmt.setString(10, new Long(size).toString());
1037 1045
            stmt.setBoolean(11, replicationAllowed);
1038 1046
            stmt.setInt(12, numberReplicas);
1047
            stmt.setString(13, obsoletes);
1048
            stmt.setString(14, obsoletedBy);
1049

  
1039 1050
            //where clause
1040 1051
            stmt.setString(13, guid);
1041 1052
            logMetacat.debug("stmt: " + stmt.toString());
......
1057 1068
        }
1058 1069
    }
1059 1070
    
1060
    private void insertSystemMetadataProvenance(String guid, String relationship, List<String> targetGuids)
1071
    private void insertSystemMetadataMap(String guid, List<String> targetGuids)
1061 1072
    {
1062 1073
        DBConnection dbConn = null;
1063 1074
        int serialNumber = -1;
......
1065 1076
        try {
1066 1077
            // Get a database connection from the pool
1067 1078
            dbConn = 
1068
                DBConnectionPool.getDBConnection("IdentifierManager.insertSystemMetadataProvenance");
1079
                DBConnectionPool.getDBConnection("IdentifierManager.insertSystemMetadataMap");
1069 1080
            serialNumber = dbConn.getCheckOutSerialNumber();
1070 1081

  
1071 1082
            // remove existing values first
1072
            String delete = "delete from systemMetadataProvenance " + 
1073
            "where guid = ? and relationship = ?";
1083
            String delete = "delete from systemMetadataMap " + 
1084
            "where guid = ?";
1074 1085
	        PreparedStatement stmt = dbConn.prepareStatement(delete);
1075 1086
	        //data values
1076 1087
	        stmt.setString(1, guid);
1077
	        stmt.setString(2, relationship);
1078 1088
	        //execute
1079 1089
	        int deletedCount = stmt.executeUpdate();
1080 1090
	        stmt.close();
1081 1091
            
1082 1092
            for (String targetGuid: targetGuids) {
1083 1093
	            // Execute the insert statement
1084
	            String insert = "insert into systemMetadataProvenance " + 
1085
	                "(guid, relationship, target_guid) " +
1086
	                "values (?, ?, ?)";
1094
	            String insert = "insert into systemMetadataMap " + 
1095
	                "(guid, target_guid) " +
1096
	                "values (?, ?)";
1087 1097
	            PreparedStatement insertStatement = dbConn.prepareStatement(insert);
1088 1098
	            
1089 1099
	            //data values
1090 1100
	            insertStatement.setString(1, guid);
1091
	            insertStatement.setString(2, relationship);
1092
	            insertStatement.setString(3, targetGuid);
1101
	            insertStatement.setString(2, targetGuid);
1093 1102
	            //execute
1094 1103
	            int rows = insertStatement.executeUpdate();
1095 1104
	            insertStatement.close();
1096 1105
            }
1097 1106
        } catch (SQLException e) {
1098
            logMetacat.error("SQL error while adding systemMetadataProvenance for: " + guid, e); 
1107
            logMetacat.error("SQL error while adding systemMetadataMap for: " + guid, e); 
1099 1108
        } finally {
1100 1109
            // Return database connection to the pool
1101 1110
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
......
1225 1234
                sm.getObjectFormat() == null ? null: sm.getObjectFormat().getFmtid().getValue(),
1226 1235
                sm.getSize(),
1227 1236
                replicationAllowed, 
1228
                numberReplicas);
1237
                numberReplicas,
1238
                sm.getObsoletes() == null ? null:sm.getObsoletes().getValue(),
1239
                sm.getObsoletedBy() == null ? null: sm.getObsoletedBy().getValue());
1229 1240
        
1230
        // add provenance information
1231 1241
        String guid = sm.getIdentifier().getValue();
1232
        Identifier id = null;
1233
        List<String> targetGuids = null;
1234
        String relationship = null;
1235
        
1236
        relationship = "obsoletedBy";
1237
        targetGuids = new ArrayList<String>();
1238
        id = sm.getObsoletedBy();
1239
        if (id != null) {
1240
	        targetGuids.add(id.getValue());
1241
	        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1242
        // ORE map pointers
1243
        List<String> targetGuids = new ArrayList<String>();
1244
        if (sm.getResourceMapList() != null) {
1245
        	for (Identifier pid: sm.getResourceMapList()) {
1246
        		targetGuids.add(pid.getValue());
1247
        	}
1248
    		insertSystemMetadataMap(guid, targetGuids);
1242 1249
        }
1243
        relationship = "obsoletes";
1244
        targetGuids = new ArrayList<String>();
1245
        id = sm.getObsoletes();
1246
        if (id != null) {
1247
	        targetGuids.add(id.getValue());
1248
	        this.insertSystemMetadataProvenance(guid, relationship, targetGuids);
1249
        }
1250 1250
        
1251
        // TODO inspect the ORE map
1252
        relationship = "describes";
1253
        relationship = "describedBy";        
1254
        relationship = "derivedFrom";
1255
                
1256 1251
        // save replication policies
1257 1252
        if (replicationPolicy != null) {
1258 1253
		    List<String> nodes = null;

Also available in: Unified diff