@Test public void caching() { assertTrue(ModelInfo.from(TestModel.class) == ModelInfo.from(TestModel.class)); }
static ModelInfo from(Class<? extends QueryResult> clazz) { if (cache.containsKey(clazz)) { return cache.get(clazz); } ModelInfo info = new ModelInfo(); final Field[] fields = Utils.getAllDeclaredFields(clazz, Object.class); for (Field field : fields) { if (field.isAnnotationPresent(DynamicColumn.class)) { ColumnField column = new ColumnField(); column.isDynamic = true; column.name = field.getAnnotation(DynamicColumn.class).value(); column.sqlType = Sprinkles.sInstance.getTypeSerializer(field.getType()).getSqlType().name(); column.field = field; if (!info.columns.add(column)) { throw new DuplicateColumnException(column.name); } } else if (field.isAnnotationPresent(Column.class)) { ColumnField column = new ColumnField(); column.isAutoIncrement = field.isAnnotationPresent(AutoIncrement.class); column.isKey = field.isAnnotationPresent(Key.class) || column.isAutoIncrement; column.name = field.getAnnotation(Column.class).value(); column.sqlType = Sprinkles.sInstance.getTypeSerializer(field.getType()).getSqlType().name(); column.field = field; if (column.isAutoIncrement && !column.sqlType.equals(SqlType.INTEGER.name())) { throw new AutoIncrementMustBeIntegerException(column.name); } if (column.isAutoIncrement) { info.autoIncrementField = column; } if (column.isKey) { info.keys.add(column); } if (!info.columns.add(column)) { throw new DuplicateColumnException(column.name); } } } if (info.columns.isEmpty()) { throw new EmptyTableException(clazz.getName()); } if (Model.class.isAssignableFrom(clazz)) { info.tableName = Utils.getTableName((Class<? extends Model>) clazz); if (info.keys.size() == 0) { throw new NoKeysException(); } } cache.put(clazz, info); return info; }
ModelInfo { static ModelInfo from(Class<? extends QueryResult> clazz) { if (cache.containsKey(clazz)) { return cache.get(clazz); } ModelInfo info = new ModelInfo(); final Field[] fields = Utils.getAllDeclaredFields(clazz, Object.class); for (Field field : fields) { if (field.isAnnotationPresent(DynamicColumn.class)) { ColumnField column = new ColumnField(); column.isDynamic = true; column.name = field.getAnnotation(DynamicColumn.class).value(); column.sqlType = Sprinkles.sInstance.getTypeSerializer(field.getType()).getSqlType().name(); column.field = field; if (!info.columns.add(column)) { throw new DuplicateColumnException(column.name); } } else if (field.isAnnotationPresent(Column.class)) { ColumnField column = new ColumnField(); column.isAutoIncrement = field.isAnnotationPresent(AutoIncrement.class); column.isKey = field.isAnnotationPresent(Key.class) || column.isAutoIncrement; column.name = field.getAnnotation(Column.class).value(); column.sqlType = Sprinkles.sInstance.getTypeSerializer(field.getType()).getSqlType().name(); column.field = field; if (column.isAutoIncrement && !column.sqlType.equals(SqlType.INTEGER.name())) { throw new AutoIncrementMustBeIntegerException(column.name); } if (column.isAutoIncrement) { info.autoIncrementField = column; } if (column.isKey) { info.keys.add(column); } if (!info.columns.add(column)) { throw new DuplicateColumnException(column.name); } } } if (info.columns.isEmpty()) { throw new EmptyTableException(clazz.getName()); } if (Model.class.isAssignableFrom(clazz)) { info.tableName = Utils.getTableName((Class<? extends Model>) clazz); if (info.keys.size() == 0) { throw new NoKeysException(); } } cache.put(clazz, info); return info; } }
ModelInfo { static ModelInfo from(Class<? extends QueryResult> clazz) { if (cache.containsKey(clazz)) { return cache.get(clazz); } ModelInfo info = new ModelInfo(); final Field[] fields = Utils.getAllDeclaredFields(clazz, Object.class); for (Field field : fields) { if (field.isAnnotationPresent(DynamicColumn.class)) { ColumnField column = new ColumnField(); column.isDynamic = true; column.name = field.getAnnotation(DynamicColumn.class).value(); column.sqlType = Sprinkles.sInstance.getTypeSerializer(field.getType()).getSqlType().name(); column.field = field; if (!info.columns.add(column)) { throw new DuplicateColumnException(column.name); } } else if (field.isAnnotationPresent(Column.class)) { ColumnField column = new ColumnField(); column.isAutoIncrement = field.isAnnotationPresent(AutoIncrement.class); column.isKey = field.isAnnotationPresent(Key.class) || column.isAutoIncrement; column.name = field.getAnnotation(Column.class).value(); column.sqlType = Sprinkles.sInstance.getTypeSerializer(field.getType()).getSqlType().name(); column.field = field; if (column.isAutoIncrement && !column.sqlType.equals(SqlType.INTEGER.name())) { throw new AutoIncrementMustBeIntegerException(column.name); } if (column.isAutoIncrement) { info.autoIncrementField = column; } if (column.isKey) { info.keys.add(column); } if (!info.columns.add(column)) { throw new DuplicateColumnException(column.name); } } } if (info.columns.isEmpty()) { throw new EmptyTableException(clazz.getName()); } if (Model.class.isAssignableFrom(clazz)) { info.tableName = Utils.getTableName((Class<? extends Model>) clazz); if (info.keys.size() == 0) { throw new NoKeysException(); } } cache.put(clazz, info); return info; } private  ModelInfo(); }
ModelInfo { static ModelInfo from(Class<? extends QueryResult> clazz) { if (cache.containsKey(clazz)) { return cache.get(clazz); } ModelInfo info = new ModelInfo(); final Field[] fields = Utils.getAllDeclaredFields(clazz, Object.class); for (Field field : fields) { if (field.isAnnotationPresent(DynamicColumn.class)) { ColumnField column = new ColumnField(); column.isDynamic = true; column.name = field.getAnnotation(DynamicColumn.class).value(); column.sqlType = Sprinkles.sInstance.getTypeSerializer(field.getType()).getSqlType().name(); column.field = field; if (!info.columns.add(column)) { throw new DuplicateColumnException(column.name); } } else if (field.isAnnotationPresent(Column.class)) { ColumnField column = new ColumnField(); column.isAutoIncrement = field.isAnnotationPresent(AutoIncrement.class); column.isKey = field.isAnnotationPresent(Key.class) || column.isAutoIncrement; column.name = field.getAnnotation(Column.class).value(); column.sqlType = Sprinkles.sInstance.getTypeSerializer(field.getType()).getSqlType().name(); column.field = field; if (column.isAutoIncrement && !column.sqlType.equals(SqlType.INTEGER.name())) { throw new AutoIncrementMustBeIntegerException(column.name); } if (column.isAutoIncrement) { info.autoIncrementField = column; } if (column.isKey) { info.keys.add(column); } if (!info.columns.add(column)) { throw new DuplicateColumnException(column.name); } } } if (info.columns.isEmpty()) { throw new EmptyTableException(clazz.getName()); } if (Model.class.isAssignableFrom(clazz)) { info.tableName = Utils.getTableName((Class<? extends Model>) clazz); if (info.keys.size() == 0) { throw new NoKeysException(); } } cache.put(clazz, info); return info; } private  ModelInfo();  }
ModelInfo { static ModelInfo from(Class<? extends QueryResult> clazz) { if (cache.containsKey(clazz)) { return cache.get(clazz); } ModelInfo info = new ModelInfo(); final Field[] fields = Utils.getAllDeclaredFields(clazz, Object.class); for (Field field : fields) { if (field.isAnnotationPresent(DynamicColumn.class)) { ColumnField column = new ColumnField(); column.isDynamic = true; column.name = field.getAnnotation(DynamicColumn.class).value(); column.sqlType = Sprinkles.sInstance.getTypeSerializer(field.getType()).getSqlType().name(); column.field = field; if (!info.columns.add(column)) { throw new DuplicateColumnException(column.name); } } else if (field.isAnnotationPresent(Column.class)) { ColumnField column = new ColumnField(); column.isAutoIncrement = field.isAnnotationPresent(AutoIncrement.class); column.isKey = field.isAnnotationPresent(Key.class) || column.isAutoIncrement; column.name = field.getAnnotation(Column.class).value(); column.sqlType = Sprinkles.sInstance.getTypeSerializer(field.getType()).getSqlType().name(); column.field = field; if (column.isAutoIncrement && !column.sqlType.equals(SqlType.INTEGER.name())) { throw new AutoIncrementMustBeIntegerException(column.name); } if (column.isAutoIncrement) { info.autoIncrementField = column; } if (column.isKey) { info.keys.add(column); } if (!info.columns.add(column)) { throw new DuplicateColumnException(column.name); } } } if (info.columns.isEmpty()) { throw new EmptyTableException(clazz.getName()); } if (Model.class.isAssignableFrom(clazz)) { info.tableName = Utils.getTableName((Class<? extends Model>) clazz); if (info.keys.size() == 0) { throw new NoKeysException(); } } cache.put(clazz, info); return info; } private  ModelInfo();   }