Skip to content

Commit

Permalink
get range added, patches the requirement #13
Browse files Browse the repository at this point in the history
  • Loading branch information
rajithsiriwardana committed Oct 22, 2013
1 parent 8a102d0 commit 13eec0f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public HashMap<Date, HashMap<TradingDataAttribute, String>> getData(String dataT
ArrayList<TradingDataAttribute> attributes)
throws DataAccessException, DataNotFoundException;

public Date[] getKeyRange(String dataType, String symbol);
@Deprecated
public Date[] getKeyRange(String dataType, String symbol) throws DataAccessException;

//TODO truncate stock data
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ public HashMap<Date, HashMap<TradingDataAttribute, String>> getData(String dataT

if(superColumns.size() > 0){

LinkedHashMap<Date, HashMap<TradingDataAttribute, String>> data = new LinkedHashMap<Date, HashMap<TradingDataAttribute, String>>();
LinkedHashMap<Date, HashMap<TradingDataAttribute, String>> data =
new LinkedHashMap<Date, HashMap<TradingDataAttribute, String>>();
for (HSuperColumn<Date, String, String> superColumn : superColumns){

List<HColumn<String, String>> hColumns = superColumn.getColumns();
Expand All @@ -198,8 +199,34 @@ public HashMap<Date, HashMap<TradingDataAttribute, String>> getData(String dataT
}

@Override
public Date[] getKeyRange(String dataType, String symbol) {
return new Date[0]; //TODO
public Date[] getKeyRange(String dataType, String symbol) throws DataAccessException {

try {
Cluster cluster = getClusterInitialized();
Keyspace keyspace = HFactory.createKeyspace(KEYSPACE, cluster);

Date[] startNEnd = new Date[2];

if(CassandraConnector.isColumnFamilyAvailable(cluster, KEYSPACE, dataType)){
SuperSlice<Date, String, String> result = HFactory.createSuperSliceQuery(keyspace,
StringSerializer.get(), DateSerializer.get(), StringSerializer.get(),
StringSerializer.get())
.setColumnFamily(dataType)
.setKey(symbol)
.setRange(new Date(0L), new Date(), false, Integer.MAX_VALUE)
.execute()
.get();

startNEnd[0] = ((result.getSuperColumns()).get(0)).getName();
startNEnd[1] = ((result.getSuperColumns()).get((result.getSuperColumns()).size() - 1)).getName();

return startNEnd;

} else
throw new DataAccessException("Requested ColumnFamily not available");
} catch (Exception e){
throw new DataAccessException(e);
}
}

private Cluster getClusterInitialized() {
Expand Down

0 comments on commit 13eec0f

Please sign in to comment.