Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
806b9177
by Tony CHEMIT at 2018-05-04T14:57:22Z
2 changed files:
- persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_6_0.java
- persistence/src/main/java/fr/ird/observe/persistence/migration/DataSourceMigrationForVersion_7_0_RC_4.java
Changes:
| ... | ... | @@ -264,6 +264,74 @@ public class DataSourceMigrationForVersion_6_0 extends AbstractObserveMigrationC |
| 264 | 264 |
super(callBack, PGDataSourceMigration.TYPE);
|
| 265 | 265 |
}
|
| 266 | 266 |
|
| 267 |
+ @Override
|
|
| 268 |
+ protected void prepareMigrationScript(TopiaSqlSupport topiaSqlSupport, List<String> queries, boolean showSql, boolean showProgression) {
|
|
| 269 |
+ Boolean withTriggers = topiaSqlSupport.findSingleResult(new TopiaSqlQuery<Boolean>() {
|
|
| 270 |
+ @Override
|
|
| 271 |
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
|
|
| 272 |
+ return connection.prepareStatement("select exists(select * from pg_proc where proname = 'sync_activity_the_geom');");
|
|
| 273 |
+ }
|
|
| 274 |
+ |
|
| 275 |
+ @Override
|
|
| 276 |
+ public Boolean prepareResult(ResultSet resultSet) throws SQLException {
|
|
| 277 |
+ return resultSet.getBoolean(1);
|
|
| 278 |
+ }
|
|
| 279 |
+ });
|
|
| 280 |
+ |
|
| 281 |
+ if (withTriggers) {
|
|
| 282 |
+ queries.add("CREATE OR REPLACE function sync_activity_the_geom () returns trigger as '\n" +
|
|
| 283 |
+ "BEGIN\n" +
|
|
| 284 |
+ " IF (TG_OP = ''DELETE'') THEN\n" +
|
|
| 285 |
+ " RETURN OLD;\n" +
|
|
| 286 |
+ " END IF;\n" +
|
|
| 287 |
+ " IF (NEW.latitude IS NULL OR NEW.longitude IS NULL) THEN\n" +
|
|
| 288 |
+ " -- on ne calcule pas le point postgis si au moins une des -- coordonnees n est pas renseignee\n" +
|
|
| 289 |
+ " RAISE NOTICE ''No latitude or longitude, can not compute postgis field for id % '', NEW.topiaId;\n" +
|
|
| 290 |
+ " NEW.the_geom := NULL;\n" +
|
|
| 291 |
+ " return NEW;\n" +
|
|
| 292 |
+ " END IF;\n" +
|
|
| 293 |
+ " IF (TG_OP = ''UPDATE'' AND NEW.latitude = OLD.latitude AND NEW.longitude = OLD.longitude)\n" +
|
|
| 294 |
+ " THEN\n" +
|
|
| 295 |
+ " -- on ne calcule pas le point postgis si les coordonnées n''ont pas changées\n" +
|
|
| 296 |
+ " return NEW;\n" +
|
|
| 297 |
+ " END IF;\n" +
|
|
| 298 |
+ " RAISE NOTICE ''Will compute the_geom for activite % - latitude % and longitude %'', NEW.topiaId, NEW.latitude, NEW.longitude;\n" +
|
|
| 299 |
+ " -- affectation du point\n" +
|
|
| 300 |
+ " NEW.the_geom := ST_SetSRID(ST_MakePoint(NEW.longitude,NEW.latitude), 4326);\n" +
|
|
| 301 |
+ " RAISE NOTICE ''Computed for activity % latitude % and longitude %, the_geom %'', NEW.topiaId, NEW.latitude, NEW.longitude, NEW.the_geom;\n" +
|
|
| 302 |
+ "\n" +
|
|
| 303 |
+ " RETURN NEW;\n" +
|
|
| 304 |
+ "END\n" +
|
|
| 305 |
+ "'\n" +
|
|
| 306 |
+ "LANGUAGE 'plpgsql';\n");
|
|
| 307 |
+ queries.add("CREATE OR REPLACE function sync_harbour_the_geom () returns trigger as '\n" +
|
|
| 308 |
+ "BEGIN\n" +
|
|
| 309 |
+ " IF (TG_OP = ''DELETE'') THEN\n" +
|
|
| 310 |
+ " RETURN OLD;\n" +
|
|
| 311 |
+ " END IF;\n" +
|
|
| 312 |
+ " IF (NEW.latitude IS NULL OR NEW.longitude IS NULL) THEN\n" +
|
|
| 313 |
+ " -- on ne calcule pas le point postgis si au moins une des -- coordonnees n est pas renseignee\n" +
|
|
| 314 |
+ " RAISE NOTICE ''No latitude or longitude, can not compute postgis field for id % '', NEW.topiaId;\n" +
|
|
| 315 |
+ " NEW.the_geom := NULL;\n" +
|
|
| 316 |
+ " return NEW;\n" +
|
|
| 317 |
+ " END IF;\n" +
|
|
| 318 |
+ " IF (TG_OP = ''UPDATE'' AND NEW.latitude = OLD.latitude AND NEW.longitude = OLD.longitude)\n" +
|
|
| 319 |
+ " THEN\n" +
|
|
| 320 |
+ " -- on ne calcule pas le point postgis si les coordonnées n''ont pas changées\n" +
|
|
| 321 |
+ " return NEW;\n" +
|
|
| 322 |
+ " END IF;\n" +
|
|
| 323 |
+ " RAISE NOTICE ''Will compute the_geom for harbour % - latitude % and longitude %'', NEW.topiaId, NEW.latitude, NEW.longitude;\n" +
|
|
| 324 |
+ " -- affectation du point\n" +
|
|
| 325 |
+ " NEW.the_geom := ST_SetSRID(ST_MakePoint(NEW.longitude,NEW.latitude), 4326);\n" +
|
|
| 326 |
+ " RAISE NOTICE ''Computed for harbour % latitude % and longitude %, the_geom %'', NEW.topiaId, NEW.latitude, NEW.longitude, NEW.the_geom;\n" +
|
|
| 327 |
+ " RETURN NEW;\n" +
|
|
| 328 |
+ "END\n" +
|
|
| 329 |
+ "'\n" +
|
|
| 330 |
+ "LANGUAGE 'plpgsql';");
|
|
| 331 |
+ addScript("00", "fix_trigger", queries);
|
|
| 332 |
+ }
|
|
| 333 |
+ super.prepareMigrationScript(topiaSqlSupport, queries, showSql, showProgression);
|
|
| 334 |
+ }
|
|
| 267 | 335 |
}
|
| 268 | 336 |
|
| 269 | 337 |
}
|
| ... | ... | @@ -22,13 +22,8 @@ package fr.ird.observe.persistence.migration; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
-import org.nuiton.topia.persistence.support.TopiaSqlQuery;
|
|
| 26 | 25 |
import org.nuiton.topia.persistence.support.TopiaSqlSupport;
|
| 27 | 26 |
|
| 28 |
-import java.sql.Connection;
|
|
| 29 |
-import java.sql.PreparedStatement;
|
|
| 30 |
-import java.sql.ResultSet;
|
|
| 31 |
-import java.sql.SQLException;
|
|
| 32 | 27 |
import java.util.List;
|
| 33 | 28 |
import java.util.Map;
|
| 34 | 29 |
import java.util.Set;
|
| ... | ... | @@ -89,76 +84,6 @@ public class DataSourceMigrationForVersion_7_0_RC_4 extends AbstractObserveMigra |
| 89 | 84 |
super(callBack, PGDataSourceMigration.TYPE);
|
| 90 | 85 |
}
|
| 91 | 86 |
|
| 92 |
- |
|
| 93 |
- @Override
|
|
| 94 |
- protected void prepareMigrationScript(TopiaSqlSupport topiaSqlSupport, List<String> queries, boolean showSql, boolean showProgression) {
|
|
| 95 |
- |
|
| 96 |
- Boolean withTriggers = topiaSqlSupport.findSingleResult(new TopiaSqlQuery<Boolean>() {
|
|
| 97 |
- @Override
|
|
| 98 |
- public PreparedStatement prepareQuery(Connection connection) throws SQLException {
|
|
| 99 |
- return connection.prepareStatement("select exists(select * from pg_proc where proname = 'sync_activity_the_geom');");
|
|
| 100 |
- }
|
|
| 101 |
- |
|
| 102 |
- @Override
|
|
| 103 |
- public Boolean prepareResult(ResultSet resultSet) throws SQLException {
|
|
| 104 |
- return resultSet.getBoolean(1);
|
|
| 105 |
- }
|
|
| 106 |
- });
|
|
| 107 |
- |
|
| 108 |
- if (withTriggers) {
|
|
| 109 |
- queries.add("CREATE OR REPLACE function sync_activity_the_geom () returns trigger as '\n" +
|
|
| 110 |
- "BEGIN\n" +
|
|
| 111 |
- " IF (TG_OP = ''DELETE'') THEN\n" +
|
|
| 112 |
- " RETURN OLD;\n" +
|
|
| 113 |
- " END IF;\n" +
|
|
| 114 |
- " IF (NEW.latitude IS NULL OR NEW.longitude IS NULL) THEN\n" +
|
|
| 115 |
- " -- on ne calcule pas le point postgis si au moins une des -- coordonnees n est pas renseignee\n" +
|
|
| 116 |
- " RAISE NOTICE ''No latitude or longitude, can not compute postgis field for id % '', NEW.topiaId;\n" +
|
|
| 117 |
- " NEW.the_geom := NULL;\n" +
|
|
| 118 |
- " return NEW;\n" +
|
|
| 119 |
- " END IF;\n" +
|
|
| 120 |
- " IF (TG_OP = ''UPDATE'' AND NEW.latitude = OLD.latitude AND NEW.longitude = OLD.longitude)\n" +
|
|
| 121 |
- " THEN\n" +
|
|
| 122 |
- " -- on ne calcule pas le point postgis si les coordonnées n''ont pas changées\n" +
|
|
| 123 |
- " return NEW;\n" +
|
|
| 124 |
- " END IF;\n" +
|
|
| 125 |
- " RAISE NOTICE ''Will compute the_geom for activite % - latitude % and longitude %'', NEW.topiaId, NEW.latitude, NEW.longitude;\n" +
|
|
| 126 |
- " -- affectation du point\n" +
|
|
| 127 |
- " NEW.the_geom := ST_SetSRID(ST_MakePoint(NEW.longitude,NEW.latitude), 4326);\n" +
|
|
| 128 |
- " RAISE NOTICE ''Computed for activity % latitude % and longitude %, the_geom %'', NEW.topiaId, NEW.latitude, NEW.longitude, NEW.the_geom;\n" +
|
|
| 129 |
- "\n" +
|
|
| 130 |
- " RETURN NEW;\n" +
|
|
| 131 |
- "END\n" +
|
|
| 132 |
- "'\n" +
|
|
| 133 |
- "LANGUAGE 'plpgsql';\n");
|
|
| 134 |
- queries.add("CREATE OR REPLACE function sync_harbour_the_geom () returns trigger as '\n" +
|
|
| 135 |
- "BEGIN\n" +
|
|
| 136 |
- " IF (TG_OP = ''DELETE'') THEN\n" +
|
|
| 137 |
- " RETURN OLD;\n" +
|
|
| 138 |
- " END IF;\n" +
|
|
| 139 |
- " IF (NEW.latitude IS NULL OR NEW.longitude IS NULL) THEN\n" +
|
|
| 140 |
- " -- on ne calcule pas le point postgis si au moins une des -- coordonnees n est pas renseignee\n" +
|
|
| 141 |
- " RAISE NOTICE ''No latitude or longitude, can not compute postgis field for id % '', NEW.topiaId;\n" +
|
|
| 142 |
- " NEW.the_geom := NULL;\n" +
|
|
| 143 |
- " return NEW;\n" +
|
|
| 144 |
- " END IF;\n" +
|
|
| 145 |
- " IF (TG_OP = ''UPDATE'' AND NEW.latitude = OLD.latitude AND NEW.longitude = OLD.longitude)\n" +
|
|
| 146 |
- " THEN\n" +
|
|
| 147 |
- " -- on ne calcule pas le point postgis si les coordonnées n''ont pas changées\n" +
|
|
| 148 |
- " return NEW;\n" +
|
|
| 149 |
- " END IF;\n" +
|
|
| 150 |
- " RAISE NOTICE ''Will compute the_geom for harbour % - latitude % and longitude %'', NEW.topiaId, NEW.latitude, NEW.longitude;\n" +
|
|
| 151 |
- " -- affectation du point\n" +
|
|
| 152 |
- " NEW.the_geom := ST_SetSRID(ST_MakePoint(NEW.longitude,NEW.latitude), 4326);\n" +
|
|
| 153 |
- " RAISE NOTICE ''Computed for harbour % latitude % and longitude %, the_geom %'', NEW.topiaId, NEW.latitude, NEW.longitude, NEW.the_geom;\n" +
|
|
| 154 |
- " RETURN NEW;\n" +
|
|
| 155 |
- "END\n" +
|
|
| 156 |
- "'\n" +
|
|
| 157 |
- "LANGUAGE 'plpgsql';");
|
|
| 158 |
- addScript("00", "fix_trigger", queries);
|
|
| 159 |
- }
|
|
| 160 |
- super.prepareMigrationScript(topiaSqlSupport, queries, showSql, showProgression);
|
|
| 161 |
- }
|
|
| 162 | 87 |
}
|
| 163 | 88 |
|
| 164 | 89 |
}
|