Search in sources :

Example 1 with SQLTimestamp

use of org.apache.derby.iapi.types.SQLTimestamp 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 2 with SQLTimestamp

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

the class SYSUSERSRowFactory method makeRow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSUSERS row. The password in the UserDescriptor will be zeroed by
 * this method.
 *
 * @return	Row suitable for inserting into SYSUSERS
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    String userName = null;
    String hashingScheme = null;
    char[] password = null;
    Timestamp lastModified = null;
    ExecRow row;
    try {
        if (td != null) {
            UserDescriptor descriptor = (UserDescriptor) td;
            userName = descriptor.getUserName();
            hashingScheme = descriptor.getHashingScheme();
            password = descriptor.getAndZeroPassword();
            lastModified = descriptor.getLastModified();
        }
        /* Build the row to insert  */
        row = getExecutionFactory().getValueRow(SYSUSERS_COLUMN_COUNT);
        /* 1st column is USERNAME (varchar(128)) */
        row.setColumn(USERNAME_COL_NUM, new SQLVarchar(userName));
        /* 2nd column is HASHINGSCHEME (varchar(32672)) */
        row.setColumn(HASHINGSCHEME_COL_NUM, new SQLVarchar(hashingScheme));
        /* 3rd column is PASSWORD (varchar(32672)) */
        row.setColumn(PASSWORD_COL_NUM, new SQLVarchar(password));
        /* 4th column is LASTMODIFIED (timestamp) */
        row.setColumn(LASTMODIFIED_COL_NUM, new SQLTimestamp(lastModified));
    } finally {
        // zero out the password to prevent it from being memory-sniffed
        if (password != null) {
            Arrays.fill(password, (char) 0);
        }
    }
    return row;
}
Also used : SQLTimestamp(org.apache.derby.iapi.types.SQLTimestamp) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) SQLTimestamp(org.apache.derby.iapi.types.SQLTimestamp) Timestamp(java.sql.Timestamp) UserDescriptor(org.apache.derby.iapi.sql.dictionary.UserDescriptor)

Aggregations

Timestamp (java.sql.Timestamp)2 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)2 SQLTimestamp (org.apache.derby.iapi.types.SQLTimestamp)2 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)2 ReferencedColumns (org.apache.derby.catalog.ReferencedColumns)1 UUID (org.apache.derby.catalog.UUID)1 ReferencedColumnsDescriptorImpl (org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl)1 TriggerDescriptor (org.apache.derby.iapi.sql.dictionary.TriggerDescriptor)1 UserDescriptor (org.apache.derby.iapi.sql.dictionary.UserDescriptor)1 SQLBoolean (org.apache.derby.iapi.types.SQLBoolean)1 SQLChar (org.apache.derby.iapi.types.SQLChar)1 UserType (org.apache.derby.iapi.types.UserType)1