Search in sources :

Example 1 with ScanConsistency

use of com.couchbase.client.java.query.consistency.ScanConsistency in project teiid by teiid.

the class CouchbaseManagedConnectionFactory method createConnectionFactory.

@SuppressWarnings("serial")
@Override
public BasicConnectionFactory<CouchbaseConnectionImpl> createConnectionFactory() throws ResourceException {
    final CouchbaseEnvironment environment = DefaultCouchbaseEnvironment.builder().managementTimeout(managementTimeout).queryTimeout(queryTimeout).viewTimeout(viewTimeout).kvTimeout(kvTimeout).searchTimeout(searchTimeout).connectTimeout(connectTimeout).dnsSrvEnabled(dnsSrvEnabled).build();
    if (this.connectionString == null) {
        // $NON-NLS-1$
        throw new InvalidPropertyException(UTIL.getString("no_server"));
    }
    if (this.keyspace == null) {
        // $NON-NLS-1$
        throw new InvalidPropertyException(UTIL.getString("no_keyspace"));
    }
    if (this.namespace == null) {
        // $NON-NLS-1$
        throw new InvalidPropertyException(UTIL.getString("no_namespace"));
    }
    final ScanConsistency consistency = ScanConsistency.valueOf(scanConsistency);
    TimeUnit unit = TimeUnit.MILLISECONDS;
    if (this.timeUnit != null) {
        try {
            unit = TimeUnit.valueOf(timeUnit);
        } catch (IllegalArgumentException e) {
            // $NON-NLS-1$
            throw new InvalidPropertyException(UTIL.getString("invalid_timeUnit", timeUnit));
        }
    }
    final TimeUnit timeoutUnit = unit;
    return new BasicConnectionFactory<CouchbaseConnectionImpl>() {

        @Override
        public CouchbaseConnectionImpl getConnection() throws ResourceException {
            return new CouchbaseConnectionImpl(environment, connectionString, keyspace, password, timeoutUnit, namespace, consistency);
        }
    };
}
Also used : BasicConnectionFactory(org.teiid.resource.spi.BasicConnectionFactory) InvalidPropertyException(javax.resource.spi.InvalidPropertyException) ScanConsistency(com.couchbase.client.java.query.consistency.ScanConsistency) TimeUnit(java.util.concurrent.TimeUnit) DefaultCouchbaseEnvironment(com.couchbase.client.java.env.DefaultCouchbaseEnvironment) CouchbaseEnvironment(com.couchbase.client.java.env.CouchbaseEnvironment)

Aggregations

CouchbaseEnvironment (com.couchbase.client.java.env.CouchbaseEnvironment)1 DefaultCouchbaseEnvironment (com.couchbase.client.java.env.DefaultCouchbaseEnvironment)1 ScanConsistency (com.couchbase.client.java.query.consistency.ScanConsistency)1 TimeUnit (java.util.concurrent.TimeUnit)1 InvalidPropertyException (javax.resource.spi.InvalidPropertyException)1 BasicConnectionFactory (org.teiid.resource.spi.BasicConnectionFactory)1