1
저주와 Java를 사용하여 수퍼 컬럼에 수퍼 컬럼을 삽입하는 방법을 명확한 예제가 필요합니다.절약을 사용하여 Cassandra에 SuperColumn을 삽입하십시오.
저주와 Java를 사용하여 수퍼 컬럼에 수퍼 컬럼을 삽입하는 방법을 명확한 예제가 필요합니다.절약을 사용하여 Cassandra에 SuperColumn을 삽입하십시오.
@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