Class EmbeddedXADataSource

  • All Implemented Interfaces:
    java.io.Serializable, java.sql.Wrapper, javax.naming.Referenceable, javax.naming.spi.ObjectFactory, javax.sql.CommonDataSource, javax.sql.DataSource, javax.sql.XADataSource, EmbeddedDataSourceInterface, EmbeddedXADataSourceInterface
    Direct Known Subclasses:
    EmbeddedXADataSource40

    public class EmbeddedXADataSource
    extends EmbeddedDataSource
    implements EmbeddedXADataSourceInterface

    This data source is suitable for an application using embedded Derby, running on full Java SE 6 or higher, corresponding to JDBC 4.0 and higher. EmbeddedXADataSource is an XADataSource implementation.

    An XADataSource is a factory for XAConnection objects. It represents a RM in a DTP environment. An object that implements the XADataSource interface is typically registered with a JNDI service provider.

    EmbeddedXADataSource automatically supports the correct JDBC specification version for the Java Virtual Machine's environment.

    • JDBC 4.0 - Java SE 6
    • JDBC 4.1 - Java SE 7
    • JDBC 4.2 - full Java SE 8

    Use BasicEmbeddedXADataSource40 if your application runs on Java 8 Compact Profile 2.

    EmbeddedXADataSource object only works on a local database. There is no client/server support. An EmbeddedXADataSource object must live in the same jvm as the database.

    EmbeddedXADataSource is serializable and referenceable.

    See EmbeddedDataSource for DataSource properties.

    See Also:
    Serialized Form
    • Field Detail

      • ra

        private transient ResourceAdapter ra
        A cached link to the database, set up with the first connection is made.
    • Constructor Detail

      • EmbeddedXADataSource

        public EmbeddedXADataSource()
        no-arg constructor
    • Method Detail

      • getXAConnection

        public final javax.sql.XAConnection getXAConnection()
                                                     throws java.sql.SQLException
        Attempt to establish a database connection.
        Specified by:
        getXAConnection in interface javax.sql.XADataSource
        Returns:
        a Connection to the database
        Throws:
        java.sql.SQLException - if a database-access error occurs.
      • getXAConnection

        public final javax.sql.XAConnection getXAConnection​(java.lang.String user,
                                                            java.lang.String password)
                                                     throws java.sql.SQLException
        Attempt to establish a database connection with the given user name and password.
        Specified by:
        getXAConnection in interface javax.sql.XADataSource
        Parameters:
        user - the database user on whose behalf the Connection is being made
        password - the user's password
        Returns:
        a Connection to the database
        Throws:
        java.sql.SQLException - if a database-access error occurs.
      • createXAConnection

        private javax.sql.XAConnection createXAConnection​(ResourceAdapter ra,
                                                          java.lang.String user,
                                                          java.lang.String password,
                                                          boolean requestPassword)
                                                   throws java.sql.SQLException
        Instantiate and return an EmbedXAConnection from this instance of EmbeddedXADataSource.
        Parameters:
        ra - The resource adapter to the database
        user - The user name
        password - The password
        requestPassword -
        Returns:
        An XA connection to the database
        Throws:
        java.sql.SQLException