Project

General

Profile

« Previous | Next » 

Revision 2597

Added by Jing Tao over 18 years ago

Add code to get revision table info

View differences:

MetacatReplication.java
1080 1080
   * The format is:
1081 1081
   * <!ELEMENT replication (server, updates)>
1082 1082
   * <!ELEMENT server (#PCDATA)>
1083
   * <!ELEMENT updates ((updatedDocument | deleteDocument)*)>
1083
   * <!ELEMENT updates ((updatedDocument | deleteDocument | revisionDocument)*)>
1084 1084
   * <!ELEMENT updatedDocument (docid, rev, datafile*)>
1085 1085
   * <!ELEMENT deletedDocument (docid, rev)>
1086
   * <!ELEMENT revisionDocument (docid, rev, datafile*)>
1086 1087
   * <!ELEMENT docid (#PCDATA)>
1087 1088
   * <!ELEMENT rev (#PCDATA)>
1088 1089
   * <!ELEMENT datafile (#PCDATA)>
......
1149 1150

  
1150 1151
      // Store the sql command
1151 1152
      StringBuffer docsql = new StringBuffer();
1153
      StringBuffer revisionSql = new StringBuffer();
1152 1154
      // Stroe the docid list
1153 1155
      StringBuffer doclist = new StringBuffer();
1154 1156
      // Store the deleted docid list
......
1165 1167
      // Get correct docid that reside on this server according the requesting
1166 1168
      // server's replicate and data replicate value in xml_replication table
1167 1169
      docsql.append("select docid, rev, doctype from xml_documents ");
1170
      revisionSql.append("select docid, rev, doctype from xml_revisions ");
1168 1171
      // If the localhost is not a hub to the remote server, only replicate
1169 1172
      // the docid' which home server is local host (server_location =1)
1170 1173
      if (!serverList.getHubValue(server))
1171 1174
      {
1172
        docsql.append("where server_location = 1");
1175
        String serverLocation = "where server_location = 1";
1176
        docsql.append(serverLocation);
1177
        revisionSql.append(serverLocation);
1173 1178
      }
1174 1179
      MetaCatUtil.debugMessage("Doc sql: "+docsql.toString(), 30);
1175 1180

  
......
1194 1199
      boolean tablehasrows = rs.next();
1195 1200
      //If metacat configed to replicate data file
1196 1201
      //if ((util.getOption("replicationsenddata")).equals("on"))
1197
      if (serverList.getDataReplicationValue(server))
1202
      boolean replicateData = serverList.getDataReplicationValue(server);
1203
      if (replicateData)
1198 1204
      {
1199 1205
        while(tablehasrows)
1200 1206
        {
......
1297 1303
        doclist.append("</rev>");
1298 1304
        doclist.append("</updatedDocument>");
1299 1305
      }
1300

  
1306
      // add revision doc list  
1307
      doclist.append(prepareRevisionDoc(dbConn,revisionSql.toString(),replicateData));
1308
        
1301 1309
      doclist.append("</updates></replication>");
1302 1310
      MetaCatUtil.debugMessage("doclist: " + doclist.toString(), 40);
1303 1311
      pstmt.close();
......
1332 1340
    }//finally
1333 1341

  
1334 1342
  }//handlUpdateRequest
1343
  
1344
  /*
1345
   * This method will get the xml string for document in xml_revision
1346
   * The schema look like <!ELEMENT revisionDocument (docid, rev, datafile*)>
1347
   */
1348
  private String prepareRevisionDoc(DBConnection dbConn, String revSql, 
1349
                            boolean replicateData) throws Exception
1350
  {
1351
      StringBuffer revDocList = new StringBuffer();
1352
      PreparedStatement pstmt = dbConn.prepareStatement(revSql.toString());
1353
      //usage count should increas 1
1354
      dbConn.increaseUsageCount(1);
1335 1355

  
1356
      pstmt.execute();
1357
      ResultSet rs = pstmt.getResultSet();
1358
      boolean tablehasrows = rs.next();
1359
      while(tablehasrows)
1360
      {
1361
        String recordDoctype = rs.getString(3);
1362
        
1363
        //If this is data file and it isn't configured to replicate data
1364
        if (recordDoctype.equals("BIN") && !replicateData)
1365
        {  
1366
            // do nothing
1367
            continue;
1368
        }
1369
        else
1370
        {  
1371
            
1372
            revDocList.append("<revisionDocument>");
1373
            revDocList.append("<docid>").append(rs.getString(1));
1374
            revDocList.append("</docid><rev>").append(rs.getInt(2));
1375
            revDocList.append("</rev>");
1376
            // data file
1377
            if (recordDoctype.equals("BIN"))
1378
            {
1379
                revDocList.append("<datafile>");
1380
                revDocList.append(MetaCatUtil.getOption("datafileflag"));
1381
                revDocList.append("</datafile>");
1382
            }
1383
            revDocList.append("</revsionDocument>");
1384
        
1385
         }//else
1386
      }
1387
      return revDocList.toString();
1388
  }
1389

  
1336 1390
  /**
1337 1391
   * Returns the xml_catalog table encoded in xml
1338 1392
   */

Also available in: Unified diff