diff options
author | Bharath Balasubramanian <bharathb@research.att.com> | 2019-02-13 13:47:17 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-02-13 13:47:17 +0000 |
commit | 3b8e0a333bb754117f41e7206a6706bad66829fb (patch) | |
tree | 542523d2ee852fd021ac6873fc3fb55946e8c0c9 /src/main/java/org/onap/music/main | |
parent | adba255959405da052552d27609aa9f7a52bf49e (diff) | |
parent | 50fa03e7c1de83a290403f8420839ba778e79302 (diff) |
Merge "Sonar code duplicates moved to MusicUtil.java"
Diffstat (limited to 'src/main/java/org/onap/music/main')
-rwxr-xr-x | src/main/java/org/onap/music/main/MusicUtil.java | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java index 805f459f..dd089683 100755 --- a/src/main/java/org/onap/music/main/MusicUtil.java +++ b/src/main/java/org/onap/music/main/MusicUtil.java @@ -4,7 +4,8 @@ * =================================================================== * Copyright (c) 2017 AT&T Intellectual Property * =================================================================== - * Modifications Copyright (c) 2018 IBM. + * Modifications Copyright (c) 2018 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. @@ -24,6 +25,10 @@ package org.onap.music.main; +import com.datastax.driver.core.ColumnDefinitions; +import com.datastax.driver.core.ColumnDefinitions.Definition; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -44,8 +49,12 @@ import java.util.concurrent.ConcurrentMap; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; +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.exceptions.MusicQueryException; import org.onap.music.exceptions.MusicServiceException; import org.onap.music.service.MusicCoreService; @@ -809,6 +818,42 @@ public class MusicUtil { // TODO Auto-generated method stub MusicUtil.isCadi = isCadi; } + + public static void writeBackToQuorum(PreparedQueryObject selectQuery, String primaryKeyName, + PreparedQueryObject updateQuery, String keyspace, String table, + Object cqlFormattedPrimaryKeyValue) + throws Exception { + try { + ResultSet results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(selectQuery); + // write it back to a quorum + Row row = results.one(); + ColumnDefinitions colInfo = row.getColumnDefinitions(); + int totalColumns = colInfo.size(); + int counter = 1; + StringBuilder fieldValueString = new StringBuilder(""); + for (Definition definition : colInfo) { + String colName = definition.getName(); + if (colName.equals(primaryKeyName)) + continue; + DataType colType = definition.getType(); + Object valueObj = MusicDataStoreHandle.getDSHandle().getColValue(row, colName, colType); + Object valueString = MusicUtil.convertToActualDataType(colType, valueObj); + fieldValueString.append(colName + " = ?"); + updateQuery.addValue(valueString); + if (counter != (totalColumns - 1)) + fieldValueString.append(","); + counter = counter + 1; + } + updateQuery.appendQueryString("UPDATE " + keyspace + "." + table + " SET " + + fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";"); + updateQuery.addValue(cqlFormattedPrimaryKeyValue); + + MusicDataStoreHandle.getDSHandle().executePut(updateQuery, "critical"); + } catch (MusicServiceException | MusicQueryException e) { + logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.QUERYERROR +""+updateQuery , + ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR); + } + } public static boolean getIsCadi() { return MusicUtil.isCadi; |