public JSONObject fromName(String intPlaceId, UserRepository userRepository) throws Exception { String queryString = "SELECT " + serverSupported.getFieldNamesList(); String clientFieldList = clientSide.getFieldNamesList(); /* * Assume there must be serverSupported fields but allow for no clientSide fields... */ if (clientFieldList != "") { queryString += "," + clientFieldList; } queryString += " FROM " + tableName + " WHERE place_id=?;"; PreparedStatement stmt = connection.prepareStatement(queryString); serverSupported.writeToPreparedStatement(stmt, "place_id", 1, intPlaceId); //logger.info(stmt.toString()); JSONArray contributions = executeContribSelectToJson(stmt, userRepository); JSONObject result = new JSONObject(); result.put("contributions", contributions); return(result); }
private void allFieldsInDb(String list, boolean checkServerSupported) throws Exception { String[] fieldNames = list.split(","); for (String field : fieldNames) { boolean exists = false; if (checkServerSupported && serverSupported.includes(field)) { exists = true; } else if (!checkServerSupported && clientSide.includes(field)) { exists = true; } if (!exists) { throw new Exception(field + " does not exist in the " + tableName + " schema."); } } }
public void insert(Map<String, List<String>> fieldPairs) throws Exception { String serverFields = serverSupported.getFieldNamesList(); String clientFields = clientSide.getFieldNamesList(); if (serverSupported.includes(idColumnName)) { // for insert - need to autoincrement id int aiValue = ColumnDataUtils.obtainNextIncrementInteger( connection, serverSupported.getColumnData(idColumnName)); List<String> paramList = fieldPairs.get(idColumnName); if (null == paramList) { queryString += ","; queryString += serverSupported.getInsertWildcard(eTokens[i]); queryString += clientSide.getInsertWildcard(oTokens[i]); serverSupported.addParameterToPreparedStatement(stmt, eTokens[i], index, fieldPairs); index++; clientSide.addParameterToPreparedStatement(stmt, oTokens[i], index, fieldPairs); index++;
public void update(Map<String, List<String>> fieldPairs) throws Exception { String[] fullList_serverFields = serverSupported.getFieldNamesList().split(","); String[] fullList_clientFields = clientSide.getFieldNamesList().split(","); queryString += ","; queryString += serverSupported.getUpdateWildcard(eTokens[i]); queryString += clientSide.getUpdateWildcard(oTokens[i]); queryString += ") WHERE id = " + serverSupported.getUpdateWildcard("id"); queryString += " AND place_id = " + serverSupported.getUpdateWildcard("place_id") + ";"; serverSupported.addParameterToPreparedStatement(stmt, eTokens[i], index, fieldPairs); index++; clientSide.addParameterToPreparedStatement(stmt, oTokens[i], index, fieldPairs); index++; serverSupported.addParameterToPreparedStatement(stmt, "id", index, fieldPairs); index++; serverSupported.addParameterToPreparedStatement(stmt, "place_id", index, fieldPairs);
private void readProperties(Properties props) throws Exception { tableName = props.getProperty(PROPERTIES_KEY_TABLE_NAME, DEFAULT_TABLE_NAME); idColumnName = props.getProperty(PROPERTIES_KEY_ID_COLUMN_NAME, DEFAULT_ID_COLUMN_NAME); idSequenceName = props.getProperty(PROPERTIES_KEY_ID_SEQUENCE_NAME, DEFAULT_ID_SEQUENCE_NAME); String serverFieldList = props.getProperty(PROPERTIES_KEY_SERVER_SUPPORTED_COLUMNS, DEFAULT_SERVER_SUPPORTED_COLUMNS); String clientFieldList = props.getProperty(PROPERTIES_KEY_CLIENT_SIDE_COLUMNS, DEFAULT_CLIENT_SIDE_COLUMNS); createServerSupportedAndClientSideLists(serverFieldList, clientFieldList); allFieldsInDb(serverFieldList, true); // verify all fields in prop lists accounted for in db - throw exception otherwise allFieldsInDb(clientFieldList, false); if (serverSupported.includes(idColumnName)) { // mark that column as auto incremented serverSupported.setAutoIncrementSequence(idColumnName, idSequenceName); } else { throw new Exception(idColumnName + " must be included in the serverSupported field list."); } deleteSqlStatement = "DELETE FROM \""+tableName+"\" WHERE \""+idColumnName+"\" = ?;"; }
throw new Exception(columnName + " is included in both the serverSupported and clientSide contribution field lists."); } else if (isServerSupported) { serverSupported.addColumn(columnName, rsmd.getColumnType(loop+1), rsmd.getColumnTypeName(loop+1)); } else if (isClientSide) { clientSide.addColumn(columnName, rsmd.getColumnType(loop+1), rsmd.getColumnTypeName(loop+1)); } else { // huh? in neither list throw new Exception(columnName + " is NOT included in either the serverSupported or clientSide contribution field lists.");