Package org.apache.ddlutils.model

Examples of org.apache.ddlutils.model.Column


    {
        ListOrderedMap columns = new ListOrderedMap();

        for (int idx = 0; idx < sourceTable.getColumnCount(); idx++)
        {
            Column sourceColumn = sourceTable.getColumn(idx);
            Column targetColumn = targetTable.findColumn(sourceColumn.getName(),
                                                         getPlatform().isDelimitedIdentifierModeOn());


            if (targetColumn != null)
            {
View Full Code Here


        buffer.append(getDelimitedIdentifier(getTableName(table)));
        buffer.append(" (");

        for (int idx = 0; idx < table.getColumnCount(); idx++)
        {
            Column column = table.getColumn(idx);

            if (columnValues.containsKey(column.getName()))
            {
                if (addComma)
                {
                    buffer.append(", ");
                }
                buffer.append(getDelimitedIdentifier(column.getName()));
                addComma = true;
            }
        }
        buffer.append(") VALUES (");
        if (genPlaceholders)
        {
            addComma = false;
            for (int idx = 0; idx < columnValues.size(); idx++)
            {
                if (addComma)
                {
                    buffer.append(", ");
                }
                buffer.append("?");
                addComma = true;
            }
        }
        else
        {
            addComma = false;
            for (int idx = 0; idx < table.getColumnCount(); idx++)
            {
                Column column = table.getColumn(idx);

                if (columnValues.containsKey(column.getName()))
                {
                    if (addComma)
                    {
                        buffer.append(", ");
                    }
                    buffer.append(getValueAsString(column, columnValues.get(column.getName())));
                    addComma = true;
                }
            }
        }
        buffer.append(")");
View Full Code Here

        buffer.append(getDelimitedIdentifier(getTableName(table)));
        buffer.append(" SET ");

        for (int idx = 0; idx < table.getColumnCount(); idx++)
        {
            Column column = table.getColumn(idx);

            if (!column.isPrimaryKey() && columnValues.containsKey(column.getName()))
            {
                if (addSep)
                {
                    buffer.append(", ");
                }
                buffer.append(getDelimitedIdentifier(column.getName()));
                buffer.append(" = ");
                if (genPlaceholders)
                {
                    buffer.append("?");
                }
                else
                {
                    buffer.append(getValueAsString(column, columnValues.get(column.getName())));
                }
                addSep = true;
            }
        }
        buffer.append(" WHERE ");
        addSep = false;
        for (int idx = 0; idx < table.getColumnCount(); idx++)
        {
            Column column = table.getColumn(idx);

            if (column.isPrimaryKey() && columnValues.containsKey(column.getName()))
            {
                if (addSep)
                {
                    buffer.append(" AND ");
                }
                buffer.append(getDelimitedIdentifier(column.getName()));
                buffer.append(" = ");
                if (genPlaceholders)
                {
                    buffer.append("?");
                }
                else
                {
                    buffer.append(getValueAsString(column, columnValues.get(column.getName())));
                }
                addSep = true;
            }
        }
        return buffer.toString();
View Full Code Here

        {
            buffer.append(" WHERE ");
            for (Iterator it = pkValues.entrySet().iterator(); it.hasNext();)
            {
                Map.Entry entry  = (Map.Entry)it.next();
                Column    column = table.findColumn((String)entry.getKey());
   
                if (addSep)
                {
                    buffer.append(" AND ");
                }
View Full Code Here

                print(" (");
   
                for (int idx = 0; idx < index.getColumnCount(); idx++)
                {
                    IndexColumn idxColumn = index.getColumn(idx);
                    Column      col       = table.findColumn(idxColumn.getName());
   
                    if (col == null)
                    {
                        // would get null pointer on next line anyway, so throw exception
                        throw new ModelException("Invalid column '" + idxColumn.getName() + "' on index " + index.getName() + " for table " + table.getName());
View Full Code Here

        print(" (");

        for (int idx = 0; idx < index.getColumnCount(); idx++)
        {
            IndexColumn idxColumn = index.getColumn(idx);
            Column      col       = table.findColumn(idxColumn.getName());

            if (col == null)
            {
                // would get null pointer on next line anyway, so throw exception
                throw new ModelException("Invalid column '" + idxColumn.getName() + "' on index " + index.getName() + " for table " + table.getName());
View Full Code Here

                String path  = "data/"+table.getName();
   
                addRule(path, new DynaSqlCreateRule(_model, table, _sink));
                for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++)
                {
                    Column           column    = (Column)table.getColumn(columnIdx);
                    SqlTypeConverter converter = _converterConf.getRegisteredConverter(table, column);
   
                    addRule(path, new SetColumnPropertyRule(column, converter, isCaseSensitive()));
                    addRule(path + "/" + column.getName(), new SetColumnPropertyFromSubElementRule(column, converter));
                }
            }
            _needsConfiguration = false;
        }
        super.configure();
View Full Code Here

  /**
     * {@inheritDoc}
     */
    protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
    {
    Column column = super.readColumn(metaData, values);

    if (column.getDefaultValue() != null)
    {
      // SapDb pads the default value with spaces
      column.setDefaultValue(column.getDefaultValue().trim());
      // SapDb uses the default value for the auto-increment specification
      if (column.getDefaultValue().startsWith("DEFAULT SERIAL"))
      {
        column.setAutoIncrement(true);
        column.setDefaultValue(null);
      }
    }
    if (column.getTypeCode() == Types.DECIMAL)
    {
      // We also perform back-mapping to BIGINT
      if ((column.getSizeAsInt() == 38) && (column.getScale() == 0))
      {
        column.setTypeCode(Types.BIGINT);
      }
    }
    return column;
  }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
    {
        Column column = super.readColumn(metaData, values);

        if (column.getDefaultValue() != null)
        {
            // SapDb pads the default value with spaces
            column.setDefaultValue(column.getDefaultValue().trim());
            // SapDb uses the default value for the auto-increment specification
            if (column.getDefaultValue().startsWith("DEFAULT SERIAL"))
            {
                column.setAutoIncrement(true);
                column.setDefaultValue(null);
            }
        }
        if (column.getTypeCode() == Types.DECIMAL)
        {
            // For some reason, the size will be reported with 2 byte more, e.g. 17 instead of 15
            // So we have to adjust the size here
            if (column.getSizeAsInt() > 2)
            {
                column.setSizeAndScale(column.getSizeAsInt() - 2, column.getScale());
            }
            // We also perform back-mapping to BIGINT
            if ((column.getSizeAsInt() == 38) && (column.getScale() == 0))
            {
                column.setTypeCode(Types.BIGINT);
            }
        }
        return column;
    }
View Full Code Here

  /**
   * {@inheritDoc}
   */
    protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
    {
    Column column = super.readColumn(metaData, values);

    if (column.getDefaultValue() != null)
    {
      if (column.getTypeCode() == Types.TIME)
      {
        PatternMatcher matcher = new Perl5Matcher();

        // Db2 returns "HH24.MI.SS"
        if (matcher.matches(column.getDefaultValue(), _db2TimePattern))
        {
          StringBuffer newDefault = new StringBuffer();

          newDefault.append("'");
          // the hour
          newDefault.append(matcher.getMatch().group(1));
          newDefault.append(":");
          // the minute
          newDefault.append(matcher.getMatch().group(2));
          newDefault.append(":");
          // the second
          newDefault.append(matcher.getMatch().group(3));
          newDefault.append("'");

          column.setDefaultValue(newDefault.toString());
        }
      }
      else if (column.getTypeCode() == Types.TIMESTAMP)
      {
        PatternMatcher matcher = new Perl5Matcher();

        // Db2 returns "YYYY-MM-DD-HH24.MI.SS.FF"
        if (matcher.matches(column.getDefaultValue(), _db2TimestampPattern))
        {
          StringBuffer newDefault = new StringBuffer();

          newDefault.append("'");
          // group 1 is the date which has the correct format
          newDefault.append(matcher.getMatch().group(1));
          newDefault.append(" ");
          // the hour
          newDefault.append(matcher.getMatch().group(2));
          newDefault.append(":");
          // the minute
          newDefault.append(matcher.getMatch().group(3));
          newDefault.append(":");
          // the second
          newDefault.append(matcher.getMatch().group(4));
          // optionally, the fraction
          if ((matcher.getMatch().groups() > 4) && (matcher.getMatch().group(4) != null))
          {
            newDefault.append(matcher.getMatch().group(5));
          }
          newDefault.append("'");

          column.setDefaultValue(newDefault.toString());
        }
      }
            else if (TypeMap.isTextType(column.getTypeCode()))
            {
                column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''"));
            }
    }
    return column;
  }
View Full Code Here

TOP

Related Classes of org.apache.ddlutils.model.Column

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.