@Override public int getSystemVersion() { try { return keyspace.prepareQuery( CF_MIGRATION_INFO ).getKey( LEGACY_ROW_KEY ).getColumn( COLUMN_VERSION ) .execute().getResult().getIntegerValue(); } //swallow, it doesn't exist catch ( NotFoundException nfe ) { return 0; } catch ( ConnectionException e ) { throw new DataMigrationException( "Unable to retrieve status", e ); } }
@Override public int getStatusCode(final String pluginName) { final ScopedRowKey<String> rowKey = ScopedRowKey.fromKey( STATIC_ID, pluginName); try { return keyspace.prepareQuery( CF_MIGRATION_INFO ).getKey( rowKey ).getColumn( COLUMN_STATUS_CODE ) .execute().getResult().getIntegerValue(); } //swallow, it doesn't exist catch ( NotFoundException nfe ) { return 0; } catch ( ConnectionException e ) { throw new DataMigrationException( "Unable to retrieve status", e ); } }
@Override public int getVersion(final String pluginName) { final ScopedRowKey<String> rowKey = ScopedRowKey.fromKey( STATIC_ID, pluginName); try { return keyspace.prepareQuery( CF_MIGRATION_INFO ).getKey( rowKey ).getColumn( COLUMN_VERSION ).execute() .getResult().getIntegerValue(); } //swallow, it doesn't exist catch ( NotFoundException nfe ) { return 0; } catch ( ConnectionException e ) { AstyanaxUtils.isSchemaMissing("Unable to connect to cassandra to retrieve status", e); return 0; } }
@Override public Integer getInteger(C columnName, Integer defaultValue) { Column<C> column = columns.get(columnName); if (column == null) return defaultValue; return column.getIntegerValue(); }
@Override public Integer getIntegerValue(C columnName, Integer defaultValue) { Column<C> column = map.get(columnName); if (column == null) { return defaultValue; } else { return column.getIntegerValue(); } }
private void testRangeColumnsForRow(ColumnList<String> columns, List<String> expected) { Iterator<Column<String>> iter1 = columns.iterator(); Iterator<String> iter2 = expected.iterator(); while (iter2.hasNext()) { Column<String> column = iter1.next(); String expectedName = iter2.next(); Assert.assertEquals(expectedName, column.getName()); int expectedValue = expectedName.charAt(0) - 'a' + 1; Assert.assertEquals(expectedValue, column.getIntegerValue()); } }
@Override public Integer getIntegerValue(C columnName, Integer defaultValue) { Column<C> column = getColumnByName(columnName); if (column == null || !column.hasValue()) return defaultValue; return column.getIntegerValue(); }
when(column.getDateValue()).thenReturn((Date) value); } else if (value instanceof Integer) { when(column.getIntegerValue()).thenReturn((Integer) value); } else if (value instanceof Long) { when(column.getLongValue()).thenReturn((Long) value);
when(column.getDateValue()).thenReturn((Date) value); } else if (value instanceof Integer) { when(column.getIntegerValue()).thenReturn((Integer) value); } else if (value instanceof Long) { when(column.getLongValue()).thenReturn((Long) value);
Object objValue = null; if ((field.getType() == Byte.class) || (field.getType() == Byte.TYPE)) { objValue = (byte) (column.getIntegerValue() & 0xff); } else if ((field.getType() == Boolean.class) || (field.getType() == Boolean.TYPE)) { } else if ((field.getType() == Short.class) || (field.getType() == Short.TYPE)) { objValue = (short) (column.getIntegerValue() & 0xff); } else if ((field.getType() == Integer.class) || (field.getType() == Integer.TYPE)) { objValue = column.getIntegerValue(); } else if ((field.getType() == Long.class) || (field.getType() == Long.TYPE)) {
private void readColumnRangeForRowKey(String rowKey, boolean rowDeleted) throws Exception { ColumnList<String> columns = keyspace .prepareQuery(CF_COLUMN_RANGE_TEST) .getKey(rowKey) .withColumnRange("a", "z", false, -1) .execute().getResult(); if (rowDeleted) { Assert.assertTrue(columns.isEmpty()); return; } Assert.assertFalse(columns.isEmpty()); char ch = 'a'; for (Column<String> c : columns) { Assert.assertEquals(String.valueOf(ch), c.getName()); Assert.assertTrue( ch-'a'+1 == c.getIntegerValue()); ch++; } }
Assert.assertEquals(value, column.getStringValue()); } else if (value instanceof Integer) { Assert.assertEquals(value, column.getIntegerValue()); } else if (value instanceof Short) { Assert.assertEquals(value, column.getShortValue());
private void testRowKeysWithAllColumns(boolean rowDeleted) throws Exception { Set<String> rowKeys = getRandomRowKeys(); Rows<String, String> rows = keyspace.prepareQuery(CF_COLUMN_RANGE_TEST).getRowSlice(rowKeys).execute().getResult(); if (rowDeleted) { Assert.assertTrue(rows.isEmpty()); return; } Assert.assertFalse(rows.isEmpty()); int rowKeysSize = rowKeys.size(); for (Row<String, String> row : rows) { boolean isPresent = rowKeys.remove(row.getKey()); Assert.assertTrue("Extraneous row: " + row.getKey(), isPresent); ColumnList<String> colList = row.getColumns(); Assert.assertEquals(26, colList.size()); for(int index=0; index<26; index++) { Column<String> col = colList.getColumnByIndex(index); Assert.assertTrue(String.valueOf((char)('a' + index)).equals(col.getName())); Assert.assertEquals(index + 1, col.getIntegerValue()); } } Assert.assertEquals(rowKeysSize, rows.size()); }
Object v = null; if(c.getName().endsWith("id")) // type induction hack v = c.getIntegerValue(); else v = c.getStringValue();
Assert.assertEquals(value, column.getStringValue()); } else if (value instanceof Integer) { Assert.assertEquals(value, column.getIntegerValue()); } else if (value instanceof Short) { Assert.assertEquals(value, column.getShortValue());
@Test public void testGetSingleColumn() throws Exception { keyspace.prepareColumnMutation(CF_STANDARD1, "A", "a").putValue(1, null).execute(); Column<String> column = keyspace.prepareQuery(CF_STANDARD1).getRow("A").getColumn("a").execute().getResult(); Assert.assertNotNull(column); Assert.assertEquals(1, column.getIntegerValue()); }
@Test public void runRowCopyTest() throws Exception { MutationBatch m = keyspace.prepareMutationBatch(); m.withRow(CF_ROW_COPY, 10).putColumn("c1", 1).putColumn("c2", 2); m.execute(); ColumnList<String> result = keyspace.prepareQuery(CF_ROW_COPY).getRow(10).execute().getResult(); Column<String> column = result.getColumnByIndex(0); Assert.assertEquals("c1", column.getName()); Assert.assertEquals(1, column.getIntegerValue()); column = result.getColumnByIndex(1); Assert.assertEquals("c2", column.getName()); Assert.assertEquals(2, column.getIntegerValue()); keyspace.prepareQuery(CF_ROW_COPY).getRow(10).copyTo(CF_ROW_COPY2, 11).execute(); ColumnList<String> result2 = keyspace.prepareQuery(CF_ROW_COPY2).getRow(11).execute().getResult(); column = result2.getColumnByIndex(0); Assert.assertEquals("c1", column.getName()); Assert.assertEquals(1, column.getIntegerValue()); column = result2.getColumnByIndex(1); Assert.assertEquals("c2", column.getName()); Assert.assertEquals(2, column.getIntegerValue()); } }
@Test public void testSingleRowColumnSliceQueryWithCollection() throws Exception { for (int i=0; i<TestRowCount; i++) { ColumnList<String> result = keyspace.prepareQuery(CF_USER_INFO) .withCaching(true) .getRow("acct_" + i) .withColumnSlice("firstname", "lastname", "address", "age") .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(4 == result.size()); Assert.assertEquals("john_" + i, result.getColumnByName("firstname").getStringValue()); Assert.assertEquals("smith_" + i, result.getColumnByName("lastname").getStringValue()); Assert.assertEquals("john smith address " + i, result.getColumnByName("address").getStringValue()); Assert.assertTrue(30 + i == result.getColumnByName("age").getIntegerValue()); } }
Assert.assertTrue(result.getResult().getIntegerValue() == 42);
.getColumn(column).execute().getResult().getIntegerValue(); Assert.assertEquals(value, v); .getColumn(column).execute().getResult().getIntegerValue(); Assert.fail(); } catch (NullPointerException e) { keyspace.prepareQuery(CF_STANDARD1).getKey(key) .getColumn(column).execute().getResult() .getIntegerValue(); Assert.fail(); } catch (Exception e) { keyspace.prepareQuery(CF_STANDARD1).getKey(key) .getColumn(column).execute().getResult() .getIntegerValue(); Assert.fail(); } catch (Exception e) {