Search in sources :

Example 6 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class SYSTABLEPERMSRowFactory method makeRow.

public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    UUID oid;
    DataValueDescriptor grantee = null;
    DataValueDescriptor grantor = null;
    String tablePermID = null;
    String tableID = null;
    String selectPriv = null;
    String deletePriv = null;
    String insertPriv = null;
    String updatePriv = null;
    String referencesPriv = null;
    String triggerPriv = null;
    if (td == null) {
        grantee = getNullAuthorizationID();
        grantor = getNullAuthorizationID();
    } else {
        TablePermsDescriptor tpd = (TablePermsDescriptor) td;
        oid = tpd.getUUID();
        if (oid == null) {
            oid = getUUIDFactory().createUUID();
            tpd.setUUID(oid);
        }
        tablePermID = oid.toString();
        grantee = getAuthorizationID(tpd.getGrantee());
        grantor = getAuthorizationID(tpd.getGrantor());
        tableID = tpd.getTableUUID().toString();
        selectPriv = tpd.getSelectPriv();
        deletePriv = tpd.getDeletePriv();
        insertPriv = tpd.getInsertPriv();
        updatePriv = tpd.getUpdatePriv();
        referencesPriv = tpd.getReferencesPriv();
        triggerPriv = tpd.getTriggerPriv();
    }
    ExecRow row = getExecutionFactory().getValueRow(COLUMN_COUNT);
    row.setColumn(TABLEPERMSID_COL_NUM, new SQLChar(tablePermID));
    row.setColumn(GRANTEE_COL_NUM, grantee);
    row.setColumn(GRANTOR_COL_NUM, grantor);
    row.setColumn(TABLEID_COL_NUM, new SQLChar(tableID));
    row.setColumn(SELECTPRIV_COL_NUM, new SQLChar(selectPriv));
    row.setColumn(DELETEPRIV_COL_NUM, new SQLChar(deletePriv));
    row.setColumn(INSERTPRIV_COL_NUM, new SQLChar(insertPriv));
    row.setColumn(UPDATEPRIV_COL_NUM, new SQLChar(updatePriv));
    row.setColumn(REFERENCESPRIV_COL_NUM, new SQLChar(referencesPriv));
    row.setColumn(TRIGGERPRIV_COL_NUM, new SQLChar(triggerPriv));
    return row;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID) TablePermsDescriptor(org.apache.derby.iapi.sql.dictionary.TablePermsDescriptor)

Example 7 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class SYSTRIGGERSRowFactory method makeRow.

/**
 * Helper method that contains common logic for {@code makeRow()} and
 * {@code makeEmptyRowForCurrentVersion()}. Creates a row for the
 * SYSTRIGGERS conglomerate.
 *
 * @param td the {@code TriggerDescriptor} to create a row from (can be
 *   {@code null} if the returned row should be empty)
 * @param columnCount the number of columns in the returned row (used for
 *   trimming off columns in soft upgrade mode to match the format in
 *   the old dictionary version)
 * @return a row for the SYSTRIGGERS conglomerate
 * @throws StandardException if an error happens when creating the row
 */
private ExecRow makeRow(TupleDescriptor td, int columnCount) throws StandardException {
    String name = null;
    UUID uuid = null;
    // schema
    UUID suuid = null;
    // referenced table
    UUID tuuid = null;
    // action sps uuid string
    UUID actionSPSID = null;
    // when clause sps uuid string
    UUID whenSPSID = null;
    Timestamp createTime = null;
    String event = null;
    String time = null;
    String type = null;
    String enabled = null;
    String triggerDefinition = null;
    String oldReferencingName = null;
    String newReferencingName = null;
    ReferencedColumns rcd = null;
    boolean referencingOld = false;
    boolean referencingNew = false;
    String whenClauseText = null;
    if (td != null) {
        TriggerDescriptor triggerDescriptor = (TriggerDescriptor) td;
        name = triggerDescriptor.getName();
        uuid = triggerDescriptor.getUUID();
        suuid = triggerDescriptor.getSchemaDescriptor().getUUID();
        createTime = triggerDescriptor.getCreationTimestamp();
        // for now we are assuming that a trigger can only listen to a single event
        event = triggerDescriptor.listensForEvent(TriggerDescriptor.TRIGGER_EVENT_UPDATE) ? "U" : triggerDescriptor.listensForEvent(TriggerDescriptor.TRIGGER_EVENT_DELETE) ? "D" : "I";
        time = triggerDescriptor.isBeforeTrigger() ? "B" : "A";
        type = triggerDescriptor.isRowTrigger() ? "R" : "S";
        enabled = triggerDescriptor.isEnabled() ? "E" : "D";
        tuuid = triggerDescriptor.getTableDescriptor().getUUID();
        int[] refCols = triggerDescriptor.getReferencedCols();
        int[] refColsInTriggerAction = triggerDescriptor.getReferencedColsInTriggerAction();
        rcd = (refCols != null || refColsInTriggerAction != null) ? new ReferencedColumnsDescriptorImpl(refCols, refColsInTriggerAction) : null;
        actionSPSID = triggerDescriptor.getActionId();
        whenSPSID = triggerDescriptor.getWhenClauseId();
        triggerDefinition = triggerDescriptor.getTriggerDefinition();
        referencingOld = triggerDescriptor.getReferencingOld();
        referencingNew = triggerDescriptor.getReferencingNew();
        oldReferencingName = triggerDescriptor.getOldReferencingName();
        newReferencingName = triggerDescriptor.getNewReferencingName();
        whenClauseText = triggerDescriptor.getWhenClauseText();
    }
    /* Build the row to insert */
    ExecRow row = getExecutionFactory().getValueRow(columnCount);
    /* 1st column is TRIGGERID */
    row.setColumn(1, new SQLChar((uuid == null) ? null : uuid.toString()));
    /* 2nd column is TRIGGERNAME */
    row.setColumn(2, new SQLVarchar(name));
    /* 3rd column is SCHEMAID */
    row.setColumn(3, new SQLChar((suuid == null) ? null : suuid.toString()));
    /* 4th column is CREATIONTIMESTAMP */
    SQLTimestamp creationTimestamp = (createTime == null) ? new SQLTimestamp(null) : new SQLTimestamp(createTime, getCalendarForCreationTimestamp());
    row.setColumn(4, creationTimestamp);
    /* 5th column is EVENT */
    row.setColumn(5, new SQLChar(event));
    /* 6th column is FIRINGTIME */
    row.setColumn(6, new SQLChar(time));
    /* 7th column is TYPE */
    row.setColumn(7, new SQLChar(type));
    /* 8th column is STATE */
    row.setColumn(8, new SQLChar(enabled));
    /* 9th column is TABLEID */
    row.setColumn(9, new SQLChar((tuuid == null) ? null : tuuid.toString()));
    /* 10th column is WHENSTMTID */
    row.setColumn(10, new SQLChar((whenSPSID == null) ? null : whenSPSID.toString()));
    /* 11th column is ACTIONSTMTID */
    row.setColumn(11, new SQLChar((actionSPSID == null) ? null : actionSPSID.toString()));
    /* 12th column is REFERENCEDCOLUMNS 
		 *  (user type org.apache.derby.catalog.ReferencedColumns)
		 */
    row.setColumn(12, new UserType(rcd));
    /* 13th column is TRIGGERDEFINITION */
    row.setColumn(13, dvf.getLongvarcharDataValue(triggerDefinition));
    /* 14th column is REFERENCINGOLD */
    row.setColumn(14, new SQLBoolean(referencingOld));
    /* 15th column is REFERENCINGNEW */
    row.setColumn(15, new SQLBoolean(referencingNew));
    /* 16th column is OLDREFERENCINGNAME */
    row.setColumn(16, new SQLVarchar(oldReferencingName));
    /* 17th column is NEWREFERENCINGNAME */
    row.setColumn(17, new SQLVarchar(newReferencingName));
    /* 18th column is WHENCLAUSETEXT */
    if (row.nColumns() >= 18) {
        // This column is present only if the data dictionary version is
        // 10.11 or higher.
        row.setColumn(18, dvf.getLongvarcharDataValue(whenClauseText));
    }
    return row;
}
Also used : ReferencedColumns(org.apache.derby.catalog.ReferencedColumns) SQLChar(org.apache.derby.iapi.types.SQLChar) ReferencedColumnsDescriptorImpl(org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) SQLTimestamp(org.apache.derby.iapi.types.SQLTimestamp) Timestamp(java.sql.Timestamp) TriggerDescriptor(org.apache.derby.iapi.sql.dictionary.TriggerDescriptor) SQLTimestamp(org.apache.derby.iapi.types.SQLTimestamp) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) UUID(org.apache.derby.catalog.UUID) UserType(org.apache.derby.iapi.types.UserType) SQLBoolean(org.apache.derby.iapi.types.SQLBoolean)

Example 8 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class SYSVIEWSRowFactory method makeRow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSVIEWS row
 *
 * @return	Row suitable for inserting into SYSVIEWS.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    DataValueDescriptor col;
    ExecRow row;
    String tableID = null;
    String compSchemaId = null;
    String viewText = null;
    String checkSType = null;
    int checkIType;
    if (td != null) {
        UUID tableUUID;
        ViewDescriptor vd = (ViewDescriptor) td;
        /*
			** We only allocate a new UUID if the descriptor doesn't already have one.
			** For descriptors replicated from a Source system, we already have an UUID.
			*/
        tableUUID = vd.getUUID();
        if (tableUUID == null) {
            tableUUID = getUUIDFactory().createUUID();
            vd.setUUID(tableUUID);
        }
        tableID = tableUUID.toString();
        viewText = vd.getViewText();
        /* RESOLVE - check constraints not supported yet */
        checkIType = vd.getCheckOptionType();
        if (SanityManager.DEBUG) {
            if (checkIType != ViewDescriptor.NO_CHECK_OPTION) {
                SanityManager.THROWASSERT("checkIType expected to be " + ViewDescriptor.NO_CHECK_OPTION + ", not " + checkIType);
            }
        }
        checkSType = "N";
        UUID tmpId = vd.getCompSchemaId();
        compSchemaId = (tmpId == null) ? null : tmpId.toString();
    }
    /* Insert info into sysviews */
    /* RESOLVE - It would be nice to require less knowledge about sysviews
		 * and have this be more table driven.
		 */
    /* Build the row to insert  */
    row = getExecutionFactory().getValueRow(SYSVIEWS_COLUMN_COUNT);
    /* 1st column is TABLEID (UUID - char(36)) */
    row.setColumn(SYSVIEWS_TABLEID, new SQLChar(tableID));
    /* 2nd column is VIEWDEFINITION */
    row.setColumn(SYSVIEWS_VIEWDEFINITION, dvf.getLongvarcharDataValue(viewText));
    /* 3rd column is CHECKOPTION (char(1)) */
    row.setColumn(SYSVIEWS_CHECKOPTION, new SQLChar(checkSType));
    /* 4th column is COMPILATIONSCHEMAID (UUID - char(36)) */
    row.setColumn(SYSVIEWS_COMPILATION_SCHEMAID, new SQLChar(compSchemaId));
    return row;
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID) ViewDescriptor(org.apache.derby.iapi.sql.dictionary.ViewDescriptor)

Example 9 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class SYSCHECKSRowFactory method makeRow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSCHECKS row
 *
 * @param td CheckConstraintDescriptorImpl
 *
 * @return	Row suitable for inserting into SYSCHECKS.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    DataValueDescriptor col;
    ExecIndexRow row;
    ReferencedColumns rcd = null;
    String checkDefinition = null;
    String constraintID = null;
    if (td != null) {
        CheckConstraintDescriptor cd = (CheckConstraintDescriptor) td;
        /*
			** We only allocate a new UUID if the descriptor doesn't already have one.
			** For descriptors replicated from a Source system, we already have an UUID.
			*/
        constraintID = cd.getUUID().toString();
        checkDefinition = cd.getConstraintText();
        rcd = cd.getReferencedColumnsDescriptor();
    }
    /* Build the row */
    row = getExecutionFactory().getIndexableRow(SYSCHECKS_COLUMN_COUNT);
    /* 1st column is CONSTRAINTID (UUID - char(36)) */
    row.setColumn(SYSCHECKS_CONSTRAINTID, new SQLChar(constraintID));
    /* 2nd column is CHECKDEFINITION */
    row.setColumn(SYSCHECKS_CHECKDEFINITION, dvf.getLongvarcharDataValue(checkDefinition));
    /* 3rd column is REFERENCEDCOLUMNS
		 *  (user type org.apache.derby.catalog.ReferencedColumns)
		 */
    row.setColumn(SYSCHECKS_REFERENCEDCOLUMNS, new UserType(rcd));
    return row;
}
Also used : ReferencedColumns(org.apache.derby.catalog.ReferencedColumns) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) CheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor) SubCheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubCheckConstraintDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) UserType(org.apache.derby.iapi.types.UserType)

Example 10 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class SYSCONSTRAINTSRowFactory method makeRow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSCONTRAINTS row
 *
 * @return	Row suitable for inserting into SYSCONTRAINTS.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    DataValueDescriptor col;
    ExecRow row;
    int constraintIType;
    UUID oid;
    String constraintSType = null;
    String constraintID = null;
    String tableID = null;
    String constraintName = null;
    String schemaID = null;
    boolean deferrable = ConstraintDefinitionNode.DEFERRABLE_DEFAULT;
    boolean initiallyDeferred = ConstraintDefinitionNode.INITIALLY_DEFERRED_DEFAULT;
    boolean enforced = ConstraintDefinitionNode.ENFORCED_DEFAULT;
    int referenceCount = 0;
    if (td != null) {
        ConstraintDescriptor constraint = (ConstraintDescriptor) td;
        /*
			** We only allocate a new UUID if the descriptor doesn't already have one.
			** For descriptors replicated from a Source system, we already have an UUID.
			*/
        oid = constraint.getUUID();
        constraintID = oid.toString();
        oid = constraint.getTableId();
        tableID = oid.toString();
        constraintName = constraint.getConstraintName();
        constraintIType = constraint.getConstraintType();
        switch(constraintIType) {
            case DataDictionary.PRIMARYKEY_CONSTRAINT:
                constraintSType = "P";
                break;
            case DataDictionary.UNIQUE_CONSTRAINT:
                constraintSType = "U";
                break;
            case DataDictionary.CHECK_CONSTRAINT:
                constraintSType = "C";
                break;
            case DataDictionary.FOREIGNKEY_CONSTRAINT:
                constraintSType = "F";
                break;
            default:
                if (SanityManager.DEBUG) {
                    SanityManager.THROWASSERT("invalid constraint type");
                }
        }
        schemaID = constraint.getSchemaDescriptor().getUUID().toString();
        // constraint characteristics
        deferrable = constraint.deferrable();
        initiallyDeferred = constraint.initiallyDeferred();
        enforced = constraint.enforced();
        referenceCount = constraint.getReferenceCount();
    }
    /* Insert info into sysconstraints */
    /* RESOLVE - It would be nice to require less knowledge about sysconstraints
		 * and have this be more table driven.
		 */
    /* Build the row to insert  */
    row = getExecutionFactory().getValueRow(SYSCONSTRAINTS_COLUMN_COUNT);
    /* 1st column is CONSTRAINTID (UUID - char(36)) */
    row.setColumn(SYSCONSTRAINTS_CONSTRAINTID, new SQLChar(constraintID));
    /* 2nd column is TABLEID (UUID - char(36)) */
    row.setColumn(SYSCONSTRAINTS_TABLEID, new SQLChar(tableID));
    /* 3rd column is NAME (varchar(128)) */
    row.setColumn(SYSCONSTRAINTS_CONSTRAINTNAME, new SQLVarchar(constraintName));
    /* 4th column is TYPE (char(1)) */
    row.setColumn(SYSCONSTRAINTS_TYPE, new SQLChar(constraintSType));
    /* 5th column is SCHEMAID (UUID - char(36)) */
    row.setColumn(SYSCONSTRAINTS_SCHEMAID, new SQLChar(schemaID));
    /* 6th column is STATE (char(1)) */
    row.setColumn(SYSCONSTRAINTS_STATE, new SQLChar(encodeCharacteristics(deferrable, initiallyDeferred, enforced)));
    /* 7th column is REFERENCED */
    row.setColumn(SYSCONSTRAINTS_REFERENCECOUNT, new SQLInteger(referenceCount));
    return row;
}
Also used : SubConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubConstraintDescriptor) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) SubCheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubCheckConstraintDescriptor) SubKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Aggregations

SQLChar (org.apache.derby.iapi.types.SQLChar)60 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)42 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)22 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)21 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)18 UUID (org.apache.derby.catalog.UUID)15 SQLLongint (org.apache.derby.iapi.types.SQLLongint)13 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)12 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)12 RowLocation (org.apache.derby.iapi.types.RowLocation)10 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)9 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)8 StandardException (org.apache.derby.shared.common.error.StandardException)8 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)7 UserType (org.apache.derby.iapi.types.UserType)7 ScanController (org.apache.derby.iapi.store.access.ScanController)6 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)4 LinkedList (java.util.LinkedList)3