use of nl.uva.cs.lobcder.catalogue.beans.CredentialBean in project lobcder by skoulouzis.
the class RandomReplicationPolicyJDBC method getSitesToReplicate.
@Override
public Set<StorageSiteBean> getSitesToReplicate() throws Exception {
try (Connection connection = getConnection()) {
connection.setAutoCommit(true);
try (Statement statement = connection.createStatement()) {
ResultSet resultSet = statement.executeQuery("SELECT storageSiteId, resourceUri, encrypt, extra, username, password FROM storage_site_table JOIN credential_table ON credentialRef=credintialId WHERE private=FALSE AND removing=FALSE AND isCache=FALSE");
ArrayList<StorageSiteBean> queryResult = new ArrayList<>(resultSet.getFetchSize());
while (resultSet.next()) {
queryResult.add(new StorageSiteBean(resultSet.getLong(1), resultSet.getString(2), resultSet.getBoolean(3), Boolean.FALSE, resultSet.getString(4), new CredentialBean(resultSet.getString(5), resultSet.getString(6))));
}
number = PropertiesHelper.getNumberOfSites();
Collections.shuffle(queryResult);
if (number > queryResult.size()) {
number = queryResult.size();
}
return new HashSet<>(queryResult.subList(0, number));
}
}
}
use of nl.uva.cs.lobcder.catalogue.beans.CredentialBean in project lobcder by skoulouzis.
the class ConnectorJDBC method getPdriGroupsToProcess.
@Override
public Collection<PdriGroupBean> getPdriGroupsToProcess() throws Exception {
try (Connection connection = datasource.getConnection()) {
connection.setAutoCommit(true);
ArrayList<Long> pdriGroups = new ArrayList<>();
try (CallableStatement s1 = connection.prepareCall("call GET_PDRI_GROUPS_FOR_DELETE(?)")) {
s1.setInt(1, limit);
ResultSet rs = s1.executeQuery();
while (rs.next()) {
pdriGroups.add(rs.getLong(1));
}
}
ArrayList<PdriGroupBean> result = new ArrayList<>(pdriGroups.size());
try (PreparedStatement ps = connection.prepareStatement("SELECT pdriId, fileName, storageSiteRef, resourceUri, username, password " + "FROM pdri_table " + "JOIN storage_site_table ON storage_site_table.storageSiteId = pdri_table.storageSiteRef " + "JOIN credential_table ON storage_site_table.credentialRef = credintialId " + "WHERE pdriGroupRef = ?")) {
for (Long pdrigrId : pdriGroups) {
ps.setLong(1, pdrigrId);
ResultSet rs = ps.executeQuery();
PdriGroupBean pdriGroupBean = new PdriGroupBean();
pdriGroupBean.setId(pdrigrId);
if (rs.next()) {
ArrayList<PdriBean> pdriBeans = new ArrayList<>();
do {
pdriBeans.add(new PdriBean(rs.getLong(1), rs.getString(2), null, new StorageSiteBean(rs.getLong(3), rs.getString(4), null, null, null, new CredentialBean(rs.getString(5), rs.getString(6)))));
} while (rs.next());
pdriGroupBean.setPdri(pdriBeans);
}
result.add(pdriGroupBean);
}
}
return result;
}
// catch (Exception ex) {
// reconnectAttemts++;
// if (reconnectAttemts < Constants.RECONNECT_NTRY) {
// sleeTime = sleeTime * 2;
// Thread.sleep(sleeTime);
// return getPdriGroupsToProcess();
// } else {
// reconnectAttemts = 0;
// sleeTime = 100;
// throw ex;
// }
// }
}
Aggregations