private int getDefaultAccessLevel() throws StandardException {
    PersistentSet tc = lcc.getTransactionExecute();

    String modeS =
        (String) PropertyUtil.getServiceProperty(tc, Property.DEFAULT_CONNECTION_MODE_PROPERTY);
    if (modeS == null) return FULL_ACCESS;
    else if (StringUtil.SQLEqualsIgnoreCase(modeS, Property.NO_ACCESS)) return NO_ACCESS;
    else if (StringUtil.SQLEqualsIgnoreCase(modeS, Property.READ_ONLY_ACCESS)) return READ_ACCESS;
    else if (StringUtil.SQLEqualsIgnoreCase(modeS, Property.FULL_ACCESS)) return FULL_ACCESS;
    else {
      if (SanityManager.DEBUG)
        SanityManager.THROWASSERT(
            "Invalid value for property "
                + Property.DEFAULT_CONNECTION_MODE_PROPERTY
                + " "
                + modeS);
      return FULL_ACCESS;
    }
  }
Пример #2
0
  /**
   * Set the width of the to the desired value. Used when CASTing. Ideally we'd recycle normalize(),
   * but the behavior is different (we issue a warning instead of an error, and we aren't interested
   * in nullability).
   *
   * @param desiredWidth the desired length
   * @param desiredScale the desired scale (ignored)
   * @param errorOnTrunc throw error on truncation
   * @exception StandardException Thrown on non-zero truncation if errorOnTrunc is true
   */
  public void setWidth(
      int desiredWidth,
      int desiredScale, // Ignored
      boolean errorOnTrunc)
      throws StandardException {
    /*
     ** If the input is NULL, nothing to do.
     */
    if (getValue() == null) {
      return;
    }

    int sourceWidth = dataValue.length;

    /*
     ** If the input is shorter than the desired type,
     ** then pad with blanks to the right length.
     */
    if (sourceWidth < desiredWidth) {
      byte[] actualData = new byte[desiredWidth];
      System.arraycopy(dataValue, 0, actualData, 0, dataValue.length);
      java.util.Arrays.fill(actualData, dataValue.length, actualData.length, SQLBinary.PAD);
      dataValue = actualData;
    }
    /*
     ** Truncation?
     */
    else if (sourceWidth > desiredWidth) {
      if (errorOnTrunc) {
        // error if truncating non pad characters.
        for (int i = desiredWidth; i < dataValue.length; i++) {

          if (dataValue[i] != SQLBinary.PAD)
            throw StandardException.newException(
                SQLState.LANG_STRING_TRUNCATION,
                getTypeName(),
                StringUtil.formatForPrint(this.toString()),
                String.valueOf(desiredWidth));
        }
      }

      /*
       ** Truncate to the desired width.
       */
      truncate(sourceWidth, desiredWidth, !errorOnTrunc);
    }
  }
Пример #3
0
  /**
   * Convert this page to requested type, as defined by input format id.
   *
   * <p>The current cache entry is a different format id than the requested type, change it. This
   * object is instantiated to the wrong subtype of cachedPage, this routine will create an object
   * with the correct subtype, and transfer all pertinent information from this to the new correct
   * object.
   *
   * <p>
   *
   * @return The new object created with the input fid and transfered info.
   * @param fid The format id of the new page.
   * @param newIdentity The key of the new page.
   * @exception StandardException Standard exception policy.
   */
  private CachedPage changeInstanceTo(int fid, PageKey newIdentity) throws StandardException {
    CachedPage realPage;

    try {
      realPage = (CachedPage) Monitor.newInstanceFromIdentifier(fid);

    } catch (StandardException se) {
      if (se.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY) {
        throw se;
      } else {
        throw StandardException.newException(
            SQLState.DATA_UNKNOWN_PAGE_FORMAT_2,
            newIdentity,
            org.apache.derby.iapi.util.StringUtil.hexDump(pageData));
      }
    }

    realPage.setFactory(dataFactory);

    // avoid creating the data buffer if possible, transfer it to the new
    // page if this is the first time the page buffer is used, then
    // createPage will create the page array with the correct page size
    if (this.pageData != null) {
      realPage.alreadyReadPage = true;
      realPage.usePageBuffer(this.pageData);
    }

    // RESOLVE (12/15/06) - the following code is commented out, but
    // not sure why.

    // this page should not be used any more, null out all its content and
    // wait for GC to clean it up

    // destroyPage();// let this subtype have a chance to get rid of stuff
    // this.pageData = null;	// this instance no longer own the data array
    // this.pageCache = null;
    // this.dataFactory = null;
    // this.containerCache = null;

    return realPage;
  }
Пример #4
0
  /**
   * Find the container and then create the page in that container.
   *
   * <p>This is the process of creating a new page in a container, in that case no need to read the
   * page from disk - just need to initialize it in the cache.
   *
   * <p>
   *
   * @return new page, higher levels have already checked the page number is valid for an open.
   * @param key Which page is this?
   * @param createParameter details needed to create page like size, format id, ...
   * @exception StandardException Standard exception policy.
   * @see Cacheable#createIdentity
   */
  public Cacheable createIdentity(Object key, Object createParameter) throws StandardException {

    if (SanityManager.DEBUG) {
      SanityManager.ASSERT(key instanceof PageKey);
    }

    initialize();

    PageKey newIdentity = (PageKey) key;

    PageCreationArgs createArgs = (PageCreationArgs) createParameter;
    int formatId = createArgs.formatId;

    if (formatId == -1) {
      throw StandardException.newException(
          SQLState.DATA_UNKNOWN_PAGE_FORMAT_2,
          newIdentity,
          org.apache.derby.iapi.util.StringUtil.hexDump(pageData));
    }

    // createArgs[0] contains the integer form of the formatId
    // if it is not the same as this instance's formatId, instantiate the
    // real page object
    if (formatId != getTypeFormatId()) {
      return (changeInstanceTo(formatId, newIdentity).createIdentity(key, createParameter));
    }

    // this is the correct page instance
    initializeHeaders(5);
    createPage(newIdentity, createArgs);

    fillInIdentity(newIdentity);

    initialRowCount = 0;

    /*
     * if we need to grow the container and the page has not been
     * preallocated, writing page before the log is written so that we
     * know if there is an IO error - like running out of disk space - then
     * we don't write out the log record, because if we do, it may fail
     * after the log goes to disk and then the database may not be
     * recoverable.
     *
     * WRITE_SYNC is used when we create the page without first
     *	preallocating it
     * WRITE_NO_SYNC is used when we are preallocating the page - there
     *	will be a SYNC call after all the pages are preallocated
     * 0 means creating a page that has already been preallocated.
     */
    int syncFlag = createArgs.syncFlag;
    if ((syncFlag & WRITE_SYNC) != 0 || (syncFlag & WRITE_NO_SYNC) != 0)
      writePage(newIdentity, (syncFlag & WRITE_SYNC) != 0);

    if (SanityManager.DEBUG) {
      if (SanityManager.DEBUG_ON(FileContainer.SPACE_TRACE)) {
        String sync =
            ((syncFlag & WRITE_SYNC) != 0)
                ? "Write_Sync"
                : (((syncFlag & WRITE_NO_SYNC) != 0) ? "Write_NO_Sync" : "No_write");

        SanityManager.DEBUG(
            FileContainer.SPACE_TRACE, "creating new page " + newIdentity + " with " + sync);
      }
    }

    return this;
  }