com.clarkparsia.stardog.api
Class ConnectionConfiguration

java.lang.Object
  extended by com.clarkparsia.stardog.api.ConnectionConfiguration
All Implemented Interfaces:
Copyable<ConnectionConfiguration>

public final class ConnectionConfiguration
extends Object
implements Copyable<ConnectionConfiguration>

Simple class to create connection strings, and connections, for Stardog.

Connection strings generally define where the Stardog server is, what database to connect to, and the parameters used when connecting. The parameters are ; delimited key-value pairs of the form key=value at the end of the URL. key's are expected to be all lowercase and values are case sensitive.

Since:
0.4.5
Version:
0.8
Author:
Michael Grove

Field Summary
static String DEFAULT_PASSWD
          Constant for username used to create a connection when no username or password is present
static String DEFAULT_USERNAME
          Constant for username used to create a connection when no username or password is present
static String PASSWD
          Constant for the password option
static String REASONING
          Constant for creating specifying the reasoning level of a connection
static String USERNAME
          Constant for the username option
static Set<String> VALID_PROPERTY_NAMES
          Set of all valid connection property names
 
Constructor Summary
ConnectionConfiguration()
           
 
Method Summary
static Connection at(String theConnectionString)
          Open a connection to the database specified directly by the connection string
static Connection at(String theConnectionString, Properties theProperties)
          Open a connection to the database specified directly by the connection string with the additional provided connection properties
 Connection connect()
          Open the connection to the database as described by this configuration
 ReasoningConnection connect(ReasoningType theReasoningType)
          Opens a reasoning connection to the database as described by this configuration and given reasoning type.
 ConnectionConfiguration copy()
          Make a copy of this ConnectionConfiguration.
 ConnectionConfiguration credentials(String theUser, String thePass)
          Specify the username and password that should be used to authenticate to the database
static ConnectionConfiguration from(String theConnectionString)
          Create a ConnectionConfiguration based on the full connection string.
 ConnectionConfiguration reasoning(ReasoningType theReasoningType)
          Specify the type of reasoning you would like the connection to utilize
static ConnectionConfiguration to(String theName)
          Create a new configuration object for connecting to the Stardog database with the provided name
 ConnectionConfiguration url(String theURL)
          Specify the URL of the database server
 ConnectionConfiguration with(Properties theProps)
          Use the key-value pairs in this dictionary as parameters to the connection
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USERNAME

public static final String USERNAME
Constant for the username option

See Also:
with(java.util.Properties), Constant Field Values

DEFAULT_USERNAME

public static final String DEFAULT_USERNAME
Constant for username used to create a connection when no username or password is present

See Also:
Constant Field Values

PASSWD

public static final String PASSWD
Constant for the password option

See Also:
with(java.util.Properties), Constant Field Values

DEFAULT_PASSWD

public static final String DEFAULT_PASSWD
Constant for username used to create a connection when no username or password is present

See Also:
Constant Field Values

REASONING

public static final String REASONING
Constant for creating specifying the reasoning level of a connection

See Also:
Constant Field Values

VALID_PROPERTY_NAMES

public static Set<String> VALID_PROPERTY_NAMES
Set of all valid connection property names

Constructor Detail

ConnectionConfiguration

public ConnectionConfiguration()
Method Detail

copy

public ConnectionConfiguration copy()
Make a copy of this ConnectionConfiguration.

Specified by:
copy in interface Copyable<ConnectionConfiguration>

credentials

public ConnectionConfiguration credentials(String theUser,
                                           String thePass)
Specify the username and password that should be used to authenticate to the database

Parameters:
theUser - the user
thePass - the pass
Returns:
this

at

public static Connection at(String theConnectionString)
                     throws StardogException
Open a connection to the database specified directly by the connection string

Parameters:
theConnectionString - the connection string
Returns:
a connection to the database
Throws:
StardogException - if there was an error while connecting

at

public static Connection at(String theConnectionString,
                            Properties theProperties)
                     throws StardogException
Open a connection to the database specified directly by the connection string with the additional provided connection properties

Parameters:
theConnectionString - the connection string
theProperties - additional connection properties
Returns:
the connection
Throws:
StardogException - if there is an error connecting to the specified repository

from

public static ConnectionConfiguration from(String theConnectionString)
Create a ConnectionConfiguration based on the full connection string. A ConnectionConfiguration is returned to give users the ability to change properties of the connection string before connecting, or to use to establish a connection pool.

Parameters:
theConnectionString - the connection string
Returns:
the configuration representing the connection string.

to

public static ConnectionConfiguration to(String theName)
Create a new configuration object for connecting to the Stardog database with the provided name

Parameters:
theName - the name
Returns:
a new connection configuration

reasoning

public ConnectionConfiguration reasoning(ReasoningType theReasoningType)
Specify the type of reasoning you would like the connection to utilize

Parameters:
theReasoningType - the type of reasoning
Returns:
this configuration

url

public ConnectionConfiguration url(String theURL)
Specify the URL of the database server

Parameters:
theURL - the db server URL
Returns:
this configuration

with

public ConnectionConfiguration with(Properties theProps)
Use the key-value pairs in this dictionary as parameters to the connection

Parameters:
theProps - the additional connection properties
Returns:
this object

connect

public Connection connect()
                   throws StardogException
Open the connection to the database as described by this configuration

Returns:
the connection
Throws:
StardogException - if there was an error while opening the connection

connect

public ReasoningConnection connect(ReasoningType theReasoningType)
                            throws StardogException
Opens a reasoning connection to the database as described by this configuration and given reasoning type. This function is equivalent reasoning(theReasoningType).connect().as(ReasoningConnection.class). This means passing ReasoningType.NONE as an argument will cause an exception.

Parameters:
theReasoningType - the type of reasoning
Returns:
the connection
Throws:
StardogException - if there was an error while opening the connection


Copyright © 2010-2013 Clark & Parsia. All Rights Reserved.