throws SQLException, CatalogIndexException {
PreparedStatement st1 = null;
PreparedStatement st2 = null;
PreparedStatement stR = null;
int nBatch = 0;
StringSet indexableUuids = new StringSet();
try {
String table = this.getCollectionMemberTableName();
String tableR = this.getResourceTableName();
String sql1 = "SELECT DOCUUID FROM "+table+" WHERE DOCUUID=? AND COLUUID=?";
String sql2 = "INSERT INTO "+table+" (DOCUUID,COLUUID) VALUES (?,?)";
String sqlR = "SELECT APPROVALSTATUS FROM "+tableR+" WHERE DOCUUID=?";
Connection con = this.returnConnection().getJdbcConnection();
st1 = con.prepareStatement(sql1);
st2 = con.prepareStatement(sql2);
stR = con.prepareStatement(sqlR);
for (String docUuid: docUuids) {
boolean bInsert = true;
st1.clearParameters();
st1.setString(1,docUuid);
st1.setString(2,colUuid);
ResultSet rs1 = st1.executeQuery();
if (rs1.next()) bInsert = false;
rs1.close();
if (bInsert) {
stR.clearParameters();
stR.setString(1,docUuid);
ResultSet rsR = stR.executeQuery();
if (rsR.next()) {
String status = Val.chkStr(rsR.getString(1));
if (MmdEnums.ApprovalStatus.isPubliclyVisible(status)) {
indexableUuids.add(docUuid);
}
}
rsR.close();
st2.setString(1,docUuid);
st2.setString(2,colUuid);
st2.addBatch();
nBatch++;
}
}
st1.close();
st1 = null;
if (nBatch > 0) {
st2.executeBatch();
}
} finally {
CollectionDao.closeStatement(st1);
CollectionDao.closeStatement(st2);
CollectionDao.closeStatement(stR);
}
if (indexableUuids.size() > 0) {
this.reindex(publisher,indexableUuids);
}
return nBatch;
}