@SuppressWarnings("unchecked")
 protected ODLDatastoreImpl(ODLDatastoreImpl<T> copyThis) {
   this.factory = copyThis.factory;
   this.flags = copyThis.flags;
   for (T table : copyThis.tablesByIndx) {
     if (ODLTableImpl.class.isInstance(table) == false) {
       throw new UnsupportedOperationException();
     }
     addTable((T) table.deepCopyWithShallowValueCopy());
   }
   this.tableIdGenerator.setNextId(copyThis.tableIdGenerator.getNextId());
 }
  /**
   * Add the table returning its index or -1 if rejected
   *
   * @param table
   * @param logger
   * @return
   */
  public int addTable(T table) {
    if (TableUtils.findTableIndex(this, table.getName(), true) != -1) {
      throw new RuntimeException("Table already exists: " + table.getName());
    }

    if (table.getImmutableId() == -1) {
      throw new RuntimeException("Invalid table immutable id in table: " + table.getName());
    }

    // we throw an exception if the id is already used because this will
    // be caused by a code error rather than a user error
    if (tablesById.get(table.getImmutableId()) != null) {
      throw new RuntimeException("Duplicate table id");
    }

    tablesByIndx.add(table);
    tablesById.put(table.getImmutableId(), table);
    return tablesByIndx.size() - 1;
  }