Skip to content

Commit

Permalink
Merge pull request #222 from arunagrawal84/oss_master
Browse files Browse the repository at this point in the history
Provide keyspaceName while executing the statements
  • Loading branch information
arunagrawal-84 authored Dec 5, 2018
2 parents 8c0ab3e + 4cd4da0 commit 3c165f1
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,24 @@ void upsertKeyspace(Session session) {

@Override
void upsertCF(Session session) {
String createTblQuery = "CREATE TABLE IF NOT EXISTS %s (key text, column1 int, %s, PRIMARY KEY ((key), column1)) WITH compression = {'sstable_compression': ''}";
String createTblQuery = "CREATE TABLE IF NOT EXISTS %s.%s (key text, column1 int, %s, PRIMARY KEY ((key), column1)) WITH compression = {'sstable_compression': ''}";

String values = IntStream.range(0, config.getColsPerRow()).mapToObj(i -> "value"+i+" text").collect(Collectors.joining(", "));
session.execute(String.format(createTblQuery, tableName, values));
session.execute(String.format(createTblQuery, keyspaceName, tableName, values));

}

@Override
void prepStatements(Session session) {

String insertQuery = "INSERT INTO %s (key, column1 , %s ) VALUES (?, ?, %s )";
String insertQuery = "INSERT INTO %s.%s (key, column1 , %s ) VALUES (?, ?, %s )";
int nCols = config.getColsPerRow();

String values = IntStream.range(0, nCols).mapToObj(i -> "value"+i).collect(Collectors.joining(", "));
String bindValues = IntStream.range(0, nCols).mapToObj(i -> "?").collect(Collectors.joining(", "));

writePstmt = session.prepare(String.format(insertQuery, tableName, values, bindValues));
readPstmt = session.prepare("SELECT * FROM " + tableName + " WHERE key = ?");
writePstmt = session.prepare(String.format(insertQuery, keyspaceName, tableName, values, bindValues));
readPstmt = session.prepare(String.format("SELECT * FROM %s.%s WHERE key = ?", keyspaceName, tableName));
}

@Override
Expand Down

0 comments on commit 3c165f1

Please sign in to comment.