This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[default@TutorialKeyspace] get TombstoneDemo[key_1]; | |
Returned 0 results. | |
Elapsed time: 1 msec(s). | |
[default@TutorialKeyspace] list TombstoneDemo; | |
Using default limit of 100 | |
------------------- | |
RowKey: key_5 | |
=> (column=column1, value=value1, timestamp=1330457550350000) | |
=> (column=column2, value=value2, timestamp=1330457550350001) | |
------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[default@TutorialKeyspace] get TombstoneDemo[key_1]; | |
=> (column=column1, value=value1, timestamp=1330457550344000) | |
=> (column=column2, value=value2, timestamp=1330457550344001) | |
Returned 2 results. | |
Elapsed time: 2 msec(s). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates an HColumn with a column name composite of the form: | |
* ['country_code']:['state]:['city name']) | |
* and a value of ['timezone'] | |
* @return | |
*/ | |
HColumn<Composite,String> staticColumnFrom() { | |
Composite composite = new Composite(); | |
composite.addComponent(getCountryCode(), StringSerializer.get()); | |
composite.addComponent(getAdmin1Code(), StringSerializer.get()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Resource name="cassandra/CassandraClientFactory" | |
auth="Container" | |
type="me.prettyprint.cassandra.api.Keyspace" | |
factory="me.prettyprint.cassandra.jndi.CassandraClientJndiResourceFactory" | |
hosts="cass1:9160,cass2:9160,cass3:9160" | |
user="user" | |
password="passwd" | |
keyspace="Keyspace1" | |
clusterName="Test Cluster" | |
maxActive="15" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean class="com.datastax.drivers.jdbc.pool.cassandra.jdbc.HCQLDataSource" | |
id="cqlDataSource"> | |
<property name="clusterName" value="TestCluster"/> | |
<property name="keyspaceName" value="PortfolioDemo"/> | |
<property name="hosts" value="127.0.0.1:9170"/> | |
</bean> | |
<bean class="org.springframework.jdbc.core.JdbcTemplate" | |
id="jdbcTemplate" > | |
<constructor-arg ref="cqlDataSource"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final String STOCK_CQL = "select price FROM Stocks WHERE KEY = ?"; | |
public Stock load(String stockTicker) { | |
jdbcTemplate.query(STOCK_CQL, stockTicker, | |
new RowMapper<Stock>() { | |
public Stock mapRow(ResultSet rs, int row) throws SQLException { | |
CassandraResultSet crs = (CassandraResultSet)rs; | |
Stock stock = new Stock(); | |
stock.setTicker(new String(crs.getKey())); | |
stock.setPrice(crs.getDouble("price")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Row row = new Row(); | |
row.put("column1", "value1").put(2, "value2").put(3, false); | |
UUID id = TimeUUIDUtils.getUniqueTimeUUIDinMillis(); | |
row.put(42, id).put(id, "uuid col name"); | |
row.increment("counter1",4).increment(1234L,1).increment("counter1",1); | |
columnFamily.insert(row); | |
CFCursor cursor = columnFamily.query(row); | |
Row foundRow = cursor.next(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String UPDATE_PORTOFOLIO_CQL = "update Portfolios set ? = ? where KEY = ?"; | |
public void save(Position position) { | |
jdbcTemplate.update(UPDATE_PORTFOLIO_CQL, | |
new Object[] { position.getTicker(), position.getCount(), portfolio.getName()}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimeseriesIterator implements Iterable<HColumn<Long,Long>> { | |
private ColumnSliceIterator<String,Long,Long> sliceIterator; | |
TimeseriesIterator(String key) { | |
SliceQuery<String,Long,Long> sliceQuery = | |
HFactory.createSliceQuery(tutorialKeyspace, StringSerializer.get(), | |
LongSerializer.get(), LongSerializer.get()); | |
sliceQuery.setColumnFamily(TimeseriesInserter.CF_TIMESERIES_SINGLE_ROW); | |
sliceQuery.setKey(key); | |
sliceIterator = new ColumnSliceIterator<String,Long,Long>(sliceQuery,0L,Long.MAX_VALUE,false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Integer call() { | |
Mutator<String> mutator = HFactory.createMutator(tutorialKeyspace, StringSerializer.get()); | |
int count = 0; | |
for (int x=0; x<5000; x++) { | |
mutator.addInsertion(myKey,CF_TIMESERIES_SINGLE_ROW, buildColumnFor(x)); | |
} | |
mutator.execute(); | |
log.debug("Inserted {} rows", count); | |
return Integer.valueOf(count); |