コード例 #1
0
 void cacheDataTypes(DBRProgressMonitor monitor) throws DBException {
   dataTypeCache.clear();
   // Cache data types
   for (final PostgreSchema pgSchema : getSchemas(monitor)) {
     pgSchema.getDataTypes(monitor);
   }
 }
コード例 #2
0
 PostgreTableBase findTable(DBRProgressMonitor monitor, long schemaId, long tableId)
     throws DBException {
   PostgreSchema schema = getSchema(monitor, schemaId);
   if (schema == null) {
     log.error("Catalog " + schemaId + " not found");
     return null;
   }
   return schema.getTable(monitor, tableId);
 }
コード例 #3
0
 public PostgreSchema getSchema(DBRProgressMonitor monitor, long oid) throws DBException {
   if (this != dataSource.getDefaultInstance()) {
     throw new DBException("Can't access non-default database");
   }
   for (PostgreSchema schema : schemaCache.getAllObjects(monitor, this)) {
     if (schema.getObjectId() == oid) {
       return schema;
     }
   }
   return null;
 }
コード例 #4
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;
  }
コード例 #5
0
 @Override
 protected PostgreSchema fetchObject(
     @NotNull JDBCSession session,
     @NotNull PostgreDatabase owner,
     @NotNull JDBCResultSet resultSet)
     throws SQLException, DBException {
   String name = JDBCUtils.safeGetString(resultSet, "nspname");
   if (name == null) {
     return null;
   }
   if (PostgreSchema.isUtilitySchema(name)
       && !owner.getDataSource().getContainer().isShowUtilityObjects()) {
     return null;
   }
   return new PostgreSchema(owner, name, resultSet);
 }
コード例 #6
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;
 }