Skip to content

Commit

Permalink
Refactor GenericSchemaBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Dec 10, 2024
1 parent a778c3e commit 41c9174
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,14 @@ private static Collection<ShardingSphereTable> convertToTables(final Collection<
}

private static Collection<ShardingSphereColumn> convertToColumns(final Collection<ColumnMetaData> columnMetaDataList) {
Collection<ShardingSphereColumn> result = new LinkedList<>();
for (ColumnMetaData each : columnMetaDataList) {
result.add(new ShardingSphereColumn(each.getName(), each.getDataType(), each.isPrimaryKey(), each.isGenerated(), each.isCaseSensitive(), each.isVisible(), each.isUnsigned(),
each.isNullable()));
}
return result;
return columnMetaDataList.stream().map(ShardingSphereColumn::new).collect(Collectors.toList());
}

private static Collection<ShardingSphereIndex> convertToIndexes(final Collection<IndexMetaData> indexMetaDataList) {
Collection<ShardingSphereIndex> result = new LinkedList<>();
for (IndexMetaData each : indexMetaDataList) {
ShardingSphereIndex index = new ShardingSphereIndex(each.getName(), each.getColumns(), each.isUnique());
result.add(index);
}
return result;
return indexMetaDataList.stream().map(ShardingSphereIndex::new).collect(Collectors.toList());
}

private static Collection<ShardingSphereConstraint> convertToConstraints(final Collection<ConstraintMetaData> constraintMetaDataList) {
Collection<ShardingSphereConstraint> result = new LinkedList<>();
for (ConstraintMetaData each : constraintMetaDataList) {
result.add(new ShardingSphereConstraint(each.getName(), each.getReferencedTableName()));
}
return result;
return constraintMetaDataList.stream().map(ShardingSphereConstraint::new).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.ColumnMetaData;

/**
* ShardingSphere column.
Expand All @@ -46,4 +47,15 @@ public final class ShardingSphereColumn {
private final boolean unsigned;

private final boolean nullable;

public ShardingSphereColumn(final ColumnMetaData columnMetaData) {
name = columnMetaData.getName();
dataType = columnMetaData.getDataType();
primaryKey = columnMetaData.isPrimaryKey();
generated = columnMetaData.isGenerated();
caseSensitive = columnMetaData.isCaseSensitive();
visible = columnMetaData.isVisible();
unsigned = columnMetaData.isUnsigned();
nullable = columnMetaData.isNullable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.ConstraintMetaData;

/**
* ShardingSphere constraint.
Expand All @@ -34,4 +35,10 @@ public final class ShardingSphereConstraint {
private final String name;

private final String referencedTableName;

public ShardingSphereConstraint(final ConstraintMetaData constraintMetaData) {
name = constraintMetaData.getName();
referencedTableName = constraintMetaData.getReferencedTableName();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.apache.shardingsphere.infra.database.core.metadata.data.model.IndexMetaData;

import java.util.Collection;

Expand All @@ -38,4 +39,10 @@ public final class ShardingSphereIndex {
private final Collection<String> columns;

private final boolean unique;

public ShardingSphereIndex(final IndexMetaData indexMetaData) {
name = indexMetaData.getName();
columns = indexMetaData.getColumns();
unique = indexMetaData.isUnique();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public final class TableMetaData {

public TableMetaData(final String name, final Collection<ColumnMetaData> columns, final Collection<IndexMetaData> indexes, final Collection<ConstraintMetaData> constraints) {
this.name = name;
type = TableType.TABLE;
this.columns = columns;
this.indexes = indexes;
this.constraints = constraints;
type = TableType.TABLE;
}
}

0 comments on commit 41c9174

Please sign in to comment.