Search in sources :

Example 6 with FormatableProperties

use of org.apache.derby.iapi.services.io.FormatableProperties in project derby by apache.

the class RealTableScanStatistics method getScanPropsDescriptor.

public Object getScanPropsDescriptor(Object scanPropsID) {
    String scanObjectType, scanObjectName;
    if (this.indexName != null) {
        if (this.isConstraint) {
            // constraint
            scanObjectType = "C";
            scanObjectName = this.indexName;
        } else {
            // index
            scanObjectType = "I";
            scanObjectName = this.indexName;
        }
    } else {
        // table
        scanObjectType = "T";
        scanObjectName = this.tableName;
    }
    String isoLevel = XPLAINUtil.getIsolationLevelCode(this.isolationLevel);
    XPLAINScanPropsDescriptor scanRSDescriptor = new XPLAINScanPropsDescriptor((UUID) scanPropsID, scanObjectName, scanObjectType, // the scan type: heap, btree, sort
    null, // the isolation level
    isoLevel, // the number of visited pages
    null, // the number of visited rows
    null, // the number of qualified rows
    null, // the number of visited deleted rows
    null, // the number of fetched columns
    null, // the bitset of fetched columns
    null, // the btree height
    null, this.fetchSize, this.startPosition, this.stopPosition, this.qualifiers, // the next qualifiers
    null, // the hash key column numbers
    null, // the hash table size
    null);
    FormatableProperties props = this.scanProperties;
    return XPLAINUtil.extractScanProps(scanRSDescriptor, props);
}
Also used : XPLAINScanPropsDescriptor(org.apache.derby.impl.sql.catalog.XPLAINScanPropsDescriptor) FormatableProperties(org.apache.derby.iapi.services.io.FormatableProperties)

Example 7 with FormatableProperties

use of org.apache.derby.iapi.services.io.FormatableProperties in project derby by apache.

the class InternalDriver method connect.

public Connection connect(String url, Properties info, int loginTimeoutSeconds) throws SQLException {
    if (!acceptsURL(url)) {
        return null;
    }
    /**
     * If we are below the low memory watermark for obtaining
     * a connection, then don't even try. Just throw an exception.
     */
    if (EmbedConnection.memoryState.isLowMemory()) {
        throw EmbedConnection.NO_MEM;
    }
    /*
		** A url "jdbc:default:connection" means get the current
		** connection.  From within a method called from JSQL, the
		** "current" connection is the one that is running the
		** JSQL statement containing the method call.
		*/
    boolean current = url.equals(Attribute.SQLJ_NESTED);
    /* If jdbc:default:connection, see if user already has a
		 * connection. All connection attributes are ignored.
		 */
    if (current) {
        ConnectionContext connContext = getConnectionContext();
        if (connContext != null) {
            return connContext.getNestedConnection(false);
        }
        // return null, as we are not the driver to handle this
        return null;
    }
    // convert the ;name=value attributes in the URL into
    // properties.
    FormatableProperties finfo = null;
    try {
        finfo = getAttributes(url, info);
        // ensure we don't use this reference directly again.
        info = null;
        /*
			** A property "shutdown=true" means shut the system or database down
			*/
        boolean shutdown = Boolean.valueOf(finfo.getProperty(Attribute.SHUTDOWN_ATTR)).booleanValue();
        if (shutdown) {
            // 
            if (InternalDriver.getDatabaseName(url, finfo).length() == 0) {
                // it is _always_ expected.
                if (this.getAuthenticationService() == null)
                    throw Util.generateCsSQLException(SQLState.LOGIN_FAILED, MessageService.getTextMessage(MessageId.AUTH_NO_SERVICE_FOR_SYSTEM));
                if (!this.getAuthenticationService().authenticate((String) null, finfo)) {
                    // not a valid user
                    throw Util.generateCsSQLException(SQLState.NET_CONNECT_AUTH_FAILED, MessageService.getTextMessage(MessageId.AUTH_INVALID));
                }
                // value is true
                if (finfo.getProperty(Attribute.DEREGISTER_ATTR) != null) {
                    boolean deregister = Boolean.valueOf(finfo.getProperty(Attribute.DEREGISTER_ATTR)).booleanValue();
                    InternalDriver.setDeregister(deregister);
                }
                // check for shutdown privileges
                // DERBY-3495: uncomment to enable system privileges checks
                // final String user = IdUtil.getUserNameFromURLProps(finfo);
                // checkShutdownPrivileges(user);
                getMonitor().shutdown();
                throw Util.generateCsSQLException(SQLState.CLOUDSCAPE_SYSTEM_SHUTDOWN);
            }
        }
        EmbedConnection conn;
        if (loginTimeoutSeconds <= 0) {
            conn = getNewEmbedConnection(url, finfo);
        } else {
            conn = timeLogin(url, finfo, loginTimeoutSeconds);
        }
        // object is returned in the closed state.
        if (conn.isClosed()) {
            return null;
        }
        return conn;
    } catch (OutOfMemoryError noMemory) {
        EmbedConnection.memoryState.setLowMemory();
        throw EmbedConnection.NO_MEM;
    } finally {
        // break any link with the user's Properties set.
        if (finfo != null)
            finfo.clearDefaults();
    }
}
Also used : FormatableProperties(org.apache.derby.iapi.services.io.FormatableProperties)

Example 8 with FormatableProperties

use of org.apache.derby.iapi.services.io.FormatableProperties in project derby by apache.

the class InternalDriver method getPropertyInfo.

/**
 * <p>The getPropertyInfo method is intended to allow a generic GUI tool to
 * discover what properties it should prompt a human for in order to get
 * enough information to connect to a database.  Note that depending on
 * the values the human has supplied so far, additional values may become
 * necessary, so it may be necessary to iterate though several calls
 * to getPropertyInfo.
 *
 * @param url The URL of the database to connect to.
 * @param info A proposed list of tag/value pairs that will be sent on
 *          connect open.
 * @return An array of DriverPropertyInfo objects describing possible
 *          properties.  This array may be an empty array if no properties
 *          are required.
 * @exception SQLException if a database-access error occurs.
 */
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
    if (info != null) {
        if (Boolean.valueOf(info.getProperty(Attribute.SHUTDOWN_ATTR)).booleanValue()) {
            // no other options possible when shutdown is set to be true
            return new DriverPropertyInfo[0];
        }
    }
    // at this point we have databaseName,
    String dbname = InternalDriver.getDatabaseName(url, info);
    // convert the ;name=value attributes in the URL into
    // properties.
    FormatableProperties finfo = getAttributes(url, info);
    // ensure we don't use this reference directly again.
    info = null;
    boolean encryptDB = Boolean.valueOf(finfo.getProperty(Attribute.DATA_ENCRYPTION)).booleanValue();
    String encryptpassword = finfo.getProperty(Attribute.BOOT_PASSWORD);
    if (dbname.length() == 0 || (encryptDB && encryptpassword == null)) {
        // with no database name we can have shutdown or a database name
        // In future, if any new attribute info needs to be included in this
        // method, it just has to be added to either string or boolean or secret array
        // depending on whether it accepts string or boolean or secret(ie passwords) value.
        String[][] connStringAttributes = { { Attribute.DBNAME_ATTR, MessageId.CONN_DATABASE_IDENTITY }, { Attribute.CRYPTO_PROVIDER, MessageId.CONN_CRYPTO_PROVIDER }, { Attribute.CRYPTO_ALGORITHM, MessageId.CONN_CRYPTO_ALGORITHM }, { Attribute.CRYPTO_KEY_LENGTH, MessageId.CONN_CRYPTO_KEY_LENGTH }, { Attribute.CRYPTO_EXTERNAL_KEY, MessageId.CONN_CRYPTO_EXTERNAL_KEY }, { Attribute.TERRITORY, MessageId.CONN_LOCALE }, { Attribute.COLLATION, MessageId.CONN_COLLATION }, { Attribute.USERNAME_ATTR, MessageId.CONN_USERNAME_ATTR }, { Attribute.LOG_DEVICE, MessageId.CONN_LOG_DEVICE }, { Attribute.ROLL_FORWARD_RECOVERY_FROM, MessageId.CONN_ROLL_FORWARD_RECOVERY_FROM }, { Attribute.CREATE_FROM, MessageId.CONN_CREATE_FROM }, { Attribute.RESTORE_FROM, MessageId.CONN_RESTORE_FROM } };
        String[][] connBooleanAttributes = { { Attribute.SHUTDOWN_ATTR, MessageId.CONN_SHUT_DOWN_CLOUDSCAPE }, { Attribute.DEREGISTER_ATTR, MessageId.CONN_DEREGISTER_AUTOLOADEDDRIVER }, { Attribute.CREATE_ATTR, MessageId.CONN_CREATE_DATABASE }, { Attribute.DATA_ENCRYPTION, MessageId.CONN_DATA_ENCRYPTION }, { Attribute.UPGRADE_ATTR, MessageId.CONN_UPGRADE_DATABASE } };
        String[][] connStringSecretAttributes = { { Attribute.BOOT_PASSWORD, MessageId.CONN_BOOT_PASSWORD }, { Attribute.PASSWORD_ATTR, MessageId.CONN_PASSWORD_ATTR } };
        DriverPropertyInfo[] optionsNoDB = new DriverPropertyInfo[connStringAttributes.length + connBooleanAttributes.length + connStringSecretAttributes.length];
        int attrIndex = 0;
        for (int i = 0; i < connStringAttributes.length; i++, attrIndex++) {
            optionsNoDB[attrIndex] = new DriverPropertyInfo(connStringAttributes[i][0], finfo.getProperty(connStringAttributes[i][0]));
            optionsNoDB[attrIndex].description = MessageService.getTextMessage(connStringAttributes[i][1]);
        }
        optionsNoDB[0].choices = getMonitor().getServiceList(Property.DATABASE_MODULE);
        // since database name is not stored in FormatableProperties, we
        // assign here explicitly
        optionsNoDB[0].value = dbname;
        for (int i = 0; i < connStringSecretAttributes.length; i++, attrIndex++) {
            optionsNoDB[attrIndex] = new DriverPropertyInfo(connStringSecretAttributes[i][0], (finfo.getProperty(connStringSecretAttributes[i][0]) == null ? "" : "****"));
            optionsNoDB[attrIndex].description = MessageService.getTextMessage(connStringSecretAttributes[i][1]);
        }
        for (int i = 0; i < connBooleanAttributes.length; i++, attrIndex++) {
            optionsNoDB[attrIndex] = new DriverPropertyInfo(connBooleanAttributes[i][0], Boolean.valueOf(finfo == null ? "" : finfo.getProperty(connBooleanAttributes[i][0])).toString());
            optionsNoDB[attrIndex].description = MessageService.getTextMessage(connBooleanAttributes[i][1]);
            optionsNoDB[attrIndex].choices = BOOLEAN_CHOICES;
        }
        return optionsNoDB;
    }
    return new DriverPropertyInfo[0];
}
Also used : FormatableProperties(org.apache.derby.iapi.services.io.FormatableProperties) DriverPropertyInfo(java.sql.DriverPropertyInfo)

Example 9 with FormatableProperties

use of org.apache.derby.iapi.services.io.FormatableProperties in project derby by apache.

the class DeleteNode method getEmptyUpdateNode.

private UpdateNode getEmptyUpdateNode(String schemaName, String targetTableName, ColumnDescriptorList cdl) throws StandardException {
    ValueNode whereClause = null;
    TableName tableName = new TableName(schemaName, targetTableName, getContextManager());
    FromList fromList = new FromList(getContextManager());
    FromTable fromTable = new FromBaseTable(tableName, null, FromBaseTable.DELETE, null, getContextManager());
    // we would like to use references index & table scan instead of
    // what optimizer says for the dependent table scan.
    Properties targetProperties = new FormatableProperties();
    targetProperties.put("index", "null");
    ((FromBaseTable) fromTable).setTableProperties(targetProperties);
    fromList.addFromTable(fromTable);
    SelectNode sn = new SelectNode(getSetClause(cdl), fromList, /* FROM list */
    whereClause, /* WHERE clause */
    null, /* GROUP BY list */
    null, /* having clause */
    null, /* windows */
    null, /* optimizer override plan */
    getContextManager());
    return new UpdateNode(tableName, sn, null, getContextManager());
}
Also used : FormatableProperties(org.apache.derby.iapi.services.io.FormatableProperties) Properties(java.util.Properties) FormatableProperties(org.apache.derby.iapi.services.io.FormatableProperties)

Aggregations

FormatableProperties (org.apache.derby.iapi.services.io.FormatableProperties)9 XPLAINScanPropsDescriptor (org.apache.derby.impl.sql.catalog.XPLAINScanPropsDescriptor)3 Properties (java.util.Properties)2 DriverPropertyInfo (java.sql.DriverPropertyInfo)1 StringTokenizer (java.util.StringTokenizer)1 XPLAINSortPropsDescriptor (org.apache.derby.impl.sql.catalog.XPLAINSortPropsDescriptor)1