Search in sources :

Example 1 with CredentialBean

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));
        }
    }
}
Also used : StorageSiteBean(nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean) Statement(java.sql.Statement) CredentialBean(nl.uva.cs.lobcder.catalogue.beans.CredentialBean) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 2 with CredentialBean

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;
// }
// }
}
Also used : StorageSiteBean(nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean) PdriBean(nl.uva.cs.lobcder.catalogue.beans.PdriBean) CredentialBean(nl.uva.cs.lobcder.catalogue.beans.CredentialBean) ArrayList(java.util.ArrayList) PdriGroupBean(nl.uva.cs.lobcder.catalogue.beans.PdriGroupBean)

Aggregations

CredentialBean (nl.uva.cs.lobcder.catalogue.beans.CredentialBean)2 StorageSiteBean (nl.uva.cs.lobcder.catalogue.beans.StorageSiteBean)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 PdriBean (nl.uva.cs.lobcder.catalogue.beans.PdriBean)1 PdriGroupBean (nl.uva.cs.lobcder.catalogue.beans.PdriGroupBean)1