Package org.beangle.db.jdbc.grammar

Examples of org.beangle.db.jdbc.grammar.TableGrammar


  /**
   * @param dialect
   * @return
   */
  public String getCreateSql(Dialect dialect, String newSchema) {
    TableGrammar grammar = dialect.getTableGrammar();
    StringBuilder buf = new StringBuilder(grammar.getCreateString()).append(' ')
        .append(identifier(newSchema)).append(" (");
    Iterator<Column> iter = columns.values().iterator();
    while (iter.hasNext()) {
      Column col = iter.next();
      buf.append(col.getName()).append(' ');
      buf.append(col.getSqlType(dialect));

      String defaultValue = col.getDefaultValue();
      if (defaultValue != null) {
        buf.append(" default ").append(defaultValue);
      }
      if (col.isNullable()) {
        buf.append(grammar.getNullColumnString());
      } else {
        buf.append(" not null");
      }
      boolean useUniqueConstraint = col.isUnique()
          && (!col.isNullable() || grammar.isSupportsNullUnique());
      if (useUniqueConstraint) {
        if (grammar.isSupportsUnique()) {
          buf.append(" unique");
        } else {
          UniqueKey uk = getOrCreateUniqueKey(col.getName() + '_');
          uk.addColumn(col);
        }
      }

      if (col.hasCheckConstraint() && grammar.isSupportsColumnCheck()) {
        buf.append(" check (").append(col.getCheckConstraint()).append(")");
      }
      String columnComment = col.getComment();
      if (columnComment != null) {
        buf.append(grammar.getColumnComment(columnComment));
      }
      if (iter.hasNext()) {
        buf.append(", ");
      }
    }
    if (hasPrimaryKey()) {
      buf.append(", ").append(getPrimaryKey().sqlConstraintString());
    }
    buf.append(')');
    if (StringUtils.isNotBlank(comment)) {
      buf.append(grammar.getComment(comment));
    }
    return buf.toString();
  }
View Full Code Here

TOP

Related Classes of org.beangle.db.jdbc.grammar.TableGrammar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.