public static Table initTable(ImplicitTransaction transaction) { if (!transaction.hasTable("class_SatsClass")) { Table table = transaction.getTable("class_SatsClass"); table.addColumn(ColumnType.STRING, "id"); table.addColumn(ColumnType.STRING, "centerFilterId"); table.addColumn(ColumnType.STRING, "classTypeId"); table.addColumn(ColumnType.INTEGER, "durationInMinutes"); table.addColumn(ColumnType.STRING, "instructorId"); table.addColumn(ColumnType.STRING, "name"); table.addColumn(ColumnType.STRING, "startTime"); table.addColumn(ColumnType.INTEGER, "bookedPersonsCount"); table.addColumn(ColumnType.INTEGER, "maxPersonsCount"); table.addColumn(ColumnType.STRING, "regionId"); table.addColumn(ColumnType.INTEGER, "waitingListCount"); if (!transaction.hasTable("class_ClassCategoryIds")) { ClassCategoryIdsRealmProxy.initTable(transaction); } table.addColumnLink( ColumnType.LINK_LIST, "classCategoryIds", transaction.getTable("class_ClassCategoryIds")); table.setIndex(table.getColumnIndex("id")); table.setPrimaryKey("id"); return table; } return transaction.getTable("class_SatsClass"); }
public static void validateTable(ImplicitTransaction transaction) { if (transaction.hasTable("class_SatsClass")) { Table table = transaction.getTable("class_SatsClass"); if (table.getColumnCount() != 12) { throw new IllegalStateException("Column count does not match"); } Map<String, ColumnType> columnTypes = new HashMap<String, ColumnType>(); for (long i = 0; i < 12; i++) { columnTypes.put(table.getColumnName(i), table.getColumnType(i)); } if (!columnTypes.containsKey("id")) { throw new IllegalStateException("Missing column 'id'"); } if (columnTypes.get("id") != ColumnType.STRING) { throw new IllegalStateException("Invalid type 'String' for column 'id'"); } if (table.getPrimaryKey() != table.getColumnIndex("id")) { throw new IllegalStateException("Primary key not defined for field 'id'"); } if (!table.hasIndex(table.getColumnIndex("id"))) { throw new IllegalStateException("Index not defined for field 'id'"); } if (!columnTypes.containsKey("centerFilterId")) { throw new IllegalStateException("Missing column 'centerFilterId'"); } if (columnTypes.get("centerFilterId") != ColumnType.STRING) { throw new IllegalStateException("Invalid type 'String' for column 'centerFilterId'"); } if (!columnTypes.containsKey("classTypeId")) { throw new IllegalStateException("Missing column 'classTypeId'"); } if (columnTypes.get("classTypeId") != ColumnType.STRING) { throw new IllegalStateException("Invalid type 'String' for column 'classTypeId'"); } if (!columnTypes.containsKey("durationInMinutes")) { throw new IllegalStateException("Missing column 'durationInMinutes'"); } if (columnTypes.get("durationInMinutes") != ColumnType.INTEGER) { throw new IllegalStateException("Invalid type 'int' for column 'durationInMinutes'"); } if (!columnTypes.containsKey("instructorId")) { throw new IllegalStateException("Missing column 'instructorId'"); } if (columnTypes.get("instructorId") != ColumnType.STRING) { throw new IllegalStateException("Invalid type 'String' for column 'instructorId'"); } if (!columnTypes.containsKey("name")) { throw new IllegalStateException("Missing column 'name'"); } if (columnTypes.get("name") != ColumnType.STRING) { throw new IllegalStateException("Invalid type 'String' for column 'name'"); } if (!columnTypes.containsKey("startTime")) { throw new IllegalStateException("Missing column 'startTime'"); } if (columnTypes.get("startTime") != ColumnType.STRING) { throw new IllegalStateException("Invalid type 'String' for column 'startTime'"); } if (!columnTypes.containsKey("bookedPersonsCount")) { throw new IllegalStateException("Missing column 'bookedPersonsCount'"); } if (columnTypes.get("bookedPersonsCount") != ColumnType.INTEGER) { throw new IllegalStateException("Invalid type 'int' for column 'bookedPersonsCount'"); } if (!columnTypes.containsKey("maxPersonsCount")) { throw new IllegalStateException("Missing column 'maxPersonsCount'"); } if (columnTypes.get("maxPersonsCount") != ColumnType.INTEGER) { throw new IllegalStateException("Invalid type 'int' for column 'maxPersonsCount'"); } if (!columnTypes.containsKey("regionId")) { throw new IllegalStateException("Missing column 'regionId'"); } if (columnTypes.get("regionId") != ColumnType.STRING) { throw new IllegalStateException("Invalid type 'String' for column 'regionId'"); } if (!columnTypes.containsKey("waitingListCount")) { throw new IllegalStateException("Missing column 'waitingListCount'"); } if (columnTypes.get("waitingListCount") != ColumnType.INTEGER) { throw new IllegalStateException("Invalid type 'int' for column 'waitingListCount'"); } if (!columnTypes.containsKey("classCategoryIds")) { throw new IllegalStateException("Missing column 'classCategoryIds'"); } if (columnTypes.get("classCategoryIds") != ColumnType.LINK_LIST) { throw new IllegalStateException( "Invalid type 'ClassCategoryIds' for column 'classCategoryIds'"); } if (!transaction.hasTable("class_ClassCategoryIds")) { throw new IllegalStateException( "Missing table 'class_ClassCategoryIds' for column 'classCategoryIds'"); } columnIndices = new HashMap<String, Long>(); for (String fieldName : getFieldNames()) { long index = table.getColumnIndex(fieldName); if (index == -1) { throw new RealmMigrationNeededException( "Field '" + fieldName + "' not found for type SatsClass"); } columnIndices.put(fieldName, index); } INDEX_ID = table.getColumnIndex("id"); INDEX_CENTERFILTERID = table.getColumnIndex("centerFilterId"); INDEX_CLASSTYPEID = table.getColumnIndex("classTypeId"); INDEX_DURATIONINMINUTES = table.getColumnIndex("durationInMinutes"); INDEX_INSTRUCTORID = table.getColumnIndex("instructorId"); INDEX_NAME = table.getColumnIndex("name"); INDEX_STARTTIME = table.getColumnIndex("startTime"); INDEX_BOOKEDPERSONSCOUNT = table.getColumnIndex("bookedPersonsCount"); INDEX_MAXPERSONSCOUNT = table.getColumnIndex("maxPersonsCount"); INDEX_REGIONID = table.getColumnIndex("regionId"); INDEX_WAITINGLISTCOUNT = table.getColumnIndex("waitingListCount"); INDEX_CLASSCATEGORYIDS = table.getColumnIndex("classCategoryIds"); } else { throw new RealmMigrationNeededException( "The SatsClass class is missing from the schema for this Realm."); } }