use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.
the class BaseBucketLoaderTest method failsWhenChildDiscoverFails.
@Test
void failsWhenChildDiscoverFails() {
BucketLoader loader = new BaseBucketLoader(core, SERVICE) {
@Override
protected Mono<byte[]> discoverConfig(NodeIdentifier seed, String bucket) {
return Mono.error(new CouchbaseException("Failed discovering for some reason"));
}
};
when(core.ensureServiceAt(eq(SEED), eq(SERVICE), eq(PORT), eq(Optional.of(BUCKET)), eq(Optional.empty()))).thenReturn(Mono.empty());
assertThrows(ConfigException.class, () -> loader.load(SEED, PORT, BUCKET, Optional.empty()).block());
}
use of com.couchbase.client.core.error.CouchbaseException in project connectors-se by Talend.
the class BinaryParser method parse.
@Override
public Record parse(Collection collection, String id) {
GetResult result;
try {
result = collection.get(id, GetOptions.getOptions().transcoder(RawBinaryTranscoder.INSTANCE));
} catch (TimeoutException | CouchbaseException e) {
LOG.error(e.getMessage());
throw new ComponentException(e.getMessage());
}
byte[] data = result.contentAs(byte[].class);
final Record.Builder recordBuilder = builderFactory.newRecordBuilder(schemaBinaryDocument);
recordBuilder.withString("id", id);
recordBuilder.withBytes("content", data);
return recordBuilder.build();
}
use of com.couchbase.client.core.error.CouchbaseException in project connectors-se by Talend.
the class CouchbaseOutput method onNext.
@ElementListener
public void onNext(@Input final Record rec) {
if (configuration.isUseN1QLQuery()) {
Map<String, String> mappings = configuration.getQueryParams().stream().collect(Collectors.toMap(N1QLQueryParameter::getColumn, N1QLQueryParameter::getQueryParameterName));
JsonObject namedParams = buildJsonObject(rec, mappings);
try {
cluster.query(configuration.getQuery(), QueryOptions.queryOptions().parameters(namedParams));
} catch (CouchbaseException ex) {
log.error("N1QL failed: {}.", ex.getMessage());
throw new ComponentException(ex.getMessage());
}
} else {
if (configuration.isPartialUpdate()) {
updatePartiallyDocument(rec);
} else {
if (configuration.getDataSet().getDocumentType() == DocumentType.BINARY) {
collection.upsert(rec.getString(idFieldName), rec.getBytes(CONTENT_FIELD_NAME), UpsertOptions.upsertOptions().transcoder(RawBinaryTranscoder.INSTANCE));
} else if (configuration.getDataSet().getDocumentType() == DocumentType.STRING) {
collection.upsert(rec.getString(idFieldName), rec.getString(CONTENT_FIELD_NAME), UpsertOptions.upsertOptions().transcoder(RawStringTranscoder.INSTANCE));
} else {
collection.upsert(rec.getString(idFieldName), buildJsonObjectWithoutId(rec));
}
}
}
}
use of com.couchbase.client.core.error.CouchbaseException in project connectors-se by Talend.
the class StringParser method parse.
@Override
public Record parse(Collection collection, String id) {
GetResult result;
try {
result = collection.get(id, GetOptions.getOptions().transcoder(RawStringTranscoder.INSTANCE));
} catch (CouchbaseException e) {
LOG.error(e.getMessage());
throw new ComponentException(e.getMessage());
}
String data = result.contentAs(String.class);
final Record.Builder recordBuilder = builderFactory.newRecordBuilder(schemaStringDocument);
recordBuilder.withString("id", id);
recordBuilder.withString("content", data);
return recordBuilder.build();
}
use of com.couchbase.client.core.error.CouchbaseException in project connectors-se by Talend.
the class CouchbaseInput method init.
@PostConstruct
public void init() {
Cluster cluster = service.openConnection(configuration.getDataSet().getDatastore());
Bucket bucket = cluster.bucket(configuration.getDataSet().getBucket());
collection = service.openDefaultCollection(cluster, configuration.getDataSet().getBucket());
if (configuration.isCreatePrimaryIndex()) {
cluster.queryIndexes().createPrimaryIndex(bucket.name(), CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions().ignoreIfExists(true));
}
columnsSet = new HashSet<>();
if (configuration.getSelectAction() == SelectAction.ANALYTICS) {
AnalyticsResult analyticsResult = null;
try {
analyticsResult = cluster.analyticsQuery(configuration.getQuery());
} catch (CouchbaseException e) {
LOG.error(i18n.queryResultError(e.getMessage()));
throw new ComponentException(i18n.queryResultError(e.getMessage()));
}
queryResultsIterator = analyticsResult.rowsAsObject().iterator();
} else {
// DSL API (Statement, AsPath classes etc. was deprecated, cannot use it anymore!)
// In most cases, a simple string statement is the best replacement.
QueryResult n1qlResult;
StringBuilder statementBuilder;
switch(configuration.getSelectAction()) {
case ALL:
statementBuilder = new StringBuilder();
statementBuilder.append("SELECT meta().id as `_meta_id_`, * FROM `").append(bucket.name()).append("`");
if (!configuration.getLimit().isEmpty()) {
statementBuilder.append(" LIMIT ").append(configuration.getLimit().trim());
}
n1qlResult = cluster.query(statementBuilder.toString());
break;
case N1QL:
/*
* should contain "meta().id as `_meta_id_`" field for non-json (binary) documents
*/
n1qlResult = cluster.query(configuration.getQuery());
break;
case ONE:
statementBuilder = new StringBuilder();
statementBuilder.append("SELECT meta().id as `_meta_id_`, * FROM `").append(bucket.name()).append("`");
statementBuilder.append(" USE KEYS \"").append(configuration.getDocumentId()).append("\"");
n1qlResult = cluster.query(statementBuilder.toString());
break;
default:
throw new ComponentException("Select action: '" + configuration.getSelectAction() + "' is unsupported");
}
queryResultsIterator = n1qlResult.rowsAsObject().iterator();
}
}
Aggregations