Added default case (as String) in the `setObjectInPreparedStatement`
This commit is contained in:
parent
9dd1b77b73
commit
c23245151f
|
@ -31,20 +31,18 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
@ToString
|
@ToString
|
||||||
public class PostgisTable {
|
public class PostgisTable {
|
||||||
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static enum GeometryType {
|
public static enum GeometryType {
|
||||||
MULTIPOINT("4326","geometry (MULTIPOINT,4326)","",""),
|
MULTIPOINT("4326", "geometry (MULTIPOINT,4326)", "", ""), POINT("4326", "geometry (POINT,4326)", "", ""),
|
||||||
POINT("4326","geometry (POINT,4326)","",""),
|
|
||||||
LINE("4326", "geometry (MULTILINESTRING,4326)", "", ""),
|
LINE("4326", "geometry (MULTILINESTRING,4326)", "", ""),
|
||||||
POLYGON("4326", "geometry (MULTIPOLYGON,4326)", "", "");
|
POLYGON("4326", "geometry (MULTIPOLYGON,4326)", "", "");
|
||||||
|
|
||||||
private final String SRID;
|
private final String SRID;
|
||||||
private final String definition;
|
private final String definition;
|
||||||
private final String InsertWKT;
|
private final String InsertWKT;
|
||||||
private final String insertWKB;
|
private final String insertWKB;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ -74,18 +72,14 @@ public class PostgisTable {
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum FieldType {
|
public enum FieldType {
|
||||||
INT("int",java.sql.Types.INTEGER),
|
INT("int", java.sql.Types.INTEGER), BOOLEAN("boolean", java.sql.Types.BOOLEAN),
|
||||||
BOOLEAN("boolean", java.sql.Types.BOOLEAN),
|
TEXT("text", java.sql.Types.LONGVARCHAR), FLOAT("float", java.sql.Types.FLOAT), GEOMETRY("", 0),
|
||||||
TEXT("text",java.sql.Types.LONGVARCHAR),
|
|
||||||
FLOAT("float",java.sql.Types.FLOAT),
|
|
||||||
GEOMETRY("",0),
|
|
||||||
AUTOINCREMENT("BIGSERIAL PRIMARY KEY", java.sql.Types.BIGINT);
|
AUTOINCREMENT("BIGSERIAL PRIMARY KEY", java.sql.Types.BIGINT);
|
||||||
|
|
||||||
private String definition;
|
private String definition;
|
||||||
private int sqlType;
|
private int sqlType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Getter
|
@Getter
|
||||||
@ToString
|
@ToString
|
||||||
|
@ -100,10 +94,12 @@ public class PostgisTable {
|
||||||
log.debug("Parsing POINT " + point);
|
log.debug("Parsing POINT " + point);
|
||||||
Matcher m = pattern.matcher(point);
|
Matcher m = pattern.matcher(point);
|
||||||
|
|
||||||
if(!m.find()) throw new DataParsingException("Unable to get x ");
|
if (!m.find())
|
||||||
|
throw new DataParsingException("Unable to get x ");
|
||||||
Double x = Double.parseDouble(m.group(1));
|
Double x = Double.parseDouble(m.group(1));
|
||||||
|
|
||||||
if(!m.find()) throw new DataParsingException("Unable to get y ");
|
if (!m.find())
|
||||||
|
throw new DataParsingException("Unable to get y ");
|
||||||
Double y = Double.parseDouble(m.group(1));
|
Double y = Double.parseDouble(m.group(1));
|
||||||
|
|
||||||
return new POINT(x, y);
|
return new POINT(x, y);
|
||||||
|
@ -119,17 +115,16 @@ public class PostgisTable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final NumberFormat DECIMAL_FORMAT = NumberFormat.getInstance(Locale.US);
|
private static final NumberFormat DECIMAL_FORMAT = NumberFormat.getInstance(Locale.US);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
((DecimalFormat) DECIMAL_FORMAT).setGroupingUsed(false);
|
((DecimalFormat) DECIMAL_FORMAT).setGroupingUsed(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getGeometryColumn() {
|
public String getGeometryColumn() {
|
||||||
for (Field f : fields)
|
for (Field f : fields)
|
||||||
if(f.getType().equals(FieldType.GEOMETRY)) return f.getName();
|
if (f.getType().equals(FieldType.GEOMETRY))
|
||||||
|
return f.getName();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +134,6 @@ public class PostgisTable {
|
||||||
@NonNull
|
@NonNull
|
||||||
private List<Field> fields;
|
private List<Field> fields;
|
||||||
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private GeometryType geometryColumnType;
|
private GeometryType geometryColumnType;
|
||||||
|
|
||||||
|
@ -173,14 +167,14 @@ public class PostgisTable {
|
||||||
return "DELETE FROM " + tablename + " WHERE " + field.getName() + " = ? ";
|
return "DELETE FROM " + tablename + " WHERE " + field.getName() + " = ? ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getInsertionStatement(boolean geometryText) {
|
public String getInsertionStatement(boolean geometryText) {
|
||||||
StringBuilder fieldList = new StringBuilder();
|
StringBuilder fieldList = new StringBuilder();
|
||||||
StringBuilder fieldInsertion = new StringBuilder();
|
StringBuilder fieldInsertion = new StringBuilder();
|
||||||
|
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
switch (field.getType()) {
|
switch (field.getType()) {
|
||||||
case AUTOINCREMENT : break;
|
case AUTOINCREMENT:
|
||||||
|
break;
|
||||||
case GEOMETRY: {
|
case GEOMETRY: {
|
||||||
fieldList.append(field.getName() + ",");
|
fieldList.append(field.getName() + ",");
|
||||||
if (geometryText)
|
if (geometryText)
|
||||||
|
@ -199,19 +193,15 @@ public class PostgisTable {
|
||||||
fieldList.deleteCharAt(fieldList.lastIndexOf(","));
|
fieldList.deleteCharAt(fieldList.lastIndexOf(","));
|
||||||
fieldInsertion.deleteCharAt(fieldInsertion.lastIndexOf(","));
|
fieldInsertion.deleteCharAt(fieldInsertion.lastIndexOf(","));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return "Insert into " + tablename + " (" + fieldList + ") VALUES (" + fieldInsertion + ")";
|
return "Insert into " + tablename + " (" + fieldList + ") VALUES (" + fieldInsertion + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void fillObjectsPreparedStatement(Map<String, Object> row, PreparedStatement toFill) throws SQLException {
|
public void fillObjectsPreparedStatement(Map<String, Object> row, PreparedStatement toFill) throws SQLException {
|
||||||
int psFieldIndex = 0;
|
int psFieldIndex = 0;
|
||||||
HashMap<String, Object> rowValues = new HashMap<String, Object>();
|
HashMap<String, Object> rowValues = new HashMap<String, Object>();
|
||||||
for (Map.Entry<String, Object> entry : row.entrySet())
|
for (Map.Entry<String, Object> entry : row.entrySet())
|
||||||
rowValues.put(sanitizeFieldName(entry.getKey()), entry.getValue());
|
rowValues.put(sanitizeFieldName(entry.getKey()), entry.getValue());
|
||||||
|
|
||||||
|
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
if (!field.getType().equals(FieldType.AUTOINCREMENT)) {
|
if (!field.getType().equals(FieldType.AUTOINCREMENT)) {
|
||||||
psFieldIndex++;
|
psFieldIndex++;
|
||||||
|
@ -221,12 +211,11 @@ public class PostgisTable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setObjectInPreparedStatement(Field field, Object value, PreparedStatement toFill, int psFieldIndex)
|
||||||
public void setObjectInPreparedStatement(Field field,Object value, PreparedStatement toFill, int psFieldIndex) throws SQLException {
|
throws SQLException {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
try {
|
try {
|
||||||
toFill.setNull(psFieldIndex, field.getType().sqlType);
|
toFill.setNull(psFieldIndex, field.getType().sqlType);
|
||||||
|
@ -234,8 +223,7 @@ public class PostgisTable {
|
||||||
log.error("Unable to set null for field " + field);
|
log.error("Unable to set null for field " + field);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
switch (field.getType()) {
|
switch (field.getType()) {
|
||||||
case FLOAT: {
|
case FLOAT: {
|
||||||
toFill.setFloat(psFieldIndex, (Float) value);
|
toFill.setFloat(psFieldIndex, (Float) value);
|
||||||
|
@ -252,7 +240,8 @@ public class PostgisTable {
|
||||||
case GEOMETRY: {
|
case GEOMETRY: {
|
||||||
if (value instanceof String)
|
if (value instanceof String)
|
||||||
toFill.setString(psFieldIndex, ((String) value));
|
toFill.setString(psFieldIndex, ((String) value));
|
||||||
else toFill.setBytes(psFieldIndex, (byte[])value);
|
else
|
||||||
|
toFill.setBytes(psFieldIndex, (byte[]) value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BOOLEAN: {
|
case BOOLEAN: {
|
||||||
|
@ -262,10 +251,26 @@ public class PostgisTable {
|
||||||
toFill.setBoolean(psFieldIndex, (Boolean) value);
|
toFill.setBoolean(psFieldIndex, (Boolean) value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// Added by Francesco
|
||||||
|
default: {
|
||||||
|
if (value instanceof String) {
|
||||||
|
toFill.setString(psFieldIndex, ((String) value));
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
String toStringValue = value.toString();
|
||||||
|
toFill.setString(psFieldIndex, toStringValue);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// silence
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillCSVPreparedStatament(Map<String,String> row, PreparedStatement toFill,boolean explicitGeometry) throws SQLException {
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillCSVPreparedStatament(Map<String, String> row, PreparedStatement toFill, boolean explicitGeometry)
|
||||||
|
throws SQLException {
|
||||||
int psFieldIndex = 0;
|
int psFieldIndex = 0;
|
||||||
|
|
||||||
HashMap<String, String> rowValues = new HashMap<String, String>();
|
HashMap<String, String> rowValues = new HashMap<String, String>();
|
||||||
|
@ -274,7 +279,6 @@ public class PostgisTable {
|
||||||
|
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
|
|
||||||
|
|
||||||
if (!field.getType().equals(FieldType.AUTOINCREMENT)) {
|
if (!field.getType().equals(FieldType.AUTOINCREMENT)) {
|
||||||
psFieldIndex++;
|
psFieldIndex++;
|
||||||
|
|
||||||
|
@ -310,11 +314,12 @@ public class PostgisTable {
|
||||||
} else {
|
} else {
|
||||||
switch (geometryColumnType) {
|
switch (geometryColumnType) {
|
||||||
case POINT: {
|
case POINT: {
|
||||||
String xRepresentation=DECIMAL_FORMAT.format(Double.parseDouble(rowValues.get(DBConstants.Defaults.XCOORD_FIELD)));
|
String xRepresentation = DECIMAL_FORMAT
|
||||||
String yRepresentation=DECIMAL_FORMAT.format(Double.parseDouble(rowValues.get(DBConstants.Defaults.YCOORD_FIELD)));
|
.format(Double.parseDouble(rowValues.get(DBConstants.Defaults.XCOORD_FIELD)));
|
||||||
|
String yRepresentation = DECIMAL_FORMAT
|
||||||
|
.format(Double.parseDouble(rowValues.get(DBConstants.Defaults.YCOORD_FIELD)));
|
||||||
|
|
||||||
toFill.setString(psFieldIndex, "POINT("+xRepresentation+" "+
|
toFill.setString(psFieldIndex, "POINT(" + xRepresentation + " " + yRepresentation + ")");
|
||||||
yRepresentation+")");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -328,9 +333,6 @@ public class PostgisTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +341,4 @@ public class PostgisTable {
|
||||||
return fieldName.toLowerCase().replaceAll("[^a-z0-9_\\\\]", "_");
|
return fieldName.toLowerCase().replaceAll("[^a-z0-9_\\\\]", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
|
||||||
centroidDoc.put(DBConstants.Defaults.PROJECT_ID, project.getId());
|
centroidDoc.put(DBConstants.Defaults.PROJECT_ID, project.getId());
|
||||||
centroidDoc.put(DBConstants.Defaults.DISPLAYED, true);
|
centroidDoc.put(DBConstants.Defaults.DISPLAYED, true);
|
||||||
|
|
||||||
|
//Added by Francesco. Creating Gis Viewer Link as public or private
|
||||||
Boolean isInternalIndex = null;
|
Boolean isInternalIndex = null;
|
||||||
try {
|
try {
|
||||||
isInternalIndex = requestArguments.getBoolean("flagInternalIndex");
|
isInternalIndex = requestArguments.getBoolean("flagInternalIndex");
|
||||||
|
|
Loading…
Reference in New Issue