Project

General

Profile

Revision 326bdb02

ID326bdb0263500ad57cf7eed786bcfb8b1320f5e8
Parent 1941a843
Child 9ec325d4

Added by Andreas Müller over 1 year ago

ref #7334 error handling in update script for pp synonyms

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v47_50/ProParteSynonymUpdater.java
158 158
    private void invokeSingle(boolean isPartial, int typeId, ICdmDataSource datasource, IProgressMonitor monitor,
159 159
            CaseType caseType, SchemaUpdateResult result) throws SQLException {
160 160

  
161
        //get maxId from taxonRelationship
162
        Integer maxId = 0;
163
        String query = "SELECT max(id) id FROM @@TaxonRelationship@@";
164
        query = doReplacements(query, caseType, datasource);
165
        ResultSet rs = datasource.executeQuery(query);
166
        if (rs.next()){
167
            maxId = rs.getInt("id");
168
        }
169

  
170
        //
171
        String attributeName = isPartial? "partial" : "proParte";
172
        query = " SELECT tb.id synId, titleCache " +
173
                " FROM @@TaxonBase@@ tb  " +
174
                " WHERE tb.%s = @TRUE@ ";
175
        query = String.format(query, attributeName);
176
        query = doReplacements(query, caseType, datasource);
177
        rs = datasource.executeQuery(query);
178
        while (rs.next()){
179
            maxId++;
180
            Integer synId = rs.getInt("synId");
181
            String insert = "INSERT INTO @@TaxonRelationship@@ (id, uuid, relatedFrom_id, relatedTo_id, "
182
                    +       " doubtful, citation_id, citationMicroReference, type_id, "
183
                    +       " created, updated, createdBy_id, updatedBy_id )"
184
                    + " SELECT %d, '%s', syn.id, acceptedTaxon_id,  "
185
                    +       " syn.doubtful, syn.sec_id secId, syn.secMicroReference, %d, "
186
                    +       " syn.created, syn.updated, syn.createdBy_id, syn.updatedBy_id "
187
                    + " FROM TaxonBase syn "
188
                    + " WHERE syn.id = %d ";
189
            insert = String.format(insert, maxId, UUID.randomUUID(), typeId, synId );
190
            insert = doReplacements(insert, caseType, datasource);
191
            datasource.executeUpdate(insert);
192

  
193
            String titleCache = rs.getString("titleCache");
194
            titleCache = normalizeTitleCache(titleCache);
195
            String update = "UPDATE @@TaxonBase@@ "
196
                    + " SET DTYPE = 'Taxon', sec_id = null, secMicroReference = null,"
197
                    + "     %s = null, titleCache = '%s', taxonStatusUnknown = @FALSE@,"
198
                    + "     doubtful = @FALSE@, acceptedTaxon_id = null, type_id = null "
199
                    + " WHERE id = %d ";
200
            update = String.format(update, attributeName, titleCache, synId);
201
            update = doReplacements(update, caseType, datasource);
202
            datasource.executeUpdate(update);
161
        try {
162
            //get maxId from taxonRelationship
163
            Integer maxId = 0;
164
            String query = "SELECT max(id) id FROM @@TaxonRelationship@@";
165
            query = doReplacements(query, caseType, datasource);
166
            ResultSet rs = datasource.executeQuery(query);
167
            if (rs.next()){
168
                maxId = rs.getInt("id");
169
            }
170

  
171
            //SELECT all record IDs
172
            String attributeName = isPartial? "partial" : "proParte";
173
            query = " SELECT tb.id synId, titleCache " +
174
                    " FROM @@TaxonBase@@ tb  " +
175
                    " WHERE tb.%s = @TRUE@ ";
176
            query = String.format(query, attributeName);
177
            query = doReplacements(query, caseType, datasource);
178
            rs = datasource.executeQuery(query);
179

  
180
            while (rs.next()){
181
                maxId++;
182
                Integer synId = rs.getInt("synId");
183
                //insert record in TaxonRelationship
184
                String insert = "INSERT INTO @@TaxonRelationship@@ (id, uuid, relatedFrom_id, relatedTo_id, "
185
                        +       " doubtful, citation_id, citationMicroReference, type_id, "
186
                        +       " created, updated, createdBy_id, updatedBy_id )"
187
                        + " SELECT %d, '%s', syn.id, acceptedTaxon_id,  "
188
                        +       " syn.doubtful, syn.sec_id secId, syn.secMicroReference, %d, "
189
                        +       " syn.created, syn.updated, syn.createdBy_id, syn.updatedBy_id "
190
                        + " FROM TaxonBase syn "
191
                        + " WHERE syn.id = %d ";
192
                insert = String.format(insert, maxId, UUID.randomUUID(), typeId, synId );
193
                insert = doReplacements(insert, caseType, datasource);
194
                datasource.executeUpdate(insert);
195

  
196
                //update Synonym record
197
                String titleCache = rs.getString("titleCache");
198
                titleCache = normalizeTitleCache(titleCache);
199
                String update = "UPDATE @@TaxonBase@@ "
200
                        + " SET DTYPE = 'Taxon', sec_id = null, secMicroReference = null,"
201
                        + "     %s = null, titleCache = '%s', taxonStatusUnknown = @FALSE@,"
202
                        + "     doubtful = @FALSE@, acceptedTaxon_id = null, type_id = null "
203
                        + " WHERE id = %d ";
204
                update = String.format(update, attributeName, titleCache, synId);
205
                update = doReplacements(update, caseType, datasource);
206
                datasource.executeUpdate(update);
207
            }
208
        } catch (Exception e) {
209
            result.addException(e, "Error occurred when trying to update proParte/partial synonyms",
210
                    this, "invokeSingle");
203 211
        }
204 212

  
205 213
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)