Class InternalDriver

  • All Implemented Interfaces:
    java.sql.Driver, ModuleControl
    Direct Known Subclasses:
    Driver42

    public class InternalDriver
    extends java.lang.Object
    implements ModuleControl, java.sql.Driver
    Factory class and API for JDBC objects.
    • Field Detail

      • syncMe

        private static final java.lang.Object syncMe
      • mbean

        private java.lang.Object mbean
      • active

        protected boolean active
      • deregister

        private static boolean deregister
        Tells whether or not AutoloadedDriver should deregister itself on shutdown. This flag is true unless the deregister attribute has been set to false by the user (DERBY-2905).
      • _executorPool

        private static final java.util.concurrent.ExecutorService _executorPool

        An executor service used for executing connection attempts when a login timeout has been specified.

        DERBY-6107: Core pool size and keep alive timeout should be zero so that no threads are cached. By creating a fresh thread each time a task is submitted, we make sure that the task will run in a thread with the same context class loader as the thread that submitted the task. This is important for example when connecting to a database using the classpath subsubprotocol, and the database lives in the context class loader. If threads are cached, a task may execute in a thread that has a different context class loader.

      • BOOLEAN_CHOICES

        private static final java.lang.String[] BOOLEAN_CHOICES
    • Constructor Detail

      • InternalDriver

        public InternalDriver()
    • Method Detail

      • boot

        public void boot​(boolean create,
                         java.util.Properties properties)
                  throws StandardException
        Description copied from interface: ModuleControl
        Boot this module with the given properties. Creates a module instance that can be found using the findModule() methods of Monitor. The module can only be found using one of these findModule() methods once this method has returned.

        An implementation's boot method can throw StandardException. If it is thrown the module is not registered by the monitor and therefore cannot be found through a findModule(). In this case the module's stop() method is not called, thus throwing this exception must free up any resources.

        When create is true the contents of the properties object will be written to the service.properties of the persistent service. Thus any code that requires an entry in service.properties must explicitly place the value in this properties set using the put method.
        Typically the properties object contains one or more default properties sets, which are not written out to service.properties. These default sets are how callers modify the create process. In a JDBC connection database create the first set of defaults is a properties object that contains the attributes that were set on the jdbc:derby: URL. This attributes properties set has the second default properties set as its default. This set (which could be null) contains the properties that the user set on their DriverManager.getConnection() call, and are thus not owned by Derby code, and thus must not be modified by Derby code.

        When create is false the properties object contains all the properties set in the service.properties file plus a limited number of attributes from the JDBC URL attributes or connection properties set. This avoids properties set by the user compromising the boot process. An example of a property passed in from the JDBC world is the bootPassword for encrypted databases.

        Code should not hold onto the passed in properties reference after boot time as its contents may change underneath it. At least after the complete boot is completed, the links to all the default sets will be removed.

        Specified by:
        boot in interface ModuleControl
        Throws:
        StandardException - Module cannot be started.
        See Also:
        Monitor, ModuleFactory
      • stop

        public void stop()
        Description copied from interface: ModuleControl
        Stop the module. The module may be found via a findModule() method until some time after this method returns. Therefore the factory must be prepared to reject requests to it once it has been stopped. In addition other modules may cache a reference to the module and make requests of it after it has been stopped, these requests should be rejected as well.
        Specified by:
        stop in interface ModuleControl
        See Also:
        Monitor, ModuleFactory
      • acceptsURL

        public boolean acceptsURL​(java.lang.String url)
                           throws java.sql.SQLException
        Specified by:
        acceptsURL in interface java.sql.Driver
        Throws:
        java.sql.SQLException
      • embeddedDriverAcceptsURL

        public static boolean embeddedDriverAcceptsURL​(java.lang.String url)
                                                throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • connect

        public java.sql.Connection connect​(java.lang.String url,
                                           java.util.Properties info,
                                           int loginTimeoutSeconds)
                                    throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • timeLogin

        private EmbedConnection timeLogin​(java.lang.String url,
                                          java.util.Properties info,
                                          int loginTimeoutSeconds)
                                   throws java.sql.SQLException
        Enforce the login timeout.
        Throws:
        java.sql.SQLException
      • processException

        private java.sql.SQLException processException​(java.lang.Throwable t)
        Process exceptions raised while running a timed login.
      • checkSystemPrivileges

        public void checkSystemPrivileges​(java.lang.String user,
                                          java.security.Permission perm)
        Checks for System Privileges.
        Parameters:
        user - The user to be checked for having the permission
        perm - The permission to be checked
        Throws:
        java.security.AccessControlException - if permissions are missing
      • checkShutdownPrivileges

        private void checkShutdownPrivileges​(java.lang.String user)
                                      throws java.sql.SQLException
        Checks for shutdown System Privileges. To perform this check the following policy grant is required
        • to run the encapsulated test: permission javax.security.auth.AuthPermission "doAsPrivileged";
        or a SQLException will be raised detailing the cause.

        In addition, for the test to succeed

        • the given user needs to be covered by a grant: principal org.apache.derby.authentication.SystemPrincipal "..." {}
        • that lists a shutdown permission: permission org.apache.derby.security.SystemPermission "shutdown";
        or it will fail with a SQLException detailing the cause.
        Parameters:
        user - The user to be checked for shutdown privileges
        Throws:
        java.sql.SQLException - if the privileges check fails
      • getMajorVersion

        public int getMajorVersion()
        Specified by:
        getMajorVersion in interface java.sql.Driver
      • getMinorVersion

        public int getMinorVersion()
        Specified by:
        getMinorVersion in interface java.sql.Driver
      • jdbcCompliant

        public boolean jdbcCompliant()
        Specified by:
        jdbcCompliant in interface java.sql.Driver
      • getAttributes

        protected FormatableProperties getAttributes​(java.lang.String url,
                                                     java.util.Properties info)
                                              throws java.sql.SQLException
        Convert all the attributes in the url into properties and combine them with the set provided.
        If the caller passed in a set of attributes (info != null) then we set that up as the default of the returned property set as the user's set. This means we can easily break the link with the user's set, ensuring that we don't hang onto the users object. It also means that we don't add our attributes into the user's own property object.
        Throws:
        java.sql.SQLException - thrown if URL form bad
      • checkBoolean

        private static void checkBoolean​(java.util.Properties set,
                                         java.lang.String attribute)
                                  throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • checkEnumeration

        private static void checkEnumeration​(java.util.Properties set,
                                             java.lang.String attribute,
                                             java.lang.String[] choices)
                                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getDatabaseName

        public static java.lang.String getDatabaseName​(java.lang.String url,
                                                       java.util.Properties info)
        Get the database name from the url. Copes with three forms jdbc:derby:dbname jdbc:derby:dbname;... jdbc:derby:;subname=dbname
        Parameters:
        url - The url being used for the connection
        info - The properties set being used for the connection, must include the properties derived from the attributes in the url
        Returns:
        a String containing the database name or an empty string ("") if no database name is present in the URL.
      • getContextServiceFactory

        public final ContextService getContextServiceFactory()
      • getNewEmbedConnection

        EmbedConnection getNewEmbedConnection​(java.lang.String url,
                                              java.util.Properties info)
                                       throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getCurrentContextManager

        private ContextManager getCurrentContextManager()
      • isActive

        public boolean isActive()
        Return true if this driver is active. Package private method.
      • getNewNestedConnection

        public java.sql.Connection getNewNestedConnection​(EmbedConnection conn)
        Get a new nested connection.
        Parameters:
        conn - The EmbedConnection.
        Returns:
        A nested connection object.
      • newEmbedStatement

        public java.sql.Statement newEmbedStatement​(EmbedConnection conn,
                                                    boolean forMetaData,
                                                    int resultSetType,
                                                    int resultSetConcurrency,
                                                    int resultSetHoldability)
      • newEmbedPreparedStatement

        public java.sql.PreparedStatement newEmbedPreparedStatement​(EmbedConnection conn,
                                                                    java.lang.String stmt,
                                                                    boolean forMetaData,
                                                                    int resultSetType,
                                                                    int resultSetConcurrency,
                                                                    int resultSetHoldability,
                                                                    int autoGeneratedKeys,
                                                                    int[] columnIndexes,
                                                                    java.lang.String[] columnNames)
                                                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException - if fails to create statement
      • newEmbedCallableStatement

        public java.sql.CallableStatement newEmbedCallableStatement​(EmbedConnection conn,
                                                                    java.lang.String stmt,
                                                                    int resultSetType,
                                                                    int resultSetConcurrency,
                                                                    int resultSetHoldability)
                                                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException - if fails to create statement
      • newEmbedDatabaseMetaData

        public java.sql.DatabaseMetaData newEmbedDatabaseMetaData​(EmbedConnection conn,
                                                                  java.lang.String dbname)
                                                           throws java.sql.SQLException
        Return a new java.sql.DatabaseMetaData instance for this implementation.
        Throws:
        java.sql.SQLException - on failure to create.
      • newEmbedResultSet

        public EmbedResultSet newEmbedResultSet​(EmbedConnection conn,
                                                ResultSet results,
                                                boolean forMetaData,
                                                EmbedStatement statement,
                                                boolean isAtomic)
                                         throws java.sql.SQLException
        Return a new java.sql.ResultSet instance for this implementation.
        Parameters:
        conn - Owning connection
        results - Top level of language result set tree
        forMetaData - Is this for meta-data
        statement - The statement that is creating the SQL ResultSet
        isAtomic -
        Returns:
        a new java.sql.ResultSet
        Throws:
        java.sql.SQLException
      • newEmbedResultSetMetaData

        public EmbedResultSetMetaData newEmbedResultSetMetaData​(ResultColumnDescriptor[] columnInfo)
        Returns a new java.sql.ResultSetMetaData for this implementation
        Parameters:
        columnInfo - a ResultColumnDescriptor that stores information about the columns in a ResultSet
      • newBrokeredConnection

        BrokeredConnection newBrokeredConnection​(BrokeredConnectionControl control)
                                          throws java.sql.SQLException
        Return a new BrokeredConnection for this implementation.
        Throws:
        java.sql.SQLException
      • getNewPooledConnection

        protected javax.sql.PooledConnection getNewPooledConnection​(BasicEmbeddedDataSource40 eds,
                                                                    java.lang.String user,
                                                                    java.lang.String password,
                                                                    boolean requestPassword)
                                                             throws java.sql.SQLException
        Create and return an EmbedPooledConnection from the received instance of EmbeddedDataSource.
        Throws:
        java.sql.SQLException
      • getNewXAConnection

        protected javax.sql.XAConnection getNewXAConnection​(BasicEmbeddedDataSource40 eds,
                                                            ResourceAdapter ra,
                                                            java.lang.String user,
                                                            java.lang.String password,
                                                            boolean requestPassword)
                                                     throws java.sql.SQLException
        Create and return an EmbedXAConnection from the received instance of BasicEmbeddedDataSource40.
        Throws:
        java.sql.SQLException
      • getPropertyInfo

        public java.sql.DriverPropertyInfo[] getPropertyInfo​(java.lang.String url,
                                                             java.util.Properties info)
                                                      throws java.sql.SQLException

        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.

        Specified by:
        getPropertyInfo in interface java.sql.Driver
        Parameters:
        url - The URL of the database to connect to.
        info - A proposed list of tag/value pairs that will be sent on connect open.
        Returns:
        An array of DriverPropertyInfo objects describing possible properties. This array may be an empty array if no properties are required.
        Throws:
        java.sql.SQLException - if a database-access error occurs.
      • connect

        public java.sql.Connection connect​(java.lang.String url,
                                           java.util.Properties info)
                                    throws java.sql.SQLException
        Specified by:
        connect in interface java.sql.Driver
        Throws:
        java.sql.SQLException
      • getParentLogger

        public java.util.logging.Logger getParentLogger()
                                                 throws java.sql.SQLFeatureNotSupportedException
        Specified by:
        getParentLogger in interface java.sql.Driver
        Throws:
        java.sql.SQLFeatureNotSupportedException
      • setDeregister

        static void setDeregister​(boolean deregister)
        Indicate to AutoloadedDriver whether it should deregister itself on shutdown.
        Parameters:
        deregister - whether or not AutoloadedDriver should deregister itself
      • getDeregister

        static boolean getDeregister()
        Check whether AutoloadedDriver should deregister itself on shutdown.
        Returns:
        the deregister value
      • getContextService

        private static ContextService getContextService()
        Privileged lookup of the ContextService. Must be private so that user code can't call this entry point.
      • getMonitor

        private static ModuleFactory getMonitor()
        Privileged Monitor lookup. Must be private so that user code can't call this entry point.
      • getSystemModule

        private static java.lang.Object getSystemModule​(java.lang.String factoryInterface)
        Privileged module lookup. Must be private so that user code can't call this entry point.
      • findService

        private static java.lang.Object findService​(java.lang.String factoryInterface,
                                                    java.lang.String serviceName)
        Privileged service lookup. Must be private so that user code can't call this entry point.