diff options
Diffstat (limited to 'src/org/traccar/model')
-rw-r--r-- | src/org/traccar/model/Data.java | 19 | ||||
-rw-r--r-- | src/org/traccar/model/Device.java | 53 | ||||
-rw-r--r-- | src/org/traccar/model/Position.java | 23 | ||||
-rw-r--r-- | src/org/traccar/model/User.java | 11 |
4 files changed, 70 insertions, 36 deletions
diff --git a/src/org/traccar/model/Data.java b/src/org/traccar/model/Data.java index 1cef813a3..e329e6c1e 100644 --- a/src/org/traccar/model/Data.java +++ b/src/org/traccar/model/Data.java @@ -15,15 +15,16 @@ */ package org.traccar.model; +import java.sql.ResultSet; import java.text.ParseException; import java.util.Date; import javax.json.Json; import javax.json.JsonObject; import javax.json.JsonObjectBuilder; -import org.traccar.database.JsonConvertable; -import static org.traccar.database.JsonConvertable.dateFormat; +import org.traccar.database.Convertable; +import org.traccar.database.ObjectConverter; -public class Data implements JsonConvertable { +public class Data implements Convertable { private long id; public long getId() { return id; } @@ -50,8 +51,8 @@ public class Data implements JsonConvertable { JsonObjectBuilder json = Json.createObjectBuilder(); json.add("id", id); json.add("deviceId", deviceId); - json.add("serverTime", dateFormat.format(serverTime)); - json.add("deviceTime", dateFormat.format(deviceTime)); + json.add("serverTime", ObjectConverter.dateFormat.format(serverTime)); + json.add("deviceTime", ObjectConverter.dateFormat.format(deviceTime)); //json.add("extendedInfo", extendedInfo); return json.build(); } @@ -60,9 +61,13 @@ public class Data implements JsonConvertable { public void fromJson(JsonObject json) throws ParseException { id = json.getJsonNumber("id").longValue(); deviceId = json.getJsonNumber("deviceId").longValue(); - serverTime = dateFormat.parse(json.getString("serverTime")); - deviceTime = dateFormat.parse(json.getString("deviceTime")); + serverTime = ObjectConverter.dateFormat.parse(json.getString("serverTime")); + deviceTime = ObjectConverter.dateFormat.parse(json.getString("deviceTime")); //extendedInfo = json.getString("extendedInfo"); } + @Override + public void fromRecord(ResultSet record) { + } + } diff --git a/src/org/traccar/model/Device.java b/src/org/traccar/model/Device.java index 4e2f57690..067d80f36 100644 --- a/src/org/traccar/model/Device.java +++ b/src/org/traccar/model/Device.java @@ -15,21 +15,25 @@ */ package org.traccar.model; +import java.sql.ResultSet; +import java.sql.SQLException; import java.text.ParseException; import java.util.Date; import javax.json.Json; import javax.json.JsonObject; import javax.json.JsonObjectBuilder; -import org.traccar.database.JsonConvertable; +import org.traccar.database.Convertable; +import org.traccar.database.ObjectConverter; +import org.traccar.helper.Log; -public class Device implements JsonConvertable { +public class Device implements Convertable { private long id; public long getId() { return id; } public void setId(long id) { this.id = id; } private String name; - public String getName() { return uniqueId; } + public String getName() { return name; } public void setName(String name) { this.name = name; } private String uniqueId; @@ -47,25 +51,40 @@ public class Device implements JsonConvertable { @Override public JsonObject toJson() { JsonObjectBuilder json = Json.createObjectBuilder(); - json.add("id", id); - json.add("name", name); - json.add("uniqueId", uniqueId); - json.add("status", status); - json.add("lastUpdate", dateFormat.format(lastUpdate)); - json.add("positionId", positionId); - json.add("dataId", dataId); + ObjectConverter.putLong(json, "id", id); + ObjectConverter.putString(json, "name", name); + ObjectConverter.putString(json, "uniqueId", uniqueId); + ObjectConverter.putString(json, "status", status); + ObjectConverter.putDate(json, "lastUpdate", lastUpdate); + ObjectConverter.putLong(json, "positionId", positionId); + ObjectConverter.putLong(json, "dataId", dataId); return json.build(); } @Override public void fromJson(JsonObject json) throws ParseException { - id = json.getJsonNumber("id").longValue(); - name = json.getString("name"); - uniqueId = json.getString("uniqueId"); - status = json.getString("status"); - lastUpdate = dateFormat.parse(json.getString("lastUpdate")); - positionId = json.getJsonNumber("positionId").longValue(); - dataId = json.getJsonNumber("dataId").longValue(); + id = ObjectConverter.getLong(json, "id"); + name = ObjectConverter.getString(json, "name"); + uniqueId = ObjectConverter.getString(json, "uniqueId"); + status = ObjectConverter.getString(json, "status"); + lastUpdate = ObjectConverter.getDate(json, "lastUpdate"); + positionId = ObjectConverter.getLong(json, "positionId"); + dataId = ObjectConverter.getLong(json, "dataId"); + } + + @Override + public void fromRecord(ResultSet record) { + try { + id = ObjectConverter.getLong(record, "id"); + name = ObjectConverter.getString(record, "name"); + uniqueId = ObjectConverter.getString(record, "uniqueId"); + status = ObjectConverter.getString(record, "status"); + lastUpdate = ObjectConverter.getDate(record, "lastUpdate"); + positionId = ObjectConverter.getLong(record, "positionId"); + dataId = ObjectConverter.getLong(record, "dataId"); + } catch (SQLException error) { + Log.warning(error); + } } } diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 7f042c409..92d5bbe5e 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -15,15 +15,16 @@ */ package org.traccar.model; +import java.sql.ResultSet; import java.text.ParseException; import java.util.Date; import javax.json.Json; import javax.json.JsonObject; import javax.json.JsonObjectBuilder; -import org.traccar.database.JsonConvertable; -import static org.traccar.database.JsonConvertable.dateFormat; +import org.traccar.database.Convertable; +import org.traccar.database.ObjectConverter; -public class Position implements JsonConvertable { +public class Position implements Convertable { private long id; public long getId() { return id; } @@ -87,9 +88,9 @@ public class Position implements JsonConvertable { JsonObjectBuilder json = Json.createObjectBuilder(); json.add("id", id); json.add("deviceId", deviceId); - json.add("serverTime", dateFormat.format(serverTime)); - json.add("deviceTime", dateFormat.format(deviceTime)); - json.add("fixTime", dateFormat.format(fixTime)); + json.add("serverTime", ObjectConverter.dateFormat.format(serverTime)); + json.add("deviceTime", ObjectConverter.dateFormat.format(deviceTime)); + json.add("fixTime", ObjectConverter.dateFormat.format(fixTime)); json.add("valid", valid); json.add("latitude", latitude); json.add("longitude", longitude); @@ -105,9 +106,9 @@ public class Position implements JsonConvertable { public void fromJson(JsonObject json) throws ParseException { id = json.getJsonNumber("id").longValue(); deviceId = json.getJsonNumber("deviceId").longValue(); - serverTime = dateFormat.parse(json.getString("serverTime")); - deviceTime = dateFormat.parse(json.getString("deviceTime")); - fixTime = dateFormat.parse(json.getString("fixTime")); + serverTime = ObjectConverter.dateFormat.parse(json.getString("serverTime")); + deviceTime = ObjectConverter.dateFormat.parse(json.getString("deviceTime")); + fixTime = ObjectConverter.dateFormat.parse(json.getString("fixTime")); valid = json.getBoolean("valid"); latitude = json.getJsonNumber("latitude").doubleValue(); longitude = json.getJsonNumber("longitude").doubleValue(); @@ -118,4 +119,8 @@ public class Position implements JsonConvertable { //extendedInfo = json.getString("extendedInfo"); } + @Override + public void fromRecord(ResultSet record) { + } + } diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java index a3eaf5a10..77740e987 100644 --- a/src/org/traccar/model/User.java +++ b/src/org/traccar/model/User.java @@ -15,12 +15,13 @@ */ package org.traccar.model; +import java.sql.ResultSet; import javax.json.Json; import javax.json.JsonObject; import javax.json.JsonObjectBuilder; -import org.traccar.database.JsonConvertable; +import org.traccar.database.Convertable; -public class User implements JsonConvertable { +public class User implements Convertable { private long id; @@ -79,5 +80,9 @@ public class User implements JsonConvertable { longitude = json.getJsonNumber("longitude").doubleValue(); zoom = json.getJsonNumber("zoom").intValue(); } - + + @Override + public void fromRecord(ResultSet record) { + } + } |