IndexMaintainerHelper { public static String generateCQLStatementForInsert(Index index) { String iTableToUpdate = Utils.calculateITableName(index); List<String> fields = index.getFieldsValues(); String fieldNamesInsertSyntax = Utils.join(", ", fields); StringBuilder fieldValueInsertSyntax = new StringBuilder(); for (int i = 0; i < fields.size(); i++) { if (i != 0) { fieldValueInsertSyntax.append(", "); } fieldValueInsertSyntax.append("?"); } return String.format(ITABLE_INSERT_CQL, iTableToUpdate, fieldNamesInsertSyntax, fieldValueInsertSyntax); } private  IndexMaintainerHelper(); static List<BoundStatement> generateDocumentCreateIndexEntriesStatements(Session session, Document entity, BucketLocator bucketLocator); static BoundStatement generateDocumentCreateIndexEntryStatement(Session session, Index index, Document entity, BucketLocator bucketLocator); static List<BoundStatement> generateDocumentUpdateIndexEntriesStatements(Session session, Document entity, BucketLocator bucketLocator); static List<BoundStatement> generateDocumentDeleteIndexEntriesStatements(Session session, Document entity, BucketLocator bucketLocator); static List<Index> getIndexForDocument(Session session, Document entity); static boolean hasIndexedFieldChanged(BSONObject oldObject, Index index, Document entity); static BSONObject getOldObjectForUpdate(Session session, Document entity); static String getCQLStatementForInsert(Index index); static String generateCQLStatementForInsert(Index index); static String getCQLStatementForWhereClauses(String CQL, Index index); static String generateCQLStatementForWhereClauses(String CQL, Index index); static final String ITABLE_INSERT_CQL; static final String ITABLE_UPDATE_CQL; static final String ITABLE_DELETE_CQL; }
@Test public void testGenerateCQLStatementForInsert() { System.out.println("generateCQLStatementForInsert"); String expResult = "INSERT INTO mydb_mytable_myindexwithonefield (bucket, id, object, created_at, updated_at, myindexedfield) VALUES (?, ?, ?, ?, ?, ?);"; String result = IndexMaintainerHelper.generateCQLStatementForInsert(index1); assertEquals(expResult, result); expResult = "INSERT INTO mydb_mytable_myindexwithtwofields (bucket, id, object, created_at, updated_at, myindexedfield1, myindexedfield2) VALUES (?, ?, ?, ?, ?, ?, ?);"; result = IndexMaintainerHelper.generateCQLStatementForInsert(index2); assertEquals(expResult, result); }