Connect to Linear Data from a Connection Pool in Jetty

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
The Linear JDBC Driver supports connection pooling: This article shows how to connect faster to Linear data from Web apps in Jetty.

The CData JDBC driver for Linear is easy to integrate with Java Web applications. This article shows how to efficiently connect to Linear data in Jetty by configuring the driver for connection pooling. You will configure a JNDI resource for Linear in Jetty.

Configure the JDBC Driver for Salesforce as a JNDI Data Source

Follow the steps below to connect to Salesforce from Jetty.

  1. Enable the JNDI module for your Jetty base. The following command enables JNDI from the command-line:

    
    java -jar ../start.jar --add-to-startd=jndi
    
  2. Add the CData and license file, located in the lib subfolder of the installation directory, into the lib subfolder of the context path.
  3. Declare the resource and its scope. Enter the required connection properties in the resource declaration. This example declares the Linear data source at the level of the Web app, in WEB-INF\jetty-env.xml.

    
    
    <Configure id='lineardemo' class="org.eclipse.jetty.webapp.WebAppContext">
        <New id="lineardemo" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg><Ref refid="lineardemo"/></Arg>
        <Arg>jdbc/lineardb</Arg>
        <Arg>
          <New class="cdata.jdbc.linear.LinearDriver">
            <Set name="url">jdbc:linear:</Set>
            <Set name="AuthScheme">APIKey</Set>
            <Set name="APIKey">myAPIKey</Set>
          </New>
        </Arg>
      </New>
    </Configure>
    

    You can authenticate to Linear with a personal API key or with OAuth 2.0. The API key is the simplest option for connecting with your own Linear account.

    Authenticating with an API Key

    Set the following connection properties:

    • AuthScheme: Set this to APIKey.
    • APIKey: A Linear personal API key.

    To create a personal API key, log in to Linear, open Settings > Security & access > Personal API keys, select New API key, and create it. Copy the key immediately, because Linear shows it only once.

    Authenticating with OAuth

    OAuth requires a custom OAuth application registered in Linear (Settings > API > OAuth applications), which provides the OAuthClientId and OAuthClientSecret. Two flows are supported:

    • Authorization code: Set AuthScheme to OAuth, InitiateOAuth to GETANDREFRESH, and provide OAuthClientId, OAuthClientSecret, and the CallbackURL defined in your application (e.g., http://localhost:33333). The driver opens Linear in your browser so you can grant access.
    • Client credentials: Set AuthScheme to OAuthClient and provide OAuthClientId and OAuthClientSecret. This authenticates the application itself, with no browser interaction, and suits machine-to-machine integrations.

    By default, the driver requests the read,write scopes. The driver refreshes the access token automatically when it expires.

  4. Configure the resource in the Web.xml:

    
    
      jdbc/lineardb
      javax.sql.DataSource
      Container
    
    
  5. You can then access Linear with a lookup to java:comp/env/jdbc/lineardb:

    
    InitialContext ctx = new InitialContext();
    DataSource mylinear = (DataSource)ctx.lookup("java:comp/env/jdbc/lineardb");
    

More Jetty Integration

The steps above show how to configure the driver in a simple connection pooling scenario. For more use cases and information, see the Working with Jetty JNDI chapter in the Jetty documentation.

Ready to get started?

Download a free trial of the Linear Driver to get started:

 Download Now

Learn more:

Linear Icon Linear JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Linear data including AgentSession, Comment, Customer, Cycle, Initiative, Integration, Issue, ProjectStatus, Release, Team, User, and more!