Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Notation support for SQL import #59

Merged
merged 30 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c27edfd
multi-notation support - cardinalities
christoph-lauscher Jun 24, 2023
20755f6
multi-notation support - UML
christoph-lauscher Jun 24, 2023
8cb3ddf
SQL export - add null constraint
christoph-lauscher Jun 24, 2023
30e112d
SQL import - set optional type
christoph-lauscher Jun 24, 2023
efb10ee
SQL export - replace underscores in column type
christoph-lauscher Jun 24, 2023
388173e
multi-notation support - min max
christoph-lauscher Jun 24, 2023
1719a49
multi-notation support - crow's foot
christoph-lauscher Jun 24, 2023
6c05880
multi-notation support - chen
christoph-lauscher Jun 24, 2023
897eaa9
multi-notation support - bachman
christoph-lauscher Jun 24, 2023
a0c7622
SQL export - use constant
christoph-lauscher Jun 24, 2023
70884d9
multi-notation support - unit tests
christoph-lauscher Jun 24, 2023
211588b
multi-notation support - unit test
christoph-lauscher Jun 24, 2023
582d549
multi-notation support - set notation option
christoph-lauscher Jun 24, 2023
c480e2b
multi-notation support - remove output files
christoph-lauscher Jun 24, 2023
f0f1785
multi-notation support - ignore output files
christoph-lauscher Jun 24, 2023
79bc53e
Merge remote-tracking branch 'origin/notations' into main
christoph-lauscher Jun 25, 2023
5d96b44
multi-notation support - initialize unit test
christoph-lauscher Jun 25, 2023
988add3
Merge remote-tracking branch 'origin/notations' into main
christoph-lauscher Jun 25, 2023
61e738f
multi-notation support - read from classpath
christoph-lauscher Jun 25, 2023
8f2c0f2
Merge remote-tracking branch 'origin/notations' into main
christoph-lauscher Jun 25, 2023
5ea2b59
multi-notation support - check directory
christoph-lauscher Jun 25, 2023
a8810da
multi-notation support - add test annotations
christoph-lauscher Jun 25, 2023
436c55f
Merge remote-tracking branch 'origin/notations' into main
christoph-lauscher Jun 25, 2023
9e01da7
Revert "multi-notation support - add test annotations"
christoph-lauscher Jun 25, 2023
f529e87
Revert "multi-notation support - initialize unit test"
christoph-lauscher Jun 25, 2023
6bed084
Merge remote-tracking branch 'origin/notations' into main
christoph-lauscher Jun 25, 2023
01f1c22
Revert "Revert "multi-notation support - initialize unit test""
christoph-lauscher Jun 25, 2023
89520f9
multi-notation support - check test input availability
christoph-lauscher Jun 25, 2023
de5d84e
Revert "Revert "Revert "multi-notation support - initialize unit test"""
christoph-lauscher Jun 25, 2023
ab403bb
Merge remote-tracking branch 'origin/notations' into main
christoph-lauscher Jun 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.big.erd.generator.sql;

public class BachmanSqlImport extends SqlImport {

protected String getNotation() {
return "bachman";
}

protected String getCardinality(boolean isMandatory, boolean isSingle, int countMultiple) {
return (isMandatory ? "1" : "0") + (isSingle ? "" : "+");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.big.erd.generator.sql;

public class ChenSqlImport extends SqlImport {

protected String getNotation() {
return "chen";
}

protected String getCardinality(boolean isMandatory, boolean isSingle, int countMultiple) {
return isSingle ? "1" : ("" + (char)(Integer.max('A', 'N' - countMultiple)));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.big.erd.generator.sql;

public class CrowsFootSqlImport extends SqlImport {

protected String getNotation() {
return "crowsfoot";
}

protected String getCardinality(boolean isMandatory, boolean isSingle, int countMultiple) {
if (!isMandatory) {
if (isSingle) {
return "?";
} else {
return "0+";
}
} else {
if (isSingle) {
return "1";
} else {
return "1+";
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.big.erd.entityRelationship.Attribute;
import org.big.erd.entityRelationship.AttributeType;

/**
* Generates SQL for DB2 from the ER model.
*/
Expand Down Expand Up @@ -117,14 +114,4 @@ protected String mapDataType(String type) {

return null;
}

@Override
protected String transformDataType(Attribute attribute, String mappedType, int size, Integer precision, StringBuilder comment) {
String transformedType = super.transformDataType(attribute, mappedType, size, precision, comment);
if (attribute.getType() == AttributeType.KEY || attribute.getType() == AttributeType.PARTIAL_KEY) {
transformedType = transformedType + " NOT NULL";
addComment(comment, "added NULL constraint");
}
return transformedType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Set;

public class GeneratorUtils {

public static final String NOT_NULL = "NOT NULL";

public static String findUniqueName(String nameOriginal, Set<String> usedNames) {
String name = nameOriginal;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.big.erd.generator.sql;

public class MinMaxSqlImport extends SqlImport {

protected String getNotation() {
return "minmax";
}

protected String getCardinality(boolean isMandatory, boolean isSingle, int countMultiple) {
return (isMandatory ? "1" : "0") + "," + (isSingle ? "1" : "*");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ public class SqlAttribute {

private String attributeName;
private String attributeType;
private String attributeKeywords;
private String attributeComment;

public boolean isMandatory() {
return attributeKeywords.toUpperCase().contains(GeneratorUtils.NOT_NULL);
}

public String getAttributeName() {
return attributeName;
}
Expand All @@ -24,4 +29,10 @@ public String getAttributeComment() {
public void setAttributeComment(String attributeComment) {
this.attributeComment = attributeComment;
}
public String getAttributeKeywords() {
return attributeKeywords;
}
public void setAttributeKeywords(String attributeKeywords) {
this.attributeKeywords = attributeKeywords;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,22 @@ protected String transformDataType(Attribute attribute, String mappedType, int s
if (precision != null && precision > 0) {
strPrecision = ", " + precision;
}
return mappedType + "(" + size + strPrecision + ")";
mappedType = mappedType + "(" + size + strPrecision + ")";
}
if (attribute.getType() != AttributeType.OPTIONAL) {
mappedType = mappedType + " " + GeneratorUtils.NOT_NULL;
}
return mappedType;
}

protected String mapDataType(String type) {
return type;
}

// ER model does not support spaces in data types
private String replaceUnderscores(String value) {
return value.replace("_", " ");
}

private Entity getStrongEntity(final Relationship r) {
if (r.getFirst().getTarget().isWeak()) {
Expand Down Expand Up @@ -286,6 +294,7 @@ private void addAttributes(StringConcatenation tableContent, Map<String, Attribu
size = 255;
addComment(comment, "added default type");
}
originalType = replaceUnderscores(originalType);
String mappedType = this.mapDataType(originalType);
if (mappedType == null) {
mappedType = originalType;
Expand Down
Loading