Project

General

Profile

Revision 149ff443

ID149ff443867be59fcdddb19754bc746cdbfb8703
Parent cb29fec9
Child b806219d

Added by Andreas Müller 2 months ago

ref #6581 ,ref #9004 fix Reference2SourceMover

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/SchemaUpdaterStepBase.java
108 108
     */
109 109
    protected int getMaxId1(ICdmDataSource datasource, String tableName, boolean includeAudit, IProgressMonitor monitor, CaseType caseType,
110 110
            SchemaUpdateResult result) throws SQLException {
111

  
111 112
        String sql = "SELECT max(id) FROM " +caseType.transformTo(tableName);
112
        Integer maxId = Integer.valueOf(datasource.getSingleValue(sql).toString());
113
        if (maxId == null){
114
            maxId = 0;
115
        }
113
        Integer maxId = getInteger(datasource, sql, 0);
114

  
116 115
        Integer maxIdAud = -1;
117 116
        if(includeAudit){
118 117
            sql = "SELECT max(id) FROM " +caseType.transformTo(tableName + "_AUD");
119
            maxIdAud = Integer.valueOf(datasource.getSingleValue(sql).toString());
120
            if (maxIdAud == null){
121
                maxIdAud = 0;
122
            }
118
            maxIdAud = getInteger(datasource, sql, 0);
123 119
        }
124 120
        return Math.max(maxId, maxIdAud) + 1;
125 121
    }
126 122

  
127
	@Override
123
    private Integer getInteger(ICdmDataSource datasource, String sql, int nullReplace) throws SQLException {
124
        Object value = datasource.getSingleValue(sql);
125
        if (value == null){
126
            return nullReplace;
127
        }else{
128
            return Integer.valueOf(value.toString());
129
        }
130
    }
131

  
132
    @Override
128 133
	public List<ISchemaUpdaterStep> getInnerSteps(){
129 134
		return new ArrayList<>();
130 135
	}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v512_515/Reference2SourceMover.java
73 73
        String sql = "SELECT * "
74 74
                + " FROM "+caseType.transformTo(tableName)+" t "
75 75
                + " WHERE t."+this.citationsIdAttr+" IS NOT NULL OR t."+this.detailAttr+" IS NOT NULL ";
76
        System.out.println(sql);
77 76

  
78 77
        ResultSet rs = datasource.executeQuery(sql);
79 78
        while(rs.next()){
......
84 83

  
85 84
            sql = "INSERT INTO @@OriginalSourceBase@@ (DTYPE, sourceType, uuid, id, citation_id, citationMicroReference, createdBy_id, created)"
86 85
               + " VALUES ('IdentifiableSource', 'PTS','"+UUID.randomUUID()+"'," + id + ", " + citationId + "," + nullSafeParam(detail) + "," + createdById + ",'" + this.getNowString() + "')";
87
            System.out.println(sql);
88 86
            datasource.executeUpdate(caseType.replaceTableNames(sql));
89 87

  
90 88
            sql = "UPDATE " + caseType.transformTo(tableName)
......
92 90
                    + " WHERE id = " + tnId;
93 91
            id++;
94 92

  
95
            System.out.println(sql);
96

  
97 93
            datasource.executeUpdate(caseType.replaceTableNames(sql));
98 94

  
99 95
        }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)