List of usage examples for com.google.gson JsonPrimitive getAsLong
@Override public long getAsLong()
From source file:ProcessRequest.java
public void newProduct(JSONObject recordObject) throws JSONException, SQLException { String valuesPortion = ""; String columnsPortion = ""; recordObject.remove(DbSingleton.ProductSchema.COLUMN_LAST_MODIFIED); recordObject.put(DbSingleton.ProductSchema.COLUMN_LAST_MODIFIED, mDateFormat.format(new java.util.Date())); recordObject.remove("TMSRowGUID"); //get column names JsonParser parser = new JsonParser(); JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet(); {// ww w. j a v a2 s . co m Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { if (!columnsPortion.equals("")) { columnsPortion += ","; } columnsPortion += entry.getKey(); } } } //get values { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); if (value.isString()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += "'" + value.getAsString() + "'"; } else if (value.isNumber()) { if (value.getAsString().contains(".")) { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += new Double(value.getAsDouble()).toString(); } else { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += new Long(value.getAsLong()).toString(); } } else if (value.isBoolean()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } if (value.getAsBoolean()) valuesPortion += "1"; else valuesPortion += "0"; } } } } String insertQuery = "INSERT INTO " + DbSingleton.PRODUCT_TABLE_NAME + "(" + columnsPortion + ") VALUES (" + valuesPortion + ")"; String identQuery = "SELECT IDENT_CURRENT ('" + DbSingleton.PRODUCT_TABLE_NAME + "') AS ProductID"; executeQuery(insertQuery); }
From source file:ProcessRequest.java
public void newCustomer(JSONObject recordObject) throws JSONException, SQLException { String valuesPortion = ""; String columnsPortion = ""; String dob = null;//from w ww.j av a 2s. c o m try { dob = mDateFormat .format(new java.util.Date(recordObject.getLong(DbSingleton.CustomerSchema.COLUMN_DL_DOB))); } catch (JSONException jsone) { dob = recordObject.getString(DbSingleton.CustomerSchema.COLUMN_DL_DOB); } finally { recordObject.put(DbSingleton.CustomerSchema.COLUMN_DL_DOB, dob); } String issueDate = null; try { issueDate = mDateFormat.format( new java.util.Date(recordObject.getLong(DbSingleton.CustomerSchema.COLUMN_DL_ISSUE_DATE))); } catch (JSONException jsone) { issueDate = recordObject.getString(DbSingleton.CustomerSchema.COLUMN_DL_ISSUE_DATE); } finally { recordObject.put(DbSingleton.CustomerSchema.COLUMN_DL_ISSUE_DATE, issueDate); } String expirationDate = null; try { expirationDate = mDateFormat.format( new java.util.Date(recordObject.getLong(DbSingleton.CustomerSchema.COLUMN_DL_EXPIRATION_DATE))); } catch (JSONException jsone) { expirationDate = recordObject.getString(DbSingleton.CustomerSchema.COLUMN_DL_EXPIRATION_DATE); } finally { recordObject.put(DbSingleton.CustomerSchema.COLUMN_DL_EXPIRATION_DATE, expirationDate); } recordObject.remove(DbSingleton.CustomerSchema.COLUMN_LAST_MODIFIED); recordObject.put(DbSingleton.CustomerSchema.COLUMN_LAST_MODIFIED, mDateFormat.format(new java.util.Date())); recordObject.remove("TMSRowGUID"); //get column names JsonParser parser = new JsonParser(); JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet(); { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { if (!columnsPortion.equals("")) { columnsPortion += ","; } columnsPortion += entry.getKey(); } } } //get values { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); if (value.isString()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += "'" + value.getAsString() + "'"; } else if (value.isNumber()) { if (value.getAsString().contains(".")) { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += new Double(value.getAsDouble()).toString(); } else { if (!valuesPortion.equals("")) { valuesPortion += ","; } valuesPortion += new Long(value.getAsLong()).toString(); } } else if (value.isBoolean()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } if (value.getAsBoolean()) valuesPortion += "1"; else valuesPortion += "0"; } } } } String insertQuery = "INSERT INTO " + DbSingleton.CUSTOMER_TABLE_NAME + "(" + columnsPortion + ") VALUES (" + valuesPortion + ")"; //String identQuery = "SELECT IDENT_CURRENT ('"+DbSingleton.CUSTOMER_TABLE_NAME+"') AS CustomerID"; //String customerIsHaulerQuery = "SELECT * FROM "+DbSingleton.CUSTOMER_TABLE_NAME+" " executeQuery(insertQuery); /* ResultSet identResultSet = executeQuery(identQuery); identResultSet.first(); //System.out.println(identResultSet.getRow()); int customerID = identResultSet.getInt(1); //System.out.println(ticketID); return customerID; */ }
From source file:ProcessRequest.java
public void updateTicket(JSONObject recordObject) throws SQLException, JSONException { //check for ticket existence //check for ticket detail existence String valuesPortion = ""; String ticketDate = null;//from w ww .java2 s. com try { ticketDate = mDateFormat .format(new java.util.Date(recordObject.getLong(DbSingleton.TicketSchema.COLUMN_TICKET_DATE))); } catch (JSONException jsone) { ticketDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_TICKET_DATE); } finally { recordObject.put(DbSingleton.TicketSchema.COLUMN_TICKET_DATE, ticketDate); } String invoiceDate = null; try { invoiceDate = mDateFormat .format(new java.util.Date(recordObject.getLong(DbSingleton.TicketSchema.COLUMN_INVOICE_DATE))); } catch (JSONException jsone) { invoiceDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_INVOICE_DATE); } finally { recordObject.put(DbSingleton.TicketSchema.COLUMN_INVOICE_DATE, invoiceDate); } String voucherRedeemableDate = null; try { voucherRedeemableDate = mDateFormat.format(new java.util.Date( recordObject.getLong(DbSingleton.TicketSchema.COLUMN_VOUCHER_REDEEMABLE_DATE))); } catch (JSONException jsone) { voucherRedeemableDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_VOUCHER_REDEEMABLE_DATE); } finally { recordObject.put(DbSingleton.TicketSchema.COLUMN_VOUCHER_REDEEMABLE_DATE, voucherRedeemableDate); } String voucherExpirationDate = null; try { voucherExpirationDate = mDateFormat.format(new java.util.Date( recordObject.getLong(DbSingleton.TicketSchema.COLUMN_VOUCHER_EXPIRATION_DATE))); } catch (JSONException jsone) { voucherExpirationDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_VOUCHER_EXPIRATION_DATE); } finally { recordObject.put(DbSingleton.TicketSchema.COLUMN_VOUCHER_EXPIRATION_DATE, voucherExpirationDate); } String paymentDate = null; try { paymentDate = mDateFormat .format(new java.util.Date(recordObject.getLong(DbSingleton.TicketSchema.COLUMN_PAYMENT_DATE))); } catch (JSONException jsone) { paymentDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_PAYMENT_DATE); } finally { recordObject.put(DbSingleton.TicketSchema.COLUMN_PAYMENT_DATE, paymentDate); } String trailerLastTareDate = null; try { trailerLastTareDate = mDateFormat.format(new java.util.Date( recordObject.getLong(DbSingleton.TicketSchema.COLUMN_TRAILER_LAST_TARE_DATE))); } catch (JSONException jsone) { trailerLastTareDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_TRAILER_LAST_TARE_DATE); } finally { recordObject.put(DbSingleton.TicketSchema.COLUMN_TRAILER_LAST_TARE_DATE, trailerLastTareDate); } String truckLastTareDate = null; try { truckLastTareDate = mDateFormat.format( new java.util.Date(recordObject.getLong(DbSingleton.TicketSchema.COLUMN_TRUCK_LAST_TARE_DATE))); } catch (JSONException jsone) { truckLastTareDate = recordObject.getString(DbSingleton.TicketSchema.COLUMN_TRUCK_LAST_TARE_DATE); } finally { recordObject.put(DbSingleton.TicketSchema.COLUMN_TRUCK_LAST_TARE_DATE, truckLastTareDate); } recordObject.remove(DbSingleton.TicketSchema.COLUMN_LAST_MODIFIED); recordObject.put(DbSingleton.TicketSchema.COLUMN_LAST_MODIFIED, mDateFormat.format(new java.util.Date())); recordObject.remove("TMSRowGUID"); //recordObject.remove(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER); //recordObject.put(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER, getNextTicketNumber()); //get column names JsonParser parser = new JsonParser(); JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet(); Integer ticketID = null; //get values { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); //System.out.println(entry.getKey()+" : "+value.getAsString()); if (value.isString()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : '"+value.getAsString()+"'"); valuesPortion += entry.getKey() + "="; valuesPortion += "'" + value.getAsString() + "'"; } else if (value.isNumber()) { if (value.getAsString().contains(".")) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Double(value.getAsDouble()).toString())); valuesPortion += entry.getKey() + "="; valuesPortion += new Double(value.getAsDouble()).toString(); } else { //String ticketNumber = new Long(value.getAsLong()).toString(); Long val = new Long(value.getAsLong()); if (entry.getKey().equals(DbSingleton.TicketSchema.COLUMN_TICKET_ID)) { ticketID = val.intValue(); } else { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Long(value.getAsLong()).toString())); valuesPortion += entry.getKey() + "="; valuesPortion += val.toString(); } } } else if (value.isBoolean()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Boolean(value.getAsBoolean()).toString())); if (value.getAsBoolean()) { valuesPortion += entry.getKey() + "="; valuesPortion += "1"; } else { valuesPortion += entry.getKey() + "="; valuesPortion += "0"; } } } } } //String insertQuery = "INSERT INTO "+DbSingleton.TICKET_DETAIL_TABLE_NAME+"("+columnsPortion+") VALUES ("+valuesPortion+")"; if (ticketID == null) { throw new SQLException("no ticket id found!"); } String updateQuery = "UPDATE " + DbSingleton.TICKET_TABLE_NAME + " SET " + valuesPortion + " WHERE " + DbSingleton.TicketSchema.COLUMN_TICKET_ID + "=" + ticketID; //String identQuery = "SELECT IDENT_CURRENT ('"+DbSingleton.TICKET_DETAIL_TABLE_NAME+"') AS TicketDetailID"; executeQuery(updateQuery); }
From source file:ProcessRequest.java
public void updateTicketDetail(Integer ticketID, JSONObject recordObject) throws SQLException, JSONException { //check for ticket detail existence String valuesPortion = ""; recordObject.remove(DbSingleton.TicketDetailSchema.COLUMN_LAST_MODIFIED); recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_LAST_MODIFIED, mDateFormat.format(new java.util.Date())); recordObject.remove("TMSRowGUID"); String grossDate = null;//from ww w. java 2s. co m try { grossDate = mDateFormat.format( new java.util.Date(recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_GROSS_LBS_DT))); } catch (JSONException jsone) { grossDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_GROSS_LBS_DT); } finally { recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_GROSS_LBS_DT, grossDate); } String grossALTDate = null; try { grossALTDate = mDateFormat.format(new java.util.Date( recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_ALT_GROSS_LBS_DT))); } catch (JSONException jsone) { grossALTDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_ALT_GROSS_LBS_DT); } finally { recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_ALT_GROSS_LBS_DT, grossALTDate); } String tareDate = null; try { tareDate = mDateFormat.format( new java.util.Date(recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_TARE_LBS_DT))); } catch (JSONException jsone) { tareDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_TARE_LBS_DT); } finally { recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_TARE_LBS_DT, tareDate); } String tareALTDate = null; try { tareALTDate = mDateFormat.format(new java.util.Date( recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_ALT_TARE_LBS_DT))); } catch (JSONException jsone) { tareALTDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_ALT_TARE_LBS_DT); } finally { recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_ALT_TARE_LBS_DT, tareALTDate); } String deductDate = null; try { deductDate = mDateFormat.format( new java.util.Date(recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_DEDUCT_LBS_DT))); } catch (JSONException jsone) { deductDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_DEDUCT_LBS_DT); } finally { recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_DEDUCT_LBS_DT, deductDate); } String deductALTDate = null; try { deductALTDate = mDateFormat.format(new java.util.Date( recordObject.getLong(DbSingleton.TicketDetailSchema.COLUMN_ALT_DEDUCT_LBS_DT))); } catch (JSONException jsone) { deductALTDate = recordObject.getString(DbSingleton.TicketDetailSchema.COLUMN_ALT_DEDUCT_LBS_DT); } finally { recordObject.put(DbSingleton.TicketDetailSchema.COLUMN_ALT_DEDUCT_LBS_DT, deductALTDate); } //recordObject.remove(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER); //recordObject.put(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER, getNextTicketNumber()); //get column names JsonParser parser = new JsonParser(); JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet(); Integer ticketDetailID = null; //get values { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); //System.out.println(entry.getKey()+" : "+value.getAsString()); if (value.isString()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : '"+value.getAsString()+"'"); valuesPortion += entry.getKey() + "="; valuesPortion += "'" + value.getAsString() + "'"; } else if (value.isNumber()) { if (value.getAsString().contains(".")) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Double(value.getAsDouble()).toString())); valuesPortion += entry.getKey() + "="; valuesPortion += new Double(value.getAsDouble()).toString(); } else { Long val = new Long(value.getAsLong()); if (entry.getKey().equals(DbSingleton.TicketDetailSchema.COLUMN_TICKET_DETAIL_ID)) { ticketDetailID = val.intValue(); } else { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Long(value.getAsLong()).toString())); valuesPortion += entry.getKey() + "="; //String ticketNumber = new Long(value.getAsLong()).toString(); valuesPortion += val.toString(); } } } else if (value.isBoolean()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Boolean(value.getAsBoolean()).toString())); if (value.getAsBoolean()) { valuesPortion += entry.getKey() + "="; valuesPortion += "1"; } else { valuesPortion += entry.getKey() + "="; valuesPortion += "0"; } } } } } //String insertQuery = "INSERT INTO "+DbSingleton.TICKET_DETAIL_TABLE_NAME+"("+columnsPortion+") VALUES ("+valuesPortion+")"; if (ticketDetailID == null) { throw new SQLException("no ticket detail id found!"); } String updateQuery = "UPDATE " + DbSingleton.TICKET_DETAIL_TABLE_NAME + " SET " + valuesPortion + " WHERE " + DbSingleton.TicketDetailSchema.COLUMN_TICKET_DETAIL_ID + "=" + ticketDetailID; //String identQuery = "SELECT IDENT_CURRENT ('"+DbSingleton.TICKET_DETAIL_TABLE_NAME+"') AS TicketDetailID"; executeQuery(updateQuery); }
From source file:ProcessRequest.java
public int insertNewTicketDetail(JSONObject recordObject) throws SQLException, JSONException { String valuesPortion = ""; String columnsPortion = ""; //recordObject.remove(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER); //recordObject.put(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER, getNextTicketNumber()); //get column names JsonParser parser = new JsonParser(); JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet(); {// ww w . j av a 2s .co m Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); //if(value.isString() && value.getAsString().equals("")) { //don't want this null value/key pair //} else { if (!columnsPortion.equals("")) { columnsPortion += ","; } columnsPortion += entry.getKey(); //System.out.println(entry.getKey()+" : "+value.getAsString()); //} } } } //get values { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); //System.out.println(entry.getKey()+" : "+value.getAsString()); if (value.isString()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : '"+value.getAsString()+"'"); valuesPortion += "'" + value.getAsString() + "'"; } else if (value.isNumber()) { if (value.getAsString().contains(".")) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Double(value.getAsDouble()).toString())); valuesPortion += new Double(value.getAsDouble()).toString(); } else { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Long(value.getAsLong()).toString())); String ticketNumber = new Long(value.getAsLong()).toString(); valuesPortion += ticketNumber; } } else if (value.isBoolean()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Boolean(value.getAsBoolean()).toString())); if (value.getAsBoolean()) valuesPortion += "1"; else valuesPortion += "0"; } } } } String insertQuery = "INSERT INTO " + DbSingleton.TICKET_DETAIL_TABLE_NAME + "(" + columnsPortion + ") VALUES (" + valuesPortion + ")"; String identQuery = "SELECT IDENT_CURRENT ('" + DbSingleton.TICKET_DETAIL_TABLE_NAME + "') AS TicketDetailID"; executeQuery(insertQuery); ResultSet identResultSet = executeQuery(identQuery); identResultSet.first(); //System.out.println(identResultSet.getRow()); int ticketDetailID = identResultSet.getInt(1); //System.out.println(ticketID); return ticketDetailID; }
From source file:ProcessRequest.java
public int insertNewTicket(JSONObject recordObject) throws SQLException, JSONException { String valuesPortion = ""; String columnsPortion = ""; recordObject.remove(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER); recordObject.put(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER, getNextTicketNumber()); //get column names JsonParser parser = new JsonParser(); JsonObject recordGson = parser.parse(recordObject.toString()).getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = recordGson.entrySet(); {//from w w w . jav a 2 s . c o m Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata") || entry.getKey().equals("TicketID")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); //if(value.isString() && value.getAsString().equals("")) { //don't want this null value/key pair //} else { if (!columnsPortion.equals("")) { columnsPortion += ","; } columnsPortion += entry.getKey(); //System.out.println(entry.getKey()+" : "+value.getAsString()); //} } } } //get values { Iterator<Map.Entry<String, JsonElement>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Map.Entry<String, JsonElement> entry = iterator.next(); if (entry.getKey().equals("metadata") || entry.getKey().equals("TicketID")) { //do nothing } else { JsonPrimitive value = entry.getValue().getAsJsonPrimitive(); //System.out.println(entry.getKey()+" : "+value.getAsString()); if (value.isString()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : '"+value.getAsString()+"'"); valuesPortion += "'" + value.getAsString() + "'"; } else if (value.isNumber()) { if (value.getAsString().contains(".")) { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Double(value.getAsDouble()).toString())); valuesPortion += new Double(value.getAsDouble()).toString(); } else { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Long(value.getAsLong()).toString())); String ticketNumber = new Long(value.getAsLong()).toString(); valuesPortion += ticketNumber; } } else if (value.isBoolean()) { if (!valuesPortion.equals("")) { valuesPortion += ","; } if (value.getAsBoolean()) valuesPortion += "1"; else valuesPortion += "0"; } } } } String insertQuery = "INSERT INTO " + DbSingleton.TICKET_TABLE_NAME + "(" + columnsPortion + ") VALUES (" + valuesPortion + ")"; String identQuery = "SELECT IDENT_CURRENT ('" + DbSingleton.TICKET_TABLE_NAME + "') AS TicketID"; executeQuery(insertQuery); ResultSet identResultSet = executeQuery(identQuery); identResultSet.first(); //System.out.println(identResultSet.getRow()); int ticketID = identResultSet.getInt(1); //System.out.println(ticketID); ////////////////////TICKET NUMBER CHECK boolean uniqueTicketNumber = false; while (!uniqueTicketNumber) { String ticketNumberCheckQuery = "SELECT * FROM " + DbSingleton.TICKET_TABLE_NAME + " WHERE " + DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER + "=" + recordObject.getInt(DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER); ResultSet ticketNumberCheckResultSet = executeQuery(ticketNumberCheckQuery); int rowCount = 0; ticketNumberCheckResultSet.last(); rowCount = ticketNumberCheckResultSet.getRow(); ticketNumberCheckResultSet.first(); if (rowCount < 1) throw new SQLException(LOG_TAG + ": wat..."); else if (rowCount > 1) { uniqueTicketNumber = false; } else { uniqueTicketNumber = true; } if (!uniqueTicketNumber) { //update the ticket for the next iteration of this loop, attempting, again, to get a unique ticket number String uniqueTicketNumberQuery = "UPDATE " + DbSingleton.TICKET_TABLE_NAME + " SET " + DbSingleton.TicketSchema.COLUMN_TICKET_NUMBER + "=" + getNextTicketNumber() + " WHERE " + DbSingleton.TicketSchema.COLUMN_TICKET_ID + "=" + ticketID; executeQuery(uniqueTicketNumberQuery); } } //////////////////// return ticketID; }
From source file:at.ac.tuwien.infosys.jcloudscale.datastore.mapping.type.json.JsonLongTypeAdapter.java
License:Apache License
@Override public Long deserialize(JsonElement element, TypeMetadata<JsonElement> typeMetadata) { JsonPrimitive jsonPrimitive = (JsonPrimitive) element; if (!jsonPrimitive.isNumber()) { throw new DatastoreException("Invalid value for long type."); }//from w ww. j ava2 s. c o m return jsonPrimitive.getAsLong(); }
From source file:com.adobe.acs.commons.remoteassets.impl.RemoteAssetsNodeSyncImpl.java
License:Apache License
/** * Set a simple resource property from the fetched JSON. * * @param value Object/*w w w .j a v a 2 s . c o m*/ * @param key String * @param resource Resource * @throws RepositoryException exception */ private void setNodeSimpleProperty(final JsonPrimitive value, final String key, final Resource resource) throws RepositoryException { ValueMap resourceProperties = resource.adaptTo(ModifiableValueMap.class); if (value.isString() && DATE_REGEX.matcher(value.getAsString()).matches()) { try { resourceProperties.put(key, GregorianCalendar.from(ZonedDateTime.parse(value.getAsString(), DATE_TIME_FORMATTER))); } catch (DateTimeParseException e) { LOG.warn("Unable to parse date '{}' for property:resource '{}'.", value, key + ":" + resource.getPath()); } } else if (value.isString() && DECIMAL_REGEX.matcher(value.getAsString()).matches()) { resourceProperties.put(key, value.getAsBigDecimal()); } else if (value.isBoolean()) { resourceProperties.put(key, value.getAsBoolean()); } else if (value.isNumber()) { if (DECIMAL_REGEX.matcher(value.getAsString()).matches()) { resourceProperties.put(key, value.getAsBigDecimal()); } else { resourceProperties.put(key, value.getAsLong()); } } else if (value.isJsonNull()) { resourceProperties.remove(key); } else { resourceProperties.put(key, value.getAsString()); } LOG.trace("Property '{}' added for resource '{}'.", key, resource.getPath()); }
From source file:com.frontier45.flume.sink.elasticsearch2.ElasticSearchLogStashEventSerializer.java
License:Apache License
private Object getValue(JsonElement obj) { JsonPrimitive jp = obj.getAsJsonPrimitive(); if (jp.isBoolean()) { return jp.getAsBoolean(); } else if (jp.isNumber()) { String value = jp.getAsString(); if (value.indexOf(".") > 0) { return jp.getAsDouble(); } else {//from w w w . ja v a2 s . c o m return jp.getAsLong(); } } else if (jp.isString()) { return jp.getAsString(); } return obj; }
From source file:com.getperka.flatpack.codexes.DateCodex.java
License:Apache License
@Override public D readNotNull(JsonElement element, DeserializationContext context) throws Exception { if (element.isJsonPrimitive()) { long instant; JsonPrimitive primitive = element.getAsJsonPrimitive(); if (primitive.isNumber()) { instant = primitive.getAsLong(); } else {// w w w. j av a 2s. co m instant = ISODateTimeFormat.dateTimeParser().parseMillis(primitive.getAsString()); } return constructor.newInstance(instant); } throw new IllegalArgumentException("Could not parse " + element.toString() + " as a date value"); }