public static final String getDominantSortAttributeValueAsString(
     CommonFieldsBase cb, DataField dominantAttr) {
   String value;
   switch (dominantAttr.getDataType()) {
     case BINARY:
       throw new IllegalStateException("cannot sort on a binary field");
     case LONG_STRING:
       throw new IllegalStateException("cannot sort on a long text field");
     case URI:
     case STRING:
       {
         value = cb.getStringField(dominantAttr);
         break;
       }
     case INTEGER:
       {
         Long l = cb.getLongField(dominantAttr);
         if (l == null) {
           value = null;
         } else {
           value = Long.toString(l);
         }
         break;
       }
     case DECIMAL:
       {
         BigDecimal bd = cb.getNumericField(dominantAttr);
         if (bd == null) {
           value = null;
         } else {
           value = bd.toString();
         }
         break;
       }
     case BOOLEAN:
       {
         Boolean b = cb.getBooleanField(dominantAttr);
         if (b == null) {
           value = null;
         } else {
           value = b.toString();
         }
         break;
       }
     case DATETIME:
       {
         Date d = cb.getDateField(dominantAttr);
         if (d == null) {
           value = null;
         } else {
           value = WebUtils.iso8601Date(d);
         }
         break;
       }
     default:
       throw new IllegalStateException("datatype not handled");
   }
   return value;
 }
 public static final boolean hasMatchingDominantSortAttribute(
     CommonFieldsBase odkLastEntity, CommonFieldsBase odkEntity, DataField dominantAttr) {
   boolean matchingDominantAttr = false;
   switch (dominantAttr.getDataType()) {
     case BINARY:
       throw new IllegalStateException("unexpected sort on binary field");
     case LONG_STRING:
       throw new IllegalStateException("unexpected sort on long text field");
     case URI:
     case STRING:
       {
         String a1 = odkLastEntity.getStringField(dominantAttr);
         String a2 = odkEntity.getStringField(dominantAttr);
         matchingDominantAttr =
             (a1 == null) ? (a2 == null) : ((a2 != null) && a1.compareTo(a2) == 0);
       }
       break;
     case INTEGER:
       {
         Long a1 = odkLastEntity.getLongField(dominantAttr);
         Long a2 = odkEntity.getLongField(dominantAttr);
         matchingDominantAttr =
             (a1 == null) ? (a2 == null) : ((a2 != null) && a1.compareTo(a2) == 0);
       }
       break;
     case DECIMAL:
       {
         BigDecimal a1 = odkLastEntity.getNumericField(dominantAttr);
         BigDecimal a2 = odkEntity.getNumericField(dominantAttr);
         matchingDominantAttr =
             (a1 == null) ? (a2 == null) : ((a2 != null) && a1.compareTo(a2) == 0);
       }
       break;
     case BOOLEAN:
       {
         Boolean a1 = odkLastEntity.getBooleanField(dominantAttr);
         Boolean a2 = odkEntity.getBooleanField(dominantAttr);
         matchingDominantAttr =
             (a1 == null) ? (a2 == null) : ((a2 != null) && a1.compareTo(a2) == 0);
       }
       break;
     case DATETIME:
       {
         Date a1 = odkLastEntity.getDateField(dominantAttr);
         Date a2 = odkEntity.getDateField(dominantAttr);
         matchingDominantAttr =
             (a1 == null) ? (a2 == null) : ((a2 != null) && a1.compareTo(a2) == 0);
       }
       break;
     default:
       throw new IllegalStateException("unexpected data type");
   }
   return matchingDominantAttr;
 }
  public FormSettingsTable(String schemaName) {
    super(schemaName, TABLE_NAME);
    fieldList.add(FORM_ID);
    fieldList.add(HAS_SETTINGS);

    fieldValueMap.put(primaryKey, CommonFieldsBase.newMD5HashUri(FormInfo.FORM_ID));
    fieldValueMap.put(FORM_ID, FormInfo.FORM_ID);
  }
  @Override
  public void delete(CallingContext cc) throws ODKDatastoreException {
    CommonFieldsBase serviceEntity = retrieveObjectEntity();
    List<? extends CommonFieldsBase> repeats = retrieveRepeatElementEntities();

    Datastore ds = cc.getDatastore();
    User user = cc.getCurrentUser();

    if (repeats != null) {
      List<EntityKey> keys = new ArrayList<EntityKey>();
      for (CommonFieldsBase repeat : repeats) {
        keys.add(repeat.getEntityKey());
      }
      ds.deleteEntities(keys, user);
      repeats.clear();
    }

    ds.deleteEntity(serviceEntity.getEntityKey(), user);
    ds.deleteEntity(fsc.getEntityKey(), user);
  }
 public static final Object getDominantSortAttributeValue(
     CommonFieldsBase odkEntity, DataField dominantAttr) {
   switch (dominantAttr.getDataType()) {
     case BINARY:
       throw new IllegalStateException("unexpected sort on binary field");
     case LONG_STRING:
       throw new IllegalStateException("unexpected sort on long text field");
     case URI:
     case STRING:
       return odkEntity.getStringField(dominantAttr);
     case INTEGER:
       return odkEntity.getLongField(dominantAttr);
     case DECIMAL:
       return odkEntity.getNumericField(dominantAttr);
     case BOOLEAN:
       return odkEntity.getBooleanField(dominantAttr);
     case DATETIME:
       return odkEntity.getDateField(dominantAttr);
     default:
       throw new IllegalStateException("unexpected data type");
   }
 }