Search in sources :

Example 1 with SqlUpdate

use of org.activityinfo.store.mysql.update.SqlUpdate in project activityinfo by bedatadriven.

the class LocationFormStorage method update.

@Override
public void update(TypedRecordUpdate update) {
    long newVersion = incrementVersion();
    int locationId = CuidAdapter.getLegacyIdFromCuid(update.getRecordId());
    SqlUpdate sql = SqlUpdate.update("location");
    sql.where("locationId", locationId);
    sql.set("timeEdited", System.currentTimeMillis());
    sql.set("version", newVersion);
    if (update.isDeleted()) {
        sql.set("workflowStatusId", "rejected");
    } else {
        sql.set("name", getName(update), 50);
        sql.set("axe", getAxe(update), 50);
        if (update.getChangedFieldValues().containsKey(pointFieldId)) {
            GeoPoint point = (GeoPoint) update.getChangedFieldValues().get(pointFieldId);
            if (point == null) {
                sql.set("x", null);
                sql.set("y", null);
            } else {
                sql.set("x", point.getLongitude());
                sql.set("y", point.getLatitude());
            }
        }
    }
    sql.execute(executor);
    if (!update.isDeleted()) {
        Set<Integer> adminEntities = fetchParents(getAdminEntities(update));
        updateAdminLinks(locationId, adminEntities);
    }
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) SqlUpdate(org.activityinfo.store.mysql.update.SqlUpdate) GeoPoint(org.activityinfo.model.type.geo.GeoPoint)

Example 2 with SqlUpdate

use of org.activityinfo.store.mysql.update.SqlUpdate in project activityinfo by bedatadriven.

the class LocationFormStorage method incrementVersion.

private long incrementVersion() {
    long newVersion = version + 1;
    SqlUpdate update = SqlUpdate.update("locationtype");
    update.where("locationTypeId", locationTypeId);
    update.set("version", newVersion);
    update.execute(executor);
    return newVersion;
}
Also used : SqlUpdate(org.activityinfo.store.mysql.update.SqlUpdate)

Aggregations

SqlUpdate (org.activityinfo.store.mysql.update.SqlUpdate)2 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)1