Example #1
0
  public PostgreDataType getDataType(String typeName) {
    if (typeName.endsWith("[]")) {
      // In some cases ResultSetMetadata returns it as []
      typeName = "_" + typeName.substring(0, typeName.length() - 2);
    }
    String alias = PostgreConstants.DATA_TYPE_ALIASES.get(typeName);
    if (alias != null) {
      typeName = alias;
    }
    {
      // First check system catalog
      final PostgreSchema schema = getCatalogSchema();
      if (schema != null) {
        final PostgreDataType dataType = schema.dataTypeCache.getCachedObject(typeName);
        if (dataType != null) {
          return dataType;
        }
      }
    }

    // Check schemas in search path
    final List<String> searchPath = dataSource.getSearchPath();
    for (String schemaName : searchPath) {
      final PostgreSchema schema = schemaCache.getCachedObject(schemaName);
      if (schema != null) {
        final PostgreDataType dataType = schema.dataTypeCache.getCachedObject(typeName);
        if (dataType != null) {
          return dataType;
        }
      }
    }
    // Check the rest
    for (PostgreSchema schema : schemaCache.getCachedObjects()) {
      if (searchPath.contains(schema.getName())) {
        continue;
      }
      final PostgreDataType dataType = schema.dataTypeCache.getCachedObject(typeName);
      if (dataType != null) {
        return dataType;
      }
    }
    log.debug("Data type '" + typeName + "' not found in database '" + getName() + "'");
    return null;
  }
Example #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;
 }