Ejemplo n.º 1
0
 private void loadInfo(JDBCResultSet dbResult) throws SQLException {
   this.oid = JDBCUtils.safeGetLong(dbResult, "oid");
   this.name = JDBCUtils.safeGetString(dbResult, "datname");
   this.ownerId = JDBCUtils.safeGetLong(dbResult, "datdba");
   this.encodingId = JDBCUtils.safeGetLong(dbResult, "encoding");
   this.collate = JDBCUtils.safeGetString(dbResult, "datcollate");
   this.ctype = JDBCUtils.safeGetString(dbResult, "datctype");
   this.isTemplate = JDBCUtils.safeGetBoolean(dbResult, "datistemplate");
   this.allowConnect = JDBCUtils.safeGetBoolean(dbResult, "datallowconn");
   this.connectionLimit = JDBCUtils.safeGetInt(dbResult, "datconnlimit");
   this.tablespaceId = JDBCUtils.safeGetLong(dbResult, "dattablespace");
 }
Ejemplo n.º 2
0
  // -----------------------
  // Constructors
  // -----------------------
  public DB2AuthIndex(
      DBRProgressMonitor monitor, DB2Grantee db2Grantee, DB2Index db2Index, ResultSet resultSet)
      throws DBException {
    super(monitor, db2Grantee, db2Index, resultSet);

    this.control =
        CommonUtils.valueOf(
            DB2AuthHeldType.class, JDBCUtils.safeGetString(resultSet, "CONTROLAUTH"));
  }
Ejemplo n.º 3
0
 void setSearchPath(DBRProgressMonitor monitor, PostgreSchema schema, JDBCExecutionContext context)
     throws DBCException {
   try (JDBCSession session =
       context.openSession(monitor, DBCExecutionPurpose.UTIL, "Change search path")) {
     JDBCUtils.executeSQL(
         session, "SET search_path = \"$user\"," + DBUtils.getQuotedIdentifier(schema));
   } catch (SQLException e) {
     throw new DBCException("Error setting search path", e, dataSource);
   }
 }
Ejemplo n.º 4
0
  // -----------------------
  // Constructors
  // -----------------------
  public DB2Grantee(
      DBRProgressMonitor monitor,
      DB2DataSource dataSource,
      ResultSet resultSet,
      String keyColName) {
    super(dataSource, true);
    this.name = JDBCUtils.safeGetStringTrimmed(resultSet, keyColName);

    cachePerObject = new HashMap<>(12);
  }
Ejemplo n.º 5
0
  @Override
  public List<GenericSequence> loadSequences(
      @NotNull DBRProgressMonitor monitor, @NotNull GenericStructContainer container)
      throws DBException {
    try (JDBCSession session =
        DBUtils.openMetaSession(monitor, container.getDataSource(), "Read sequences")) {
      try (JDBCPreparedStatement dbStat =
          session.prepareStatement("SELECT * FROM INFORMATION_SCHEMA.SEQUENCES")) {
        List<GenericSequence> result = new ArrayList<>();

        try (JDBCResultSet dbResult = dbStat.executeQuery()) {
          while (dbResult.next()) {
            String name = JDBCUtils.safeGetString(dbResult, "SEQUENCE_NAME");
            if (name == null) {
              continue;
            }
            String description = JDBCUtils.safeGetString(dbResult, "REMARKS");
            GenericSequence sequence =
                new GenericSequence(
                    container,
                    name,
                    description,
                    JDBCUtils.safeGetLong(dbResult, "CURRENT_VALUE"),
                    JDBCUtils.safeGetLong(dbResult, "MIN_VALUE"),
                    JDBCUtils.safeGetLong(dbResult, "MAX_VALUE"),
                    JDBCUtils.safeGetLong(dbResult, "INCREMENT"));
            result.add(sequence);
          }
        }
        return result;
      }
    } catch (SQLException e) {
      throw new DBException(e, container.getDataSource());
    }
  }
Ejemplo n.º 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;
 }
Ejemplo n.º 7
0
  // -----------------
  // Constructors
  // -----------------
  public DB2TableBase(DBRProgressMonitor monitor, DB2Schema schema, ResultSet dbResult) {
    super(schema, true);

    setName(JDBCUtils.safeGetString(dbResult, "TABNAME"));

    DB2DataSource db2DataSource = schema.getDataSource();

    this.owner = JDBCUtils.safeGetString(dbResult, "OWNER");
    this.tableId = JDBCUtils.safeGetInteger(dbResult, "TABLEID");
    this.createTime = JDBCUtils.safeGetTimestamp(dbResult, "CREATE_TIME");
    this.invalidateTime = JDBCUtils.safeGetTimestamp(dbResult, "INVALIDATE_TIME");
    this.lastRegenTime = JDBCUtils.safeGetTimestamp(dbResult, "LAST_REGEN_TIME");

    this.remarks = JDBCUtils.safeGetString(dbResult, "REMARKS");

    if (db2DataSource.isAtLeastV9_5()) {
      this.alterTime = JDBCUtils.safeGetTimestamp(dbResult, "ALTER_TIME");
      this.ownerType =
          CommonUtils.valueOf(DB2OwnerType.class, JDBCUtils.safeGetString(dbResult, "OWNERTYPE"));
    }
  }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
0
  public DB2RoutineParm(DBRProgressMonitor monitor, DB2Routine procedure, ResultSet dbResult)
      throws DBException {
    super();

    this.procedure = procedure;

    DB2DataSource db2DataSource = getDataSource();

    this.name = JDBCUtils.safeGetStringTrimmed(dbResult, "PARMNAME");
    this.scale = JDBCUtils.safeGetInteger(dbResult, "SCALE");
    this.length = JDBCUtils.safeGetInteger(dbResult, "LENGTH");
    this.remarks = JDBCUtils.safeGetStringTrimmed(dbResult, "REMARKS");
    this.rowType =
        CommonUtils.valueOf(DB2RoutineRowType.class, JDBCUtils.safeGetString(dbResult, "ROWTYPE"));

    String typeSchemaName = JDBCUtils.safeGetStringTrimmed(dbResult, "TYPESCHEMA");
    String typeModuleName = JDBCUtils.safeGetStringTrimmed(dbResult, "TYPEMODULENAME");
    this.typeName = JDBCUtils.safeGetStringTrimmed(dbResult, "TYPENAME");
    this.dataTypeSchema = db2DataSource.getSchema(monitor, typeSchemaName);

    // -------------------
    // Search for DataType
    // -------------------

    // First Search in System/Standard Data Types
    this.dataType = db2DataSource.getLocalDataType(typeName);
    if (this.dataType != null) {
      return;
    }

    // Not found : Search for a UDT in Module
    if (typeModuleName != null) {
      DB2Module db2Module =
          DB2Utils.findModuleBySchemaNameAndName(
              monitor, db2DataSource, typeSchemaName, typeModuleName);
      this.dataType = db2Module.getType(monitor, typeName);
      return;
    }

    // Not found, search for a UDT
    this.dataType = this.dataTypeSchema.getUDT(monitor, typeName);
  }
Ejemplo n.º 10
0
  // -----------------
  // Constructors
  // -----------------
  public DB2Index(
      DBRProgressMonitor monitor, DB2Schema schema, DB2TableBase table, ResultSet dbResult) {
    super(schema, table, JDBCUtils.safeGetStringTrimmed(dbResult, "INDNAME"), null, true);

    DB2DataSource db2DataSource = (DB2DataSource) schema.getDataSource();

    this.uniqueRule =
        CommonUtils.valueOf(DB2UniqueRule.class, JDBCUtils.safeGetString(dbResult, "UNIQUERULE"));
    this.colCount = JDBCUtils.safeGetInteger(dbResult, "COLCOUNT");
    this.uniqueColCount = JDBCUtils.safeGetInteger(dbResult, "UNIQUE_COLCOUNT");
    this.pctFree = JDBCUtils.safeGetInteger(dbResult, "PCTFREE");
    this.indexId = JDBCUtils.safeGetInteger(dbResult, "IID");
    this.minPctUsed = JDBCUtils.safeGetInteger(dbResult, "MINPCTUSED");
    this.reverseScans = JDBCUtils.safeGetBoolean(dbResult, "REVERSE_SCANS", DB2YesNo.Y.name());
    this.tablespaceId = JDBCUtils.safeGetInteger(dbResult, "TBSPACEID");
    this.pageSplit =
        CommonUtils.valueOf(
            DB2IndexPageSplit.class, JDBCUtils.safeGetStringTrimmed(dbResult, "PAGESPLIT"));
    this.remarks = JDBCUtils.safeGetString(dbResult, "REMARKS");

    this.createTime = JDBCUtils.safeGetTimestamp(dbResult, "CREATE_TIME");
    this.madeUnique = JDBCUtils.safeGetBoolean(dbResult, "MADE_UNIQUE");

    this.statsTime = JDBCUtils.safeGetTimestamp(dbResult, "STATS_TIME");
    this.fullKeycard = JDBCUtils.safeGetLong(dbResult, "FULLKEYCARD");
    this.firstKeycard = JDBCUtils.safeGetLong(dbResult, "FIRSTKEYCARD");
    this.first2Keycard = JDBCUtils.safeGetLong(dbResult, "FIRST2KEYCARD");
    this.first3Keycard = JDBCUtils.safeGetLong(dbResult, "FIRST3KEYCARD");
    this.first4Keycard = JDBCUtils.safeGetLong(dbResult, "FIRST4KEYCARD");
    this.clusterRatio = JDBCUtils.safeGetInteger(dbResult, "CLUSTERRATIO");

    if (db2DataSource.isAtLeastV9_5()) {
      this.compression = JDBCUtils.safeGetBoolean(dbResult, "COMPRESSION", DB2YesNo.Y.name());
    }

    // DF: Could have been done in constructor. More "readable" to do it here
    this.db2IndexType =
        CommonUtils.valueOf(
            DB2IndexType.class, JDBCUtils.safeGetStringTrimmed(dbResult, "INDEXTYPE"));
    this.indexType = db2IndexType.getDBSIndexType();
  }
Ejemplo n.º 11
0
  // -----------------------
  // Constructors
  // -----------------------
  public DB2Sequence(DB2Schema schema, ResultSet dbResult) {
    super(schema, JDBCUtils.safeGetString(dbResult, "SEQNAME"), true);

    DB2DataSource db2DataSource = schema.getDataSource();

    this.owner = JDBCUtils.safeGetString(dbResult, "OWNER");
    this.seqId = JDBCUtils.safeGetInteger(dbResult, "SEQID");
    this.seqType =
        CommonUtils.valueOf(DB2SequenceType.class, JDBCUtils.safeGetString(dbResult, "SEQTYPE"));
    this.incrementBy = JDBCUtils.safeGetLong(dbResult, "INCREMENT");
    this.start = JDBCUtils.safeGetLong(dbResult, "START");
    this.maxValue = JDBCUtils.safeGetLong(dbResult, "MAXVALUE");
    this.minValue = JDBCUtils.safeGetLong(dbResult, "MINVALUE");
    this.nextCacheFirstValue = JDBCUtils.safeGetLong(dbResult, "NEXTCACHEFIRSTVALUE");
    this.cycle = JDBCUtils.safeGetBoolean(dbResult, "CYCLE", DB2YesNo.Y.name());
    this.cache = JDBCUtils.safeGetInteger(dbResult, "CACHE");
    this.order = JDBCUtils.safeGetBoolean(dbResult, "ORDER", DB2YesNo.Y.name());
    this.dataTypeId = JDBCUtils.safeGetInteger(dbResult, "DATATYPEID");
    this.sourceTypeId = JDBCUtils.safeGetInteger(dbResult, "SOURCETYPEID");
    this.createTime = JDBCUtils.safeGetTimestamp(dbResult, "CREATE_TIME");
    this.alterTime = JDBCUtils.safeGetTimestamp(dbResult, "ALTER_TIME");
    this.precision =
        DB2SequencePrecision.getFromDataType(JDBCUtils.safeGetInteger(dbResult, "PRECISION"));
    this.origin =
        CommonUtils.valueOf(DB2OwnerType.class, JDBCUtils.safeGetString(dbResult, "ORIGIN"));
    this.remarks = JDBCUtils.safeGetString(dbResult, "REMARKS");

    if (db2DataSource.isAtLeastV9_5()) {
      this.ownerType =
          CommonUtils.valueOf(DB2OwnerType.class, JDBCUtils.safeGetString(dbResult, "OWNERTYPE"));
    }
    if (db2DataSource.isAtLeastV9_7()) {
      this.baseSchema = JDBCUtils.safeGetStringTrimmed(dbResult, "BASE_SEQSCHEMA");
      this.baseSequence = JDBCUtils.safeGetString(dbResult, "BASE_SEQNAME");
    }
  }
Ejemplo n.º 12
0
  // -----------------
  // Constructors
  // -----------------
  public DB2Table(DBRProgressMonitor monitor, DB2Schema schema, ResultSet dbResult)
      throws DBException {
    super(monitor, schema, dbResult);

    this.status =
        CommonUtils.valueOf(DB2TableStatus.class, JDBCUtils.safeGetString(dbResult, "STATUS"));
    this.type = CommonUtils.valueOf(DB2TableType.class, JDBCUtils.safeGetString(dbResult, "TYPE"));
    this.statsTime = JDBCUtils.safeGetTimestamp(dbResult, "STATS_TIME");

    this.dataCapture = JDBCUtils.safeGetString(dbResult, "DATACAPTURE");
    this.constChecked = JDBCUtils.safeGetString(dbResult, "CONST_CHECKED");
    this.partitionMode =
        CommonUtils.valueOf(
            DB2TablePartitionMode.class, JDBCUtils.safeGetString(dbResult, "PARTITION_MODE"));
    this.append = JDBCUtils.safeGetBoolean(dbResult, "APPEND_MODE", DB2YesNo.Y.name());
    this.volatileMode = JDBCUtils.safeGetString(dbResult, "VOLATILE");
    this.compression =
        CommonUtils.valueOf(
            DB2TableCompressionMode.class, JDBCUtils.safeGetString(dbResult, "COMPRESSION"));
    this.accessMode =
        CommonUtils.valueOf(
            DB2TableAccessMode.class, JDBCUtils.safeGetString(dbResult, "ACCESS_MODE"));
    this.mdcClustered = JDBCUtils.safeGetBoolean(dbResult, "CLUSTERED", DB2YesNo.Y.name());
    this.dropRule =
        CommonUtils.valueOf(DB2TableDropRule.class, JDBCUtils.safeGetString(dbResult, "DROPRULE"));

    this.card = JDBCUtils.safeGetLongNullable(dbResult, "CARD");
    this.nPages = JDBCUtils.safeGetLongNullable(dbResult, "NPAGES");
    this.fPages = JDBCUtils.safeGetLongNullable(dbResult, "FPAGES");
    this.overFLow = JDBCUtils.safeGetLongNullable(dbResult, "OVERFLOW");

    this.invalidateTime = JDBCUtils.safeGetTimestamp(dbResult, "INVALIDATE_TIME");
    this.lastRegenTime = JDBCUtils.safeGetTimestamp(dbResult, "LAST_REGEN_TIME");
    if (getDataSource().isAtLeastV9_5()) {
      this.alterTime = JDBCUtils.safeGetTimestamp(dbResult, "ALTER_TIME");
    }
    if (getDataSource().isAtLeastV10_1()) {
      this.temporalType =
          CommonUtils.valueOf(
              DB2TableTemporalType.class, JDBCUtils.safeGetString(dbResult, "TEMPORALTYPE"));
    }

    String lockSizeString = JDBCUtils.safeGetString(dbResult, "LOCKSIZE");
    if (CommonUtils.isNotEmpty(lockSizeString)) {
      this.lockSize = CommonUtils.valueOf(DB2TableLockSize.class, lockSizeString);
    }

    this.tablespace = JDBCUtils.safeGetString(dbResult, "TBSPACE");
    this.indexTablespace = JDBCUtils.safeGetString(dbResult, "INDEX_TBSPACE");
    this.longTablespace = JDBCUtils.safeGetString(dbResult, "LONG_TBSPACE");

    this.partitionCache =
        new JDBCObjectSimpleCache<>(DB2TablePartition.class, C_PT, schema.getName(), getName());
    this.periodCache =
        new JDBCObjectSimpleCache<>(DB2TablePeriod.class, C_PE, schema.getName(), getName());
  }
Ejemplo n.º 13
0
 public ExasolPlanNode(ExasolPlanNode parent, ResultSet dbResult) {
   this.parent = parent;
   this.stmtId = JDBCUtils.safeGetInt(dbResult, "STMT_ID");
   this.commandName = JDBCUtils.safeGetString(dbResult, "COMMAND_NAME");
   this.commandClass = JDBCUtils.safeGetString(dbResult, "COMMAND_CLASS");
   this.partId = JDBCUtils.safeGetInt(dbResult, "PART_ID");
   this.partName = JDBCUtils.safeGetString(dbResult, "PART_NAME");
   this.partInfo = JDBCUtils.safeGetString(dbResult, "PART_INFO");
   this.objectSchema = JDBCUtils.safeGetString(dbResult, "OBJECT_SCHEMA");
   this.objectName = JDBCUtils.safeGetString(dbResult, "OBJECT_NAME");
   this.objectRows = JDBCUtils.safeGetDouble(dbResult, "OBJECT_ROWS");
   this.outRows = JDBCUtils.safeGetDouble(dbResult, "OUT_ROWS");
   this.duration = JDBCUtils.safeGetDouble(dbResult, "DURATION");
   this.cpu = JDBCUtils.safeGetDouble(dbResult, "CPU");
   this.tempDbRamPeak = JDBCUtils.safeGetDouble(dbResult, "TEMP_DB_RAM_PEAK");
   this.hddRead = JDBCUtils.safeGetDouble(dbResult, "HDD_READ");
   this.hddWrite = JDBCUtils.safeGetDouble(dbResult, "HDD_WRITE");
   this.netTransfer = JDBCUtils.safeGetDouble(dbResult, "NET");
   this.detailInfo = JDBCUtils.safeGetString(dbResult, "REMARKS");
 }