Examples of TableColumnInfo


Examples of net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo

    try
    {
      String tableName = _info[0].getSimpleName();
      for (int i = 0; i < columns.length; i++)
      {
        TableColumnInfo info = columns[i];
        String columnName = info.getColumnName();
        result[i] = _dialect.getColumnDropSQL(tableName, columnName, _qualifier, _sqlPrefs);
      }
    } catch (UnsupportedOperationException e2)
    {
      _session.showMessage(s_stringMgr.getString("RemoveColumnCommand.unsupportedOperationMsg",
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo

    return s_stringMgr.getString(stringMgrKey);
  }

  private void updateControlStatus()
  {
    final TableColumnInfo tci = _columnsCmb.getSelectedColumn();
    _dataTypesCmb.setSelectedItem(_dataTypesByTypeName.get(tci.getTypeName().toUpperCase()));



    _columnLengthField.setInt(tci.getColumnSize());
    _defaultvalue.setText(tci.getDefaultValue());



//    selectedIndex = cbFieldName.getSelectedIndex();
//    DefaultComboBoxModel comboModel =
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo

   * @see net.sourceforge.squirrel_sql.plugins.refactoring.commands.AbstractRefactoringCommand#generateSQLStatements()
   */
  @Override
  protected String[] generateSQLStatements() throws Exception
  {
    TableColumnInfo info = customDialog.getColumnInfo();
    String[] result = null;
    DatabaseObjectQualifier qualifier =
      new DatabaseObjectQualifier(info.getCatalogName(), info.getSchemaName());
   
    try
    {
      result =  _dialect.getAddColumnSQL(info, qualifier, _sqlPrefs);
    } catch (HibernateException e1)
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo

        String catalog = null;
        String schema = "public";
        String employeIdentifactionTable = "EmployeeIdentification";

        String[] employeeColumns = {"EmployeeNumber", "Name", "PhoneNumber"};
        TableColumnInfo newColumn = new TableColumnInfo(
                catalog, schema, employeIdentifactionTable, employeeColumns[0],
                Types.VARCHAR, JDBCTypeMapper.getJdbcTypeName(Types.VARCHAR), 30,
                0, 0, 1, null, null, 0, 1, "YES");

        new AddAutoIncrementDialog(newColumn).setVisible(true);
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo

        HashMap<String, TableColumnInfo[]> tables = new HashMap<String, TableColumnInfo[]>();
        ArrayList<TableColumnInfo> tableColumnInfo = new ArrayList<TableColumnInfo>();

        for (String column : employeeIdentificationColumns) {
            TableColumnInfo newColumn = new TableColumnInfo(
                    catalog, schema, employeIdentifactionTable, column,
                    Types.VARCHAR, JDBCTypeMapper.getJdbcTypeName(Types.VARCHAR), 30,
                    0, 0, 1, null, null, 0, 1, "YES");
            tableColumnInfo.add(newColumn);
        }
        tables.put(employeIdentifactionTable, tableColumnInfo.toArray(new TableColumnInfo[]{}));

        tableColumnInfo.clear();
        ArrayList<TableColumnInfo> employeColumnsInfo = new ArrayList<TableColumnInfo>();
        for (String column : employeeColumns) {
            TableColumnInfo newColumn = new TableColumnInfo(
                    catalog, schema, employeIdentifactionTable, column,
                    Types.VARCHAR, JDBCTypeMapper.getJdbcTypeName(Types.VARCHAR), 30,
                    0, 0, 1, null, null, 0, 1, "YES");
            employeColumnsInfo.add(newColumn);
        }


        tableColumnInfo.clear();
        for (String column : customerColumns) {
            TableColumnInfo newColumn = new TableColumnInfo(
                    catalog, schema, employeIdentifactionTable, column,
                    Types.VARCHAR, JDBCTypeMapper.getJdbcTypeName(Types.VARCHAR), 30,
                    0, 0, 1, null, null, 0, 1, "YES");
            tableColumnInfo.add(newColumn);
        }
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo

    String schema = _info[0].getSchemaName();

    String lookupTableName = _customDialog.getLookupTableName();
    String lookupPrimaryKey = _customDialog.getLookupPrimaryKey();

    TableColumnInfo sourceColumn = null;
    for (TableColumnInfo info : md.getColumnInfo((ITableInfo) _info[0]))
    {
      if (info.getColumnName().equals(_customDialog.getSourceColumn()))
      {
        sourceColumn = info;
        break;
      }
    }
    if (sourceColumn == null)
      throw new IllegalStateException("The selected source column was not found.");
    String sourceTableName = sourceColumn.getTableName();
    String sourceColumnName = sourceColumn.getColumnName();

    // Creates the lookup table with it's columns (depenting on the mode).
    ArrayList<TableColumnInfo> columns = new ArrayList<TableColumnInfo>();
    ArrayList<TableColumnInfo> primaryKeys = new ArrayList<TableColumnInfo>();

    if (_customDialog.getMode() == AddLookupTableDialog.MODE_KEEP)
    {
      TableColumnInfo pk =
        new TableColumnInfocatalog,
                      schema,
                      lookupTableName,
                      lookupPrimaryKey,
                      sourceColumn.getDataType(),
                      sourceColumn.getTypeName(),
                      sourceColumn.getColumnSize(),
                      sourceColumn.getDecimalDigits(),
                      sourceColumn.getRadix(),
                      sourceColumn.isNullAllowed(),
                      sourceColumn.getRemarks(),
                      sourceColumn.getDefaultValue(),
                      sourceColumn.getOctetLength(),
                      1,
                      sourceColumn.isNullable(),
                      md);
      columns.add(pk);
      primaryKeys.add(pk);
    } else if (_customDialog.getMode() == AddLookupTableDialog.MODE_REPLACE)
    {
      TableColumnInfo pk =
        new TableColumnInfocatalog,
                      schema,
                      lookupTableName,
                      lookupPrimaryKey,
                      Types.INTEGER,
                      JDBCTypeMapper.getJdbcTypeName(Types.INTEGER),
                      0,
                      0,
                      0,
                      0,
                      null,
                      null,
                      0,
                      1,
                      "NO",
                      md);

      TableColumnInfo second =
        new TableColumnInfocatalog,
                      schema,
                      lookupTableName,
                      _customDialog.getLookupSecondColumn(),
                      sourceColumn.getDataType(),
                      sourceColumn.getTypeName(),
                      sourceColumn.getColumnSize(),
                      sourceColumn.getDecimalDigits(),
                      sourceColumn.getRadix(),
                      0,
                      sourceColumn.getRemarks(),
                      sourceColumn.getDefaultValue(),
                      sourceColumn.getOctetLength(),
                      2,
                      "NO",
                      md);

      columns.add(pk);
      columns.add(second);
      primaryKeys.add(pk);
    }
    results.add(_dialect.getCreateTableSQL(lookupTableName, columns, primaryKeys, _sqlPrefs, _qualifier));

    if (_customDialog.getMode() == AddLookupTableDialog.MODE_KEEP)
    {
      // Copys the distinct values from the source column into the lookup table.
      ArrayList<String> insertColumns = new ArrayList<String>();
      insertColumns.add(lookupPrimaryKey);
      String dataQuery = getDataQuery(schema, sourceTableName, sourceColumnName);

      results.add(_dialect.getInsertIntoSQL(lookupTableName,
        insertColumns,
        dataQuery,
        _qualifier,
        _sqlPrefs));

      // Adds a foreign key constraint to the source table.
      String constraintName = _customDialog.getForeignKeyName();
      ArrayList<String[]> refs = new ArrayList<String[]>();
      refs.add(new String[] { sourceColumnName, lookupPrimaryKey });

      String[] fkSQLs =
        _dialect.getAddForeignKeyConstraintSQL(sourceTableName,
          lookupTableName,
          constraintName,
          false,
          false,
          false,
          false,
          null,
          refs,
          "NO ACTION",
          "NO ACTION",
          _qualifier,
          _sqlPrefs);

      results.addAll(Arrays.asList(fkSQLs));

    } else if (_customDialog.getMode() == AddLookupTableDialog.MODE_REPLACE)
    {
      // Selects the distinct values from the source column.
      String dataQuery = getDataQuery(schema, sourceTableName, sourceColumnName);
      List<String> data = executeStringQuery(dataQuery);

      // Copys the gathered values into the lookup table.
      ArrayList<String> insertColumns = new ArrayList<String>();
      insertColumns.add(lookupPrimaryKey);
      insertColumns.add(_customDialog.getLookupSecondColumn());

      for (int i = 0; i < data.size(); i++)
      {
        // TODO: This won't work when the column has values with quotes in them.
        // Use PreparedStatements instead. Hmmm... instead of insert statements, could we not
        // just create a sequence and generate a select statement that:
        // a) uses the sequence for the pkid
        // b) selects distinct values
        // That would be a more efficient approach that would also eliminate this quoting problem
        String valuesPart = " VALUES ( " + i + ", '" + data.get(i) + "' )";
        results.add(_dialect.getInsertIntoSQL(lookupTableName,
          insertColumns,
          valuesPart,
          _qualifier,
          _sqlPrefs));
      }

      // Renames the source column.
      TableColumnInfo tempColumn =
        new TableColumnInfocatalog,
                      schema,
                      sourceTableName,
                      sourceColumnName + "_temp",
                      sourceColumn.getDataType(),
                      sourceColumn.getTypeName(),
                      sourceColumn.getColumnSize(),
                      sourceColumn.getDecimalDigits(),
                      sourceColumn.getRadix(),
                      sourceColumn.isNullAllowed(),
                      sourceColumn.getRemarks(),
                      sourceColumn.getDefaultValue(),
                      sourceColumn.getOctetLength(),
                      sourceColumn.getOrdinalPosition(),
                      sourceColumn.isNullable(),
                      md);

      results.add(_dialect.getColumnNameAlterSQL(sourceColumn, tempColumn, _qualifier, _sqlPrefs));

      // Adds the new column (type: integer).
      TableColumnInfo newColumn =
        new TableColumnInfocatalog,
                      schema,
                      sourceTableName,
                      sourceColumnName,
                      Types.INTEGER,
                      JDBCTypeMapper.getJdbcTypeName(Types.INTEGER),
                      0,
                      0,
                      0,
                      1,
                      sourceColumn.getRemarks(),
                      null,
                      0,
                      sourceColumn.getOrdinalPosition(),
                      "YES",
                      md);
      String[] addColumnResults = _dialect.getAddColumnSQL(newColumn, _qualifier, _sqlPrefs);
      for (String addColumnResult : addColumnResults)
      {
        results.add(addColumnResult);
      }

      // Adds a foreign key constraint to the source table for the new column.
      String constraintName = _customDialog.getForeignKeyName();
      ArrayList<String[]> refs = new ArrayList<String[]>();
      refs.add(new String[] { sourceColumnName, lookupPrimaryKey });

      String[] fkSQLs =
        _dialect.getAddForeignKeyConstraintSQL(sourceTableName,
          lookupTableName,
          constraintName,
          false,
          false,
          false,
          false,
          null,
          refs,
          "NO ACTION",
          "NO ACTION",
          _qualifier,
          _sqlPrefs);

      results.addAll(Arrays.asList(fkSQLs));

      // Inserts all keys into the new column depending on the content in the old column.
      for (int i = 0; i < data.size(); i++)
      {
        // TODO: This won't work when the column has values with quotes in them.
        // Use PreparedStatements instead.
        results.addAll(Arrays.asList(_dialect.getUpdateSQL(sourceTableName,
          new String[] { sourceColumnName },
          new String[] { String.valueOf(i) },
          null,
          new String[] { sourceColumnName + "_temp" },
          new String[] { "'" + data.get(i) + "'" },
          _qualifier,
          _sqlPrefs)));
      }

      // Sets constraints like NOT NULL for the new column, depending on the constraints for the old
      // column.
      if (sourceColumn.isNullAllowed() == 0)
      {
        TableColumnInfo newColumnNotNull =
          new TableColumnInfocatalog,
                        schema,
                        sourceTableName,
                        newColumn.getColumnName(),
                        newColumn.getDataType(),
                        newColumn.getTypeName(),
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo

       destSession, destCatalog, destSchema, ti.getSimpleName(), DialectFactory.DEST_TYPE);
    StringBuilder result = new StringBuilder("CREATE TABLE ");
    result.append(destinationTableName);
    result.append(" ( ");
    result.append("\n");
    TableColumnInfo colInfo = null;
    try
    {
      ISQLConnection sourceCon = prov.getCopySourceSession().getSQLConnection();
      TableColumnInfo[] colInfoArr = sourceCon.getSQLMetaData().getColumnInfo(ti);
      if (colInfoArr.length == 0)
      {
        // i18n[DBUtil.error.nocolumns=Table '{0}' in schema '{1}' has
        // no columns to copy]
        String msg = s_stringMgr.getString("DBUtil.error.nocolumns", new String[]
          { ti.getSimpleName(), ti.getSchemaName() });
        throw new MappingException(msg);
      }
      for (int i = 0; i < colInfoArr.length; i++)
      {
        colInfo = colInfoArr[i];
        result.append("\t");
        String columnSql = DBUtil.getColumnSql(prov, colInfo, sourceTableName, destinationTableName);
        result.append(columnSql);
        if (i < colInfoArr.length - 1)
        {
          result.append(",\n");
        }
      }

      // If the user wants the primary key copied and the source session
      // isn't Axion (Axion throws SQLException for getPrimaryKeys())

      // TODO: Perhaps we can tell the user when they click "Copy Table"
      // if the source session is Axion and they want primary keys that
      // it's not possible.
      if (_prefs.isCopyPrimaryKeys() && !DialectFactory.isAxion(sourceSession.getMetaData()))
      {
        String pkString = DBUtil.getPKColumnString(sourceCon, ti);
        if (pkString != null)
        {
          result.append(",\n\tPRIMARY KEY ");
          result.append(pkString);
        }
      }
      result.append(")");
    } catch (MappingException e)
    {
      if (colInfo != null)
      {
        // i18n[DBUtil.error.maptype=Couldn't map type for table='{0}'
        // column='{1}']
        String msg = s_stringMgr.getString("DBUtil.error.maptype", new String[]
          { destinationTableName, colInfo.getColumnName() });
        log.error(msg, e);
      }
      throw e;
    }
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo

  {
    StringBuilder result = new StringBuilder();

    for (int i = 0; i < colInfoArr.length; i++)
    {
      TableColumnInfo colInfo = colInfoArr[i];
      String columnName = colInfo.getColumnName();
      result.append(columnName);
      if (i < colInfoArr.length - 1)
      {
        result.append(", ");
      }
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo

   */
  public static String getColumnName(ISQLConnection sourceConn, ITableInfo ti, int column)
        throws SQLException
  {
    TableColumnInfo[] infoArr = sourceConn.getSQLMetaData().getColumnInfo(ti);
    TableColumnInfo colInfo = infoArr[column];
    return colInfo.getColumnName();
  }
View Full Code Here

Examples of net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo

  {
    TableColumnInfo[] infoArr = sourceConn.getSQLMetaData().getColumnInfo(ti);
    String[] result = new String[infoArr.length];
    for (int i = 0; i < result.length; i++)
    {
      TableColumnInfo colInfo = infoArr[i];
      result[i] = colInfo.getColumnName();
    }
    return result;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.