예제 #1
0
  private SQLCompletionProposal makeProposalsFromObject(
      DBPNamedObject object, @Nullable DBPImage objectIcon) {
    String objectName = DBUtils.getObjectFullName(object);

    StringBuilder info = new StringBuilder();
    PropertyCollector collector = new PropertyCollector(object, false);
    collector.collectProperties();
    for (DBPPropertyDescriptor descriptor : collector.getPropertyDescriptors2()) {
      Object propValue = collector.getPropertyValue(descriptor.getId());
      if (propValue == null) {
        continue;
      }
      String propString = propValue.toString();
      info.append("<b>").append(descriptor.getDisplayName()).append(":  </b>");
      info.append(propString);
      info.append("<br>");
    }

    boolean isSingleObject = true;
    String replaceString = null;
    DBPDataSource dataSource = editor.getDataSource();
    if (dataSource != null) {
      // If we replace short name with referenced object
      // and current active schema (catalog) is not this object's container then
      // replace with full qualified name
      if (!getPreferences().getBoolean(SQLPreferenceConstants.PROPOSAL_SHORT_NAME)
          && object instanceof DBSObjectReference) {
        if (wordDetector.getFullWord().indexOf(editor.getSyntaxManager().getStructSeparator())
            == -1) {
          DBSObjectReference structObject = (DBSObjectReference) object;
          if (structObject.getContainer() != null) {
            DBSObject selectedObject = getSelectedObject(dataSource);
            if (selectedObject != structObject.getContainer()) {
              replaceString =
                  DBUtils.getFullQualifiedName(dataSource, structObject.getContainer(), object);
              isSingleObject = false;
            }
          }
        }
      }
      if (replaceString == null) {
        replaceString = DBUtils.getQuotedIdentifier(dataSource, object.getName());
      }
    } else {
      replaceString = DBUtils.getObjectShortName(object);
    }
    return createCompletionProposal(
        replaceString, objectName, info.toString(), objectIcon, isSingleObject, object);
  }
 @Override
 public void appendModifier(
     OBJECT_TYPE column, StringBuilder sql, DBECommandAbstract<OBJECT_TYPE> command) {
   if (column.isRequired()) {
     sql.append(" NOT NULL"); // $NON-NLS-1$
   }
 }
        @Override
        public void appendModifier(
            OBJECT_TYPE column, StringBuilder sql, DBECommandAbstract<OBJECT_TYPE> command) {
          String defaultValue = CommonUtils.toString(column.getDefaultValue());
          if (!CommonUtils.isEmpty(defaultValue)) {
            boolean useQuotes =
                column.getDataKind() == DBPDataKind.STRING
                    || column.getDataKind() == DBPDataKind.DATETIME;

            if (useQuotes && defaultValue.trim().startsWith(QUOTE)) {
              useQuotes = false;
            }

            sql.append(" DEFAULT "); // $NON-NLS-1$
            if (useQuotes) sql.append(QUOTE);
            sql.append(defaultValue);
            if (useQuotes) sql.append(QUOTE);
          }
        }
 @Override
 public void appendModifier(
     OBJECT_TYPE column, StringBuilder sql, DBECommandAbstract<OBJECT_TYPE> command) {
   final String typeName = column.getTypeName();
   DBPDataKind dataKind = column.getDataKind();
   final DBSDataType dataType = findDataType(column.getDataSource(), typeName);
   sql.append(' ').append(typeName);
   if (dataType == null) {
     log.debug(
         "Type name '"
             + typeName
             + "' is not supported by driver"); //$NON-NLS-1$ //$NON-NLS-2$
   } else {
     dataKind = dataType.getDataKind();
   }
   String modifiers = SQLUtils.getColumnTypeModifiers(column, typeName, dataKind);
   if (modifiers != null) {
     sql.append(modifiers);
   }
 }
  @Override
  protected StringBuilder getNestedDeclaration(
      TABLE_TYPE owner, DBECommandAbstract<OBJECT_TYPE> command) {
    OBJECT_TYPE column = command.getObject();

    // Create column
    String columnName = DBUtils.getQuotedIdentifier(column.getDataSource(), column.getName());

    if (command instanceof SQLObjectEditor.ObjectRenameCommand) {
      columnName = ((ObjectRenameCommand) command).getNewName();
    }

    StringBuilder decl = new StringBuilder(40);
    decl.append(columnName);
    for (ColumnModifier modifier : getSupportedModifiers()) {
      modifier.appendModifier(column, decl, command);
    }

    return decl;
  }
 @Override
 public void appendModifier(
     OBJECT_TYPE column, StringBuilder sql, DBECommandAbstract<OBJECT_TYPE> command) {
   sql.append(column.isRequired() ? " NOT NULL" : " NULL");
 }