Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r320 - trunk/src/org/argouml/language/sql

argouml-sql
Discussion topic

Back to topic list

svn commit: r320 - trunk/src/org/argouml/language/sql

Author linus
Full name Linus Tolke
Date 2015-10-11 08:09:35 PDT
Message Author: linus
Date: 2015-10-11 08:09:26-0700
New Revision: 320

Modified:
   trunk/src/org/argoum​l/language/sql/Colum​nDefinition.java
   trunk/src/org/argoum​l/language/sql/Gener​atorSql.java
   trunk/src/org/argoum​l/language/sql/MySql​CodeCreator.java
   trunk/src/org/argoum​l/language/sql/Utils​.java

Log:
Added an implementation of auto increment attributes.

Contributed by: Thomas Eitzenberger.

Modified: trunk/src/org/argoum​l/language/sql/Colum​nDefinition.java
Url: http://argouml-sql.t​igris.org/source/bro​wse/argouml-sql/trun​k/src/org/argouml/la​nguage/sql/ColumnDef​inition.java?view=di​ff&pathrev=320​&r1=319&r2=320​
====================​====================​====================​==================
--- trunk/src/org/argoum​l/language/sql/Colum​nDefinition.java (original)
+++ trunk/src/org/argoum​l/language/sql/Colum​nDefinition.java 2015-10-11 08:09:26-0700
@@ -53,6 +53,8 @@
 
     private Boolean nullable;
 
+ private Boolean autoinc;
+
     private Integer length;
     
     private Integer nbDecimal;
@@ -150,6 +152,14 @@
     }
 
     /**
+ *
+ * @return Whether this column's values shall be AUTO INCREMENTed
+ */
+ public Boolean getAutoInc() {
+ return autoinc;
+ }
+
+ /**
      * Set the datatype of the column.
      *
      * @param datatype
@@ -184,7 +194,17 @@
     public void setNullable(Boolean nullable) {
         this.nullable = nullable;
     }
-
+
+ /**
+ *
+ * Set whether this column's values shall be AUTO INCREMENTed.
+ *
+ * @param autoinc
+ */
+ public void setAutoInc(Boolean autoinc) {
+ this.autoinc = autoinc;
+ }
+
     public Integer getLength() {
         return length;
     }

Modified: trunk/src/org/argoum​l/language/sql/Gener​atorSql.java
Url: http://argouml-sql.t​igris.org/source/bro​wse/argouml-sql/trun​k/src/org/argouml/la​nguage/sql/Generator​Sql.java?view=diff​&pathrev=320&r​1=319&r2=320
====================​====================​====================​==================
--- trunk/src/org/argoum​l/language/sql/Gener​atorSql.java (original)
+++ trunk/src/org/argoum​l/language/sql/Gener​atorSql.java 2015-10-11 08:09:26-0700
@@ -85,6 +85,12 @@
 
     /**
      * Constant representing the attribute stereotype (as <code>String​</code>)
+ * that will be used to recognize a foreign key attribute.
+ */
+ static final String AUTOINC_KEY_STEREOTYPE = "AUTOINC";
+
+ /**
+ * Constant representing the attribute stereotype (as <code>String​</code>)
      * that will be used to recognize an attribute to be not nullable.
      */
     static final String NOT_NULL_STEREOTYPE = "NOT_NULL";
@@ -211,7 +217,6 @@
 
         for (Object attribute : Model.getFacade().ge​tAttributes(element)​) {
             String name = Model.getFacade().ge​tName(attribute);
-
             ColumnDefinition cd = new ColumnDefinition();
             cd.setName(name);
 
@@ -228,6 +233,11 @@
             } else {
                 cd.setNullable(null);
             }
+ if (Utils.isAutoIncreme​nt(attribute)) {
+ cd.setAutoInc(Boolean.TRUE);
+ } else {
+ cd.setAutoInc(Boolean.FALSE);
+ }
 
             tableDefinition.addC​olumnDefinition(cd);​
 

Modified: trunk/src/org/argoum​l/language/sql/MySql​CodeCreator.java
Url: http://argouml-sql.t​igris.org/source/bro​wse/argouml-sql/trun​k/src/org/argouml/la​nguage/sql/MySqlCode​Creator.java?view=di​ff&pathrev=320​&r1=319&r2=320​
====================​====================​====================​==================
--- trunk/src/org/argoum​l/language/sql/MySql​CodeCreator.java (original)
+++ trunk/src/org/argoum​l/language/sql/MySql​CodeCreator.java 2015-10-11 08:09:26-0700
@@ -44,7 +44,7 @@
         sb.append(Utils.stri​ngsToCommaString(col​umnNames));
         sb.append(") REFERENCES ").append(references​TableName).append(" (");
         sb.append(Utils.stri​ngsToCommaString(ref​erencesColumnNames))​;
- sb.append(");");
+ sb.append(");").appe​nd(LINE_SEPARATOR);
 
         return sb.toString();
     }
@@ -68,7 +68,7 @@
         Iterator it = tableDefinition.getC​olumnDefinitions().i​terator();
         while (it.hasNext()) {
             ColumnDefinition colDef = (ColumnDefinition) it.next();
- sb.append(colDef.get​Name()).append(" ");
+ sb.append(" ").append(colDef.get​Name()).append(" ");
             sb.append(colDef.get​Datatype());
             Boolean nullable = colDef.getNullable();
             if (nullable != null) {
@@ -78,7 +78,16 @@
                     sb.append(" ").append("NOT NULL");
                 }
             }
+ Boolean autoinc = colDef.getAutoInc();
+ if (autoinc != null) {
+ if (autoinc.equals(Boolean.TRUE)) {
+ sb.append(" AUTO INCREMENT");
+ }
+ }
             sb.append(",").appen​d(LINE_SEPARATOR);
+ if (colDef.getComment() != null) {
+ sb.append("/* ").append(colDef.get​Comment()).append(" */");
+ }
         }
 
         StringBuffer sbPk = new StringBuffer();
@@ -91,11 +100,11 @@
             sbPk.append(primaryKeyField);
         }
 
- sb.append("PRIMARY KEY (");
+ sb.append(" PRIMARY KEY (");
         sb.append(sbPk);
         sb.append(")").appen​d(LINE_SEPARATOR);
 
- sb.append(");");
+ sb.append(");").appe​nd(LINE_SEPARATOR);
 
         primaryKeyCounter++;
 

Modified: trunk/src/org/argoum​l/language/sql/Utils​.java
Url: http://argouml-sql.t​igris.org/source/bro​wse/argouml-sql/trun​k/src/org/argouml/la​nguage/sql/Utils.jav​a?view=diff&path​rev=320&r1=319​&r2=320
====================​====================​====================​==================
--- trunk/src/org/argoum​l/language/sql/Utils​.java (original)
+++ trunk/src/org/argoum​l/language/sql/Utils​.java 2015-10-11 08:09:26-0700
@@ -187,6 +187,22 @@
     }
 
     /**
+ * Returns if an attribute is an attribute that should be auto incremented.
+ * Effectively checks if the attribute is of stereotype
+ * {@link GeneratorSql#AUTOINC​_KEY_STEREOTYPE}.
+ *
+ * @param attribute
+ * The attribute to check.
+ * @return <code>true</code> if it is a auto increment attribute,
+ * <code>false</code> else.
+ * @see Facade#isStereotype(Object, String)
+ */
+ public static boolean isAutoIncrement(Object attribute) {
+ return Model.getFacade().is​Stereotype(attribute​,
+ GeneratorSql.AUTOINC​_KEY_STEREOTYPE);
+ }
+
+ /**
      * Returns if an attribute is not nullable. Effectively checks if the
      * attribute is of stereotype {@link GeneratorSql#NOT_NUL​L_STEREOTYPE}.
      *

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r320 - trunk/src/org/argouml/language/sql linus Linus Tolke 2015-10-11 08:09:35 PDT
Messages per page: