Configuration hbaseConf = HBaseConfiguration.create();
hbaseConf.set("hbase.zookeeper.quorum", zkConnectionString);
IndexManager indexManager = new IndexManager(hbaseConf, new HBaseTableFactoryImpl(hbaseConf));
LinkIndex linkIndex = new LinkIndex(indexManager, lilyClient);
//
// Determine the index to query
//
boolean incoming = true; // false = outgoing
if (cmd.hasOption(indexOption.getOpt())) {
String index = cmd.getOptionValue(indexOption.getOpt());
if (index.equals("incoming") || index.equals("backward")) {
incoming = true;
} else if (index.equals("outgoing") || index.equals("forward")) {
incoming = false;
} else {
System.err.println("Invalid index name: " + index);
return -1;
}
}
//
// Determine the record id
//
String recordIdParam = cmd.getOptionValue(recordIdOption.getOpt());
if (recordIdParam == null) {
System.out.println("Specify record id with -" + recordIdOption.getOpt());
return 1;
}
RecordId recordId = repository.getIdGenerator().fromString(recordIdParam);
//
// Determine the vtag
//
SchemaId vtagId = null;
if (cmd.hasOption(vtagOption.getOpt())) {
String vtagParam = cmd.getOptionValue(vtagOption.getOpt());
vtagId = typeManager.getFieldTypeByName(new QName("org.lilyproject.vtag", vtagParam)).getId();
}
//
// Determine the field
//
SchemaId fieldId = null;
if (cmd.hasOption(fieldOption.getOpt())) {
if (vtagId == null) {
System.err.println("A field can only be specified in combination with a vtag.");
return -1;
}
String fieldParam = cmd.getOptionValue(fieldOption.getOpt());
FieldType field = typeManager.getFieldTypeByName(QName.fromString(fieldParam));
fieldId = field.getId();
if (!field.getValueType().getDeepestValueType().getBaseName().equals("LINK")) {
System.err.println("The field '" + field.getName() + "' is not a link field.");
return -1;
}
}
//
// Perform the query
//
if (incoming) {
System.out.println("Querying the incoming links (backward index)");
System.out.println("Record id: " + recordId);
System.out.println("vtag id: " + vtagId + getFieldTypeNameSuffix(vtagId));
System.out.println("field id: " + fieldId + getFieldTypeNameSuffix(fieldId));
System.out.println();
if (fieldId != null) {
Set<RecordId> records = linkIndex.getReferrers(recordId, vtagId, fieldId);
printRecords(records);
} else {
Set<FieldedLink> fieldedLinks = linkIndex.getFieldedReferrers(recordId, vtagId);
printFieldedLinks(fieldedLinks);
}
} else {
System.out.println("Querying the outgoing links (forward index)");
System.out.println("Record id: " + recordId);
System.out.println("vtag id: " + vtagId + getFieldTypeNameSuffix(vtagId));
System.out.println("field id: " + fieldId + getFieldTypeNameSuffix(fieldId));
System.out.println();
if (fieldId != null) {
Set<RecordId> records = linkIndex.getForwardLinks(recordId, vtagId, fieldId);
printRecords(records);
} else {
Set<FieldedLink> fieldedLinks = linkIndex.getFieldedForwardLinks(recordId, vtagId);
printFieldedLinks(fieldedLinks);
}
}
return 0;