io.helidon.dbclient.mongodb.MongoDbStatement Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of helidon-dbclient-mongodb Show documentation
Show all versions of helidon-dbclient-mongodb Show documentation
Helidon Database Client MongoDB Support
The newest version!
/*
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.dbclient.mongodb;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.helidon.dbclient.DbClientServiceContext;
import io.helidon.dbclient.DbExecuteContext;
import io.helidon.dbclient.DbIndexedStatementParameters;
import io.helidon.dbclient.DbNamedStatementParameters;
import io.helidon.dbclient.DbStatement;
import io.helidon.dbclient.DbStatementBase;
import io.helidon.dbclient.DbStatementParameters;
import io.helidon.dbclient.DbStatementType;
import com.mongodb.client.MongoDatabase;
import jakarta.json.Json;
import org.bson.Document;
import static io.helidon.dbclient.mongodb.MongoDbStatement.MongoOperation.COMMAND;
import static io.helidon.dbclient.mongodb.MongoDbStatement.MongoOperation.DELETE;
import static io.helidon.dbclient.mongodb.MongoDbStatement.MongoOperation.INSERT;
import static io.helidon.dbclient.mongodb.MongoDbStatement.MongoOperation.QUERY;
import static io.helidon.dbclient.mongodb.MongoDbStatement.MongoOperation.UPDATE;
/**
* Common MongoDB statement builder.
*
* @param type of subclass
*/
abstract class MongoDbStatement> extends DbStatementBase {
/**
* Empty JSON object.
*/
static final Document EMPTY = Document.parse(Json.createObjectBuilder().build().toString());
/**
* Operation JSON parameter name.
*/
protected static final String JSON_OPERATION = "operation";
/**
* Collection JSON parameter name.
*/
protected static final String JSON_COLLECTION = "collection";
/**
* Query JSON parameter name.
*/
protected static final String JSON_QUERY = "query";
/**
* Value JSON parameter name.
*/
protected static final String JSON_VALUE = "value";
/**
* Projection JSON parameter name: Defines projection to restrict returned fields.
*/
protected static final String JSON_PROJECTION = "projection";
private final MongoDatabase db;
/**
* Create a new instance.
*
* @param db MongoDb instance
* @param context context
*/
MongoDbStatement(MongoDatabase db, DbExecuteContext context) {
super(context);
this.db = db;
}
/**
* Get the mongo db instance.
*
* @return MongoDatabase
*/
MongoDatabase db() {
return db;
}
/**
* Prepare the statement string.
*
* @return prepared statement string
*/
String prepareStatement(DbClientServiceContext serviceContext) {
String statement = serviceContext.statement();
DbStatementParameters stmtParams = serviceContext.statementParameters();
if (stmtParams instanceof DbIndexedStatementParameters indexed) {
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy