@Override public String getDescription() { return "The referenced element " + col.getId() + ", is not enabled. Disabled elements will " + "not be generated. Thus, referencing a disabled element " + "will result in broken code.\n" + "This might be a result of the element in question not being enabled, " + "or that an ancestor of the element is not enabled. \n" + "To fix this issue, make sure the element " + targetName + " is enabled."; }
@Override public String getTitle() { return "Reference not enabled: " + col.getId(); }
/** * Locate the {@link Column} child with the specified id if it exists, else * return an empty {@code Optional}. * * @param id the {@link HasId#getId()} of the column * @return the child found or an empty {@code Optional} */ default Optional<? extends Column> findColumn(String id) { return columns().filter(child -> child.getId().equals(id)).findAny(); }
public static Optional<? extends Column> referencedColumnIfPresent(Project project, String dbmsId, String schemaId, String tableId, String columnId) { return referencedTableIfPresent(project, dbmsId, schemaId, tableId) .flatMap(table -> table.columns().filter(column -> columnId.equals(column.getId())) .findAny() ); }
@Override public Persister<ENTITY> persister(HasLabelSet<ENTITY> includedFields) { Predicate<Column> columns = insertColumnFilter.and(c -> includedFields.test(c.getId())); String statement = getInsertStatement(updateColumnFilter.and(c12 -> includedFields.test(c12.getId()))); return entity -> persist(entity, f -> columns.test(columnsByFields.get(f)), statement); }
@Override public Updater<ENTITY> updater(HasLabelSet<ENTITY> includedFields) { assertHasPrimaryKeyColumns(); Predicate<Column> columns = updateColumnFilter.and(c -> includedFields.test(c.getId())); String statement = getUpdateStatement(updateColumnFilter.and(c12 -> includedFields.test(c12.getId()))); return entity -> update(entity, f -> columns.test(columnsByFields.get(f)), statement); }
/** * A helper method for accessing the foreign {@link Column} referenced by * this key. * * @return the foreign {@link Column} referenced by this */ default Optional<? extends Column> findForeignColumn() { return findForeignTable() .flatMap(table -> table.columns() .filter(col -> col.getId().equals(getForeignColumnName())) .findAny() ); }
/** * Returns {@code true} if the two specified documents represents the same * element in the database. Two documents are considered same if they have * the same name and type and their parents are considered same. * * @param first the first document * @param second the second document * @return {@code true} if same, else {@code false} */ public static boolean isSame(Column first, Column second) { if (first.getId().equals(second.getId())) { final Table firstParent = first.getParentOrThrow(); final Table secondParent = second.getParentOrThrow(); return isSame(firstParent, secondParent); } else { return false; } }
/** * Locates and returns the column referenced by the {@link #getId()} * method. * * @return the referenced column */ default Optional<? extends Column> findColumn() { return ancestors() .filter(Table.class::isInstance) .map(Table.class::cast) .findFirst() .flatMap(table -> table .columns() .filter(col -> col.getId().equals(getId())) .findAny() ); }
/** * Returns a list of all the enum constants in a particular column. * The list is created each time this method is called and is therefore * safe to edit without affecting the column. * <p> * If no enum constants was specified in the column, an exception is * thrown. * * @param column the column to retreive the constants from * @return list of the constants */ public static List<String> enumConstantsOf(Column column) { return Stream.of(column.getEnumConstants() .orElseThrow(() -> new RuntimeException( "Column '" + column.getId() + "' in table '" + column.getParentOrThrow().getId() + "' was marked as an enum but no enum constants was specified." )) .split(",") ).sorted().collect(toList()); }
private static int findNullOffset( final Table table, final Stage<?> stage, final HasComparableOperators<?, ?> field ) { int result = -1; final String onColumnId = field .identifier() .getColumnId(); final List<Column> columns = table.columns() .filter(Column::isEnabled) .collect(toList()); for (int j = 0; j < columns.size(); j++) { final String columnId = columns.get(j).getId(); if (columnId.equals(onColumnId)) { // Compose a null detecting entity mapper result = j; break; } } if (result == -1) { throw new IllegalStateException( "Unable to locate column " + onColumnId + " in table " + table.getId() + " for stage " + stage.toString() + " Columns: " + columns.stream().map(Column::getId).collect(joining(", ")) ); } return result; }
private SqlPersistenceImpl(SqlPersistenceImpl<ENTITY> template, HasLabelSet<ENTITY> includedFields) { primaryKeyFields = template.primaryKeyFields; fields = template.fields; dbms = template.dbms; table = template.table; dbmsType = template.dbmsType; sqlTableReference = template.sqlTableReference; hasPrimaryKeyColumns = template.hasPrimaryKeyColumns; naming = template.naming; operationHandler = template.operationHandler; columnHandler = template.columnHandler; entityClass = template.entityClass; this.insertColumnFilter = columnHandler.excludedInInsertStatement().negate().and(c -> includedFields.test(c.getId())); this.insertStatement = getInsertStatement(insertColumnFilter); this.updateColumnFilter = columnHandler.excludedInUpdateStatement().negate().and(c -> includedFields.test(c.getId())); this.updateStatement = getUpdateStatement(updateColumnFilter); deleteStatement = template.deleteStatement; generatedFieldSupports = template.generatedFieldSupports; generatedFields = template.generatedFields; columnsByFields = template.columnsByFields; }
+ "Fallback to JDBC-type %s", table.getId(), column.getId(), md.getTypeName(), md.getDataType(),
ImmutableColumn(ImmutableTable parent, Map<String, Object> data) { super(parent, data); final Column prototype = new ColumnImpl(parent, data); this.enabled = prototype.isEnabled(); this.id = prototype.getId(); this.name = prototype.getName(); this.alias = prototype.getAlias(); this.nullable = prototype.isNullable(); this.nullableImplementation = prototype.getNullableImplementation(); this.autoincrement = prototype.isAutoIncrement(); this.typeMapper = prototype.getTypeMapper(); this.databaseType = prototype.getDatabaseType(); this.databaseTypeObject = prototype.findDatabaseType(); this.enumConstants = prototype.getEnumConstants(); this.decimalDigits = prototype.getDecimalDigits(); this.columnSize = prototype.getColumnSize(); this.ordinalPosition = prototype.getOrdinalPosition(); }
identifierEnum.add(EnumConstant.of(constant).add(Value.ofText(col.getId())));
@Override public Persister<ENTITY> persister(HasLabelSet<ENTITY> includedFields) { Predicate<Column> columns = insertColumnFilter.and(c -> includedFields.test(c.getId())); String statement = getInsertStatement(updateColumnFilter.and(c12 -> includedFields.test(c12.getId()))); return entity -> persist(entity, f -> columns.test(columnsByFields.get(f)), statement); }
@Override public Updater<ENTITY> updater(HasLabelSet<ENTITY> includedFields) { assertHasPrimaryKeyColumns(); Predicate<Column> columns = updateColumnFilter.and(c -> includedFields.test(c.getId())); String statement = getUpdateStatement(updateColumnFilter.and(c12 -> includedFields.test(c12.getId()))); return entity -> update(entity, f -> columns.test(columnsByFields.get(f)), statement); }
private static int findNullOffset( final Table table, final Stage<?> stage, final HasComparableOperators<?, ?> field ) { int result = -1; final String onColumnId = field .identifier() .getColumnId(); final List<Column> columns = table.columns() .filter(Column::isEnabled) .collect(toList()); for (int j = 0; j < columns.size(); j++) { final String columnId = columns.get(j).getId(); if (columnId.equals(onColumnId)) { // Compose a null detecting entity mapper result = j; break; } } if (result == -1) { throw new IllegalStateException( "Unable to locate column " + onColumnId + " in table " + table.getId() + " for stage " + stage.toString() + " Columns: " + columns.stream().map(Column::getId).collect(joining(", ")) ); } return result; }
private SqlPersistenceImpl(SqlPersistenceImpl<ENTITY> template, HasLabelSet<ENTITY> includedFields) { primaryKeyFields = template.primaryKeyFields; fields = template.fields; dbms = template.dbms; table = template.table; dbmsType = template.dbmsType; sqlTableReference = template.sqlTableReference; hasPrimaryKeyColumns = template.hasPrimaryKeyColumns; naming = template.naming; operationHandler = template.operationHandler; columnHandler = template.columnHandler; entityClass = template.entityClass; this.insertColumnFilter = columnHandler.excludedInInsertStatement().negate().and(c -> includedFields.test(c.getId())); this.insertStatement = getInsertStatement(insertColumnFilter); this.updateColumnFilter = columnHandler.excludedInUpdateStatement().negate().and(c -> includedFields.test(c.getId())); this.updateStatement = getUpdateStatement(updateColumnFilter); deleteStatement = template.deleteStatement; generatedFieldSupports = template.generatedFieldSupports; generatedFields = template.generatedFields; columnsByFields = template.columnsByFields; }