@Override
public int addConstraint(ByteBuffer login, String tableName, String constraintClassName) throws org.apache.accumulo.proxy.thrift.AccumuloException,
org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, TException {
try {
Connector connector = getConnector(login);
checkTableExists(connector, tableName);
TreeSet<Integer> constraintNumbers = new TreeSet<Integer>();
TreeMap<String,Integer> constraintClasses = new TreeMap<String,Integer>();
int i;
for (Map.Entry<String,String> property : connector.tableOperations().getProperties(tableName)) {
if (property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) {
try {
i = Integer.parseInt(property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length()));
} catch (NumberFormatException e) {
throw new org.apache.accumulo.proxy.thrift.AccumuloException("Bad key for existing constraint: " + property.toString());
}
constraintNumbers.add(i);
constraintClasses.put(property.getValue(), i);
}
}
i = 1;
while (constraintNumbers.contains(i))
i++;
if (constraintClasses.containsKey(constraintClassName))
throw new AccumuloException("Constraint " + constraintClassName + " already exists for table " + tableName + " with number "
+ constraintClasses.get(constraintClassName));
connector.tableOperations().setProperty(tableName, Property.TABLE_CONSTRAINT_PREFIX.toString() + i, constraintClassName);
return i;
} catch (Exception e) {
handleExceptionTNF(e);
return -1;
}