Fixed create query
This commit is contained in:
parent
1deb586924
commit
5ecaf67020
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.accounting.utility.postgresql;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.SortedSet;
|
||||
|
@ -8,9 +9,14 @@ import java.util.TimeZone;
|
|||
import java.util.TreeSet;
|
||||
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.postgresql.core.Utils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PostgreSQLQuery {
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(PostgreSQLQuery.class);
|
||||
|
||||
private static final String UTC_TIME_ZONE = "UTC";
|
||||
|
||||
public static final TimeZone DEFAULT_TIME_ZONE = TimeZone.getTimeZone(UTC_TIME_ZONE);
|
||||
|
@ -19,12 +25,12 @@ public class PostgreSQLQuery {
|
|||
|
||||
protected StringBuffer stringBuffer;
|
||||
|
||||
protected String getQuotedString(String string) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append("'");
|
||||
buffer.append(string);
|
||||
buffer.append("'");
|
||||
return buffer.toString();
|
||||
protected String getQuotedString(String string) throws SQLException {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("'");
|
||||
Utils.escapeLiteral(builder, string, false);
|
||||
builder.append("'");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
protected void appendString(String string) {
|
||||
|
@ -33,11 +39,11 @@ public class PostgreSQLQuery {
|
|||
stringBuffer.append("'");
|
||||
}
|
||||
|
||||
protected void appendValue(Serializable serializable) {
|
||||
protected void appendValue(Serializable serializable) throws SQLException {
|
||||
stringBuffer.append(getValue(serializable));
|
||||
}
|
||||
|
||||
protected String getValue(Serializable serializable) {
|
||||
protected String getValue(Serializable serializable) throws SQLException {
|
||||
if(serializable instanceof Number) {
|
||||
return serializable.toString();
|
||||
}
|
||||
|
@ -94,8 +100,14 @@ public class PostgreSQLQuery {
|
|||
}
|
||||
stringBuffer.append(") VALUES");
|
||||
stringBuffer.append(values);
|
||||
stringBuffer.append(");");
|
||||
return stringBuffer.toString();
|
||||
stringBuffer.append(")");
|
||||
stringBuffer.append(" ON CONFLICT (");
|
||||
String dbField = recordToDBFields.getTableField(Record.ID);
|
||||
stringBuffer.append(dbField);
|
||||
stringBuffer.append(") DO NOTHING;");
|
||||
String ret = stringBuffer.toString();
|
||||
logger.trace("Created query {}", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue