Skip to content

Commit

Permalink
Multi-Notation support for SQL import (#59)
Browse files Browse the repository at this point in the history
* multi-notation support - cardinalities

* multi-notation support - UML

* SQL export - add null constraint

* SQL import - set optional type

* SQL export - replace underscores in column type

* multi-notation support - min max

* multi-notation support - crow's foot

* multi-notation support - chen

* multi-notation support - bachman

* SQL export - use constant

* multi-notation support - unit tests

* multi-notation support - unit test

* multi-notation support - set notation option

* multi-notation support - remove output files

* multi-notation support - ignore output files

* multi-notation support - initialize unit test

* multi-notation support - read from classpath

* multi-notation support - check directory

* multi-notation support - add test annotations

* Revert "multi-notation support - add test annotations"

This reverts commit a8810da.

* Revert "multi-notation support - initialize unit test"

* Revert "Revert "multi-notation support - initialize unit test""

This reverts commit f529e87.

* multi-notation support - check test input availability

* Revert "Revert "Revert "multi-notation support - initialize unit test"""

This reverts commit 01f1c22.
  • Loading branch information
christoph-lauscher authored Aug 23, 2023
1 parent c01451c commit 0772570
Show file tree
Hide file tree
Showing 80 changed files with 7,284 additions and 67 deletions.
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

0 comments on commit 0772570

Please sign in to comment.