IndexMaintainerHelper { public static List<BoundStatement> generateDocumentDeleteIndexEntriesStatements(Session session, Document entity, BucketLocator bucketLocator) throws IndexParseException { List<Index> indices = getIndexForDocument(session, entity); ArrayList<BoundStatement> statementList = new ArrayList<>(indices.size()); for (Index index : indices) { BoundStatement bs = generateDocumentDeleteIndexEntryStatement(session, index, entity.getObject(), bucketLocator); if (bs != null) { statementList.add(bs); } } return statementList; } 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 testGenerateDocumentDeleteIndexEntriesStatements() throws IndexParseException { System.out.println("generateDocumentDeleteIndexEntriesStatements"); Document entity = Fixtures.createTestDocument2(); entity.setObjectAsString("{'greeting':'hello', 'myindexedfield': 'this is my field', 'myindexedfield1':'my second field', 'myindexedfield2':'my third field'}"); List<BoundStatement> result = IndexMaintainerHelper.generateDocumentDeleteIndexEntriesStatements(f.getSession(), entity, PrimaryIndexBucketLocatorImpl.getInstance()); assertEquals(2, result.size()); BoundStatement one = result.get(0); assertNotNull(one); assertTrue(one.isSet(0)); assertEquals("docussandra", one.getKeyspace()); assertEquals("DELETE FROM mydb_mytable_myindexwithonefield WHERE bucket = ? AND myindexedfield = ?;", one.preparedStatement().getQueryString()); BoundStatement two = result.get(1); assertNotNull(two); for (int i = 0; i < 1; i++) { assertTrue(two.isSet(i)); } assertEquals("docussandra", two.getKeyspace()); assertEquals("DELETE FROM mydb_mytable_myindexwithtwofields WHERE bucket = ? AND myindexedfield1 = ? AND myindexedfield2 = ?;", two.preparedStatement().getQueryString()); }
@Test public void testGenerateDocumentDeleteIndexEntriesStatementsWithDataTypes() throws IndexParseException { System.out.println("generateDocumentDeleteIndexEntriesStatementsWithDataTypes"); Document entity = Fixtures.createTestDocument3(); f.insertIndex(index3); entity.setObjectAsString("{\"thisisastring\":\"hello\", \"thisisanint\": \"5\", \"thisisadouble\":\"5.555\"," + " \"thisisbase64\":\"VGhpcyBpcyBhIGdvb2RseSB0ZXN0IG1lc3NhZ2Uu\", \"thisisaboolean\":\"f\"," + " \"thisisadate\":\"Thu Apr 30 09:52:04 MDT 2015\", \"thisisauudid\":\"3d069a5a-ef51-11e4-90ec-1681e6b88ec1\", \"thisisalong\":\"378657657654654\"}"); List<BoundStatement> result = IndexMaintainerHelper.generateDocumentDeleteIndexEntriesStatements(f.getSession(), entity, PrimaryIndexBucketLocatorImpl.getInstance()); assertEquals(1, result.size()); BoundStatement one = result.get(0); assertNotNull(one); assertTrue(one.isSet(0)); assertNotNull(one.getLong(0)); assertNotNull(one.getUUID(1)); assertNotNull(one.getString(2)); assertNotNull(one.getInt(3)); assertNotNull(one.getDouble(4)); assertNotNull(one.getBytes(5)); assertNotNull(one.getBool(6)); assertNotNull(one.getDate(7)); assertEquals("docussandra", one.getKeyspace()); assertEquals("DELETE FROM mydb_mytable_myindexallfields WHERE bucket = ? AND thisisauudid = ? AND thisisastring = ? AND" + " thisisanint = ? AND thisisadouble = ? AND thisisbase64 = ? AND thisisaboolean = ? AND thisisadate = ? AND thisisalong = ?;", one.preparedStatement().getQueryString()); }