1
スローリフトとjavaを使用してスーパーカラムにスーパーカラムを挿入する方法を明確にする必要があります。Cassandraにスローリフトを使ってスーパーカラムを挿入する
スローリフトとjavaを使用してスーパーカラムにスーパーカラムを挿入する方法を明確にする必要があります。Cassandraにスローリフトを使ってスーパーカラムを挿入する
@Override
public void insertAllReportsByHost(Map<String, List<IReport>> hostReports) throws DatabaseException {
try {
Cassandra.Client client = getClient();
Map<ByteBuffer, Map<String, List<Mutation>>> mutationsMap = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
for (Map.Entry<String, List<IReport>> entryReport : hostReports.entrySet()) {
ByteBuffer host = toByteBuffer(entryReport.getKey());
List<IReport> reports = entryReport.getValue();
Map<String, List<Mutation>> keyMutations = new HashMap<String, List<Mutation>>();
List<Mutation> mutations = new ArrayList<Mutation>();
for (IReport report : reports) {
report.getProperties();
Column reportDataColumn = new Column(toByteBuffer("Report Data"));
reportDataColumn.setValue(toByteBuffer(report.toString()));//TODO make another way
reportDataColumn.setTimestamp(System.currentTimeMillis());
Long nano = System.nanoTime();
SuperColumn superColumn = new SuperColumn(toByteBuffer(report.getReportId().toString()), Arrays.asList(reportDataColumn));
ColumnOrSuperColumn col = new ColumnOrSuperColumn();
col.super_column = superColumn;
Mutation m = new Mutation();
m.setColumn_or_supercolumn(col);
mutations.add(m);
}
keyMutations.put(COLUMN_FAMILY, mutations);
mutationsMap.put(host, keyMutations);
}
client.batch_mutate(mutationsMap, ConsistencyLevel.ONE);
} catch (UnsupportedEncodingException e) {
LOGGER.error(e.getMessage(), e);
throw new DatabaseException(e);
} catch (UnavailableException e) {
LOGGER.error(e.getMessage(), e);
throw new DatabaseException(e);
} catch (TException e) {
LOGGER.error(e.getMessage(), e);
throw new DatabaseException(e);
} catch (InvalidRequestException e) {
LOGGER.error(e.getMessage(), e);
throw new DatabaseException(e);
} catch (TimedOutException e) {
LOGGER.error(e.getMessage(), e);
throw new DatabaseException(e);
}
}
未処理の低速クライアントではなく、上位レベルのクライアントを使用することをお勧めします。 http://wiki.apache.org/cassandra/ClientOptionsを参照してください。おそらく、カラムカラムにスーパーカラムを挿入することを意味しますか?またはスーパーカラムへの列? – DNA
[このスレッド]にいくつかの例があります(http://cassandra-user-incubator-apache-org.3065146.n2.nabble.com/how-to-insert-a-supercolumn-with-java-td4451521.html)。 ) – DNA
私は倹約だけで作業する必要があります。私はhectorを使いたくありません。この例をありがとう。 – alnasfire