Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2013-2014 Effectiva Solutions company
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
 package org.ujorm.orm;
 
 import java.util.List;
Extended SQL dialect class.

Author(s):
Effectiva Solutions company
 
 @SuppressWarnings("unchecked")
 public class SqlDialectEx {

    
Logger
 
     private static final UjoLogger LOGGER = UjoLoggerFactory.getLogger(SqlDialectEx.class);

    
The main dialect
 
     protected final SqlDialect dialect;

    
Constructor
 
     public SqlDialectEx(SqlDialect dialect) {
         this. = dialect;
     }

    
Print an DROP INDEX for the parameter column.

Returns:
More statements separated by the ';' charactes are enabled
 
     public Appendable printDropIndex(final MetaIndex indexfinal Appendable outthrows IOException {
         out.append("DROP INDEX ");
         out.append(..of(index));
         out.append(" ON ");
         .printFullTableName(..of(index), out);
         return out;
     }
 
 
     public Appendable printPrimaryKey(MetaColumn columnStringBuilder sqlthrows Exception {
         sql.append("ALTER TABLE ");
         .printFullTableName(column.getTable(), sql);
         sql.append(" ADD ");
         printPrimaryKeyConstraint(column.getTable(), Arrays.asList(column), sql);
         return sql;
     }

    
SQL Name Provider
 
     public String buildConstraintName(final MetaColumn columnfinal MetaTable table) {
         final String cn = column.getConstraintName();
         if (.isFilled(cn)) {
             return cn;
         } else {
             return getNameProvider().buildDefaultConstraintName(tablecolumn);
         }
     }
 
     public String buildPrimaryKeyOverColumn(MetaTable tableList<MetaColumncolumnsthrows IOException {
         String overColumn = "";
         String separator = "";
         for (MetaColumn col : columns) {
             String name = col.getName();
             overColumn += separator;
             overColumn += name;
             separator = ",";
         }
         return overColumn;
     }

    
Print Unique Constraint
 
     public Appendable printUniqueConstraint(List<MetaColumncolumnsStringBuilder outthrows IOException {
         return printUniqueConstraint(outcolumns.toArray(new MetaColumn[] {} ));
     }

    
printUniqueConstraint
 
     public Appendable printUniqueConstraint(StringBuilder outMetaColumn... columnsthrows IOException {
         assert columns.length > 0;
         MetaTable table = columns[0].getTable();
         out.append("ALTER TABLE ");
         .printFullTableName(tableout);
         out.append(" ADD CONSTRAINT ");
 
        out.append(getNameProvider().getUniqueConstraintName(columns));
        out.append(" UNIQUE (");
        String separator = "";
        for (MetaColumn column : columns) {
            out.append(separator);
            .printQuotedName(column.getName(), out);
            separator = ",";
        }
        out.append(")");
        return out;
    }

    
Prints primary key constraint
    protected void printPrimaryKeyConstraint(MetaTable tableList<MetaColumncolumnsAppendable outthrows IOException {
        out.append(" CONSTRAINT ");
        String pkName = getNameProvider().buildPrimaryKeyName(tablecolumns);
        out.append(pkName);
        out.append(" PRIMARY KEY ");
        String pkOverColumn = buildPrimaryKeyOverColumn(tablecolumns);
        out.append("(");
        .printQuotedName(pkOverColumnout);
        out.append(")");
    }

    
Print the next Sequence value
    public Appendable printSequenceNextValueWithValues(final UjoSequencer sequencelong seqfinal Appendable outthrows IOException {
        out.append("UPDATE ");
        .printSequenceTableName(sequenceout);
        out.append(" SET ");
        out.append("=" + seq);
        out.append(" WHERE ");
        out.append("=?");
        return out;
    }

    
Print SQL LIST ALL SEQUENCE IDs.
    public Appendable printSequenceListAllId(final UjoSequencer sequencefinal Appendable outthrows IOException {
        final SeqTableModel tm = .getSeqTableModel();
        out.append("SELECT ");
        .printQuotedNameAlways(tm.getId(), out);
        out.append(" FROM ");
        .printSequenceTableName(sequenceout);
        return out;
    }

    
Returns a name provider

Returns:
Current SQL name provider
Throws:
java.lang.IllegalStateException A problem during creating an instance.
    final protected SqlNameProvider getNameProvider() throws IllegalStateException {
        return .getNameProvider();
    }
New to GrepCode? Check out our FAQ X