Search in sources :

Example 1 with PDRIFactory

use of nl.uva.cs.lobcder.resources.PDRIFactory in project lobcder by skoulouzis.

the class DeleteSweep method run.

@Override
public void run() {
    PDRIFactory factory;
    try (Connection connection = datasource.getConnection()) {
        // This query interferes with the assimilator
        try {
            connection.setAutoCommit(false);
            try (Statement s1 = connection.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_UPDATABLE)) {
                ResultSet rs1 = s1.executeQuery("SELECT pdriGroupId FROM pdrigroup_table WHERE refCount = 0 ");
                while (rs1.next()) {
                    Long groupId = rs1.getLong(1);
                    try (PreparedStatement ps2 = connection.prepareStatement("SELECT pdriId, fileName, storageSiteRef FROM pdri_table WHERE pdriGroupRef = ?", java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_UPDATABLE)) {
                        ps2.setLong(1, groupId);
                        ResultSet rs2 = ps2.executeQuery();
                        while (rs2.next()) {
                            // here better to use a kind a local cache, i.e. hashmap
                            try (PreparedStatement ps3 = connection.prepareStatement("SELECT resourceUri, username, password FROM storage_site_table " + "JOIN credential_table ON credentialRef = credintialId " + "WHERE storageSiteId = ?", java.sql.ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {
                                String fileName = rs2.getString(2);
                                Long storageSiteRef = rs2.getLong(3);
                                ps3.setLong(1, storageSiteRef);
                                ResultSet rs3 = ps3.executeQuery();
                                if (rs3.next()) {
                                    String resourceUri = rs3.getString(1);
                                    String username = rs3.getString(2);
                                    String password = rs3.getString(3);
                                    // For deleteing we don't care for encryption
                                    PDRIDescr pdriDescr = new PDRIDescr(fileName, storageSiteRef, resourceUri, username, password, false, null, null, null);
                                    DeleteSweep.log.log(Level.FINE, "PDRI Description: {0}, {1}, {2}, {3}, {4}", new Object[] { fileName, storageSiteRef, resourceUri, username, password });
                                    DeleteSweep.log.log(Level.FINE, "PDRI pdriDescr: {0}", new Object[] { pdriDescr });
                                    factory = PDRIFactory.getFactory();
                                    DeleteSweep.log.log(Level.FINE, "PDRIFactory: {0}", factory);
                                    PDRI pdri = factory.createInstance(pdriDescr, false);
                                    DeleteSweep.log.log(Level.FINE, "pdri: {0}", pdri);
                                    DeleteSweep.log.log(Level.FINE, "PDRI Instance file name: {0}", new Object[] { pdri.getFileName() });
                                    pdri.delete();
                                    DeleteSweep.log.log(Level.FINE, "DELETE:", pdri.getURI());
                                    rs2.deleteRow();
                                    connection.commit();
                                }
                            }
                        }
                        rs1.deleteRow();
                        connection.commit();
                    }
                }
            }
        } catch (SQLException | IOException e) {
            DeleteSweep.log.log(Level.SEVERE, null, e);
            connection.rollback();
        }
    } catch (SQLException e) {
        DeleteSweep.log.log(Level.SEVERE, null, e);
    }
}
Also used : PDRIFactory(nl.uva.cs.lobcder.resources.PDRIFactory) PDRIDescr(nl.uva.cs.lobcder.resources.PDRIDescr) IOException(java.io.IOException) PDRI(nl.uva.cs.lobcder.resources.PDRI)

Aggregations

IOException (java.io.IOException)1 PDRI (nl.uva.cs.lobcder.resources.PDRI)1 PDRIDescr (nl.uva.cs.lobcder.resources.PDRIDescr)1 PDRIFactory (nl.uva.cs.lobcder.resources.PDRIFactory)1