X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fmusic%2Fconductor%2Fconditionals%2FMusicConditional.java;h=18fa8a18fa6cdc4dd68a98a31b50f2549f686ae0;hb=f9f7fa56adf725801a789ed6c3f5503bb5d243a2;hp=0e8cc14a759acefa85651a8742601c7b4f068b02;hpb=8a4224bffad3139e151722dcc9ddd52731d3d5e6;p=music.git diff --git a/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java b/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java index 0e8cc14a..18fa8a18 100644 --- a/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java +++ b/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java @@ -4,6 +4,9 @@ * =================================================================== * Copyright (c) 2017 AT&T Intellectual Property * =================================================================== + * Modifications Copyright (C) 2019 IBM. + * Modifications Copyright (c) 2019 Samsung + * =================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -19,6 +22,7 @@ * ============LICENSE_END============================================= * ==================================================================== */ + package org.onap.music.conductor.conditionals; import java.io.PrintWriter; @@ -27,12 +31,15 @@ import java.util.HashMap; import java.util.Map; import org.codehaus.jettison.json.JSONObject; +import org.onap.music.datastore.MusicDataStoreHandle; import org.onap.music.datastore.PreparedQueryObject; import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.eelf.logging.format.AppMessages; import org.onap.music.eelf.logging.format.ErrorSeverity; import org.onap.music.eelf.logging.format.ErrorTypes; -import org.onap.music.lockingservice.MusicLockState; +import org.onap.music.exceptions.MusicLockingException; +import org.onap.music.exceptions.MusicQueryException; +import org.onap.music.exceptions.MusicServiceException; import org.onap.music.main.MusicCore; import org.onap.music.main.MusicUtil; import org.onap.music.main.ResultType; @@ -46,251 +53,266 @@ import com.datastax.driver.core.Row; import com.datastax.driver.core.TableMetadata; public class MusicConditional { - private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicDataAPI.class); - private static final String CRITICAL = "critical"; - - public static ReturnType conditionalInsert(String keyspace, String tablename, String casscadeColumnName, - Map casscadeColumnData, String primaryKey, Map valuesMap, - Map status) throws Exception { - - Map queryBank = new HashMap<>(); - TableMetadata tableInfo = null; - tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename); - DataType primaryIdType = tableInfo.getPrimaryKey().get(0).getType(); - String primaryId = tableInfo.getPrimaryKey().get(0).getName(); - DataType casscadeColumnType = tableInfo.getColumn(casscadeColumnName).getType(); - String vector = String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis()); - - PreparedQueryObject select = new PreparedQueryObject(); - select.appendQueryString("SELECT * FROM " + keyspace + "." + tablename + " where " + primaryId + " = ?"); - select.addValue(MusicUtil.convertToActualDataType(primaryIdType, primaryKey)); - queryBank.put(MusicUtil.SELECT, select); - - PreparedQueryObject update = new PreparedQueryObject(); - Map updateColumnvalues = new HashMap<>(); //casscade column values - updateColumnvalues = getValues(true, casscadeColumnData, status); - Object formatedValues = MusicUtil.convertToActualDataType(casscadeColumnType, updateColumnvalues); - update.appendQueryString("UPDATE " + keyspace + "." + tablename + " SET " + casscadeColumnName + " =" - + casscadeColumnName + " + ? , vector_ts = ?" + " WHERE " + primaryId + " = ? "); - update.addValue(formatedValues); - update.addValue(MusicUtil.convertToActualDataType(DataType.text(), vector)); - update.addValue(MusicUtil.convertToActualDataType(primaryIdType, primaryKey)); - queryBank.put(MusicUtil.UPDATE, update); - - - Map insertColumnvalues = new HashMap<>();//casscade column values - insertColumnvalues = getValues(false, casscadeColumnData, status); - formatedValues = MusicUtil.convertToActualDataType(casscadeColumnType, insertColumnvalues); - PreparedQueryObject insert = extractQuery(valuesMap, tableInfo, tablename, keyspace, primaryId, primaryKey,casscadeColumnName,formatedValues); - queryBank.put(MusicUtil.INSERT, insert); - - - String key = keyspace + "." + tablename + "." + primaryKey; - String lockId = MusicCore.createLockReference(key); - long leasePeriod = MusicUtil.getDefaultLockLeasePeriod(); - ReturnType lockAcqResult = MusicCore.acquireLockWithLease(key, lockId, leasePeriod); - - try { - if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) { - ReturnType criticalPutResult = conditionalInsertAtomic(lockId, keyspace, tablename, primaryKey, - queryBank); - MusicCore.destroyLockRef(lockId); - if (criticalPutResult.getMessage().contains("insert")) - criticalPutResult - .setMessage("Insert values: "); - else if (criticalPutResult.getMessage().contains("update")) - criticalPutResult - .setMessage("Update values: " + updateColumnvalues); - return criticalPutResult; - - } else { - MusicCore.destroyLockRef(lockId); - return lockAcqResult; - } - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED); - MusicCore.destroyLockRef(lockId); - return new ReturnType(ResultType.FAILURE, e.getMessage()); - } - - } - - public static ReturnType conditionalInsertAtomic(String lockId, String keyspace, String tableName, - String primaryKey, Map queryBank) { - - ResultSet results = null; - - try { - - MusicLockState mls = MusicCore.getLockingServiceHandle() - .getLockState(keyspace + "." + tableName + "." + primaryKey); - if (mls.getLockHolder().equals(lockId)) { - try { - results = MusicCore.getDSHandle().executeCriticalGet(queryBank.get(MusicUtil.SELECT)); - } catch (Exception e) { - return new ReturnType(ResultType.FAILURE, e.getMessage()); - } - if (results.all().isEmpty()) { - MusicCore.getDSHandle().executePut(queryBank.get(MusicUtil.INSERT), CRITICAL); - return new ReturnType(ResultType.SUCCESS, "insert"); - } else { - MusicCore.getDSHandle().executePut(queryBank.get(MusicUtil.UPDATE), CRITICAL); - return new ReturnType(ResultType.SUCCESS, "update"); - } - } else { - return new ReturnType(ResultType.FAILURE, - "Cannot perform operation since you are the not the lock holder"); - } - - } catch (Exception e) { - StringWriter sw = new StringWriter(); - e.printStackTrace(new PrintWriter(sw)); - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); - String exceptionAsString = sw.toString(); - return new ReturnType(ResultType.FAILURE, - "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n" - + exceptionAsString); - } - - } - - public static ReturnType update(Map queryBank, String keyspace, String tableName, String primaryKey,String primaryKeyValue,String planId,String cascadeColumnName,Map cascadeColumnValues) { - - String key = keyspace + "." + tableName + "." + primaryKeyValue; - String lockId = MusicCore.createLockReference(key); - long leasePeriod = MusicUtil.getDefaultLockLeasePeriod(); - ReturnType lockAcqResult = MusicCore.acquireLockWithLease(key, lockId, leasePeriod); - - try { - - if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) { - return updateAtomic(lockId, keyspace, tableName, primaryKey,primaryKeyValue, queryBank,planId,cascadeColumnValues,cascadeColumnName); - - } else { - MusicCore.destroyLockRef(lockId); - return lockAcqResult; - } - - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); - MusicCore.destroyLockRef(lockId); - return new ReturnType(ResultType.FAILURE, e.getMessage()); - - } - } - - public static ReturnType updateAtomic(String lockId, String keyspace, String tableName, String primaryKey,String primaryKeyValue, - Map queryBank,String planId,Map cascadeColumnValues,String casscadeColumnName) { - try { - - MusicLockState mls = MusicCore.getLockingServiceHandle() - .getLockState(keyspace + "." + tableName + "." + primaryKeyValue); - if (mls.getLockHolder().equals(lockId)) { - Row row = MusicCore.getDSHandle().executeCriticalGet(queryBank.get(MusicUtil.SELECT)).one(); - - if(row != null) { - Map updatedValues = cascadeColumnUpdateSpecific(row, cascadeColumnValues, casscadeColumnName, planId); - JSONObject json = new JSONObject(updatedValues); - PreparedQueryObject update = new PreparedQueryObject(); - String vector_ts = String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis()); - update.appendQueryString("UPDATE " + keyspace + "." + tableName + " SET " + casscadeColumnName + "['" + planId - + "'] = ?, vector_ts = ? WHERE " + primaryKey + " = ?"); - update.addValue(MusicUtil.convertToActualDataType(DataType.text(), json.toString())); - update.addValue(MusicUtil.convertToActualDataType(DataType.text(), vector_ts)); - update.addValue(MusicUtil.convertToActualDataType(DataType.text(), primaryKeyValue)); - try { - MusicCore.getDSHandle().executePut(update, CRITICAL); - } catch (Exception ex) { - return new ReturnType(ResultType.FAILURE, ex.getMessage()); - } - }else { - return new ReturnType(ResultType.FAILURE,"Cannot find data related to key: "+primaryKey); - } - MusicCore.getDSHandle().executePut(queryBank.get(MusicUtil.UPSERT), CRITICAL); - return new ReturnType(ResultType.SUCCESS, "update success"); - - } else { - return new ReturnType(ResultType.FAILURE, - "Cannot perform operation since you are the not the lock holder"); - } - - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); - StringWriter sw = new StringWriter(); - e.printStackTrace(new PrintWriter(sw)); - String exceptionAsString = sw.toString(); - return new ReturnType(ResultType.FAILURE, - "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n" - + exceptionAsString); - } - - } - - @SuppressWarnings("unchecked") - public static Map getValues(boolean isExists, Map casscadeColumnData, - Map status) { - - Map value = new HashMap<>(); - Map returnMap = new HashMap<>(); - Object key = casscadeColumnData.get("key"); - String setStatus = ""; - value = (Map) casscadeColumnData.get("value"); - - if (isExists) - setStatus = status.get("exists"); - else - setStatus = status.get("nonexists"); - - value.put("status", setStatus); - JSONObject valueJson = new JSONObject(value); - returnMap.put(key.toString(), valueJson.toString()); - return returnMap; - - } - - public static PreparedQueryObject extractQuery(Map valuesMap, TableMetadata tableInfo, String tableName, - String keySpaceName,String primaryKeyName,String primaryKey,String casscadeColumn,Object casscadeColumnValues) throws Exception { - - PreparedQueryObject queryObject = new PreparedQueryObject(); - StringBuilder fieldsString = new StringBuilder("(vector_ts"+","); - StringBuilder valueString = new StringBuilder("(" + "?" + ","); - String vector = String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis()); - queryObject.addValue(vector); - if(casscadeColumn!=null && casscadeColumnValues!=null) { - fieldsString.append("" +casscadeColumn+" ," ); - valueString.append("?,"); - queryObject.addValue(casscadeColumnValues); - } - - int counter = 0; - for (Map.Entry entry : valuesMap.entrySet()) { + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicDataAPI.class); + + public static ReturnType conditionalInsert(String keyspace, String tablename, String casscadeColumnName, + Map casscadeColumnData, String primaryKey, Map valuesMap, + Map status) throws Exception { + + Map queryBank = new HashMap<>(); + TableMetadata tableInfo = null; + tableInfo = MusicDataStoreHandle.returnColumnMetadata(keyspace, tablename); + DataType primaryIdType = tableInfo.getPrimaryKey().get(0).getType(); + String primaryId = tableInfo.getPrimaryKey().get(0).getName(); + DataType casscadeColumnType = tableInfo.getColumn(casscadeColumnName).getType(); + String vector = String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis()); + + PreparedQueryObject select = new PreparedQueryObject(); + select.appendQueryString("SELECT * FROM " + keyspace + "." + tablename + " where " + primaryId + " = ?"); + select.addValue(MusicUtil.convertToActualDataType(primaryIdType, primaryKey)); + queryBank.put(MusicUtil.SELECT, select); + + PreparedQueryObject update = new PreparedQueryObject(); + //casscade column values + Map updateColumnvalues = getValues(true, casscadeColumnData, status); + Object formatedValues = MusicUtil.convertToActualDataType(casscadeColumnType, updateColumnvalues); + update.appendQueryString("UPDATE " + keyspace + "." + tablename + " SET " + casscadeColumnName + " =" + + casscadeColumnName + " + ? , vector_ts = ?" + " WHERE " + primaryId + " = ? "); + update.addValue(formatedValues); + update.addValue(MusicUtil.convertToActualDataType(DataType.text(), vector)); + update.addValue(MusicUtil.convertToActualDataType(primaryIdType, primaryKey)); + queryBank.put(MusicUtil.UPDATE, update); + + + //casscade column values + Map insertColumnvalues = getValues(false, casscadeColumnData, status); + formatedValues = MusicUtil.convertToActualDataType(casscadeColumnType, insertColumnvalues); + PreparedQueryObject insert = extractQuery(valuesMap, tableInfo, tablename, keyspace, primaryId, primaryKey,casscadeColumnName,formatedValues); + queryBank.put(MusicUtil.INSERT, insert); + + + String key = keyspace + "." + tablename + "." + primaryKey; + String lockId; + try { + lockId = MusicCore.createLockReference(key); + } catch (MusicLockingException e) { + return new ReturnType(ResultType.FAILURE, e.getMessage()); + } + long leasePeriod = MusicUtil.getDefaultLockLeasePeriod(); + ReturnType lockAcqResult = MusicCore.acquireLockWithLease(key, lockId, leasePeriod); + + try { + if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) { + ReturnType criticalPutResult = conditionalInsertAtomic(lockId, keyspace, tablename, primaryKey, + queryBank); + MusicCore.destroyLockRef(lockId); + if (criticalPutResult.getMessage().contains("insert")) + criticalPutResult + .setMessage("Insert values: "); + else if (criticalPutResult.getMessage().contains("update")) + criticalPutResult + .setMessage("Update values: " + updateColumnvalues); + return criticalPutResult; + + } else { + MusicCore.destroyLockRef(lockId); + return lockAcqResult; + } + } catch (Exception e) { + logger.error(EELFLoggerDelegate.applicationLogger, e); + MusicCore.destroyLockRef(lockId); + return new ReturnType(ResultType.FAILURE, e.getMessage()); + } + + } + + public static ReturnType conditionalInsertAtomic(String lockId, String keyspace, String tableName, + String primaryKey, Map queryBank) { + + ResultSet results = null; + + try { + String fullyQualifiedKey = keyspace + "." + tableName + "." + primaryKey; + ReturnType lockAcqResult = MusicCore.acquireLock(fullyQualifiedKey, lockId); + if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) { + try { + results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(queryBank.get(MusicUtil.SELECT)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.applicationLogger, e); + return new ReturnType(ResultType.FAILURE, e.getMessage()); + } + if (results.all().isEmpty()) { + MusicDataStoreHandle.getDSHandle().executePut(queryBank.get(MusicUtil.INSERT), "critical"); + return new ReturnType(ResultType.SUCCESS, "insert"); + } else { + MusicDataStoreHandle.getDSHandle().executePut(queryBank.get(MusicUtil.UPDATE), "critical"); + return new ReturnType(ResultType.SUCCESS, "update"); + } + } else { + return new ReturnType(ResultType.FAILURE, + "Cannot perform operation since you are the not the lock holder"); + } + + } catch (Exception e) { + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw)); + String exceptionAsString = sw.toString(); + logger.error(EELFLoggerDelegate.applicationLogger, e); + return new ReturnType(ResultType.FAILURE, + "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n" + + exceptionAsString); + } + + } + + public static ReturnType update(UpdateDataObject dataObj) + throws MusicLockingException, MusicQueryException, MusicServiceException { + + String key = dataObj.getKeyspace() + "." + dataObj.getTableName() + "." + dataObj.getPrimaryKeyValue(); + String lockId = MusicCore.createLockReference(key); + long leasePeriod = MusicUtil.getDefaultLockLeasePeriod(); + ReturnType lockAcqResult = MusicCore.acquireLockWithLease(key, lockId, leasePeriod); + + try { + + if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) { + ReturnType criticalPutResult = updateAtomic(new UpdateDataObject().setLockId(lockId) + .setKeyspace(dataObj.getKeyspace()) + .setTableName( dataObj.getTableName()) + .setPrimaryKey(dataObj.getPrimaryKey()) + .setPrimaryKeyValue(dataObj.getPrimaryKeyValue()) + .setQueryBank(dataObj.getQueryBank()) + .setPlanId(dataObj.getPlanId()) + .setCascadeColumnValues(dataObj.getCascadeColumnValues()) + .setCascadeColumnName(dataObj.getCascadeColumnName())); + + MusicCore.destroyLockRef(lockId); + return criticalPutResult; + } else { + MusicCore.destroyLockRef(lockId); + return lockAcqResult; + } + + } catch (Exception e) { + MusicCore.destroyLockRef(lockId); + logger.error(EELFLoggerDelegate.applicationLogger, e); + return new ReturnType(ResultType.FAILURE, e.getMessage()); + + } + } + + public static ReturnType updateAtomic(UpdateDataObject dataObj) { + try { + String fullyQualifiedKey = dataObj.getKeyspace() + "." + dataObj.getTableName() + "." + dataObj.getPrimaryKeyValue(); + ReturnType lockAcqResult = MusicCore.acquireLock(fullyQualifiedKey, dataObj.getLockId()); + + if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) { + Row row = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(dataObj.getQueryBank().get(MusicUtil.SELECT)).one(); + + if(row != null) { + Map updatedValues = cascadeColumnUpdateSpecific(row, dataObj.getCascadeColumnValues(), dataObj.getCascadeColumnName(), dataObj.getPlanId()); + JSONObject json = new JSONObject(updatedValues); + PreparedQueryObject update = new PreparedQueryObject(); + String vector_ts = String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis()); + update.appendQueryString("UPDATE " + dataObj.getKeyspace() + "." + dataObj.getTableName() + " SET " + dataObj.getCascadeColumnName() + "['" + dataObj.getPlanId() + + "'] = ?, vector_ts = ? WHERE " + dataObj.getPrimaryKey() + " = ?"); + update.addValue(MusicUtil.convertToActualDataType(DataType.text(), json.toString())); + update.addValue(MusicUtil.convertToActualDataType(DataType.text(), vector_ts)); + update.addValue(MusicUtil.convertToActualDataType(DataType.text(), dataObj.getPrimaryKeyValue())); + try { + MusicDataStoreHandle.getDSHandle().executePut(update, "critical"); + } catch (Exception ex) { + logger.error(EELFLoggerDelegate.applicationLogger, ex); + return new ReturnType(ResultType.FAILURE, ex.getMessage()); + } + }else { + return new ReturnType(ResultType.FAILURE,"Cannot find data related to key: "+dataObj.getPrimaryKey()); + } + MusicDataStoreHandle.getDSHandle().executePut(dataObj.getQueryBank().get(MusicUtil.UPSERT), "critical"); + return new ReturnType(ResultType.SUCCESS, "update success"); + + } else { + return new ReturnType(ResultType.FAILURE, + "Cannot perform operation since you are the not the lock holder"); + } + + } catch (Exception e) { + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw)); + String exceptionAsString = sw.toString(); + logger.error(EELFLoggerDelegate.applicationLogger, e); + return new ReturnType(ResultType.FAILURE, + "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n" + + exceptionAsString); + } + + } + + @SuppressWarnings("unchecked") + public static Map getValues(boolean isExists, Map casscadeColumnData, + Map status) { + + Map returnMap = new HashMap<>(); + Object key = casscadeColumnData.get("key"); + String setStatus = ""; + Map value = (Map) casscadeColumnData.get("value"); + + if (isExists) + setStatus = status.get("exists"); + else + setStatus = status.get("nonexists"); + + value.put("status", setStatus); + JSONObject valueJson = new JSONObject(value); + returnMap.put(key.toString(), valueJson.toString()); + return returnMap; + + } + + public static PreparedQueryObject extractQuery(Map valuesMap, TableMetadata tableInfo, String tableName, + String keySpaceName,String primaryKeyName,String primaryKey,String casscadeColumn,Object casscadeColumnValues) throws Exception { + + PreparedQueryObject queryObject = new PreparedQueryObject(); + StringBuilder fieldsString = new StringBuilder("(vector_ts"+","); + StringBuilder valueString = new StringBuilder("(" + "?" + ","); + String vector = String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis()); + String localPrimaryKey; + queryObject.addValue(vector); + if(casscadeColumn!=null && casscadeColumnValues!=null) { + fieldsString.append(casscadeColumn).append(" ,"); + valueString.append("?,"); + queryObject.addValue(casscadeColumnValues); + } + + int counter = 0; + for (Map.Entry entry : valuesMap.entrySet()) { - fieldsString.append("" + entry.getKey()); + fieldsString.append(entry.getKey()); Object valueObj = entry.getValue(); if (primaryKeyName.equals(entry.getKey())) { - primaryKey = entry.getValue() + ""; - primaryKey = primaryKey.replace("'", "''"); + localPrimaryKey = entry.getValue() + ""; + localPrimaryKey = localPrimaryKey.replace("'", "''"); } DataType colType = null; try { colType = tableInfo.getColumn(entry.getKey()).getType(); } catch(NullPointerException ex) { - logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage() +" Invalid column name : "+entry.getKey(), AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR); - + logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage() +" Invalid column name : "+entry.getKey(), + AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR, ex); } Object formattedValue = null; try { - formattedValue = MusicUtil.convertToActualDataType(colType, valueObj); + formattedValue = MusicUtil.convertToActualDataType(colType, valueObj); } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger,e.getMessage()); - } + logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), e); + } - valueString.append("?"); + valueString.append("?"); queryObject.addValue(formattedValue); - if (counter == valuesMap.size() - 1) { + if (counter == valuesMap.size() - 1) { fieldsString.append(")"); valueString.append(")"); } else { @@ -301,58 +323,57 @@ public class MusicConditional { } queryObject.appendQueryString("INSERT INTO " + keySpaceName + "." + tableName + " " + fieldsString + " VALUES " + valueString); - return queryObject; - } - - public static Object getColValue(Row row, String colName, DataType colType) { - switch (colType.getName()) { - case VARCHAR: - return row.getString(colName); - case UUID: - return row.getUUID(colName); - case VARINT: - return row.getVarint(colName); - case BIGINT: - return row.getLong(colName); - case INT: - return row.getInt(colName); - case FLOAT: - return row.getFloat(colName); - case DOUBLE: - return row.getDouble(colName); - case BOOLEAN: - return row.getBool(colName); - case MAP: - return row.getMap(colName, String.class, String.class); - default: - return null; - } - } - - @SuppressWarnings("unchecked") - public static Map cascadeColumnUpdateSpecific(Row row, Map changeOfStatus, - String cascadeColumnName, String planId) { - - ColumnDefinitions colInfo = row.getColumnDefinitions(); - DataType colType = colInfo.getType(cascadeColumnName); - Map values = new HashMap<>(); - Object columnValue = getColValue(row, cascadeColumnName, colType); - - Map finalValues = new HashMap<>(); - values = (Map) columnValue; - if (values != null && values.keySet().contains(planId)) { - String valueString = values.get(planId); - String tempValueString = valueString.replaceAll("\\{", "").replaceAll("\"", "").replaceAll("\\}", ""); - String[] elements = tempValueString.split(","); - for (String str : elements) { - String[] keyValue = str.split(":"); - if ((changeOfStatus.keySet().contains(keyValue[0].replaceAll("\\s", "")))) - keyValue[1] = changeOfStatus.get(keyValue[0].replaceAll("\\s", "")); - finalValues.put(keyValue[0], keyValue[1]); - } - } - return finalValues; - - } - -} \ No newline at end of file + return queryObject; + } + + public static Object getColValue(Row row, String colName, DataType colType) { + switch (colType.getName()) { + case VARCHAR: + return row.getString(colName); + case UUID: + return row.getUUID(colName); + case VARINT: + return row.getVarint(colName); + case BIGINT: + return row.getLong(colName); + case INT: + return row.getInt(colName); + case FLOAT: + return row.getFloat(colName); + case DOUBLE: + return row.getDouble(colName); + case BOOLEAN: + return row.getBool(colName); + case MAP: + return row.getMap(colName, String.class, String.class); + default: + return null; + } + } + + @SuppressWarnings("unchecked") + public static Map cascadeColumnUpdateSpecific(Row row, Map changeOfStatus, + String cascadeColumnName, String planId) { + + ColumnDefinitions colInfo = row.getColumnDefinitions(); + DataType colType = colInfo.getType(cascadeColumnName); + Object columnValue = getColValue(row, cascadeColumnName, colType); + + Map finalValues = new HashMap<>(); + Map values = (Map) columnValue; + if (values != null && values.keySet().contains(planId)) { + String valueString = values.get(planId); + String tempValueString = valueString.replaceAll("\\{", "").replaceAll("\"", "").replaceAll("\\}", ""); + String[] elements = tempValueString.split(","); + for (String str : elements) { + String[] keyValue = str.split(":"); + if ((changeOfStatus.keySet().contains(keyValue[0].replaceAll("\\s", "")))) + keyValue[1] = changeOfStatus.get(keyValue[0].replaceAll("\\s", "")); + finalValues.put(keyValue[0], keyValue[1]); + } + } + return finalValues; + + } + +}