public TableRowReader(Table<T> table) { this.table = table; try { constructor = table.getRecordType().getDeclaredConstructor(); } catch (Exception e) { throw new IllegalArgumentException("Cannot find constructor for class " + table.getRecordType().getName()); } }
@Override public T readResult(Record record, int offset) { T toReturn; try { toReturn = constructor.newInstance(); } catch (Exception e) { throw new IllegalArgumentException("Cannot construct class " + table.getRecordType().getName()); } Field<?>[] fields = table.fields(); for (int idx = 0; idx < fields.length; idx++) { Field<?> f = fields[idx]; copyValueIntoRecord(toReturn, record, f, idx); } return toReturn; }
private void findMetamodelGetters(Schema schema) { for (Table<?> table: schema.getTables()) { String recordClassName = Type.getInternalName(table.getRecordType()); for (Field<?> field: table.fields()) { String name = field.getName(); String getterName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); MethodSignature methodSig = new MethodSignature( recordClassName, getterName, Type.getMethodDescriptor(Type.getType(field.getType()))); fieldMethods.put(methodSig, field); } } }
@Override public final Class<? extends R> getRecordType() { return table.getRecordType(); }
@Override public final Class<? extends R> getRecordType() { return table.getRecordType(); }
public TableRowReader(Table<T> table) { this.table = table; try { constructor = table.getRecordType().getDeclaredConstructor(); } catch (Exception e) { throw new IllegalArgumentException("Cannot find constructor for class " + table.getRecordType().getName()); } }
protected Object newObject(TableMapping mapping) { Class<?> clz = mapping.originalTable.getRecordType(); try { return clz.newInstance(); } catch (InstantiationException e) { throw new IllegalStateException("Failed to construct [" + clz + "]", e); } catch (IllegalAccessException e) { throw new IllegalStateException("Failed to construct [" + clz + "]", e); } }
@Override public Class<? extends R> getRecordType() { return alias.wrapped().getRecordType(); } }
@Override public Class<? extends R> getRecordType() { return alias.wrapped().getRecordType(); } }
@SuppressWarnings("unchecked") TableDataType(Table<R> table) { super(SQLDialect.DEFAULT, (Class<R>) table.getRecordType(), getQualifiedName(table)); }
private void initTable(Schema schema) { Class<?> is = findInterface(entityClass) .orElseThrow(() -> new RuntimeException("Entity class must implements one interface at least.")); table = schema.getTables().stream().filter(t -> is.isAssignableFrom(t.getRecordType())).findFirst() .orElseThrow(() -> new RuntimeException("Can't find a table for the entity.")); }
protected void registerTableFields(Table<?> table) { Class<?> clz = table.getClass(); for (java.lang.reflect.Field field : clz.getFields()) { if (TableField.class.isAssignableFrom(field.getType()) && Modifier.isPublic(field.getModifiers())) { try { field.setAccessible(true); TableField<?, ?> tableField = (TableField<?, ?>) field.get(table); String name = getNameFromField(table.getRecordType(), tableField.getName()); tableFields.put(new FieldCacheKey(table.getRecordType(), name), tableField); } catch (IllegalArgumentException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } } } }
public List<Class<?>> getRecordTypes() { List<Class<?>> result = new ArrayList<Class<?>>(); Schema schema = null; try { for (Field field : schemaClass.getFields()) { if (field.getType() == schemaClass) { schema = (Schema) field.get(schemaClass); } } } catch (IllegalAccessException e) { throw new IllegalArgumentException(e); } if (schema == null) { throw new IllegalArgumentException("Failed to find TABLE field on [" + schemaClass + "]"); } for (Table<?> table : schema.getTables()) { result.add(table.getRecordType()); } return result; }
@Override public T readResult(Record record, int offset) { T toReturn; try { toReturn = constructor.newInstance(); } catch (Exception e) { throw new IllegalArgumentException("Cannot construct class " + table.getRecordType().getName()); } Field<?>[] fields = table.fields(); for (int idx = 0; idx < fields.length; idx++) { Field<?> f = fields[idx]; copyValueIntoRecord(toReturn, record, f, idx); } return toReturn; }
/** * Create a new record */ @SuppressWarnings("unchecked") static final <R extends Record> RecordDelegate<R> newRecord(boolean fetched, Table<R> type, Configuration configuration) { return (RecordDelegate<R>) newRecord(fetched, type.getRecordType(), type.fields(), configuration); }
/** * Create a new record */ @SuppressWarnings("unchecked") static final <R extends Record> RecordDelegate<R> newRecord(Table<R> type, Configuration configuration) { return (RecordDelegate<R>) newRecord(type.getRecordType(), type.fields(), configuration); }
@SuppressWarnings({ "unchecked", "hiding" }) public <T extends Table<?>> T add(T input, Field<?>... selectedFields) { Set<String> selectFields = selectedFields == null || selectedFields.length == 0 ? null : new HashSet<String>(); int index = count++; String prefix = String.format("%s_%d", input.getName(), index); Table<?> alias = input.as(prefix); for (Field<?> field : selectedFields) { selectFields.add(field.getName()); } for (Field<?> field : alias.fields()) { if (selectFields != null && !"id".equals(field.getName()) && !selectFields.contains(field.getName())) { continue; } String fieldAlias = String.format("%s_%s", prefix, field.getName()); Target target = new Target(field.getName(), index); targets.put(fieldAlias, target); fields.add(field.as(String.format("%s_%s", prefix, field.getName()))); } classes.add(input.getRecordType()); return (T) alias; }
private void findMetamodelGetters(Schema schema) { for (Table<?> table: schema.getTables()) { String recordClassName = Type.getInternalName(table.getRecordType()); for (Field<?> field: table.fields()) { String name = field.getName(); String getterName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); MethodSignature methodSig = new MethodSignature( recordClassName, getterName, Type.getMethodDescriptor(Type.getType(field.getType()))); fieldMethods.put(methodSig, field); } } }
@SuppressWarnings("unchecked") @Override public final Class<? extends R> getRecordType() { // Generated record classes only come into play, when the select is // - on a single table // - a select * if (getFrom().size() == 1 && getSelect0().isEmpty()) { return (Class<? extends R>) getFrom().get(0).asTable().getRecordType(); } else { return (Class<? extends R>) RecordImpl.class; } }
@SuppressWarnings("unchecked") @Override public final Class<? extends R> getRecordType() { // Generated record classes only come into play, when the select is // - on a single table // - a select * if (getFrom().size() == 1 && getSelect0().isEmpty()) { return (Class<? extends R>) getFrom().get(0).asTable().getRecordType(); } else { return (Class<? extends R>) RecordImpl.class; } }