List of usage examples for com.google.gson JsonPrimitive getAsDouble
@Override public double getAsDouble()
From source file:ProcessRequest.java
public void updateProduct(JSONObject recordObject) throws JSONException, SQLException { String valuesPortion = ""; 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(); String productID = null;//from ww w. ja v a 2s. com //construct the SQL query from the JSON elements. //the valuesPortion String will contain the values we want to update in the record { 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() + "'"; if (entry.getKey().equals(DbSingleton.ProductSchema.COLUMN_ID)) { productID = 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 { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Long(value.getAsLong()).toString())); valuesPortion += entry.getKey() + "="; valuesPortion += value.getAsString(); } } 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 (productID == null) { throw new SQLException("no customer id found!"); } String updateQuery = "UPDATE " + DbSingleton.PRODUCT_TABLE_NAME + " SET " + valuesPortion + " WHERE " + DbSingleton.ProductSchema.COLUMN_ID + "='" + productID + "'"; //String identQuery = "SELECT IDENT_CURRENT ('"+DbSingleton.TICKET_DETAIL_TABLE_NAME+"') AS TicketDetailID"; executeQuery(updateQuery); }
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(); {//w w w . j a va 2s .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")) { //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 updateCustomer(JSONObject recordObject) throws JSONException, SQLException { String valuesPortion = ""; String dob = null;//from w w w .j a v a2s . 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(); String customerID = 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() + "'"; if (entry.getKey().equals(DbSingleton.CustomerSchema.COLUMN_ID)) { customerID = 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 { if (!valuesPortion.equals("")) { valuesPortion += ","; } //System.out.println(entry.getKey()+" : "+(new Long(value.getAsLong()).toString())); valuesPortion += entry.getKey() + "="; valuesPortion += value.getAsString(); } } 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 (customerID == null) { throw new SQLException("no customer id found!"); } String updateQuery = "UPDATE " + DbSingleton.CUSTOMER_TABLE_NAME + " SET " + valuesPortion + " WHERE " + DbSingleton.CustomerSchema.COLUMN_ID + "='" + customerID + "'"; //String identQuery = "SELECT IDENT_CURRENT ('"+DbSingleton.TICKET_DETAIL_TABLE_NAME+"') AS TicketDetailID"; executeQuery(updateQuery); }
From source file:ProcessRequest.java
public void newCustomer(JSONObject recordObject) throws JSONException, SQLException { String valuesPortion = ""; String columnsPortion = ""; String dob = null;//from w w w . j a v 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 .j ava 2 s . c o m 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 w w w . j a v a 2 s.c o 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(); {//from w w w . ja v a2 s . c om 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(); {// w ww . ja v 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.JsonDoubleTypeAdapter.java
License:Apache License
@Override public Double deserialize(JsonElement element, TypeMetadata<JsonElement> typeMetadata) { JsonPrimitive jsonPrimitive = (JsonPrimitive) element; if (!jsonPrimitive.isNumber()) { throw new DatastoreException("Invalid value for double type."); }/*from www. j a va 2 s . c o m*/ return jsonPrimitive.getAsDouble(); }
From source file:at.orz.arangodb.util.JsonUtils.java
License:Apache License
public static double toDouble(JsonElement elem) { if (elem != null && !elem.isJsonNull()) { JsonPrimitive primitive = elem.getAsJsonPrimitive(); if (primitive.isNumber()) { return primitive.getAsDouble(); } else if (primitive.isString()) { if ("INF".equals(primitive.getAsString())) { return Double.POSITIVE_INFINITY; } else if ("NaN".equals(primitive.getAsString())) { return Double.NaN; }// w w w . ja v a 2 s .co m } } return Double.NaN; }