Search in sources :

Example 21 with SQLVarchar

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

the class SYSSTATEMENTSRowFactory method makeSYSSTATEMENTSrow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSSTATEMENTS row.
 * <p>
 * <B>WARNING</B>: When empty row is true, this method takes
 * a snapshot of the SPSD and creates a row.  It is imperative
 * that that row remain consistent with the descriptor (the
 * valid and StorablePreparedStatement fields must be in sync).
 * If this row is to be written out and valid is true, then
 * this call and the insert should be synchronized on the
 * SPSD. This method has <B>NO</B> synchronization.
 *
 * @param compileMe			passed into SPSDescriptorImpl.getPreparedStatement().
 *							if true, we (re)compile the stmt
 * @param spsDescriptor		In-memory tuple to be converted to a disk row.
 *
 * @return	Row suitable for inserting into SYSSTATEMENTS.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeSYSSTATEMENTSrow(boolean compileMe, SPSDescriptor spsDescriptor) throws StandardException {
    DataTypeDescriptor dtd;
    ExecRow row;
    DataValueDescriptor col;
    String name = null;
    UUID uuid = null;
    String uuidStr = null;
    // schema
    String suuidStr = null;
    // compilation schema
    String compUuidStr = null;
    String text = null;
    String usingText = null;
    ExecPreparedStatement preparedStatement = null;
    String typeStr = null;
    boolean valid = true;
    Timestamp time = null;
    boolean initiallyCompilable = true;
    if (spsDescriptor != null) {
        name = spsDescriptor.getName();
        uuid = spsDescriptor.getUUID();
        suuidStr = spsDescriptor.getSchemaDescriptor().getUUID().toString();
        uuidStr = uuid.toString();
        text = spsDescriptor.getText();
        valid = spsDescriptor.isValid();
        time = spsDescriptor.getCompileTime();
        typeStr = spsDescriptor.getTypeAsString();
        initiallyCompilable = spsDescriptor.initiallyCompilable();
        preparedStatement = spsDescriptor.getPreparedStatement(compileMe);
        compUuidStr = (spsDescriptor.getCompSchemaId() != null) ? spsDescriptor.getCompSchemaId().toString() : null;
        usingText = spsDescriptor.getUsingText();
    }
    /* Build the row to insert */
    row = getExecutionFactory().getValueRow(SYSSTATEMENTS_COLUMN_COUNT);
    /* 1st column is STMTID */
    row.setColumn(1, new SQLChar(uuidStr));
    /* 2nd column is STMTNAME */
    row.setColumn(2, new SQLVarchar(name));
    /* 3rd column is SCHEMAID */
    row.setColumn(3, new SQLChar(suuidStr));
    /* 4th column is TYPE */
    row.setColumn(4, new SQLChar(typeStr));
    /* 5th column is VALID */
    row.setColumn(5, new SQLBoolean(valid));
    /* 6th column is TEXT */
    row.setColumn(6, dvf.getLongvarcharDataValue(text));
    /* 7th column is LASTCOMPILED */
    row.setColumn(7, new SQLTimestamp(time));
    /* 8th column is COMPILATIONSCHEMAID */
    row.setColumn(8, new SQLChar(compUuidStr));
    /* 9th column is USINGTEXT */
    row.setColumn(9, dvf.getLongvarcharDataValue(usingText));
    /* 
		** 10th column is CONSTANTSTATE
		**
		** CONSTANTSTATE is really a formatable StorablePreparedStatement.
		*/
    row.setColumn(10, new UserType(preparedStatement));
    /* 11th column is INITIALLY_COMPILABLE */
    row.setColumn(11, new SQLBoolean(initiallyCompilable));
    return row;
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) Timestamp(java.sql.Timestamp) ExecPreparedStatement(org.apache.derby.iapi.sql.execute.ExecPreparedStatement) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID) UserType(org.apache.derby.iapi.types.UserType) SQLBoolean(org.apache.derby.iapi.types.SQLBoolean)

Example 22 with SQLVarchar

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

the class SYSTABLESRowFactory method makeRow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSTABLES row
 *
 * @return	Row suitable for inserting into SYSTABLES.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    UUID oid;
    String tabSType = null;
    int tabIType;
    ExecRow row;
    String lockGranularity = null;
    String tableID = null;
    String schemaID = null;
    String tableName = null;
    if (td != null) {
        /*
			** 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.
			*/
        TableDescriptor descriptor = (TableDescriptor) td;
        SchemaDescriptor schema = (SchemaDescriptor) parent;
        oid = descriptor.getUUID();
        if (oid == null) {
            oid = getUUIDFactory().createUUID();
            descriptor.setUUID(oid);
        }
        tableID = oid.toString();
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(schema != null, "Schema should not be null unless empty row is true");
            if (schema.getUUID() == null) {
                SanityManager.THROWASSERT("schema " + schema + " has a null OID");
            }
        }
        schemaID = schema.getUUID().toString();
        tableName = descriptor.getName();
        /* RESOLVE - Table Type should really be a char in the descriptor
			 * T, S, V, S instead of 0, 1, 2, 3
			 */
        tabIType = descriptor.getTableType();
        switch(tabIType) {
            case TableDescriptor.BASE_TABLE_TYPE:
                tabSType = "T";
                break;
            case TableDescriptor.SYSTEM_TABLE_TYPE:
                tabSType = "S";
                break;
            case TableDescriptor.VIEW_TYPE:
                tabSType = "V";
                break;
            case TableDescriptor.SYNONYM_TYPE:
                tabSType = "A";
                break;
            default:
                if (SanityManager.DEBUG)
                    SanityManager.THROWASSERT("invalid table type");
        }
        char[] lockGChar = new char[1];
        lockGChar[0] = descriptor.getLockGranularity();
        lockGranularity = new String(lockGChar);
    }
    /* Insert info into systables */
    /* RESOLVE - It would be nice to require less knowledge about systables
		 * and have this be more table driven.
		 */
    /* Build the row to insert  */
    row = getExecutionFactory().getValueRow(SYSTABLES_COLUMN_COUNT);
    /* 1st column is TABLEID (UUID - char(36)) */
    row.setColumn(SYSTABLES_TABLEID, new SQLChar(tableID));
    /* 2nd column is NAME (varchar(30)) */
    row.setColumn(SYSTABLES_TABLENAME, new SQLVarchar(tableName));
    /* 3rd column is TABLETYPE (char(1)) */
    row.setColumn(SYSTABLES_TABLETYPE, new SQLChar(tabSType));
    /* 4th column is SCHEMAID (UUID - char(36)) */
    row.setColumn(SYSTABLES_SCHEMAID, new SQLChar(schemaID));
    /* 5th column is LOCKGRANULARITY (char(1)) */
    row.setColumn(SYSTABLES_LOCKGRANULARITY, new SQLChar(lockGranularity));
    return row;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) UUID(org.apache.derby.catalog.UUID) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 23 with SQLVarchar

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

the class SYSTABLESRowFactory method buildEmptyIndexRow.

/**
 * Builds an empty index row.
 *
 *	@param	indexNumber	Index to build empty row for.
 *  @param  rowLocation	Row location for last column of index row
 *
 * @return corresponding empty index row
 * @exception   StandardException thrown on failure
 */
ExecIndexRow buildEmptyIndexRow(int indexNumber, RowLocation rowLocation) throws StandardException {
    int ncols = getIndexColumnCount(indexNumber);
    ExecIndexRow row = getExecutionFactory().getIndexableRow(ncols + 1);
    row.setColumn(ncols + 1, rowLocation);
    switch(indexNumber) {
        case SYSTABLES_INDEX1_ID:
            /* 1st column is TABLENAME (varchar(128)) */
            row.setColumn(1, new SQLVarchar());
            /* 2nd column is SCHEMAID (UUID - char(36)) */
            row.setColumn(2, new SQLChar());
            break;
        case SYSTABLES_INDEX2_ID:
            /* 1st column is TABLEID (UUID - char(36)) */
            row.setColumn(1, new SQLChar());
            break;
    }
    return row;
}
Also used : SQLChar(org.apache.derby.iapi.types.SQLChar) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 24 with SQLVarchar

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

the class SYSUSERSRowFactory method buildDescriptor.

// /////////////////////////////////////////////////////////////////////////
// 
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
// 
// /////////////////////////////////////////////////////////////////////////
/**
 * Make a descriptor out of a SYSUSERS row. The password column in the
 * row will be zeroed out.
 *
 * @param row a row
 * @param parentTupleDescriptor	Null for this kind of descriptor.
 * @param dd dataDictionary
 *
 * @return	a descriptor equivalent to a row
 *
 * @exception   StandardException thrown on failure
 */
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
    if (SanityManager.DEBUG) {
        if (row.nColumns() != SYSUSERS_COLUMN_COUNT) {
            SanityManager.THROWASSERT("Wrong number of columns for a SYSUSERS row: " + row.nColumns());
        }
    }
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    String userName;
    String hashingScheme;
    char[] password = null;
    Timestamp lastModified;
    DataValueDescriptor col;
    SQLVarchar passwordCol = null;
    UserDescriptor result;
    try {
        /* 1st column is USERNAME */
        col = row.getColumn(USERNAME_COL_NUM);
        userName = col.getString();
        /* 2nd column is HASHINGSCHEME */
        col = row.getColumn(HASHINGSCHEME_COL_NUM);
        hashingScheme = col.getString();
        /* 3nd column is PASSWORD */
        passwordCol = (SQLVarchar) row.getColumn(PASSWORD_COL_NUM);
        password = passwordCol.getRawDataAndZeroIt();
        /* 4th column is LASTMODIFIED */
        col = row.getColumn(LASTMODIFIED_COL_NUM);
        lastModified = col.getTimestamp(new java.util.GregorianCalendar());
        result = ddg.newUserDescriptor(userName, hashingScheme, password, lastModified);
    } finally {
        // zero out the password so that it can't be memory-sniffed
        if (password != null) {
            Arrays.fill(password, (char) 0);
        }
        if (passwordCol != null) {
            passwordCol.zeroRawData();
        }
    }
    return result;
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) 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)

Example 25 with SQLVarchar

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

SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)45 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)33 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)30 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)22 SQLChar (org.apache.derby.iapi.types.SQLChar)18 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)13 UUID (org.apache.derby.catalog.UUID)9 SQLLongint (org.apache.derby.iapi.types.SQLLongint)6 ScanController (org.apache.derby.iapi.store.access.ScanController)5 UserType (org.apache.derby.iapi.types.UserType)5 Timestamp (java.sql.Timestamp)4 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)4 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)4 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)4 SQLBoolean (org.apache.derby.iapi.types.SQLBoolean)4 ArrayList (java.util.ArrayList)3 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)3 SQLTimestamp (org.apache.derby.iapi.types.SQLTimestamp)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2