Ejemplo n.º 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);
  }
Ejemplo n.º 2
0
 @NotNull
 @Override
 public JDBCStatement prepareLookupStatement(
     @NotNull JDBCSession session,
     @NotNull PostgreDatabase database,
     @Nullable PostgreSchema object,
     @Nullable String objectName)
     throws SQLException {
   /*
               // Do not apply filters
               // We need all schemas to have access to types
               return session.prepareStatement(
                   "SELECT n.oid,n.* FROM pg_catalog.pg_namespace n ORDER BY nspname");
   */
   StringBuilder catalogQuery =
       new StringBuilder("SELECT n.oid,n.* FROM pg_catalog.pg_namespace n");
   DBSObjectFilter catalogFilters =
       database.getDataSource().getContainer().getObjectFilter(PostgreSchema.class, null, false);
   if ((catalogFilters != null && !catalogFilters.isNotApplicable())
       || object != null
       || objectName != null) {
     if (object != null || objectName != null) {
       catalogFilters = new DBSObjectFilter();
       catalogFilters.addInclude(object != null ? object.getName() : objectName);
     } else {
       catalogFilters = new DBSObjectFilter(catalogFilters);
       // Always read catalog schema
       catalogFilters.addInclude(PostgreConstants.CATALOG_SCHEMA_NAME);
     }
     JDBCUtils.appendFilterClause(catalogQuery, catalogFilters, "nspname", true);
   }
   catalogQuery.append(" ORDER BY nspname");
   JDBCPreparedStatement dbStat = session.prepareStatement(catalogQuery.toString());
   if (catalogFilters != null) {
     JDBCUtils.setFilterParameters(dbStat, 1, catalogFilters);
   }
   return dbStat;
 }