问题
Right now, I have to manually generate the composite key by formatting the subkeys together. It's ugly and not efficient. I wonder if Hector provides such set of APIs to handle composite keys in a more decent way.
回答1:
yes it does.
You can look at DynamicCompositeTest for examples:
https://github.com/rantav/hector/blob/master/core/src/test/java/me/prettyprint/hector/api/beans/DynamicCompositeTest.java
@Test
public void allTypesSerialize() {
DynamicComposite composite = new DynamicComposite();
UUID lexUUID = UUID.randomUUID();
com.eaio.uuid.UUID timeUUID = new com.eaio.uuid.UUID();
//add all forward comparators
composite.addComponent(0, "AsciiText", AsciiSerializer.get(), "AsciiType", ComponentEquality.EQUAL);
composite.addComponent(1, new byte[]{0, 1, 2, 3}, BytesArraySerializer.get(), "BytesType", ComponentEquality.EQUAL);
composite.addComponent(2, -1, IntegerSerializer.get(), "IntegerType", ComponentEquality.EQUAL);
composite.addComponent(3, lexUUID, UUIDSerializer.get(), "LexicalUUIDType", ComponentEquality.EQUAL);
composite.addComponent(4, -1l, LongSerializer.get(), "LongType", ComponentEquality.EQUAL);
composite.addComponent(5, timeUUID, TimeUUIDSerializer.get(), "TimeUUIDType", ComponentEquality.EQUAL);
composite.addComponent(6, "UTF8Text", StringSerializer.get(), "UTF8Type", ComponentEquality.EQUAL);
composite.addComponent(7, lexUUID, UUIDSerializer.get(), "UUIDType", ComponentEquality.EQUAL);
来源:https://stackoverflow.com/questions/7440530/does-hector-provide-apis-to-support-composite-key