All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pivotal.gemfirexd.internal.client.am.Section Maven / Gradle / Ivy

There is a newer version: 1.6.7
Show newest version
/*
 *
 * Derby - Class com.pivotal.gemfirexd.internal.client.am.Section
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 */

package com.pivotal.gemfirexd.internal.client.am;

import java.util.ArrayList;
import java.util.HashSet;

import com.pivotal.gemfirexd.internal.client.net.TxID;
import com.pivotal.gemfirexd.internal.shared.common.SharedUtils;
import com.pivotal.gemfirexd.internal.shared.common.SingleHopInformation;
import com.pivotal.gemfirexd.internal.shared.common.sanity.SanityManager;

public class Section {

    protected int sectionNumber;
    protected String packageName;
    protected String serverCursorName; // As given by dnc package set
    int resultSetHoldability_;

    // Stores the package name and consistency token
    byte[] PKGNAMCBytes;
    boolean isGenerated; // flag to identify server generated sections

    public Section(Agent agent, String name, int sectionNumber, String cursorName, int resultSetHoldability) {
        // default for all sections except for generated section , isGenerated is set to false
        init(agent, name, sectionNumber, cursorName, resultSetHoldability, false);
    }

    public Section(Agent agent, String name, int sectionNumber, String cursorName, int resultSetHoldability, boolean isGenerated) {
        init(agent, name, sectionNumber, cursorName, resultSetHoldability, isGenerated);
    }
    
    private void init(Agent agent, String name, int sectionNumber, String cursorName, int resultSetHoldability, boolean isGenerated) {
        this.packageName = name;
        this.sectionNumber = sectionNumber;
        this.serverCursorName = cursorName;
        resultSetHoldability_ = resultSetHoldability;
        agent_ = agent;
        this.isGenerated = isGenerated;

        // Store the packagename and consistency token bytes depending on the holdability
        // PKGNAMCBytes will point to the appropriate byte array in SectionManager
        // that stores the PKGNAMCBytes for reuse
        // There are 2 byte arrays in SectionManager
        // 1. holdPKGNAMCBytes which stores the PKGNAMCBytes when holdability is set
        // 2. noHoldPKGNAMCBytes which stores the PKGNAMCBytes when holdability is non hold
        // Note for generated sections, PKGNAMCBytes is generated by the server.
        if (!isGenerated) {
            if (resultSetHoldability_ == ResultSet.HOLD_CURSORS_OVER_COMMIT) {
                PKGNAMCBytes = agent_.sectionManager_.holdPKGNAMCBytes;
            } else if (resultSetHoldability_ == ResultSet.CLOSE_CURSORS_AT_COMMIT) {
                PKGNAMCBytes = agent_.sectionManager_.noHoldPKGNAMCBytes;
            }
        }
    }

    /**
     * Store the Packagename and consistency token information for reuse. Case 1: if it is generated section, just store
     * the byte array in PKGNAMCBytes Case 2: for not a generated section, information is stored in the correct byte
     * array depending on the holdability in SectionManager
     */
    public void setPKGNAMCBytes(byte[] b) {
        if (isGenerated) {
            PKGNAMCBytes = b;
        } else {
            agent_.sectionManager_.setPKGNAMCBytes(b, resultSetHoldability_);
        }
    }

    /**
     * retrieve the package name and consistency token information
     */
    public byte[] getPKGNAMCBytes() {
        return PKGNAMCBytes;
    }

    public String getPackageName() {
        return this.packageName;
    }


    // Add a finalizer to free() the section, useful for Statement.executes that result in exceptions

    public int getSectionNumber() {
        return this.sectionNumber;
    }

    public String getPackage() {
        return this.packageName;
    }

    public String getServerCursorName() {
        return this.serverCursorName;
    }

    // ------------------------ transient members --------------------------------

    public String serverCursorNameForPositionedUpdate_ = null; // member for positioned update sections only
    transient protected String clientCursorName_; // As given by jdbc setCursorName(), this can change

    public String getServerCursorNameForPositionedUpdate() {
        return serverCursorNameForPositionedUpdate_;
    }

    public String getClientCursorName() {
        return clientCursorName_;
    }

    public void setClientCursorName(String clientCursorName) { //
        //System.out.println("clientCursorName is set"+ clientCursorName);
        this.clientCursorName_ = clientCursorName;
    }

    protected Agent agent_;


    public void free() {
        if (resultSetHoldability_ != -1) {
            this.agent_.sectionManager_.freeSection(this, resultSetHoldability_);
        }
        // Gemstone changes BEGIN
        this.isCopiedSection = false;
        this.bucketIds = null;
        this.sql_ = null;
        this.sqlStrSent = false;
        this.singleHopInfoRequired = false;
        this.regionName = null;
        this.sinfo = null;
        this.parentPS = null;
        this.execSeq = 0;
        if (SanityManager.TraceSingleHop) {
          SanityManager.DEBUG_PRINT(SanityManager.TRACE_SINGLE_HOP,
              "section " + this + " has been freed for resuse");
        }
        // Gemstone changes END
    }

    public boolean isReservedPositionedUpdate() {
        return false;
    }

    public int getStaticStatementType() {
        return 0;
    }

    public Section getPositionedUpdateSection() throws SqlException {
        return agent_.sectionManager_.getPositionedUpdateSection(this);
    }

    public void setCursorName(String name) {
        serverCursorName = name;
    }

    // Gemstone changes BEGIN
    private volatile boolean singleHopInfoRequired;
    
    // TODO: KN Please see if some of these volatiles can be removed
    private SingleHopInformation sinfo;
    private volatile HashSet bucketIds;
    private volatile String sql_;
    private volatile String regionName;
    private boolean sqlStrSent;
    private volatile boolean isCopiedSection;
    private volatile PreparedStatement parentPS;
    private int execSeq;
    private boolean txIdToBeSent;

    public void setSingleHopInfoRequired(boolean flag) {
      this.singleHopInfoRequired = flag;
    }

    public boolean isSingleHopInfoRequired() {
      return this.singleHopInfoRequired;
    }

    public void setSingleHopInformation(SingleHopInformation singleHopInfoObj) {
      this.sinfo = singleHopInfoObj;
    }

    public SingleHopInformation getSingleHopInformationObj() {
      return this.sinfo;
    }

    public String getSQLString() {
      if (sqlStrSent) {
        return null;
      }
      return this.sql_;
    }
    
    public void setStringSent() {
      this.sqlStrSent = true;
    }

    public void setBucketIds(HashSet bucketIds) {
      this.bucketIds = bucketIds;
    }

    public boolean isThisACopiedSection() {
      return this.isCopiedSection;
    }

    public HashSet getBucketIds() {
      return this.bucketIds;
    }

    public void setSqlStringToNull() {
      this.sql_ = null;
    }
    
  public String toString() {
    String s = super.toString() + "  \\ sn: " + this.sectionNumber + ", pn: "
        + this.packageName + ", isGenerated: " + isGenerated
        + ", isCopiedSection: " + isCopiedSection + ", bucketIds: " + bucketIds
        + ", sql: " + sql_ + " execution sequence: " + this.execSeq;
    return s;
  }
    
    public void setSqlString(String sql) {
      this.sql_ = sql;
    }
    
    public void setCopiedSection(boolean flag, PreparedStatement parentPstmnt) {
      this.isCopiedSection = flag;
      this.parentPS = parentPstmnt;
      if (SanityManager.TraceSingleHop) {
        SanityManager.DEBUG_PRINT(SanityManager.TRACE_SINGLE_HOP,
            "Section::setCopiedSection isCopiedSection being set to true for section: " + this);
      }
    }
    
    public void setRegionName(String regionName) {
      this.regionName = regionName;
    }
    
    public String getRegionName() {
      return this.regionName;
    }
 
    public void setExecutionSequence(int seq) {
      // System.out.println("KN: Setting execSeq = " + execSeq + "  in section obj = " + System.identityHashCode(this));
      this.execSeq = seq;
    }
    
    public void recordSuccessAndclearExecutionSequence(Connection conn,
        int successSeq) {
      // System.out.println("KN: record success = " + System.identityHashCode(this));
      conn.successfulExecutionSequence = successSeq;
      this.execSeq = 0;
    }
    
    public int getExecutionSequence() {
      return this.execSeq;
    }
    
    public TxID getParentTxID() {
      if (this.parentPS == null) {
        return null;
      }
      return this.parentPS.connection_.currTXID;
    }

    public void setTxIdToBeSent(boolean flag) {
      this.txIdToBeSent = flag;
    }
    
    public boolean txIdToBeSent() {
      return this.txIdToBeSent;
    }
// Gemstone changes END 
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy