index int64 | repo_id string | file_path string | content string |
|---|---|---|---|
0 | java-sources/ai/silot/taurus/taurus-sdk-java/1.0.0/ai/silot/taurus | java-sources/ai/silot/taurus/taurus-sdk-java/1.0.0/ai/silot/taurus/util/Method.java | package ai.silot.taurus.util;
public enum Method {
GET, POST, PUT, DELETE, PATCH
}
|
0 | java-sources/ai/silot/taurus/taurus-sdk-java/1.0.0/ai/silot/taurus | java-sources/ai/silot/taurus/taurus-sdk-java/1.0.0/ai/silot/taurus/util/TaurusHttpUtil.java | package ai.silot.taurus.util;
import ai.silot.taurus.config.Taurus;
import com.google.gson.Gson;
import java.io.IOException;
import java.lang.reflect.Type;
public class TaurusHttpUtil {
private static String getAuthorization() {
return "Basic " + Base64.encode(Taurus.apiKey + ":");
}
public static <T> T get(String url, Type type) throws IOException {
String response = HttpRequest.get(url)
.header("Authorization", getAuthorization())
.execute().body();
return new Gson().fromJson(response, type);
}
public static <T> T post(String url, Type type, String jsonBody) throws IOException {
String response = HttpRequest.post(url)
.header("Authorization", getAuthorization())
.body(jsonBody)
.execute().body();
return new Gson().fromJson(response, type);
}
}
|
0 | java-sources/ai/spice/spiceai/0.3.0/ai | java-sources/ai/spice/spiceai/0.3.0/ai/spice/Config.java | /*
Copyright 2024 The Spice.ai OSS Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package ai.spice;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Provides default configuration for Spice client.
*/
public class Config {
/** Cloud flight address */
public static final String CLOUD_FLIGHT_ADDRESS;
/** Local flight address */
public static final String LOCAL_FLIGHT_ADDRESS;
/** Cloud HTTP address */
public static final String CLOUD_HTTP_ADDRESS;
/** Local HTTP address */
public static final String LOCAL_HTTP_ADDRESS;
static {
CLOUD_FLIGHT_ADDRESS = System.getenv("SPICE_FLIGHT_URL") != null ? System.getenv("SPICE_FLIGHT_URL")
: "https://flight.spiceai.io:443";
LOCAL_FLIGHT_ADDRESS = System.getenv("SPICE_FLIGHT_URL") != null ? System.getenv("SPICE_FLIGHT_URL")
: "http://localhost:50051";
CLOUD_HTTP_ADDRESS = System.getenv("SPICE_HTTP_URL") != null ? System.getenv("SPICE_HTTP_URL")
: "https://data.spiceai.io";
LOCAL_HTTP_ADDRESS = System.getenv("SPICE_HTTP_URL") != null ? System.getenv("SPICE_HTTP_URL")
: "http://localhost:8090";
}
/**
* Returns the local flight address
*
* @return URI of the local flight address.
* @throws URISyntaxException if the string could not be parsed as a URI.
*/
public static URI getLocalFlightAddressUri() throws URISyntaxException {
return new URI(LOCAL_FLIGHT_ADDRESS);
}
/**
* Returns the cloud flight address
*
* @return URI of the cloud flight address.
* @throws URISyntaxException if the string could not be parsed as a URI.
*/
public static URI getCloudFlightAddressUri() throws URISyntaxException {
return new URI(CLOUD_FLIGHT_ADDRESS);
}
/**
* Returns the local HTTP address
*
* @return URI of the local HTTP address.
* @throws URISyntaxException if the string could not be parsed as a URI.
*/
public static URI getLocalHttpAddressUri() throws URISyntaxException {
return new URI(LOCAL_HTTP_ADDRESS);
}
/**
* Returns the cloud HTTP address
*
* @return URI of the cloud HTTP address.
* @throws URISyntaxException if the string could not be parsed as a URI.
*/
public static URI getCloudHttpAddressUri() throws URISyntaxException {
return new URI(CLOUD_HTTP_ADDRESS);
}
} |
0 | java-sources/ai/spice/spiceai/0.3.0/ai | java-sources/ai/spice/spiceai/0.3.0/ai/spice/SpiceClient.java | /*
Copyright 2024 The Spice.ai OSS Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package ai.spice;
import java.net.ConnectException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.concurrent.ExecutionException;
import org.apache.arrow.flight.CallStatus;
import org.apache.arrow.flight.FlightClient;
import org.apache.arrow.flight.FlightClient.Builder;
import org.apache.arrow.flight.FlightStream;
import org.apache.arrow.flight.Location;
import org.apache.arrow.flight.Ticket;
import org.apache.arrow.flight.auth2.BasicAuthCredentialWriter;
import org.apache.arrow.flight.auth2.ClientBearerHeaderHandler;
import org.apache.arrow.flight.auth2.ClientIncomingAuthHeaderMiddleware;
import org.apache.arrow.flight.grpc.CredentialCallOption;
import org.apache.arrow.flight.FlightInfo;
import org.apache.arrow.flight.FlightRuntimeException;
import org.apache.arrow.memory.RootAllocator;
import com.github.rholder.retry.RetryException;
import com.github.rholder.retry.Retryer;
import com.github.rholder.retry.RetryerBuilder;
import com.github.rholder.retry.StopStrategies;
import com.github.rholder.retry.WaitStrategies;
import com.google.common.base.Strings;
import org.apache.arrow.flight.sql.FlightSqlClient;
/**
* Client to execute SQL queries against Spice.ai Cloud and Spice.ai OSS
*/
public class SpiceClient implements AutoCloseable {
private String appId;
private String apiKey;
private URI flightAddress;
private URI httpAddress;
private int maxRetries;
private FlightSqlClient flightClient;
private CredentialCallOption authCallOptions = null;
/**
* Returns a new instance of SpiceClientBuilder
*
* @return A new SpiceClientBuilder instance
* @throws URISyntaxException if there is an error in constructing the URI
*/
public static SpiceClientBuilder builder() throws URISyntaxException {
return new SpiceClientBuilder();
}
/**
* Constructs a new SpiceClient instance with the specified parameters
*
* @param appId the application ID used to identify the client
* application
* @param apiKey the API key used for authentication with Spice.ai
* services
* @param flightAddress the URI of the flight address for connecting to Spice.ai
* services
* @param httpAddress the URI of the Spice.ai runtime HTTP address
*
* @param maxRetries the maximum number of connection retries for the client
*/
public SpiceClient(String appId, String apiKey, URI flightAddress, URI httpAddress, int maxRetries) {
this.appId = appId;
this.apiKey = apiKey;
this.maxRetries = maxRetries;
this.httpAddress = httpAddress;
// Arrow Flight requires URI to be grpc protocol, convert http/https for
// convinience
if (flightAddress.getScheme().equals("https")) {
this.flightAddress = URI.create("grpc+tls://" + flightAddress.getHost() + ":" + flightAddress.getPort());
} else if (flightAddress.getScheme().equals("http")) {
this.flightAddress = URI.create("grpc+tcp://" + flightAddress.getHost() + ":" + flightAddress.getPort());
} else {
this.flightAddress = flightAddress;
}
Builder builder = FlightClient.builder(new RootAllocator(Long.MAX_VALUE), new Location(this.flightAddress));
if (Strings.isNullOrEmpty(apiKey)) {
this.flightClient = new FlightSqlClient(builder.build());
return;
}
final ClientIncomingAuthHeaderMiddleware.Factory factory = new ClientIncomingAuthHeaderMiddleware.Factory(
new ClientBearerHeaderHandler());
final FlightClient client = builder.intercept(factory).build();
client.handshake(new CredentialCallOption(new BasicAuthCredentialWriter(this.appId, this.apiKey)));
this.authCallOptions = factory.getCredentialCallOption();
this.flightClient = new FlightSqlClient(client);
}
/**
* Executes a sql query
*
* @param sql the SQL query to execute
* @return a FlightStream with the query results
* @throws ExecutionException if there is an error executing the query
*/
public FlightStream query(String sql) throws ExecutionException {
if (Strings.isNullOrEmpty(sql)) {
throw new IllegalArgumentException("No SQL query provided");
}
try {
return this.queryInternalWithRetry(sql);
} catch (RetryException e) {
Throwable err = e.getLastFailedAttempt().getExceptionCause();
throw new ExecutionException("Failed to execute query due to error: " + err.toString(), err);
}
}
public void refresh(String dataset) throws ExecutionException {
if (Strings.isNullOrEmpty(dataset)) {
throw new IllegalArgumentException("No dataset name provided");
}
try {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(String.format("%s/v1/datasets/%s/acceleration/refresh", this.httpAddress, dataset)))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() != 201) {
throw new ExecutionException(
String.format("Failed to trigger dataset refresh. Status Code: %d, Response: %s",
response.statusCode(),
response.body()),
null);
}
} catch (ExecutionException e) {
// no need to wrap ExecutionException
throw e;
} catch (ConnectException err) {
throw new ExecutionException(
String.format("The Spice runtime is unavailable at %s. Is it running?", this.httpAddress), err);
} catch (Exception err) {
throw new ExecutionException("Failed to trigger dataset refresh due to error: " + err.toString(), err);
}
}
private FlightStream queryInternal(String sql) {
FlightInfo flightInfo = this.flightClient.execute(sql, authCallOptions);
Ticket ticket = flightInfo.getEndpoints().get(0).getTicket();
return this.flightClient.getStream(ticket, authCallOptions);
}
private FlightStream queryInternalWithRetry(String sql) throws ExecutionException, RetryException {
Retryer<FlightStream> retryer = RetryerBuilder.<FlightStream>newBuilder()
.retryIfException(throwable -> {
if (throwable instanceof FlightRuntimeException) {
FlightRuntimeException flightException = (FlightRuntimeException) throwable;
CallStatus status = flightException.status();
return shouldRetry(status);
}
return false;
})
.withWaitStrategy(WaitStrategies.fibonacciWait())
.withStopStrategy(StopStrategies.stopAfterAttempt(this.maxRetries + 1))
.build();
return retryer.call(() -> this.queryInternal(sql));
}
private boolean shouldRetry(CallStatus status) {
switch (status.code()) {
case UNAVAILABLE:
case UNKNOWN:
case TIMED_OUT:
case INTERNAL:
return true;
default:
return false;
}
}
@Override
public void close() throws Exception {
this.flightClient.close();
}
}
|
0 | java-sources/ai/spice/spiceai/0.3.0/ai | java-sources/ai/spice/spiceai/0.3.0/ai/spice/SpiceClientBuilder.java | /*
Copyright 2024 The Spice.ai OSS Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package ai.spice;
import java.net.URI;
import java.net.URISyntaxException;
import com.google.common.base.Strings;
/**
* Builder class for creating instances of SpiceClient.
*/
public class SpiceClientBuilder {
private String appId;
private String apiKey;
private URI flightAddress;
private URI httpAddress;
private int maxRetries = 3;
/**
* Constructs a new SpiceClientBuilder instance
*
* @throws URISyntaxException if the URI syntax is incorrect.
*/
SpiceClientBuilder() throws URISyntaxException {
this.flightAddress = Config.getLocalFlightAddressUri();
this.httpAddress = Config.getLocalHttpAddressUri();
}
/**
* Sets the client's flight address
*
* @param flightAddress The URI of the flight address
* @return The current instance of SpiceClientBuilder for method chaining.
*/
public SpiceClientBuilder withFlightAddress(URI flightAddress) {
if (flightAddress == null) {
throw new IllegalArgumentException("flightAddress can't be null");
}
this.flightAddress = flightAddress;
return this;
}
/**
* Sets the client's HTTP address
*
* @param httpAddress The URI of the HTTP address
* @return The current instance of SpiceClientBuilder for method chaining.
*/
public SpiceClientBuilder withHttpAddress(URI httpAddress) {
if (httpAddress == null) {
throw new IllegalArgumentException("httpAddress can't be null");
}
this.httpAddress = httpAddress;
return this;
}
/**
* Sets the client's Api Key.
*
* @param apiKey The Spice Cloud api key
* @return The current instance of SpiceClientBuilder for method chaining.
* @throws IllegalArgumentException Thrown when the apiKey is in wrong format.
*/
public SpiceClientBuilder withApiKey(String apiKey) {
if (Strings.isNullOrEmpty(apiKey)) {
throw new IllegalArgumentException("apiKey can't be null or empty");
}
String[] parts = apiKey.split("\\|");
if (parts.length != 2) {
throw new IllegalArgumentException("apiKey is invalid");
}
this.appId = parts[0];
this.apiKey = apiKey;
return this;
}
/**
* Sets the client's flight address to default Spice Cloud address.
*
* @return The current instance of SpiceClientBuilder for method chaining.
* @throws URISyntaxException Thrown when the URI syntax is incorrect.
*/
public SpiceClientBuilder withSpiceCloud() throws URISyntaxException {
this.flightAddress = Config.getCloudFlightAddressUri();
this.httpAddress = Config.getCloudHttpAddressUri();
return this;
}
/**
* Sets the maximum number of connection retries for the client.
*
* @param maxRetries The maximum number of connection retries
* @return The current instance of SpiceClientBuilder for method chaining.
*/
public SpiceClientBuilder withMaxRetries(int maxRetries) {
if (maxRetries < 0) {
throw new IllegalArgumentException("maxRetries must be greater than or equal to 0");
}
this.maxRetries = maxRetries;
return this;
}
/**
* Creates SpiceClient with provided parameters.
*
* @return The SpiceClient instance
*/
public SpiceClient build() {
return new SpiceClient(appId, apiKey, flightAddress, httpAddress, maxRetries);
}
} |
0 | java-sources/ai/spice/spiceai/0.3.0/ai/spice | java-sources/ai/spice/spiceai/0.3.0/ai/spice/example/ExampleDatasetRefreshSpiceOSS.java | /*
Copyright 2024 The Spice.ai OSS Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package ai.spice.example;
import java.net.URI;
import org.apache.arrow.flight.FlightStream;
import org.apache.arrow.vector.VectorSchemaRoot;
import ai.spice.SpiceClient;
/**
* Example of using SDK with Spice.ai OSS (Local)
* _JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED" mvn exec:java -Dexec.mainClass="ai.spice.example.ExampleDatasetRefreshSpiceOSS"
*
* Requires local Spice OSS running. Follow the quickstart
* https://github.com/spiceai/spiceai?tab=readme-ov-file#%EF%B8%8F-quickstart-local-machine.
*/
public class ExampleDatasetRefreshSpiceOSS {
public static void main(String[] args) {
try (SpiceClient client = SpiceClient.builder()
.withFlightAddress(URI.create("http://localhost:50051"))
.withHttpAddress(URI.create("http://localhost:8090"))
.build()) {
client.refresh("taxi_trips");
System.out.println("Dataset refresh triggered for taxi_trips");
System.out.println("Query taxi_trips dataset");
FlightStream stream = client.query("SELECT * FROM taxi_trips LIMIT 1;");
while (stream.next()) {
try (VectorSchemaRoot batches = stream.getRoot()) {
System.out.println(batches.contentToTSVString());
}
}
} catch (Exception e) {
System.err.println("An unexpected error occurred: " + e.getMessage());
}
}
}
|
0 | java-sources/ai/spice/spiceai/0.3.0/ai/spice | java-sources/ai/spice/spiceai/0.3.0/ai/spice/example/ExampleSpiceCloudPlatform.java | /*
Copyright 2024 The Spice.ai OSS Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package ai.spice.example;
import org.apache.arrow.flight.FlightStream;
import org.apache.arrow.vector.VectorSchemaRoot;
import ai.spice.SpiceClient;
/**
* Example of using Spice.ai client to query data from Spice.ai Cloud
* _JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED" mvn exec:java -Dexec.mainClass="ai.spice.example.ExampleSpiceCloudPlatform"
*/
public class ExampleSpiceCloudPlatform {
// Create free Spice.ai account to obtain API_KEY: https://spice.ai/login
final static String API_KEY = "api-key";
public static void main(String[] args) {
try (SpiceClient client = SpiceClient.builder()
.withApiKey(API_KEY)
.withSpiceCloud()
.build()) {
FlightStream stream = client.query("SELECT * FROM eth.recent_blocks LIMIT 10;");
while (stream.next()) {
try (VectorSchemaRoot batches = stream.getRoot()) {
System.out.println(batches.contentToTSVString());
}
}
} catch (Exception e) {
System.err.println("An unexpected error occurred: " + e.getMessage());
}
}
}
|
0 | java-sources/ai/spice/spiceai/0.3.0/ai/spice | java-sources/ai/spice/spiceai/0.3.0/ai/spice/example/ExampleSpiceOSS.java | /*
Copyright 2024 The Spice.ai OSS Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package ai.spice.example;
import org.apache.arrow.flight.FlightStream;
import org.apache.arrow.vector.VectorSchemaRoot;
import ai.spice.SpiceClient;
/**
* Example of using SDK with Spice.ai OSS (Local)
* _JAVA_OPTIONS="--add-opens=java.base/java.nio=ALL-UNNAMED" mvn exec:java -Dexec.mainClass="ai.spice.example.ExampleSpiceOSS"
*
* Requires local Spice OSS running. Follow the quickstart
* https://github.com/spiceai/spiceai?tab=readme-ov-file#%EF%B8%8F-quickstart-local-machine.
*/
public class ExampleSpiceOSS {
public static void main(String[] args) {
try (SpiceClient client = SpiceClient.builder()
.build()) {
FlightStream stream = client.query("SELECT * FROM taxi_trips LIMIT 10;");
while (stream.next()) {
try (VectorSchemaRoot batches = stream.getRoot()) {
System.out.println(batches.contentToTSVString());
}
}
} catch (Exception e) {
System.err.println("An unexpected error occurred: " + e.getMessage());
}
}
}
|
0 | java-sources/ai/stainless/micronaut-jupyter/0.2.1/ai/stainless/micronaut/jupyter | java-sources/ai/stainless/micronaut-jupyter/0.2.1/ai/stainless/micronaut/jupyter/kernel/ClosableKernelSocketsZMQ.java | package ai.stainless.micronaut.jupyter.kernel;
/*
* Customized KernelSockets implementation that can be shutdown programmatically.
* Uses implementation of KernelSocketsZMQ in BeakerX project.
* License from BeakerX pasted below.
*/
/*
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
*
* 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.
*/
import com.twosigma.beakerx.handler.Handler;
import com.twosigma.beakerx.kernel.Config;
import com.twosigma.beakerx.kernel.KernelFunctionality;
import com.twosigma.beakerx.kernel.KernelSockets;
import com.twosigma.beakerx.kernel.SocketCloseAction;
import com.twosigma.beakerx.kernel.msg.JupyterMessages;
import com.twosigma.beakerx.message.Header;
import com.twosigma.beakerx.message.Message;
import com.twosigma.beakerx.message.MessageSerializer;
import com.twosigma.beakerx.security.HashedMessageAuthenticationCode;
import com.twosigma.beakerx.socket.MessageParts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zeromq.ZFrame;
import org.zeromq.ZMQ;
import org.zeromq.ZMsg;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import static com.twosigma.beakerx.kernel.msg.JupyterMessages.SHUTDOWN_REPLY;
import static com.twosigma.beakerx.kernel.msg.JupyterMessages.SHUTDOWN_REQUEST;
import static com.twosigma.beakerx.message.MessageSerializer.toJson;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
public class ClosableKernelSocketsZMQ extends KernelSockets {
public static final Logger logger = LoggerFactory.getLogger(ClosableKernelSocketsZMQ.class);
public static final String DELIM = "<IDS|MSG>";
private KernelFunctionality kernel;
private SocketCloseAction closeAction;
private HashedMessageAuthenticationCode hmac;
private ZMQ.Socket hearbeatSocket;
private ZMQ.Socket controlSocket;
private ZMQ.Socket shellSocket;
private ZMQ.Socket iopubSocket;
private ZMQ.Socket stdinSocket;
private ZMQ.Poller sockets;
private ZMQ.Context context;
private boolean shutdownSystem = false;
public ClosableKernelSocketsZMQ(KernelFunctionality kernel, Config configuration, SocketCloseAction closeAction) {
this.closeAction = closeAction;
this.kernel = kernel;
this.hmac = new HashedMessageAuthenticationCode(configuration.getKey());
this.context = ZMQ.context(1);
configureSockets(configuration);
}
private void configureSockets(Config configuration) {
final String connection = configuration.getTransport() + "://" + configuration.getHost();
hearbeatSocket = getNewSocket(ZMQ.REP, configuration.getHeartbeat(), connection, context);
iopubSocket = getNewSocket(ZMQ.PUB, configuration.getIopub(), connection, context);
controlSocket = getNewSocket(ZMQ.ROUTER, configuration.getControl(), connection, context);
stdinSocket = getNewSocket(ZMQ.ROUTER, configuration.getStdin(), connection, context);
shellSocket = getNewSocket(ZMQ.ROUTER, configuration.getShell(), connection, context);
sockets = new ZMQ.Poller(4);
sockets.register(controlSocket, ZMQ.Poller.POLLIN);
sockets.register(hearbeatSocket, ZMQ.Poller.POLLIN);
sockets.register(shellSocket, ZMQ.Poller.POLLIN);
sockets.register(stdinSocket, ZMQ.Poller.POLLIN);
}
public void publish(List<Message> message) {
sendMsg(this.iopubSocket, message);
}
public void send(Message message) {
sendMsg(this.shellSocket, singletonList(message));
}
public String sendStdIn(Message message) {
sendMsg(this.stdinSocket, singletonList(message));
return handleStdIn();
}
private synchronized void sendMsg(ZMQ.Socket socket, List<Message> messages) {
if (!isShutdown()) {
messages.forEach(message -> {
String header = toJson(message.getHeader());
String parent = toJson(message.getParentHeader());
String meta = toJson(message.getMetadata());
String content = toJson(message.getContent());
String digest = hmac.sign(Arrays.asList(header, parent, meta, content));
ZMsg newZmsg = new ZMsg();
message.getIdentities().forEach(newZmsg::add);
newZmsg.add(DELIM);
newZmsg.add(digest.getBytes(StandardCharsets.UTF_8));
newZmsg.add(header.getBytes(StandardCharsets.UTF_8));
newZmsg.add(parent.getBytes(StandardCharsets.UTF_8));
newZmsg.add(meta.getBytes(StandardCharsets.UTF_8));
newZmsg.add(content.getBytes(StandardCharsets.UTF_8));
message.getBuffers().forEach(x -> newZmsg.add(x));
newZmsg.send(socket);
});
}
}
private Message readMessage(ZMQ.Socket socket) {
ZMsg zmsg = null;
Message message = null;
try {
zmsg = ZMsg.recvMsg(socket);
ZFrame[] parts = new ZFrame[zmsg.size()];
zmsg.toArray(parts);
byte[] uuid = parts[MessageParts.UUID].getData();
byte[] header = parts[MessageParts.HEADER].getData();
byte[] parent = parts[MessageParts.PARENT].getData();
byte[] metadata = parts[MessageParts.METADATA].getData();
byte[] content = parts[MessageParts.CONTENT].getData();
byte[] expectedSig = parts[MessageParts.HMAC].getData();
verifyDelim(parts[MessageParts.DELIM]);
verifySignatures(expectedSig, header, parent, metadata, content);
message = new Message(parse(header, Header.class));
if (uuid != null) {
message.getIdentities().add(uuid);
}
message.setParentHeader(parse(parent, Header.class));
message.setMetadata(parse(metadata, LinkedHashMap.class));
message.setContent(parse(content, LinkedHashMap.class));
} finally {
if (zmsg != null) {
zmsg.destroy();
}
}
return message;
}
@Override
public void run() {
try {
while (!this.isShutdown()) {
sockets.poll(1000);
if (isControlMsg()) {
handleControlMsg();
} else if (isHeartbeatMsg()) {
handleHeartbeat();
} else if (isShellMsg()) {
handleShell();
} else if (isStdinMsg()) {
handleStdIn();
} else if (this.isShutdown()) {
break;
}
}
} catch (Exception e) {
throw new RuntimeException(e);
} catch (Error e) {
logger.error(e.toString());
} finally {
close();
}
}
private String handleStdIn() {
Message msg = readMessage(stdinSocket);
return (String) msg.getContent().get("value");
}
private void handleShell() {
Message message = readMessage(shellSocket);
Handler<Message> handler = kernel.getHandler(message.type());
if (handler != null) {
handler.handle(message);
}
}
private void handleHeartbeat() {
byte[] buffer = hearbeatSocket.recv(0);
hearbeatSocket.send(buffer);
}
private void handleControlMsg() {
Message message = readMessage(controlSocket);
JupyterMessages type = message.getHeader().getTypeEnum();
if (type.equals(SHUTDOWN_REQUEST)) {
Message reply = new Message(new Header(SHUTDOWN_REPLY, message.getHeader().getSession()));
reply.setParentHeader(message.getHeader());
reply.setContent(message.getContent());
sendMsg(controlSocket, Collections.singletonList(reply));
shutdown();
}
}
private ZMQ.Socket getNewSocket(int type, int port, String connection, ZMQ.Context context) {
ZMQ.Socket socket = context.socket(type);
socket.bind(connection + ":" + String.valueOf(port));
return socket;
}
private void close() {
closeAction.close();
closeSockets();
}
private void closeSockets() {
try {
if (shellSocket != null) {
shellSocket.close();
}
if (controlSocket != null) {
controlSocket.close();
}
if (iopubSocket != null) {
iopubSocket.close();
}
if (stdinSocket != null) {
stdinSocket.close();
}
if (hearbeatSocket != null) {
hearbeatSocket.close();
}
context.close();
} catch (Exception e) {
}
}
private void verifySignatures(byte[] expectedSig, byte[] header, byte[] parent, byte[] metadata, byte[] content) {
String actualSig = hmac.signBytes(new ArrayList<>(asList(header, parent, metadata, content)));
String expectedSigAsString = new String(expectedSig, StandardCharsets.UTF_8);
if (!expectedSigAsString.equals(actualSig)) {
throw new RuntimeException("Signatures do not match.");
}
}
private String verifyDelim(ZFrame zframe) {
String delim = new String(zframe.getData(), StandardCharsets.UTF_8);
if (!DELIM.equals(delim)) {
throw new RuntimeException("Delimiter <IDS|MSG> not found");
}
return delim;
}
private boolean isStdinMsg() {
return sockets.pollin(3);
}
private boolean isShellMsg() {
return sockets.pollin(2);
}
private boolean isHeartbeatMsg() {
return sockets.pollin(1);
}
private boolean isControlMsg() {
return sockets.pollin(0);
}
public void shutdown() {
logger.debug("kernel shutdown");
this.shutdownSystem = true;
}
private boolean isShutdown() {
return this.shutdownSystem;
}
private <T> T parse(byte[] bytes, Class<T> theClass) {
return bytes != null ? MessageSerializer.parse(new String(bytes, StandardCharsets.UTF_8), theClass) : null;
}
}
/*
* End BeakerX implementation.
*/
|
0 | java-sources/ai/stainless/micronaut-jupyter/0.2.1/ai/stainless/micronaut/jupyter | java-sources/ai/stainless/micronaut-jupyter/0.2.1/ai/stainless/micronaut/jupyter/kernel/KernelExitException.java | package ai.stainless.micronaut.jupyter.kernel;
public class KernelExitException extends Exception {
public KernelExitException (String msg) {
super(msg);
}
public KernelExitException(String msg, Throwable cause) {
super(msg, cause);
}
}
|
0 | java-sources/ai/stainless/micronaut-jupyter/0.2.1/ai/stainless/micronaut/jupyter | java-sources/ai/stainless/micronaut-jupyter/0.2.1/ai/stainless/micronaut/jupyter/kernel/PublicGroovyCodeRunner.java | package ai.stainless.micronaut.jupyter.kernel;
/*
* Customized GroovyCodeRunner implementation that is public.
* Uses implementation of GroovyCodeRunner in BeakerX project.
* License from BeakerX pasted below.
*/
/*
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
*
* 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.
*/
import com.twosigma.beakerx.TryResult;
import com.twosigma.beakerx.evaluator.Evaluator;
import com.twosigma.beakerx.groovy.evaluator.GroovyEvaluator;
import com.twosigma.beakerx.jvm.object.SimpleEvaluationObject;
import groovy.lang.Script;
import org.codehaus.groovy.runtime.StackTraceUtils;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.Callable;
import static com.twosigma.beakerx.evaluator.BaseEvaluator.INTERUPTED_MSG;
import static com.twosigma.beakerx.groovy.evaluator.GroovyStackTracePrettyPrinter.printStacktrace;
public class PublicGroovyCodeRunner implements Callable<TryResult> {
public static final String SCRIPT_NAME = "script";
private GroovyEvaluator groovyEvaluator;
private final String theCode;
private final SimpleEvaluationObject theOutput;
public PublicGroovyCodeRunner(GroovyEvaluator groovyEvaluator, String code, SimpleEvaluationObject out) {
this.groovyEvaluator = groovyEvaluator;
theCode = code;
theOutput = out;
}
@Override
public TryResult call() {
ClassLoader oldld = Thread.currentThread().getContextClassLoader();
TryResult either;
String scriptName = SCRIPT_NAME;
try {
Object result = null;
theOutput.setOutputHandler();
Thread.currentThread().setContextClassLoader(groovyEvaluator.getGroovyClassLoader());
scriptName += System.currentTimeMillis();
Class<?> parsedClass = groovyEvaluator.getGroovyClassLoader().parseClass(theCode, scriptName);
if (canBeInstantiated(parsedClass)) {
Object instance = parsedClass.newInstance();
if (instance instanceof Script) {
result = runScript((Script) instance);
}
}
either = TryResult.createResult(result);
} catch (Throwable e) {
either = handleError(scriptName, e);
} finally {
theOutput.clrOutputHandler();
Thread.currentThread().setContextClassLoader(oldld);
}
return either;
}
private TryResult handleError(String scriptName, Throwable e) {
TryResult either;
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
if (e instanceof InterruptedException || e instanceof InvocationTargetException || e instanceof ThreadDeath) {
either = TryResult.createError(INTERUPTED_MSG);
} else {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
StackTraceUtils.sanitize(e).printStackTrace(pw);
String value = sw.toString();
value = printStacktrace(scriptName, value);
either = TryResult.createError(value);
}
return either;
}
private Object runScript(Script script) {
groovyEvaluator.getScriptBinding().setVariable(Evaluator.BEAKER_VARIABLE_NAME, groovyEvaluator.getBeakerX());
script.setBinding(groovyEvaluator.getScriptBinding());
return script.run();
}
private boolean canBeInstantiated(Class<?> parsedClass) {
return !parsedClass.isEnum();
}
}
|
0 | java-sources/ai/stainless/micronaut-jupyter/0.2.1/ai/stainless/micronaut/jupyter | java-sources/ai/stainless/micronaut-jupyter/0.2.1/ai/stainless/micronaut/jupyter/kernel/TrackableKernelSocketsFactory.java | package ai.stainless.micronaut.jupyter.kernel;
/*
* Customized KernelSocketsFactory implementation that tracks and stores the
* instances it creates.
* Uses implementation of KernelSocketsFactoryImpl in BeakerX project.
* License from BeakerX pasted below.
*/
/*
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
*
* 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.
*/
import com.twosigma.beakerx.kernel.*;
import java.util.ArrayList;
import static com.twosigma.beakerx.util.Preconditions.checkNotNull;
public class TrackableKernelSocketsFactory implements KernelSocketsFactory {
private ConfigurationFile configurationFile;
private ArrayList<KernelSockets> instances = new ArrayList<>();
public TrackableKernelSocketsFactory(ConfigurationFile configurationFile) {
this.configurationFile = checkNotNull(configurationFile);
}
public KernelSockets create(final KernelFunctionality kernel, final SocketCloseAction closeAction) {
// create new ZMQ sockets instance
KernelSockets sockets = new ClosableKernelSocketsZMQ(kernel, configurationFile.getConfig(), closeAction);
// store this instance for later tracking
instances.add(sockets);
// return this instance
return sockets;
}
public ArrayList<KernelSockets> getInstances() {
return instances;
}
}
|
0 | java-sources/ai/stainless/micronaut-jupyter/0.2.1/ai/stainless/micronaut/jupyter | java-sources/ai/stainless/micronaut-jupyter/0.2.1/ai/stainless/micronaut/jupyter/kernel/UnexpectedExitException.java | package ai.stainless.micronaut.jupyter.kernel;
public class UnexpectedExitException extends SecurityException {
public UnexpectedExitException (String msg) {
super(msg);
}
public UnexpectedExitException(String msg, Throwable cause) {
super(msg, cause);
}
}
|
0 | java-sources/ai/stapi/arango-axon/0.0.2/ai/stapi | java-sources/ai/stapi/arango-axon/0.0.2/ai/stapi/arangoaxon/ArangoCommandMessageStore.java | package ai.stapi.arangoaxon;
import ai.stapi.axonsystem.commandpersisting.CommandMessageStore;
import ai.stapi.axonsystem.commandpersisting.PersistedCommandMessage;
import com.arangodb.ArangoCollection;
import com.arangodb.ArangoDB;
import com.arangodb.serde.jackson.Key;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.axonframework.commandhandling.CommandMessage;
public class ArangoCommandMessageStore implements CommandMessageStore {
public static final String COMMAND_COLLECTION_NAME = "persistedCommandMessage";
private final ArangoDB arangoDB;
public ArangoCommandMessageStore(ArangoDB arangoDB) {
this.arangoDB = arangoDB;
var collection = this.arangoDB.db().collection(COMMAND_COLLECTION_NAME);
if (!collection.exists()) {
this.arangoDB.db().createCollection(COMMAND_COLLECTION_NAME);
}
}
@Override
public void storeCommand(CommandMessage<?> commandMessage) {
var collection = this.getCommandCollection();
if (!collection.exists()) {
this.arangoDB.db().createCollection(COMMAND_COLLECTION_NAME);
}
var identifier = this.extractId(commandMessage);
var payload = this.extractPayload(commandMessage);
collection.insertDocument(
new ArangoPersistedCommandMessage<>(
identifier,
commandMessage.getCommandName(),
payload,
new HashMap<>(commandMessage.getMetaData())
)
);
}
@Override
public List<PersistedCommandMessage<?>> getAll() {
var db = arangoDB.db();
var cursor = db.query(
"FOR c IN " + COMMAND_COLLECTION_NAME + " RETURN c",
ArangoPersistedCommandMessage.class
);
var result = new ArrayList<PersistedCommandMessage<?>>();
cursor.stream().forEach(result::add);
return result;
}
@Override
public void wipeAll() {
var db = arangoDB.db();
var collection = this.getCommandCollection();
if (collection.exists()) {
db.query(
"FOR c IN " + COMMAND_COLLECTION_NAME + " REMOVE c IN " + COMMAND_COLLECTION_NAME,
ArangoPersistedCommandMessage.class
);
}
}
private ArangoCollection getCommandCollection() {
var db = this.arangoDB.db();
return db.collection(COMMAND_COLLECTION_NAME);
}
private static class ArangoPersistedCommandMessage<T> implements PersistedCommandMessage<T> {
@Key
@JsonIgnore
private String key;
private String targetAggregateIdentifier;
private String commandName;
private T commandPayload;
private Map<String, Object> commandMetaData;
protected ArangoPersistedCommandMessage() {
}
public ArangoPersistedCommandMessage(
String targetAggregateIdentifier,
String commandName,
T commandPayload,
Map<String, Object> commandMetaData
) {
this.targetAggregateIdentifier = targetAggregateIdentifier;
this.commandName = commandName;
this.commandPayload = commandPayload;
this.commandMetaData = commandMetaData;
}
@JsonIgnore
@JsonProperty("_key")
public String getKey() {
return key;
}
public T getCommandPayload() {
return commandPayload;
}
public String getCommandName() {
return commandName;
}
public Map<String, Object> getCommandMetaData() {
return commandMetaData;
}
public String getTargetAggregateIdentifier() {
return targetAggregateIdentifier;
}
}
}
|
0 | java-sources/ai/stapi/arango-axon/0.0.2/ai/stapi | java-sources/ai/stapi/arango-axon/0.0.2/ai/stapi/arangoaxon/ArangoTokenStore.java | package ai.stapi.arangoaxon;
import com.arangodb.ArangoDB;
import com.arangodb.serde.jackson.Key;
import java.lang.management.ManagementFactory;
import java.util.Map;
import org.axonframework.eventhandling.TrackingToken;
import org.axonframework.eventhandling.tokenstore.TokenStore;
import org.axonframework.serialization.Serializer;
import org.axonframework.serialization.SimpleSerializedObject;
import org.axonframework.serialization.SimpleSerializedType;
import org.jetbrains.annotations.NotNull;
public class ArangoTokenStore implements TokenStore {
public static final String TOKEN_COLLECTION_NAME = "axonTrackingToken";
private final ArangoDB arangoDB;
private final Serializer serializer;
public ArangoTokenStore(ArangoDB arangoDB, Serializer serializer) {
this.arangoDB = arangoDB;
this.serializer = serializer;
var collection = this.arangoDB.db().collection(TOKEN_COLLECTION_NAME);
if (!collection.exists()) {
this.arangoDB.db().createCollection(TOKEN_COLLECTION_NAME);
}
}
private static String getCurrentOwnerName() {
return ManagementFactory.getRuntimeMXBean().getName();
}
@NotNull
private static SimpleSerializedObject<byte[]> createSimpleSerializedObject(
byte[] serializedToken) {
return new SimpleSerializedObject<>(
serializedToken, byte[].class,
new SimpleSerializedType(
TrackingToken.class.getCanonicalName(),
null
)
);
}
@Override
public void storeToken(TrackingToken token, String processorName, int segment) {
// Use the arangoDB Java driver to store the token in the database
var db = arangoDB.db();
var key = this.createKey(processorName, segment);
byte[] serializedToken = null;
if (token != null) {
serializedToken = this.serializer.serialize(token, byte[].class).getData();
}
var arangoToken = new Token(
key,
serializedToken,
processorName,
segment,
getCurrentOwnerName()
);
if (db.collection(TOKEN_COLLECTION_NAME).documentExists(key)) {
db.collection(TOKEN_COLLECTION_NAME).replaceDocument(key, arangoToken);
return;
}
db.collection(TOKEN_COLLECTION_NAME).insertDocument(arangoToken);
}
@Override
public TrackingToken fetchToken(String processorName, int segment) {
// Use the arangoDB Java driver to fetch the token from the database
var db = arangoDB.db();
var key = this.createKey(processorName, segment);
var token = db.collection(TOKEN_COLLECTION_NAME).getDocument(
key,
Token.class
);
if (token != null) {
token.setOwner(getCurrentOwnerName());
db.collection(TOKEN_COLLECTION_NAME).replaceDocument(key, token);
var serializedToken = token.getSerializedToken();
return serializedToken == null ? null
: this.serializer.deserialize(createSimpleSerializedObject(serializedToken));
}
return null;
}
@Override
public void releaseClaim(String processorName, int segment) {
// Use the arangoDB Java driver to release the claim for the token in the database
var db = arangoDB.db();
var key = this.createKey(processorName, segment);
var token = db.collection(TOKEN_COLLECTION_NAME).getDocument(
key,
Token.class
);
token.setOwner(null);
db.collection(TOKEN_COLLECTION_NAME).replaceDocument(token.getKey(), token);
}
@Override
public int[] fetchSegments(String processorName) {
var db = arangoDB.db();
var cursor = db.query(
"FOR t IN " + TOKEN_COLLECTION_NAME
+ " FILTER t.processorName == @processorName RETURN t.segment",
Integer.class,
Map.of("processorName", processorName)
);
return cursor.stream().mapToInt(segment -> segment).toArray();
}
private String createKey(String processorName, int segment) {
return processorName + "_" + segment;
}
private static class Token {
@Key
protected String key;
private byte[] serializedToken;
private String processorName;
private Integer segment;
private String owner;
protected Token() {
}
public Token(String key, byte[] serializedToken, String processorName, Integer segment,
String owner) {
this.key = key;
this.serializedToken = serializedToken;
this.processorName = processorName;
this.segment = segment;
this.owner = owner;
}
public String getProcessorName() {
return processorName;
}
public void setProcessorName(String processorName) {
this.processorName = processorName;
}
public Integer getSegment() {
return segment;
}
public void setSegment(Integer segment) {
this.segment = segment;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public byte[] getSerializedToken() {
return serializedToken;
}
public void setSerializedToken(byte[] serializedToken) {
this.serializedToken = serializedToken;
}
}
} |
0 | java-sources/ai/stapi/arango-axon/0.0.2/ai/stapi/arangoaxon | java-sources/ai/stapi/arango-axon/0.0.2/ai/stapi/arangoaxon/configuration/ArangoAxonConfiguration.java | package ai.stapi.arangoaxon.configuration;
import ai.stapi.arangoaxon.ArangoCommandMessageStore;
import ai.stapi.arangoaxon.ArangoTokenStore;
import com.arangodb.ArangoDB;
import org.axonframework.serialization.Serializer;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
@AutoConfiguration
public class ArangoAxonConfiguration {
@Bean
public ArangoTokenStore arangoTokenStore(ArangoDB arangoDB, Serializer serializer) {
return new ArangoTokenStore(arangoDB, serializer);
}
@Bean
public ArangoCommandMessageStore arangoCommandMessageStore(ArangoDB arangoDB) {
return new ArangoCommandMessageStore(arangoDB);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/ArangoAttributeVersion.java | package ai.stapi.arangograph;
import ai.stapi.graphoperations.serializableGraph.SerializableAttributeValue;
import java.util.List;
import java.util.Map;
public class ArangoAttributeVersion {
private final List<SerializableAttributeValue> values;
private final Map<String, Object> metaData;
public ArangoAttributeVersion(
List<SerializableAttributeValue> values,
Map<String, Object> metaData
) {
this.values = values;
this.metaData = metaData;
}
public List<SerializableAttributeValue> getValues() {
return values;
}
public Map<String, Object> getMetaData() {
return metaData;
}
@Override
public String toString() {
return "ArangoAttributeVersion{"
+ "values=" + values
+ ", metaData=" + metaData
+ '}';
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/ArangoEdgeRepository.java | package ai.stapi.arangograph;
import ai.stapi.graph.EdgeRepository;
import ai.stapi.graph.EdgeTypeInfo;
import ai.stapi.graph.NodeIdAndType;
import ai.stapi.graph.exceptions.EdgeNotFound;
import ai.stapi.graph.exceptions.EdgeWithSameIdAndTypeAlreadyExists;
import ai.stapi.graph.exceptions.OneOrBothNodesOnEdgeDoesNotExist;
import ai.stapi.graph.graphElementForRemoval.EdgeForRemoval;
import ai.stapi.graph.graphelements.Edge;
import ai.stapi.graph.traversableGraphElements.TraversableEdge;
import ai.stapi.identity.UniqueIdentifier;
import com.arangodb.ArangoCollection;
import com.arangodb.ArangoCursor;
import com.arangodb.ArangoDB;
import com.arangodb.ArangoDBException;
import com.arangodb.entity.BaseDocument;
import com.arangodb.entity.BaseEdgeDocument;
import com.arangodb.entity.CollectionType;
import com.arangodb.model.CollectionCreateOptions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
public class ArangoEdgeRepository implements EdgeRepository {
private static final String EDGE_TYPES_COLLECTION_NAME = "edge_types";
private static final String ATTRIBUTE_COUNT = "count";
private final ArangoDB arangoDb;
private final ArangoNodeRepository nodeRepository;
public ArangoEdgeRepository(
ArangoDB arangoDb,
ArangoNodeRepository nodeRepository
) {
this.arangoDb = arangoDb;
this.nodeRepository = nodeRepository;
}
@Override
public void save(Edge edge) {
if (!this.nodeRepository.nodeExists(
edge.getNodeFromId(),
edge.getNodeFromType()
) || !this.nodeRepository.nodeExists(
edge.getNodeToId(),
edge.getNodeToType()
)) {
throw new OneOrBothNodesOnEdgeDoesNotExist(edge);
}
ArangoCollection collection = this.getEdgeCollection(edge.getType());
if (this.edgeExists(edge.getId(), edge.getType())) {
throw new EdgeWithSameIdAndTypeAlreadyExists(edge.getId().getId(), edge.getType());
}
collection.insertDocument(edge);
ArangoCollection edgeTypesCollection = this.getEdgeTypesCollection();
var typeRecord = arangoDb.db()
.collection(EDGE_TYPES_COLLECTION_NAME)
.getDocument(edge.getType(), BaseDocument.class);
if (typeRecord != null) {
typeRecord.updateAttribute(ATTRIBUTE_COUNT,
Integer.parseInt(typeRecord.getAttribute(ATTRIBUTE_COUNT).toString()) + 1
);
edgeTypesCollection.replaceDocument(edge.getType(), typeRecord);
} else {
typeRecord = new BaseDocument(edge.getType());
typeRecord.addAttribute(ATTRIBUTE_COUNT, 1);
edgeTypesCollection.insertDocument(typeRecord);
}
}
@Override
public TraversableEdge loadEdge(
UniqueIdentifier id,
String type
) {
var baseDocument = this.arangoDb.db()
.collection(type)
.getDocument(id.toString(), Edge.class);
if (baseDocument == null) {
throw new EdgeNotFound(id, type);
}
return TraversableEdge.from(baseDocument, this.nodeRepository);
}
@Override
public boolean edgeExists(
UniqueIdentifier id,
String type
) {
var baseDocument = this.arangoDb.db()
.collection(type)
.getDocument(id.toString(), Edge.class);
return baseDocument != null;
}
@Override
public void replace(Edge edge) {
ArangoCollection collection = this.getEdgeCollection(edge.getType());
collection.deleteDocument(edge.getId().getId());
collection.insertDocument(edge);
}
@Override
public void removeEdge(
UniqueIdentifier edgeId,
String edgeType
) {
ArangoCollection collection = this.getEdgeCollection(edgeType);
if (!collection.documentExists(edgeId.toString())) {
return;
}
collection.deleteDocument(edgeId.toString());
}
@Override
public void removeEdge(EdgeForRemoval edgeForRemoval) {
this.removeEdge(edgeForRemoval.getGraphElementId(), edgeForRemoval.getGraphElementType());
}
@Override
public List<EdgeTypeInfo> getEdgeTypeInfos() {
var bindParameters = new HashMap<String, Object>();
bindParameters.put("@collection", EDGE_TYPES_COLLECTION_NAME);
var query = "FOR doc IN @@collection\n RETURN doc\n";
ArangoCursor<BaseDocument> arangoCursorIterator;
try {
arangoCursorIterator = this.arangoDb.db().query(query, BaseDocument.class, bindParameters);
} catch (ArangoDBException e) {
return new ArrayList<>();
}
return arangoCursorIterator.stream()
.map(baseDocument -> new EdgeTypeInfo(baseDocument.getKey(),
Long.parseLong(baseDocument.getAttribute(ATTRIBUTE_COUNT).toString())
))
.collect(Collectors.toList());
}
@Override
public Set<TraversableEdge> findInAndOutEdgesForNode(
UniqueIdentifier nodeId,
String nodeType
) {
var edges = new HashSet<TraversableEdge>();
this.getEdgeTypeInfos().forEach(edgeTypeInfo -> {
var collection = this.arangoDb.db().collection(edgeTypeInfo.getType());
if (!collection.exists()) {
return;
}
var bindParameters = new HashMap<String, Object>();
bindParameters.put("@collection", edgeTypeInfo.getType());
bindParameters.put("node", nodeType + "/" + nodeId.toString());
var query = "FOR e IN @@collection\nFILTER e._from == @node || e._to == @node\nRETURN e";
var arangoCursorIterator = this.arangoDb.db()
.query(query, BaseEdgeDocument.class, bindParameters);
while (arangoCursorIterator.hasNext()) {
var document = arangoCursorIterator.next();
edges.add(this.loadEdge(new UniqueIdentifier(document.getKey()), edgeTypeInfo.getType()));
}
});
return edges;
}
@Override
public TraversableEdge findEdgeByTypeAndNodes(
String edgeType,
NodeIdAndType nodeFrom,
NodeIdAndType nodeTo
) {
var collection = this.arangoDb.db().collection(edgeType);
if (!collection.exists()) {
return null;
}
var bindParameters = new HashMap<String, Object>();
bindParameters.put("@collection", edgeType);
bindParameters.put("nodeFrom", nodeFrom.getType() + "/" + nodeFrom.getId().toString());
bindParameters.put("nodeTo", nodeTo.getType() + "/" + nodeTo.getId().toString());
var query = "FOR e IN @@collection\nFILTER e._from == @nodeFrom && e._to == @nodeTo\nRETURN e";
var arangoCursorIterator = this.arangoDb.db().query(query, BaseDocument.class, bindParameters);
if (arangoCursorIterator.hasNext()) {
var document = arangoCursorIterator.next();
return this.loadEdge(new UniqueIdentifier(document.getKey()), edgeType);
}
return null;
}
@NotNull
private ArangoCollection getEdgeCollection(String edgeType) {
var collection = this.arangoDb.db().collection(edgeType);
if (!collection.exists()) {
this.arangoDb.db()
.createCollection(edgeType, new CollectionCreateOptions().type(CollectionType.EDGES));
}
return collection;
}
private ArangoCollection getEdgeTypesCollection() {
var collection = this.arangoDb.db().collection(EDGE_TYPES_COLLECTION_NAME);
if (!collection.exists()) {
this.arangoDb.db().createCollection(EDGE_TYPES_COLLECTION_NAME);
}
return collection;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/ArangoNodeRepository.java | package ai.stapi.arangograph;
import ai.stapi.graph.NodeInfo;
import ai.stapi.graph.NodeRepository;
import ai.stapi.graph.NodeTypeInfo;
import ai.stapi.graph.exceptions.NodeNotFound;
import ai.stapi.graph.exceptions.NodeWithSameIdAndTypeAlreadyExists;
import ai.stapi.graph.graphElementForRemoval.NodeForRemoval;
import ai.stapi.graph.graphelements.Node;
import ai.stapi.graph.traversableGraphElements.TraversableNode;
import ai.stapi.identity.UniqueIdentifier;
import com.arangodb.ArangoCollection;
import com.arangodb.ArangoDB;
import com.arangodb.ArangoDBException;
import com.arangodb.entity.BaseDocument;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
public class ArangoNodeRepository implements NodeRepository {
public static final String NODE_TYPES_COLLECTION_NAME = "node_types";
public static final String ATTRIBUTE_COUNT = "count";
private final ArangoDB arangoDb;
private final ArangoEdgeRepository edgeRepository;
public ArangoNodeRepository(
ArangoDB arangoDb,
ArangoEdgeRepository edgeRepository
) {
this.arangoDb = arangoDb;
this.edgeRepository = edgeRepository;
}
private static void insertDocumentToCollection(
Node node,
ArangoCollection nodeTypesCollection
) {
try {
nodeTypesCollection.insertDocument(node);
} catch (Exception exception) {
throw new RuntimeException(
String.format(
"Unable to insert document:\nnode type:\n%s\nid:\n%s",
node.getType(),
node.getId()
),
exception
);
}
}
@Override
public void save(Node node) {
ArangoCollection collection = this.getNodeCollection(node.getType());
if (this.nodeExists(node.getId(), node.getType())) {
throw new NodeWithSameIdAndTypeAlreadyExists(node.getId(), node.getType());
}
this.insertDocumentToCollection(
node,
collection
);
ArangoCollection nodeTypesCollection = this.getNodeTypesCollection();
var typeRecord = arangoDb.db()
.collection(NODE_TYPES_COLLECTION_NAME)
.getDocument(node.getType(), BaseDocument.class);
if (typeRecord != null) {
typeRecord.updateAttribute(
ATTRIBUTE_COUNT,
Integer.parseInt(typeRecord.getAttribute(ATTRIBUTE_COUNT).toString()) + 1
);
nodeTypesCollection.replaceDocument(node.getType(), typeRecord);
} else {
typeRecord = new BaseDocument(node.getType());
typeRecord.addAttribute(ATTRIBUTE_COUNT, 1);
nodeTypesCollection.insertDocument(typeRecord);
}
}
@Override
public void replace(Node node) {
ArangoCollection collection = getNodeCollection(node.getType());
collection.deleteDocument(node.getId().getId());
collection.insertDocument(node);
}
@Override
public void removeNode(
UniqueIdentifier id,
String nodeType
) {
ArangoCollection collection = getNodeCollection(nodeType);
if (!collection.documentExists(id.toString())) {
return;
}
edgeRepository.findInAndOutEdgesForNode(id, nodeType)
.forEach(traversableEdge -> edgeRepository.removeEdge(
traversableEdge.getId(),
traversableEdge.getType()
));
collection.deleteDocument(id.toString());
ArangoCollection nodeTypesCollection = this.getNodeTypesCollection();
var typeRecord =
arangoDb.db()
.collection(NODE_TYPES_COLLECTION_NAME)
.getDocument(nodeType, BaseDocument.class);
if (typeRecord != null) {
typeRecord.updateAttribute(ATTRIBUTE_COUNT,
Integer.parseInt(typeRecord.getAttribute("count").toString()) - 1
);
nodeTypesCollection.replaceDocument(nodeType, typeRecord);
}
}
@Override
public void removeNode(NodeForRemoval nodeForRemoval) {
this.removeNode(nodeForRemoval.getGraphElementId(), nodeForRemoval.getGraphElementType());
}
@Override
public boolean nodeExists(
UniqueIdentifier id,
String nodeType
) {
var baseDocument =
this.arangoDb.db()
.collection(nodeType)
.getDocument( id.toString(), BaseDocument.class);
return baseDocument != null;
}
@Override
public TraversableNode loadNode(
UniqueIdentifier uuid,
String nodeType
) {
var baseDocument = this.arangoDb.db()
.collection(nodeType)
.getDocument(uuid.toString(), Node.class);
if (baseDocument == null) {
throw new NodeNotFound(uuid, nodeType);
}
return TraversableNode.from(baseDocument, edgeRepository);
}
@Override
public List<NodeTypeInfo> getNodeTypeInfos() {
var bindParameters = new HashMap<String, Object>();
bindParameters.put("@collection", NODE_TYPES_COLLECTION_NAME);
var query = "FOR doc IN @@collection\n" + " RETURN doc\n";
var arangoCursorIterator = this.arangoDb.db().query(
query,
BaseDocument.class,
bindParameters
);
return arangoCursorIterator.stream().map(baseDocument -> new NodeTypeInfo(
baseDocument.getKey(),
Long.parseLong(baseDocument.getAttribute(ATTRIBUTE_COUNT).toString())
)).collect(Collectors.toList());
}
@Override
public List<NodeInfo> getNodeInfosBy(String nodeType) {
var bindParameters = new HashMap<String, Object>();
bindParameters.put("@collection", nodeType);
var query = "FOR doc IN @@collection\n" + " RETURN doc\n";
var arangoCursorIterator = this.arangoDb.db().query(
query,
Node.class,
bindParameters
);
return arangoCursorIterator.stream().map(baseDocument -> {
var node = TraversableNode.from(baseDocument, this.edgeRepository);
var name = node.getSortingNameWithNodeTypeFallback();
return new NodeInfo(new UniqueIdentifier(baseDocument.getId().getId()), nodeType, name);
}).sorted(Comparator.comparing(NodeInfo::getName)).collect(Collectors.toList());
}
public int getNodeHashCodeWithoutEdges(
UUID uuid,
String nodeType
) {
// TODO
return 0;
}
@NotNull
private ArangoCollection getNodeCollection(String nodeType) {
var collection = this.arangoDb.db().collection(nodeType);
if (!collection.exists()) {
this.arangoDb.db().createCollection(nodeType);
}
return collection;
}
@NotNull
private ArangoCollection getNodeTypesCollection() {
return this.getNodeTypesCollection(5);
}
@NotNull
private ArangoCollection getNodeTypesCollection(int retries) {
var collection = this.arangoDb.db().collection(NODE_TYPES_COLLECTION_NAME);
if (!collection.exists()) {
try {
this.arangoDb.db().createCollection(NODE_TYPES_COLLECTION_NAME);
collection = this.arangoDb.db().collection(NODE_TYPES_COLLECTION_NAME);
} catch (ArangoDBException e) {
if (retries < 1) {
throw new ArangoDBException("Arango cannot initialize collection. Is it running?");
}
return this.getNodeTypesCollection(retries - 1);
}
}
return collection;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/configuration/ArangoConfigurationProperties.java | package ai.stapi.arangograph.configuration;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("arango.arangodb")
public class ArangoConfigurationProperties {
private String host = "127.0.0.1";
private String user;
private String password;
private String port = "8529";
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/configuration/ArangoDBConfiguration.java | package ai.stapi.arangograph.configuration;
import ai.stapi.graphoperations.serializableGraph.jackson.SerializableGraphConfigurer;
import ai.stapi.serialization.jackson.JavaTimeConfigurer;
import ai.stapi.serialization.jackson.SerializableObjectConfigurer;
import com.arangodb.ArangoDB;
import com.arangodb.ContentType;
import com.arangodb.serde.jackson.JacksonSerde;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@AutoConfiguration
@EnableConfigurationProperties({ArangoConfigurationProperties.class})
public class ArangoDBConfiguration {
private final ArangoConfigurationProperties arangoConfigurationProperties;
public ArangoDBConfiguration(ArangoConfigurationProperties arangoConfigurationProperties) {
this.arangoConfigurationProperties = arangoConfigurationProperties;
}
@Bean
public ArangoDB arangoDB(JacksonSerde serde) {
var port = this.arangoConfigurationProperties.getPort();
return new ArangoDB.Builder()
.serde(serde)
.host(
this.arangoConfigurationProperties.getHost(),
Integer.parseInt(port)
)
.user(this.arangoConfigurationProperties.getUser())
.password(this.arangoConfigurationProperties.getPassword())
.build();
}
@Bean
public JacksonSerde jacksonSerde(
@Autowired SerializableObjectConfigurer serializableObjectConfigurer,
@Autowired SerializableGraphConfigurer serializableGraphConfigurer
) {
var serde = JacksonSerde.of(ContentType.JSON);
serde.configure(
mapper -> {
serializableObjectConfigurer.configure(mapper);
serializableGraphConfigurer.configure(mapper);
JavaTimeConfigurer.configureJavaTimeModule(mapper);
}
);
return serde;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/configuration/ArangoGraphLoaderConfiguration.java | package ai.stapi.arangograph.configuration;
import ai.stapi.arangograph.ArangoEdgeRepository;
import ai.stapi.arangograph.ArangoNodeRepository;
import ai.stapi.arangograph.graphLoader.ArangoGraphLoader;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver.ArangoEdgeCollectionSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver.ArangoEdgeGetSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver.ArangoGraphTraversalSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver.ArangoNodeCollectionSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver.ArangoNodeGetSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver.ArangoSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver.GenericSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoQueryBuilderProvider;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoAllMatchFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoAndFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoAnyMatchFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoAscendingSortOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoContainsFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoDescendingSortOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoEndsWithFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoEqualsFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGreaterThanFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGreaterThanOrEqualFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoLowerThanFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoLowerThanOrEqualFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoNoneMatchFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoNotEqualsFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoNotFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoOffsetPaginationOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoOrFilterOptionResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoStartsWithFilterOptionResolver;
import ai.stapi.graphoperations.graphLoader.graphLoaderOGMFactory.GraphLoaderOgmFactory;
import ai.stapi.graphoperations.graphLoader.search.GenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLoader.search.SearchOptionResolver;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import com.arangodb.ArangoDB;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
@AutoConfiguration
public class ArangoGraphLoaderConfiguration {
@Bean
public ArangoGraphLoader arangoGraphLoader(
ArangoDB arangoDb,
ArangoEdgeRepository arangoEdgeRepository,
ArangoNodeRepository arangoNodeRepository,
ArangoQueryBuilderProvider arangoQueryBuilderProvider,
GenericSubQueryResolver genericSubQueryResolver,
ObjectMapper objectMapper,
GraphLoaderOgmFactory graphLoaderOgmFactory
) {
return new ArangoGraphLoader(
arangoDb,
arangoEdgeRepository,
arangoNodeRepository,
arangoQueryBuilderProvider,
genericSubQueryResolver,
objectMapper,
graphLoaderOgmFactory
);
}
@Bean
@ConditionalOnBean(ArangoGraphLoader.class)
public ArangoQueryBuilderProvider arangoQueryBuilderProvider(
ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder
) {
return new ArangoQueryBuilderProvider(
arangoGenericSearchOptionResolver,
structureSchemaFinder
);
}
@Bean
@ConditionalOnBean(ArangoGraphLoader.class)
public GenericSubQueryResolver genericSubQueryResolver(
List<ArangoSubQueryResolver> subQueryResolvers
) {
return new GenericSubQueryResolver(subQueryResolvers);
}
@Bean
@ConditionalOnBean(ArangoGraphLoader.class)
public ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver(
List<SearchOptionResolver<ArangoQuery>> searchOptionResolvers
) {
return new ArangoGenericSearchOptionResolver(searchOptionResolvers);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoAllMatchFilterOptionResolver arangoAllMatchFilterOptionResolver(
StructureSchemaFinder structureSchemaFinder,
@Lazy GenericSearchOptionResolver<ArangoQuery> genericFilterOptionResolver
) {
return new ArangoAllMatchFilterOptionResolver(structureSchemaFinder, genericFilterOptionResolver);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoAnyMatchFilterOptionResolver arangoAnyMatchFilterOptionResolver(
StructureSchemaFinder structureSchemaFinder,
@Lazy GenericSearchOptionResolver<ArangoQuery> genericFilterOptionResolver
) {
return new ArangoAnyMatchFilterOptionResolver(structureSchemaFinder, genericFilterOptionResolver);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoNoneMatchFilterOptionResolver arangoNoneMatchFilterOptionResolver(
StructureSchemaFinder structureSchemaFinder,
@Lazy GenericSearchOptionResolver<ArangoQuery> genericFilterOptionResolver
) {
return new ArangoNoneMatchFilterOptionResolver(structureSchemaFinder, genericFilterOptionResolver);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoAndFilterOptionResolver arangoAndFilterOptionResolver(
StructureSchemaFinder structureSchemaFinder,
@Lazy GenericSearchOptionResolver<ArangoQuery> genericFilterOptionResolver
) {
return new ArangoAndFilterOptionResolver(structureSchemaFinder, genericFilterOptionResolver);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoOrFilterOptionResolver arangoOrFilterOptionResolver(
StructureSchemaFinder structureSchemaFinder,
@Lazy GenericSearchOptionResolver<ArangoQuery> genericFilterOptionResolver
) {
return new ArangoOrFilterOptionResolver(structureSchemaFinder, genericFilterOptionResolver);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoNotFilterOptionResolver arangoNotFilterOptionResolver(
StructureSchemaFinder structureSchemaFinder,
@Lazy GenericSearchOptionResolver<ArangoQuery> genericFilterOptionResolver
) {
return new ArangoNotFilterOptionResolver(structureSchemaFinder, genericFilterOptionResolver);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoAscendingSortOptionResolver arangoAscendingSortOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOGMFactory
) {
return new ArangoAscendingSortOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOGMFactory
);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoContainsFilterOptionResolver arangoContainsFilterOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOGMFactory
) {
return new ArangoContainsFilterOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOGMFactory
);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoDescendingSortOptionResolver arangoDescendingSortOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOGMFactory
) {
return new ArangoDescendingSortOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOGMFactory
);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoEndsWithFilterOptionResolver arangoEndsWithFilterOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOGMFactory
) {
return new ArangoEndsWithFilterOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOGMFactory
);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoEqualsFilterOptionResolver arangoEqualsFilterOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOGMFactory
) {
return new ArangoEqualsFilterOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOGMFactory
);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoGreaterThanFilterOptionResolver arangoGreaterThanFilterOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOGMFactory
) {
return new ArangoGreaterThanFilterOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOGMFactory
);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoGreaterThanOrEqualFilterOptionResolver arangoGreaterThanOrEqualFilterOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOGMFactory
) {
return new ArangoGreaterThanOrEqualFilterOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOGMFactory
);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoLowerThanFilterOptionResolver arangoLowerThanFilterOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOGMFactory
) {
return new ArangoLowerThanFilterOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOGMFactory
);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoLowerThanOrEqualFilterOptionResolver arangoLowerThanOrEqualFilterOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOGMFactory
) {
return new ArangoLowerThanOrEqualFilterOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOGMFactory
);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoStartsWithFilterOptionResolver arangoStartsWithFilterOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOGMFactory
) {
return new ArangoStartsWithFilterOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOGMFactory
);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoNotEqualsFilterOptionResolver arangoNotEqualsFilterOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOGMFactory
) {
return new ArangoNotEqualsFilterOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOGMFactory
);
}
@Bean
@ConditionalOnBean(ArangoGenericSearchOptionResolver.class)
public ArangoOffsetPaginationOptionResolver arangoOffsetPaginationOptionResolver(
@Lazy ArangoGenericSearchOptionResolver arangoGenericSearchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
GenericSubQueryResolver genericSubQueryResolver,
GraphLoaderOgmFactory graphLoaderOgmFactory
) {
return new ArangoOffsetPaginationOptionResolver(
arangoGenericSearchOptionResolver,
structureSchemaFinder,
genericSubQueryResolver,
graphLoaderOgmFactory
);
}
@Bean
@ConditionalOnBean(GenericSubQueryResolver.class)
public ArangoEdgeCollectionSubQueryResolver arangoEdgeCollectionSubQueryResolver(
@Lazy GenericSubQueryResolver genericSubQueryResolver
) {
return new ArangoEdgeCollectionSubQueryResolver(genericSubQueryResolver);
}
@Bean
@ConditionalOnBean(GenericSubQueryResolver.class)
public ArangoNodeCollectionSubQueryResolver arangoNodeCollectionSubQueryResolver(
@Lazy GenericSubQueryResolver genericSubQueryResolver
) {
return new ArangoNodeCollectionSubQueryResolver(genericSubQueryResolver);
}
@Bean
@ConditionalOnBean(GenericSubQueryResolver.class)
public ArangoEdgeGetSubQueryResolver arangoEdgeGetSubQueryResolver(
@Lazy GenericSubQueryResolver genericSubQueryResolver
) {
return new ArangoEdgeGetSubQueryResolver(genericSubQueryResolver);
}
@Bean
@ConditionalOnBean(GenericSubQueryResolver.class)
public ArangoGraphTraversalSubQueryResolver arangoGraphTraversalSubQueryResolver(
@Lazy GenericSubQueryResolver genericSubQueryResolver
) {
return new ArangoGraphTraversalSubQueryResolver(genericSubQueryResolver);
}
@Bean
@ConditionalOnBean(GenericSubQueryResolver.class)
public ArangoNodeGetSubQueryResolver arangoNodeGetSubQueryResolver(
@Lazy GenericSubQueryResolver genericSubQueryResolver
) {
return new ArangoNodeGetSubQueryResolver(genericSubQueryResolver);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/configuration/ArangoRepositoryConfiguration.java | package ai.stapi.arangograph.configuration;
import ai.stapi.arangograph.ArangoEdgeRepository;
import ai.stapi.arangograph.ArangoNodeRepository;
import ai.stapi.arangograph.repositorypruner.ArangoRepositoryPruner;
import ai.stapi.graph.repositorypruner.RepositoryPruner;
import com.arangodb.ArangoDB;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
@AutoConfiguration
public class ArangoRepositoryConfiguration {
@Bean
public ArangoNodeRepository arangoNodeRepository(
ArangoDB arangoDb,
@Lazy ArangoEdgeRepository arangoEdgeRepository
) {
return new ArangoNodeRepository(arangoDb, arangoEdgeRepository);
}
@Bean
public ArangoEdgeRepository arangoEdgeRepository(
ArangoDB arangoDB,
ArangoNodeRepository arangoNodeRepository
) {
return new ArangoEdgeRepository(arangoDB, arangoNodeRepository);
}
@Bean
public RepositoryPruner arangoRepositoryPruner(ArangoDB arangoDB) {
return new ArangoRepositoryPruner(arangoDB);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/exceptions/CannotDeserializeArangoDocument.java | package ai.stapi.arangograph.exceptions;
import ai.stapi.arangograph.ArangoAttributeVersion;
import ai.stapi.graphoperations.serializableGraph.GraphElementKeys;
import java.util.List;
import java.util.Map;
public class CannotDeserializeArangoDocument extends RuntimeException {
protected CannotDeserializeArangoDocument(String message) {
super("Cannot deserialize Arango Document, because " + message);
}
public static CannotDeserializeArangoDocument becauseDocumentDoesNotContainAttributesProperty(
String id,
String graphElementType,
Map<String, Object> properties
) {
return new CannotDeserializeArangoDocument(
"document does not contain property with key: "
+ GraphElementKeys.ATTRIBUTES
+ "\nProvided Id: " + id
+ "\nProvided graph element type: " + graphElementType
+ "\nActual properties: " + properties
);
}
public static CannotDeserializeArangoDocument becauseAttributesPropertyIsNotCorrectType(
String id,
String graphElementType,
Object uncasedAttributes
) {
return new CannotDeserializeArangoDocument(
"attributes property is not Map: "
+ "\nProvided Id: " + id
+ "\nProvided graph element type: " + graphElementType
+ "\nActual attributes: " + uncasedAttributes
);
}
public static CannotDeserializeArangoDocument becauseAttributeWasNotList(
String id,
String graphElementType,
String attributeName,
Object attributeValues
) {
return new CannotDeserializeArangoDocument(
"attribute was not list: "
+ "\nProvided Id: " + id
+ "\nProvided graph element type: " + graphElementType
+ "\nAttribute name: " + attributeName
+ "\nActual attribute values: " + attributeValues
);
}
public static CannotDeserializeArangoDocument becauseAttributeNameWasNotString(
String id,
String graphElementType,
Object attributeName
) {
return new CannotDeserializeArangoDocument(
"attribute was not list: "
+ "\nProvided Id: " + id
+ "\nProvided graph element type: " + graphElementType
+ "\nActual attribute name: " + attributeName
);
}
public static CannotDeserializeArangoDocument becauseAttributeVersionWasNotOfCorrectType(
String id,
String graphElementType,
String stringAttributeName,
Object arangoAttributeVersion
) {
return new CannotDeserializeArangoDocument(
"attribute version was not of type: " + ArangoAttributeVersion.class.getSimpleName()
+ "\nProvided Id: " + id
+ "\nProvided graph element type: " + graphElementType
+ "\nAttribute name: " + stringAttributeName
+ "\nActual attribute version: " + arangoAttributeVersion
);
}
public static CannotDeserializeArangoDocument becauseAttributeVersionValuesWasNotOfCorrectType(
String id,
String graphElementType,
String stringAttributeName,
Object arangoAttributeVersion
) {
return new CannotDeserializeArangoDocument(
"attribute version values was not of type: " + List.class.getSimpleName()
+ "\nProvided Id: " + id
+ "\nProvided graph element type: " + graphElementType
+ "\nAttribute name: " + stringAttributeName
+ "\nActual attribute version: " + arangoAttributeVersion
);
}
public static CannotDeserializeArangoDocument becauseAttributeVersionValueWasNotOfCorrectType(
String id,
String graphElementType,
String stringAttributeName,
Object arangoAttributeVersionValue
) {
return new CannotDeserializeArangoDocument(
"attribute version value was not of type: " + Map.class.getSimpleName()
+ "\nProvided Id: " + id
+ "\nProvided graph element type: " + graphElementType
+ "\nAttribute name: " + stringAttributeName
+ "\nActual attribute version value: " + arangoAttributeVersionValue
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/ArangoGraphLoader.java | package ai.stapi.arangograph.graphLoader;
import ai.stapi.arangograph.ArangoEdgeRepository;
import ai.stapi.arangograph.ArangoNodeRepository;
import ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver.GenericSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects.ArangoEdgeFindDocument;
import ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects.ArangoEdgeGetDocument;
import ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects.ArangoNodeFindDocument;
import ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects.ArangoNodeGetDocument;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoEdgeCollectionSubQueryBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoEdgeGetSubQueryBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoQueryBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoQueryBuilderProvider;
import ai.stapi.graph.RepositoryEdgeLoader;
import ai.stapi.graph.graphelements.Edge;
import ai.stapi.graph.graphelements.Node;
import ai.stapi.graph.inMemoryGraph.InMemoryGraphRepository;
import ai.stapi.graph.traversableGraphElements.TraversableEdge;
import ai.stapi.graph.traversableGraphElements.TraversableGraphElement;
import ai.stapi.graph.traversableGraphElements.TraversableNode;
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractEdgeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractNodeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.EdgeDescriptionParameters;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.NodeDescriptionParameters;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.query.GraphElementQueryDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.query.NodeQueryGraphDescription;
import ai.stapi.graphoperations.graphLoader.GraphLoader;
import ai.stapi.graphoperations.graphLoader.GraphLoaderFindAsObjectOutput;
import ai.stapi.graphoperations.graphLoader.GraphLoaderGetAsObjectOutput;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import ai.stapi.graphoperations.graphLoader.exceptions.GraphLoaderException;
import ai.stapi.graphoperations.graphLoader.graphLoaderOGMFactory.GraphLoaderOgmFactory;
import ai.stapi.identity.UniqueIdentifier;
import com.arangodb.ArangoDB;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.NotNull;
public class ArangoGraphLoader implements GraphLoader {
private final ArangoDB arangoDb;
private final ArangoEdgeRepository arangoEdgeRepository;
private final ArangoNodeRepository arangoNodeRepository;
private final ArangoQueryBuilderProvider arangoQueryBuilderProvider;
private final GenericSubQueryResolver genericSubQueryResolver;
private final ObjectMapper objectMapper;
private final GraphLoaderOgmFactory graphLoaderOgmFactory;
public ArangoGraphLoader(
ArangoDB arangoDb,
ArangoEdgeRepository arangoEdgeRepository,
ArangoNodeRepository arangoNodeRepository,
ArangoQueryBuilderProvider arangoQueryBuilderProvider,
GenericSubQueryResolver genericSubQueryResolver,
ObjectMapper objectMapper,
GraphLoaderOgmFactory graphLoaderOgmFactory
) {
this.arangoDb = arangoDb;
this.arangoEdgeRepository = arangoEdgeRepository;
this.arangoNodeRepository = arangoNodeRepository;
this.arangoQueryBuilderProvider = arangoQueryBuilderProvider;
this.genericSubQueryResolver = genericSubQueryResolver;
this.objectMapper = objectMapper;
this.graphLoaderOgmFactory = graphLoaderOgmFactory;
}
@Override
public List<TraversableGraphElement> findAsTraversable(GraphElementQueryDescription graphDescription) {
var output = this.find(
graphDescription,
Object.class,
GraphLoaderReturnType.GRAPH
).getGraphLoaderFindAsGraphOutput();
String elementType;
if (graphDescription instanceof NodeQueryGraphDescription nodeQueryGraphDescription) {
elementType = ((NodeDescriptionParameters) nodeQueryGraphDescription.getParameters()).getNodeType();
} else {
elementType = ((EdgeDescriptionParameters) graphDescription.getParameters()).getEdgeType();
}
InMemoryGraphRepository outputRepository = output.getGraph();
return output.getFoundGraphElementIds()
.stream()
.map(id -> outputRepository.loadGraphElement(id, elementType))
.toList();
}
@Override
public TraversableGraphElement getAsTraversable(
UniqueIdentifier elementId,
GraphElementQueryDescription graphDescription
) {
var graph = this.get(
elementId,
graphDescription,
Object.class,
GraphLoaderReturnType.GRAPH
).getGraph();
String elementType;
if (graphDescription instanceof NodeQueryGraphDescription nodeQueryGraphDescription) {
elementType = ((NodeDescriptionParameters) nodeQueryGraphDescription.getParameters()).getNodeType();
} else {
elementType = ((EdgeDescriptionParameters) graphDescription.getParameters()).getEdgeType();
}
return graph.loadGraphElement(elementId, elementType);
}
@Override
public <T> GraphLoaderFindAsObjectOutput<T> find(
GraphElementQueryDescription graphDescription,
Class<T> objectClass,
GraphLoaderReturnType... returnTypes
) {
var collectionType = this.getCollectionType(graphDescription);
var collection = this.arangoDb.db().collection(collectionType);
if (!collection.exists()) {
return new GraphLoaderFindAsObjectOutput<>();
}
var arangoQueryBuilder = this.arangoQueryBuilderProvider.provide();
var finalReturnTypes = returnTypes.length == 0
? new GraphLoaderReturnType[] {GraphLoaderReturnType.OBJECT}
: returnTypes;
if (graphDescription instanceof AbstractNodeDescription) {
return resolveFindNodesQuery(
collectionType,
graphDescription,
arangoQueryBuilder,
objectClass,
finalReturnTypes
);
}
if (graphDescription instanceof AbstractEdgeDescription edgeDescription) {
return resolveFindEdgesQuery(
collectionType,
edgeDescription,
arangoQueryBuilder,
objectClass,
finalReturnTypes
);
}
throw new NotImplementedException(
"There should not be any other Query graph description, than node and edge");
}
@Override
public <T> GraphLoaderGetAsObjectOutput<T> get(
UniqueIdentifier elementId,
GraphElementQueryDescription graphDescription,
Class<T> objectClass,
GraphLoaderReturnType... returnTypes
) {
var collectionType = this.getCollectionType(graphDescription);
var arangoQueryBuilder = this.arangoQueryBuilderProvider.provide();
GraphLoaderReturnType[] finalReturnTypes = returnTypes.length == 0
? new GraphLoaderReturnType[] {GraphLoaderReturnType.OBJECT}
: returnTypes;
if (graphDescription instanceof AbstractNodeDescription) {
if (!this.arangoNodeRepository.nodeExists(elementId, collectionType)) {
throw GraphLoaderException.becauseThereIsNoGraphElementWithProvidedUuid(
elementId,
graphDescription
);
}
return resolveGetNodeQuery(
elementId,
collectionType,
graphDescription,
arangoQueryBuilder,
objectClass,
finalReturnTypes
);
}
if (graphDescription instanceof AbstractEdgeDescription edgeDescription) {
if (!this.arangoEdgeRepository.edgeExists(elementId, collectionType)) {
throw GraphLoaderException.becauseThereIsNoGraphElementWithProvidedUuid(
elementId,
graphDescription
);
}
return resolveGetEdgeQuery(
elementId,
collectionType,
edgeDescription,
arangoQueryBuilder,
objectClass,
finalReturnTypes
);
}
throw new NotImplementedException(
"There should not be any other Query graph description, than node and edge");
}
@Deprecated
public List<TraversableNode> findAsTraversableNodesWithOriginalRepository(
NodeQueryGraphDescription graphDescription
) {
var output = this.find(
graphDescription,
Object.class,
GraphLoaderReturnType.GRAPH
).getGraphLoaderFindAsGraphOutput();
var nodeParam = (NodeDescriptionParameters) graphDescription.getParameters();
return output
.getFoundGraphElementIds()
.stream()
.map(uuid -> output.getGraph().loadNode(uuid, nodeParam.getNodeType()))
.map(oldNode -> new TraversableNode(
oldNode.getId(),
oldNode.getType(),
oldNode.getVersionedAttributes(),
new RepositoryEdgeLoader(this.arangoEdgeRepository)
)).toList();
}
@NotNull
private <T> GraphLoaderGetAsObjectOutput<T> resolveGetNodeQuery(
UniqueIdentifier elementId,
String elementType,
GraphElementQueryDescription graphDescription,
ArangoQueryBuilder arangoQueryBuilder,
Class<T> objectClass,
GraphLoaderReturnType[] returnTypes
) {
var mainQueryBuilder = arangoQueryBuilder.setGetNodeMainQuery(elementType, elementId);
if (Arrays.asList(returnTypes).contains(GraphLoaderReturnType.OBJECT)) {
var generatedOgm = this.graphLoaderOgmFactory.create(graphDescription);
this.genericSubQueryResolver.resolve(mainQueryBuilder, generatedOgm);
} else {
this.genericSubQueryResolver.resolve(mainQueryBuilder, graphDescription);
}
var query = arangoQueryBuilder.build(returnTypes);
var getQueryArangoDocuments = this.arangoDb.db()
.query(query.getQueryString(), ArangoNodeGetDocument.class, query.getBindParameters())
.stream()
.toList();
return this.mapNodeToInMemoryGraph(getQueryArangoDocuments, objectClass);
}
@NotNull
private <T> GraphLoaderGetAsObjectOutput<T> resolveGetEdgeQuery(
UniqueIdentifier elementId,
String elementType,
AbstractEdgeDescription edgeDescription,
ArangoQueryBuilder arangoQueryBuilder,
Class<T> objectClass,
GraphLoaderReturnType[] returnTypes
) {
ArangoEdgeGetSubQueryBuilder mainQueryBuilder;
if (edgeDescription.isOutgoing()) {
mainQueryBuilder = arangoQueryBuilder.setGetOutgoingEdgeMainQuery(elementType, elementId);
} else {
mainQueryBuilder = arangoQueryBuilder.setGetIngoingEdgeMainQuery(elementType, elementId);
}
if (Arrays.asList(returnTypes).contains(GraphLoaderReturnType.OBJECT)) {
var generatedOgm = this.graphLoaderOgmFactory.create(edgeDescription);
this.genericSubQueryResolver.resolve(mainQueryBuilder, generatedOgm);
} else {
this.genericSubQueryResolver.resolve(mainQueryBuilder, edgeDescription);
}
var query = arangoQueryBuilder.build(returnTypes);
// var pretty = new AqlFormatter().format(query.getQueryString());
var getQueryArangoDocuments = this.arangoDb.db()
.query(query.getQueryString(), ArangoEdgeGetDocument.class, query.getBindParameters())
.stream()
.toList();
return this.mapEdgeToInMemoryGraph(getQueryArangoDocuments, objectClass);
}
@NotNull
private <T> GraphLoaderFindAsObjectOutput<T> resolveFindNodesQuery(
String elementType,
GraphElementQueryDescription graphDescription,
ArangoQueryBuilder arangoQueryBuilder,
Class<T> objectClass,
GraphLoaderReturnType[] returnTypes
) {
var mainQueryBuilder = arangoQueryBuilder.setFindNodesMainQuery(elementType);
if (Arrays.asList(returnTypes).contains(GraphLoaderReturnType.OBJECT)) {
var generatedOgm = this.graphLoaderOgmFactory.create(graphDescription);
this.genericSubQueryResolver.resolve(mainQueryBuilder, generatedOgm);
} else {
this.genericSubQueryResolver.resolve(mainQueryBuilder, graphDescription);
}
var query = arangoQueryBuilder.build(returnTypes);
// var pretty = new AqlFormatter().format(query.getQueryString());
var findQueryArangoDocuments = this.arangoDb.db()
.query(query.getQueryString(), ArangoNodeFindDocument.class, query.getBindParameters())
.stream()
.toList();
return this.mapNodesToGraphLoaderOutput(findQueryArangoDocuments, objectClass);
}
@NotNull
private <T> GraphLoaderFindAsObjectOutput<T> resolveFindEdgesQuery(
String elementType,
AbstractEdgeDescription edgeDescription,
ArangoQueryBuilder arangoQueryBuilder,
Class<T> objectClass,
GraphLoaderReturnType[] returnTypes
) {
ArangoEdgeCollectionSubQueryBuilder mainQueryBuilder;
if (edgeDescription.isOutgoing()) {
mainQueryBuilder = arangoQueryBuilder.setFindOutgoingEdgeMainQuery(elementType);
} else {
mainQueryBuilder = arangoQueryBuilder.setFindIngoingEdgeMainQuery(elementType);
}
if (Arrays.asList(returnTypes).contains(GraphLoaderReturnType.OBJECT)) {
var generatedOgm = this.graphLoaderOgmFactory.create(edgeDescription);
this.genericSubQueryResolver.resolve(mainQueryBuilder, generatedOgm);
} else {
this.genericSubQueryResolver.resolve(mainQueryBuilder, edgeDescription);
}
var query = arangoQueryBuilder.build(returnTypes);
// var pretty = new AqlFormatter().format(query.getQueryString());
var findQueryArangoDocuments = this.arangoDb.db()
.query(query.getQueryString(), ArangoEdgeFindDocument.class, query.getBindParameters())
.stream()
.toList();
return this.mapEdgesToGraphLoaderOutput(findQueryArangoDocuments, objectClass);
}
@NotNull
private <T> GraphLoaderFindAsObjectOutput<T> mapNodesToGraphLoaderOutput(
List<ArangoNodeFindDocument> results,
Class<T> objectClass
) {
final InMemoryGraphRepository graph = new InMemoryGraphRepository();
var originUuids = new ArrayList<UniqueIdentifier>();
results.forEach(result -> {
if (result.getGraphResponse().getMainGraphElements() == null) {
return;
}
result.getGraphResponse().getMainGraphElements()
.forEach(baseDocument -> {
var traversableNode = TraversableNode.from(baseDocument, graph);
graph.save(new Node(traversableNode));
originUuids.add(traversableNode.getId());
});
result.getGraphResponse().getNodes()
.forEach(graph::save);
result.getGraphResponse().getEdges()
.forEach(graph::save);
});
var finalData = new ArrayList<T>();
results.forEach(
result -> finalData.addAll(
result.getData().stream().map(data -> this.objectMapper.convertValue(data, objectClass))
.toList()
)
);
return new GraphLoaderFindAsObjectOutput<>(
finalData,
originUuids,
graph
);
}
@NotNull
private <T> GraphLoaderFindAsObjectOutput<T> mapEdgesToGraphLoaderOutput(
List<ArangoEdgeFindDocument> results,
Class<T> objectClass
) {
final InMemoryGraphRepository graph = new InMemoryGraphRepository();
var originUUIDs = new ArrayList<UniqueIdentifier>();
results.forEach(result -> {
if (result.getGraphResponse().getMainGraphElements() == null) {
return;
}
result.getGraphResponse()
.getNodes()
.forEach(graph::save);
result.getGraphResponse().getMainGraphElements()
.forEach(baseDocument -> {
var traversableEdge = TraversableEdge.from(baseDocument, graph);
graph.save(new Edge(traversableEdge));
originUUIDs.add(traversableEdge.getId());
});
result.getGraphResponse().getEdges()
.forEach(graph::save);
});
var finalData = new ArrayList<T>();
results.forEach(
result -> finalData.addAll(
result.getData().stream().map(data -> this.objectMapper.convertValue(data, objectClass))
.toList()
)
);
return new GraphLoaderFindAsObjectOutput<>(
finalData,
originUUIDs,
graph
);
}
@NotNull
private <T> GraphLoaderGetAsObjectOutput<T> mapNodeToInMemoryGraph(
List<ArangoNodeGetDocument> results,
Class<T> objectClass
) {
var graph = new InMemoryGraphRepository();
results.forEach(result -> {
if (result.getGraphResponse().getMainGraphElement() == null) {
return;
}
var main = result.getGraphResponse().getMainGraphElement();
graph.save(main);
result.getGraphResponse().getNodes()
.forEach(graph::save);
result.getGraphResponse().getEdges()
.forEach(graph::save);
});
var data = results.get(0).getData();
return new GraphLoaderGetAsObjectOutput<>(
this.objectMapper.convertValue(data, objectClass),
graph
);
}
@NotNull
private <T> GraphLoaderGetAsObjectOutput<T> mapEdgeToInMemoryGraph(
List<ArangoEdgeGetDocument> results,
Class<T> objectClass
) {
var graph = new InMemoryGraphRepository();
results.forEach(result -> {
if (result.getGraphResponse().getMainGraphElement() == null) {
return;
}
result.getGraphResponse()
.getNodes()
.forEach(graph::save);
var main = result.getGraphResponse().getMainGraphElement();
var traversableEdge = TraversableEdge.from(main, graph);
graph.save(new Edge(traversableEdge));
result.getGraphResponse()
.getEdges()
.forEach(graph::save);
});
var data = results.get(0).getData();
return new GraphLoaderGetAsObjectOutput<>(
this.objectMapper.convertValue(data, objectClass),
graph
);
}
private String getCollectionType(GraphDescription graphDescription) {
if (graphDescription instanceof AbstractNodeDescription) {
var params = (NodeDescriptionParameters) graphDescription.getParameters();
return params.getNodeType();
}
if (graphDescription instanceof AbstractEdgeDescription) {
var params = (EdgeDescriptionParameters) graphDescription.getParameters();
return params.getEdgeType();
}
throw new NotImplementedException("There should never be any other graph descriptions");
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ArangoQuery.java | package ai.stapi.arangograph.graphLoader.arangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.graphoperations.graphLoader.search.ResolvedQueryPart;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Map;
public class ArangoQuery implements ResolvedQueryPart {
private final AqlNode aqlNode;
private final Map<String, Object> bindParameters;
public ArangoQuery(AqlNode aqlNode, Map<String, Object> bindParameters) {
this.aqlNode = aqlNode;
this.bindParameters = bindParameters;
}
@JsonIgnore
public AqlNode getAqlNode() {
return aqlNode;
}
public String getQueryString() {
return this.aqlNode.toQueryString();
}
public Map<String, Object> getBindParameters() {
return bindParameters;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ArangoQueryType.java | package ai.stapi.arangograph.graphLoader.arangoQuery;
public enum ArangoQueryType {
NODE,
OUTGOING_EDGE,
INGOING_EDGE,
GRAPH_TRAVERSAL
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/aqlFormatter/AqlFormatter.java | package ai.stapi.arangograph.graphLoader.arangoQuery.aqlFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class AqlFormatter {
private static final List<String> SYMBOLS_WITH_NEWLINE_BEFORE = new ArrayList<>(List.of(
"LET",
"}",
")",
"FOR",
"RETURN",
"FILTER",
"SORT",
"LIMIT"
));
private static final List<String> SYMBOLS_WITH_NEWLINE_AFTER = new ArrayList<>(List.of(
"(",
"{"
));
private static final List<String> SYMBOLS_CONTAINING_STRING_WITH_NEWLINE_AFTER =
new ArrayList<>(List.of(
","
));
private static final List<String> SYMBOLS_INCREASING_INDENT = new ArrayList<>(List.of(
"(",
"{"
));
private static final List<String> SYMBOLS_DECREASING_INDENT = new ArrayList<>(List.of(
")",
"}"
));
public String format(String simpleAQL) {
simpleAQL = simpleAQL
.replace("(", " ( ")
.replace(")", " ) ")
.replace("{", " { ")
.replace("}", " } ")
.replace(",", " , ");
var aqlTokens = Arrays.stream(simpleAQL.split("\\s+")).toList();
var textBuilder = new FormattedTextBuilder();
aqlTokens.forEach(
token -> {
if (this.shouldIncreaseIndent(token)) {
textBuilder.increaseIndent();
}
if (this.shouldDecreaseIndent(token)) {
textBuilder.decreaseIndent();
}
if (this.shouldAddSpace(textBuilder)) {
textBuilder.addSpace();
}
if (this.shouldAddNewlineBefore(
token,
textBuilder
)) {
textBuilder.addNewline();
}
textBuilder.addTextPart(token);
if (this.shouldAddNewlineAfter(token)) {
textBuilder.addNewline();
}
}
);
return textBuilder.addNewline().build()
.replace(" ,", ",")
.replace(" .", ".")
.replaceAll("[^\\S\\r\\n]+\n", "\n");
}
private boolean shouldDecreaseIndent(String token) {
return SYMBOLS_DECREASING_INDENT.contains(token);
}
private boolean shouldIncreaseIndent(String token) {
return SYMBOLS_INCREASING_INDENT.contains(token);
}
private boolean shouldAddNewlineBefore(String token, FormattedTextBuilder textBuilder) {
if (textBuilder.countParts() == 0) {
return false;
}
return SYMBOLS_WITH_NEWLINE_BEFORE.contains(token);
}
private boolean shouldAddNewlineAfter(String token) {
if (SYMBOLS_WITH_NEWLINE_AFTER.contains(token)) {
return true;
}
return SYMBOLS_CONTAINING_STRING_WITH_NEWLINE_AFTER.stream()
.anyMatch(token::contains);
}
private boolean shouldAddSpace(FormattedTextBuilder textBuilder) {
return textBuilder.countParts() != 0 && textBuilder.getCurrentPartOnLine() != 0;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/aqlFormatter/FormattedTextBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.aqlFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
public class FormattedTextBuilder {
public static final String DEFAULT_SYMBOL_SPACE = " ";
private static final String SYMBOL_NEWLINE = "\n";
private static final String SYMBOL_INDENT = " ";
private Integer currentLineNumber = 0;
private Integer currentIndent = 0;
private Integer currentPartOnLine = 0;
private final String symbolSpace = DEFAULT_SYMBOL_SPACE;
private final String symbolNewline = SYMBOL_NEWLINE;
private final String symbolIndent = SYMBOL_INDENT;
private final ArrayList<String> textParts = new ArrayList<>();
public FormattedTextBuilder addTextPart(String textPart) {
this.textParts.add(textPart);
this.currentPartOnLine = this.currentPartOnLine + 1;
return this;
}
public FormattedTextBuilder addNewline() {
this.textParts.add(this.symbolNewline);
List<Integer> range = IntStream.range(0, this.currentIndent)
.boxed()
.toList();
range.forEach(index -> this.textParts.add(this.symbolIndent));
this.currentLineNumber = this.currentLineNumber + 1;
this.currentPartOnLine = 0;
return this;
}
public FormattedTextBuilder addSpace() {
this.textParts.add(this.symbolSpace);
return this;
}
public Integer getCurrentLineNumber() {
return currentLineNumber;
}
public Integer getCurrentIndent() {
return currentIndent;
}
public Integer countParts() {
return this.textParts.size();
}
public Integer getCurrentPartOnLine() {
return currentPartOnLine;
}
public String build() {
return String.join("", this.textParts);
}
public FormattedTextBuilder increaseIndent() {
this.currentIndent = this.currentIndent + 1;
return this;
}
public FormattedTextBuilder decreaseIndent() {
this.currentIndent = this.currentIndent - 1;
return this;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/arangoSubQueryResolver/AbstractArangoSubQueryResolver.java | package ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoGraphTraversalJoinable;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoKeptAttributesBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoMappedObjectBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoSearchOptionsBuilder;
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractAttributeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractEdgeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractNodeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AllAttributesDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AttributeDescriptionParameters;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.GraphElementTypeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.UuidIdentityDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.query.EdgeQueryDescription;
import ai.stapi.graphoperations.graphLoader.search.SearchQueryParameters;
import ai.stapi.graphoperations.objectGraphLanguage.LeafObjectGraphMapping;
import ai.stapi.graphoperations.objectGraphLanguage.ListObjectGraphMapping;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectFieldDefinition;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectObjectGraphMapping;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
public abstract class AbstractArangoSubQueryResolver implements ArangoSubQueryResolver {
protected GenericSubQueryResolver genericSubQueryResolver;
protected AbstractArangoSubQueryResolver(GenericSubQueryResolver genericSubQueryResolver) {
this.genericSubQueryResolver = genericSubQueryResolver;
}
protected void resolveAttributes(
GraphDescription graphDescription,
ArangoKeptAttributesBuilder keptAttributesBuilder
) {
var childGraphDescriptions = graphDescription.getChildGraphDescriptions();
if (childGraphDescriptions.stream().anyMatch(UuidIdentityDescription.class::isInstance)) {
keptAttributesBuilder.addId();
}
var hasAllAttributeDescription = childGraphDescriptions
.stream()
.anyMatch(AllAttributesDescription.class::isInstance);
if (!hasAllAttributeDescription) {
childGraphDescriptions.stream()
.filter(AbstractAttributeDescription.class::isInstance)
.map(description -> (AttributeDescriptionParameters) description.getParameters())
.forEach(
description -> keptAttributesBuilder.addAttribute(description.getAttributeName())
);
} else {
keptAttributesBuilder.keepAllAttributes();
}
}
protected void resolveSearchOptions(
SearchQueryParameters searchParam,
ArangoSearchOptionsBuilder searchOptionsBuilder
) {
searchOptionsBuilder
.addFilterOptions(searchParam.getFilterOptions())
.addSortOptions(searchParam.getSortOptions())
.setPaginationOption(searchParam.getPaginationOption());
}
protected void resolveSearchOptionsWithoutPagination(
SearchQueryParameters searchParam,
ArangoSearchOptionsBuilder searchOptionsBuilder
) {
searchOptionsBuilder
.addFilterOptions(searchParam.getFilterOptions())
.addSortOptions(searchParam.getSortOptions());
}
protected void resolveGraphTraversalJoins(
GraphDescription graphDescription,
ArangoGraphTraversalJoinable subQueryBuilder
) {
graphDescription.getChildGraphDescriptions().stream()
.filter(AbstractEdgeDescription.class::isInstance)
.map(AbstractEdgeDescription.class::cast)
.forEach(edgeDescription -> {
var joinedGraphTraversal = subQueryBuilder.joinGraphTraversal(edgeDescription);
this.genericSubQueryResolver.resolve(joinedGraphTraversal, edgeDescription);
});
}
protected void resolveMappedAttributes(
Map<String, ObjectFieldDefinition> fields,
ArangoMappedObjectBuilder mappedObjectBuilder
) {
fields.forEach((key, value) -> {
var objectGraphMapping = value.getFieldObjectGraphMapping();
if (objectGraphMapping instanceof LeafObjectGraphMapping leafObjectGraphMapping) {
this.resolveLeafOGM(key, leafObjectGraphMapping, mappedObjectBuilder);
}
});
}
protected void resolveLeafOGM(
String fieldName,
LeafObjectGraphMapping leafObjectGraphMapping,
ArangoMappedObjectBuilder mappedObjectBuilder
) {
var graphDescription = leafObjectGraphMapping.getGraphDescription();
if (graphDescription instanceof AbstractAttributeDescription attributeValueDescription) {
var param = (AttributeDescriptionParameters) attributeValueDescription.getParameters();
mappedObjectBuilder.mapAttribute(fieldName, param.getAttributeName());
}
if (graphDescription instanceof UuidIdentityDescription) {
mappedObjectBuilder.mapId(fieldName);
}
if (graphDescription instanceof GraphElementTypeDescription) {
mappedObjectBuilder.mapType(fieldName);
}
}
protected void resolveGraphTraversalMapping(
Map<String, ObjectFieldDefinition> fields,
ArangoGraphTraversalJoinable subQueryBuilder
) {
fields.forEach((key, value) -> {
var objectGraphMapping = value.getFieldObjectGraphMapping();
if (objectGraphMapping instanceof ListObjectGraphMapping listObjectGraphMapping) {
var childMapping = listObjectGraphMapping.getChildObjectGraphMapping();
if (childMapping instanceof ObjectObjectGraphMapping) {
var description = childMapping.getGraphDescription();
if (description instanceof AbstractEdgeDescription edgeDescription) {
if (edgeDescription instanceof EdgeQueryDescription edgeQueryDescription
&& (!edgeQueryDescription.isCompact())) {
var traversalBuilder = subQueryBuilder.mapGraphTraversalAsConnections(
key,
edgeDescription
);
this.genericSubQueryResolver.resolve(traversalBuilder, childMapping);
return;
}
var traversalBuilder = subQueryBuilder.mapGraphTraversal(
key,
edgeDescription
);
this.genericSubQueryResolver.resolve(traversalBuilder, childMapping);
}
}
}
});
}
@NotNull
protected List<GraphDescription> getChildNodeDescriptions(
AbstractEdgeDescription edgeDescription) {
return edgeDescription.getChildGraphDescriptions().stream()
.filter(AbstractNodeDescription.class::isInstance)
.toList();
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/arangoSubQueryResolver/ArangoEdgeCollectionSubQueryResolver.java | package ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoEdgeCollectionSubQueryBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoSubQueryBuilder;
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractEdgeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractNodeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.NodeDescriptionParameters;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.query.GraphElementQueryDescription;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectGraphMapping;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectObjectGraphMapping;
public class ArangoEdgeCollectionSubQueryResolver extends AbstractArangoSubQueryResolver {
public ArangoEdgeCollectionSubQueryResolver(GenericSubQueryResolver genericSubQueryResolver) {
super(genericSubQueryResolver);
}
@Override
public boolean supports(ArangoSubQueryBuilder builder, GraphDescription graphDescription) {
return builder instanceof ArangoEdgeCollectionSubQueryBuilder
&& graphDescription instanceof AbstractEdgeDescription;
}
@Override
public void resolve(ArangoSubQueryBuilder builder, GraphDescription graphDescription) {
var edgeDescription = (AbstractEdgeDescription) graphDescription;
var collectionSubQueryBuilder = (ArangoEdgeCollectionSubQueryBuilder) builder;
this.resolveAttributes(edgeDescription, collectionSubQueryBuilder.setKeptAttributes());
if (edgeDescription instanceof GraphElementQueryDescription graphElementQueryDescription) {
this.resolveSearchOptions(
graphElementQueryDescription.getSearchQueryParameters(),
collectionSubQueryBuilder.setSearchOptions()
);
}
var nodeDescriptions = this.getChildNodeDescriptions(edgeDescription);
nodeDescriptions.forEach(description -> {
var param = (NodeDescriptionParameters) description.getParameters();
this.genericSubQueryResolver.resolve(
collectionSubQueryBuilder.joinNodeGetSubQuery(param.getNodeType()),
description
);
});
}
@Override
public void resolve(ArangoSubQueryBuilder builder, ObjectGraphMapping objectGraphMapping) {
var objectOGM = (ObjectObjectGraphMapping) objectGraphMapping;
var subQueryBuilder = (ArangoEdgeCollectionSubQueryBuilder) builder;
if (objectOGM.getGraphDescription() instanceof GraphElementQueryDescription graphElementQueryDescription) {
this.resolveSearchOptions(
graphElementQueryDescription.getSearchQueryParameters(),
subQueryBuilder.setSearchOptions()
);
}
this.resolveMappedAttributes(objectOGM.getFields(), subQueryBuilder.setMappedScalars());
var nodeFields = objectOGM.getFields().entrySet()
.stream()
.filter(
entry -> {
var fieldOGM = entry.getValue().getFieldObjectGraphMapping();
if (fieldOGM instanceof ObjectObjectGraphMapping) {
return fieldOGM.getGraphDescription() instanceof AbstractNodeDescription;
}
return false;
}
).toList();
nodeFields.forEach(nodeField -> {
var fieldObjectGraphMapping = nodeField.getValue().getFieldObjectGraphMapping();
var graphDescription = fieldObjectGraphMapping.getGraphDescription();
var nodeParams = (NodeDescriptionParameters) graphDescription.getParameters();
var joinedNodeBuilder = subQueryBuilder.mapNodeGetSubQuery(
nodeParams.getNodeType()
);
this.genericSubQueryResolver.resolve(joinedNodeBuilder, fieldObjectGraphMapping);
});
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/arangoSubQueryResolver/ArangoEdgeGetSubQueryResolver.java | package ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoEdgeGetSubQueryBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoSubQueryBuilder;
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractEdgeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractNodeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.NodeDescriptionParameters;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectGraphMapping;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectObjectGraphMapping;
public class ArangoEdgeGetSubQueryResolver extends AbstractArangoSubQueryResolver {
public ArangoEdgeGetSubQueryResolver(GenericSubQueryResolver genericSubQueryResolver) {
super(genericSubQueryResolver);
}
@Override
public boolean supports(ArangoSubQueryBuilder builder, GraphDescription graphDescription) {
return builder instanceof ArangoEdgeGetSubQueryBuilder
&& graphDescription instanceof AbstractEdgeDescription;
}
@Override
public void resolve(ArangoSubQueryBuilder builder, GraphDescription graphDescription) {
var edgeDescription = (AbstractEdgeDescription) graphDescription;
var subQueryBuilder = (ArangoEdgeGetSubQueryBuilder) builder;
this.resolveAttributes(edgeDescription, subQueryBuilder.setKeptAttributes());
var nodeDescriptions = this.getChildNodeDescriptions(edgeDescription);
nodeDescriptions.forEach(description -> {
var nodeDescription = (AbstractNodeDescription) description;
var param = (NodeDescriptionParameters) nodeDescription.getParameters();
this.genericSubQueryResolver.resolve(
subQueryBuilder.joinNodeGetSubQuery(param.getNodeType()),
nodeDescription
);
});
}
@Override
public void resolve(ArangoSubQueryBuilder builder, ObjectGraphMapping objectGraphMapping) {
var objectOgm = (ObjectObjectGraphMapping) objectGraphMapping;
var subQueryBuilder = (ArangoEdgeGetSubQueryBuilder) builder;
this.resolveMappedAttributes(objectOgm.getFields(), subQueryBuilder.setMappedScalars());
var nodeFields = objectOgm.getFields().entrySet()
.stream()
.filter(
entry -> {
var fieldOgm = entry.getValue().getFieldObjectGraphMapping();
if (fieldOgm instanceof ObjectObjectGraphMapping) {
return fieldOgm.getGraphDescription() instanceof AbstractNodeDescription;
}
return false;
}
).toList();
nodeFields.forEach(nodeField -> {
var fieldObjectGraphMapping = nodeField.getValue().getFieldObjectGraphMapping();
var graphDescription = fieldObjectGraphMapping.getGraphDescription();
var nodeParams = (NodeDescriptionParameters) graphDescription.getParameters();
var joinedNodeBuilder = subQueryBuilder.mapNodeGetSubQuery(
nodeParams.getNodeType()
);
this.genericSubQueryResolver.resolve(joinedNodeBuilder, fieldObjectGraphMapping);
});
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/arangoSubQueryResolver/ArangoGraphTraversalSubQueryResolver.java | package ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoGraphTraversalNodeOptionBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoGraphTraversalSubQueryBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoSubQueryBuilder;
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractEdgeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractNodeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.NodeDescriptionParameters;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.query.GraphElementQueryDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.query.NodeQueryGraphDescription;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectFieldDefinition;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectGraphMapping;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectObjectGraphMapping;
import java.util.Map;
public class ArangoGraphTraversalSubQueryResolver extends AbstractArangoSubQueryResolver {
public ArangoGraphTraversalSubQueryResolver(GenericSubQueryResolver genericSubQueryResolver) {
super(genericSubQueryResolver);
}
@Override
public boolean supports(ArangoSubQueryBuilder builder, GraphDescription graphDescription) {
return builder instanceof ArangoGraphTraversalSubQueryBuilder
&& graphDescription instanceof AbstractEdgeDescription;
}
@Override
public void resolve(ArangoSubQueryBuilder builder, GraphDescription graphDescription) {
var graphTraversalSubQueryBuilder = (ArangoGraphTraversalSubQueryBuilder) builder;
var edgeDescription = (AbstractEdgeDescription) graphDescription;
this.resolveAttributes(edgeDescription, graphTraversalSubQueryBuilder.setEdgeKeptAttributes());
if (edgeDescription instanceof GraphElementQueryDescription graphElementQueryDescription) {
this.resolveSearchOptions(
graphElementQueryDescription.getSearchQueryParameters(),
graphTraversalSubQueryBuilder.setEdgeSearchOptions()
);
}
this.resolveJoinToOtherNodes(edgeDescription, graphTraversalSubQueryBuilder);
}
@Override
public void resolve(ArangoSubQueryBuilder builder, ObjectGraphMapping objectGraphMapping) {
var objectOGM = (ObjectObjectGraphMapping) objectGraphMapping;
var subQueryBuilder = (ArangoGraphTraversalSubQueryBuilder) builder;
var graphDescription = objectOGM.getGraphDescription();
if (graphDescription instanceof GraphElementQueryDescription graphElementQueryDescription) {
this.resolveSearchOptions(
graphElementQueryDescription.getSearchQueryParameters(),
subQueryBuilder.setEdgeSearchOptions()
);
}
this.resolveMappedAttributes(objectOGM.getFields(), subQueryBuilder.setEdgeMappedScalars());
this.mapToOtherNode(
objectOGM.getFields(),
subQueryBuilder
);
}
private void resolveJoinToOtherNodes(
AbstractEdgeDescription edgeDescription,
ArangoGraphTraversalSubQueryBuilder graphTraversalSubQueryBuilder
) {
var nodeDescriptions = this.getChildNodeDescriptions(edgeDescription);
nodeDescriptions.forEach(nodeDescription -> {
var nodeParameters = (NodeDescriptionParameters) nodeDescription.getParameters();
var nodeOptionBuilder =
graphTraversalSubQueryBuilder.setOtherNode(nodeParameters.getNodeType());
this.resolveAttributes(nodeDescription, nodeOptionBuilder.setKeptAttributes());
if (nodeDescription instanceof NodeQueryGraphDescription nodeQueryGraphDescription) {
this.resolveSearchOptionsWithoutPagination(
nodeQueryGraphDescription.getSearchQueryParameters(),
graphTraversalSubQueryBuilder.setNodeSearchOptions()
);
}
this.resolveGraphTraversalJoins(nodeDescription, nodeOptionBuilder);
});
}
private void mapToOtherNode(
Map<String, ObjectFieldDefinition> fieldDefinitionMap,
ArangoGraphTraversalSubQueryBuilder graphTraversalSubQueryBuilder
) {
var nodeFields = fieldDefinitionMap.entrySet()
.stream()
.filter(
entry -> {
var fieldOGM = entry.getValue().getFieldObjectGraphMapping();
if (fieldOGM instanceof ObjectObjectGraphMapping) {
return fieldOGM.getGraphDescription() instanceof AbstractNodeDescription;
}
return false;
}
).toList();
nodeFields.forEach(nodeField -> {
var fieldObjectGraphMapping = nodeField.getValue().getFieldObjectGraphMapping();
var graphDescription = fieldObjectGraphMapping.getGraphDescription();
var nodeParams = (NodeDescriptionParameters) graphDescription.getParameters();
var nodeOptionBuilder = graphTraversalSubQueryBuilder.mapOtherNode(
nodeParams.getNodeType()
);
this.mapGraphTraversalOtherNode(
nodeOptionBuilder,
graphTraversalSubQueryBuilder,
(ObjectObjectGraphMapping) fieldObjectGraphMapping
);
});
}
private void mapGraphTraversalOtherNode(
ArangoGraphTraversalNodeOptionBuilder builder,
ArangoGraphTraversalSubQueryBuilder graphTraversalBuilder,
ObjectObjectGraphMapping objectGraphMapping
) {
var graphDescription = objectGraphMapping.getGraphDescription();
this.resolveMappedAttributes(objectGraphMapping.getFields(), builder.setMappedScalars());
if (graphDescription instanceof GraphElementQueryDescription graphElementQueryDescription) {
this.resolveSearchOptionsWithoutPagination(
graphElementQueryDescription.getSearchQueryParameters(),
graphTraversalBuilder.setNodeSearchOptions()
);
}
this.resolveGraphTraversalMapping(objectGraphMapping.getFields(), builder);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/arangoSubQueryResolver/ArangoNodeCollectionSubQueryResolver.java | package ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoNodeCollectionSubQueryBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoSubQueryBuilder;
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractNodeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.query.GraphElementQueryDescription;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectGraphMapping;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectObjectGraphMapping;
public class ArangoNodeCollectionSubQueryResolver extends AbstractArangoSubQueryResolver {
public ArangoNodeCollectionSubQueryResolver(GenericSubQueryResolver genericSubQueryResolver) {
super(genericSubQueryResolver);
}
@Override
public boolean supports(ArangoSubQueryBuilder builder, GraphDescription graphDescription) {
return builder instanceof ArangoNodeCollectionSubQueryBuilder
&& graphDescription instanceof AbstractNodeDescription;
}
@Override
public void resolve(ArangoSubQueryBuilder builder, GraphDescription graphDescription) {
var collectionSubQueryBuilder = (ArangoNodeCollectionSubQueryBuilder) builder;
this.resolveAttributes(graphDescription, collectionSubQueryBuilder.setKeptAttributes());
this.resolveGraphTraversalJoins(graphDescription, collectionSubQueryBuilder);
if (graphDescription instanceof GraphElementQueryDescription graphElementQueryDescription) {
this.resolveSearchOptions(
graphElementQueryDescription.getSearchQueryParameters(),
collectionSubQueryBuilder.setSearchOptions()
);
}
}
@Override
public void resolve(ArangoSubQueryBuilder builder, ObjectGraphMapping objectGraphMapping) {
var objectOgm = (ObjectObjectGraphMapping) objectGraphMapping;
var subQueryBuilder = (ArangoNodeCollectionSubQueryBuilder) builder;
var graphDescription = objectGraphMapping.getGraphDescription();
this.resolveMappedAttributes(objectOgm.getFields(), subQueryBuilder.setMappedScalars());
if (graphDescription instanceof GraphElementQueryDescription graphElementQueryDescription) {
this.resolveSearchOptions(
graphElementQueryDescription.getSearchQueryParameters(),
subQueryBuilder.setSearchOptions()
);
}
this.resolveGraphTraversalMapping(objectOgm.getFields(), subQueryBuilder);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/arangoSubQueryResolver/ArangoNodeGetSubQueryResolver.java | package ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoNodeGetSubQueryBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoSubQueryBuilder;
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractNodeDescription;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectGraphMapping;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectObjectGraphMapping;
public class ArangoNodeGetSubQueryResolver extends AbstractArangoSubQueryResolver {
public ArangoNodeGetSubQueryResolver(GenericSubQueryResolver genericSubQueryResolver) {
super(genericSubQueryResolver);
}
@Override
public boolean supports(ArangoSubQueryBuilder builder, GraphDescription graphDescription) {
return builder instanceof ArangoNodeGetSubQueryBuilder
&& graphDescription instanceof AbstractNodeDescription;
}
@Override
public void resolve(ArangoSubQueryBuilder builder, GraphDescription graphDescription) {
var subQueryBuilder = (ArangoNodeGetSubQueryBuilder) builder;
this.resolveAttributes(graphDescription, subQueryBuilder.setKeptAttributes());
this.resolveGraphTraversalJoins(graphDescription, subQueryBuilder);
}
@Override
public void resolve(ArangoSubQueryBuilder builder, ObjectGraphMapping objectGraphMapping) {
var objectOGM = (ObjectObjectGraphMapping) objectGraphMapping;
var subQueryBuilder = (ArangoNodeGetSubQueryBuilder) builder;
this.resolveMappedAttributes(objectOGM.getFields(), subQueryBuilder.setMappedScalars());
this.resolveGraphTraversalMapping(objectOGM.getFields(), subQueryBuilder);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/arangoSubQueryResolver/ArangoSubQueryResolver.java | package ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoSubQueryBuilder;
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectGraphMapping;
public interface ArangoSubQueryResolver {
boolean supports(ArangoSubQueryBuilder builder, GraphDescription graphDescription);
void resolve(ArangoSubQueryBuilder builder, GraphDescription graphDescription);
void resolve(ArangoSubQueryBuilder builder, ObjectGraphMapping objectGraphMapping);
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/arangoSubQueryResolver/GenericSubQueryResolver.java | package ai.stapi.arangograph.graphLoader.arangoQuery.arangoSubQueryResolver;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoSubQueryBuilder;
import ai.stapi.arangograph.graphLoader.arangoQuery.exceptions.CannotBuildArangoQuery;
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription;
import ai.stapi.graphoperations.objectGraphLanguage.ObjectGraphMapping;
import java.util.List;
import org.jetbrains.annotations.NotNull;
public class GenericSubQueryResolver {
private final List<ArangoSubQueryResolver> subQueryResolvers;
public GenericSubQueryResolver(List<ArangoSubQueryResolver> subQueryResolvers) {
this.subQueryResolvers = subQueryResolvers;
}
public void resolve(ArangoSubQueryBuilder builder, GraphDescription graphDescription) {
var supported = getSupportedResolver(builder, graphDescription);
supported.resolve(builder, graphDescription);
}
public void resolve(ArangoSubQueryBuilder builder, ObjectGraphMapping objectGraphMapping) {
var graphDescription = objectGraphMapping.getGraphDescription();
var supported = getSupportedResolver(builder, graphDescription);
supported.resolve(builder, objectGraphMapping);
}
@NotNull
private ArangoSubQueryResolver getSupportedResolver(
ArangoSubQueryBuilder builder,
GraphDescription graphDescription
) {
var supported = this.subQueryResolvers.stream()
.filter(resolver -> resolver.supports(builder, graphDescription))
.toList();
if (supported.size() == 0) {
throw CannotBuildArangoQuery.becauseThereWasNoSubQueryResolversForBuilder(
builder,
graphDescription
);
}
if (supported.size() > 1) {
throw CannotBuildArangoQuery.becauseThereWereMoreSubQueryResolversForBuilder(
builder,
graphDescription
);
}
return supported.get(0);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/AqlInteger.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast;
public class AqlInteger implements AqlNode {
private final Integer integer;
public AqlInteger(Integer integer) {
this.integer = integer;
}
public Integer getInteger() {
return integer;
}
@Override
public String toQueryString() {
return String.format("%s", this.integer);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/AqlList.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class AqlList implements AqlNode {
private final List<AqlNode> aqlNodeList;
public AqlList(List<AqlNode> aqlNodeList) {
this.aqlNodeList = aqlNodeList;
}
public AqlList(AqlNode... aqlNodeList) {
this.aqlNodeList = Arrays.stream(aqlNodeList).toList();
}
public List<AqlNode> getAqlNodeList() {
return aqlNodeList;
}
@Override
public String toQueryString() {
return String.format(
"[ %s ]",
this.getAqlNodeList().stream()
.map(AqlNode::toQueryString)
.collect(Collectors.joining(", "))
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/AqlNode.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast;
public interface AqlNode {
String toQueryString();
default AqlVariable getItem(Integer index) {
return new AqlVariable(String.format("%s[%s]", this.toQueryString(), index));
}
default AqlVariable getAllItems() {
return new AqlVariable(String.format("%s[*]", this.toQueryString()));
}
default AqlVariable getFlattenItems() {
return new AqlVariable(String.format("%s[**]", this.toQueryString()));
}
default AqlVariable getField(String fieldName) {
return new AqlVariable(String.format("%s.%s", this.toQueryString(), fieldName));
}
default AqlVariable markAsBindParameter() {
return new AqlVariable("@" + this.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/AqlObject.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast;
import java.util.Map;
import java.util.stream.Collectors;
public class AqlObject implements AqlNode {
private final Map<AqlNode, AqlNode> fields;
public AqlObject(Map<AqlNode, AqlNode> fields) {
this.fields = fields;
}
public Map<AqlNode, AqlNode> getFields() {
return fields;
}
@Override
public String toQueryString() {
return String.format(
"{ %s }",
fields.entrySet().stream()
.map(entry -> String.format("[%s]: %s", entry.getKey().toQueryString(),
entry.getValue().toQueryString()))
.sorted()
.collect(Collectors.joining(", "))
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/AqlOperator.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast;
public class AqlOperator implements AqlNode {
protected final String operatorName;
public AqlOperator(String operatorName) {
this.operatorName = operatorName;
}
public static AqlOperator equality() {
return new AqlOperator("==");
}
public static AqlOperator inequality() {
return new AqlOperator("!=");
}
public static AqlOperator lessThan() {
return new AqlOperator("<");
}
public static AqlOperator lessOrEqual() {
return new AqlOperator("<=");
}
public static AqlOperator greaterThan() {
return new AqlOperator(">");
}
public static AqlOperator greaterOrEqual() {
return new AqlOperator(">=");
}
public static AqlOperator in() {
return new AqlOperator("IN");
}
public static AqlOperator notIn() {
return new AqlOperator("NOT IN");
}
public static AqlOperator like() {
return new AqlOperator("LIKE");
}
public static AqlOperator notLike() {
return new AqlOperator("NOT LIKE");
}
public static AqlOperator matches() {
return new AqlOperator("=~");
}
public static AqlOperator notMatches() {
return new AqlOperator("!~");
}
@Override
public String toQueryString() {
return this.operatorName;
}
public String getOperatorName() {
return operatorName;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/AqlOperatorStatement.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast;
public class AqlOperatorStatement implements AqlNode {
private final AqlNode leftExpression;
private final AqlOperator operator;
private final AqlNode rightExpression;
public AqlOperatorStatement(
AqlNode leftExpression,
AqlOperator operator,
AqlNode rightExpression
) {
this.leftExpression = leftExpression;
this.operator = operator;
this.rightExpression = rightExpression;
}
public AqlNode getLeftExpression() {
return leftExpression;
}
public AqlOperator getOperator() {
return operator;
}
public AqlNode getRightExpression() {
return rightExpression;
}
@Override
public String toQueryString() {
return String.format(
"%s %s %s",
this.leftExpression.toQueryString(),
this.operator.toQueryString(),
this.rightExpression.toQueryString()
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/AqlRootNode.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class AqlRootNode implements AqlNode {
private final List<AqlNode> aqlNodeList;
public AqlRootNode(List<AqlNode> aqlNodeList) {
this.aqlNodeList = aqlNodeList;
}
public AqlRootNode(AqlNode... aqlNodeList) {
this.aqlNodeList = Arrays.stream(aqlNodeList).toList();
}
public List<AqlNode> getAqlNodeList() {
return aqlNodeList;
}
@Override
public String toQueryString() {
return this.aqlNodeList.stream().map(AqlNode::toQueryString).collect(Collectors.joining(" "));
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/AqlString.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast;
public class AqlString implements AqlNode {
private final String string;
public AqlString(String string) {
this.string = string;
}
public String getString() {
return string;
}
@Override
public String toQueryString() {
return String.format("\"%s\"", this.string);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/AqlVariable.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast;
public class AqlVariable implements AqlNode {
private final String variableName;
public AqlVariable(String variableName) {
this.variableName = variableName;
}
public String getVariableName() {
return variableName;
}
@Override
public String toQueryString() {
return this.variableName;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/arrayComparisonOperators/AqlAll.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.arrayComparisonOperators;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlOperator;
public class AqlAll extends AqlOperator {
private final AqlOperator aqlNode;
public AqlAll(AqlOperator aqlNode) {
super("ALL");
this.aqlNode = aqlNode;
}
public AqlNode getAqlNode() {
return aqlNode;
}
@Override
public String toQueryString() {
return String.format("%s %s", this.operatorName, this.aqlNode.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/arrayComparisonOperators/AqlAny.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.arrayComparisonOperators;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlOperator;
public class AqlAny extends AqlOperator {
private final AqlOperator aqlNode;
public AqlAny(AqlOperator aqlNode) {
super("ANY");
this.aqlNode = aqlNode;
}
public AqlNode getAqlNode() {
return aqlNode;
}
@Override
public String toQueryString() {
return String.format("%s %s", this.operatorName, this.aqlNode.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/arrayComparisonOperators/AqlNone.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.arrayComparisonOperators;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlOperator;
public class AqlNone extends AqlOperator {
private final AqlOperator aqlNode;
public AqlNone(AqlOperator aqlNode) {
super("NONE");
this.aqlNode = aqlNode;
}
public AqlNode getAqlNode() {
return aqlNode;
}
@Override
public String toQueryString() {
return String.format("%s %s", this.operatorName, this.aqlNode.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/functions/AqlConcatSeparator.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class AqlConcatSeparator implements AqlNode {
private final AqlNode separator;
private final List<AqlNode> aqlNodeList;
public AqlConcatSeparator(AqlNode separator, List<AqlNode> aqlNodeList) {
this.separator = separator;
this.aqlNodeList = aqlNodeList;
}
public AqlConcatSeparator(AqlNode separator, AqlNode... aqlNodeList) {
this.separator = separator;
this.aqlNodeList = Arrays.stream(aqlNodeList).toList();
}
public AqlNode getSeparator() {
return separator;
}
public List<AqlNode> getAqlNodeList() {
return aqlNodeList;
}
@Override
public String toQueryString() {
return String.format(
"CONCAT_SEPARATOR(%s, %s)",
this.separator.toQueryString(),
this.aqlNodeList.stream().map(AqlNode::toQueryString).collect(Collectors.joining(", "))
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/functions/AqlDocument.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
public class AqlDocument implements AqlNode {
private final AqlNode documentId;
public AqlDocument(AqlNode documentId) {
this.documentId = documentId;
}
public AqlDocument(String collection, String key) {
this.documentId = new AqlVariable(String.format("%s/%s", collection, key));
}
public AqlNode getDocumentId() {
return documentId;
}
@Override
public String toQueryString() {
return String.format("DOCUMENT(%s)", this.documentId.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/functions/AqlKeep.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import java.util.List;
import java.util.stream.Collectors;
public class AqlKeep implements AqlNode {
private final AqlNode aqlObjectExpression;
private final List<AqlNode> attributeNames;
public AqlKeep(
AqlNode aqlObjectExpression,
List<AqlNode> attributeNames
) {
this.aqlObjectExpression = aqlObjectExpression;
this.attributeNames = attributeNames;
}
public AqlNode getAqlObjectExpression() {
return aqlObjectExpression;
}
public List<AqlNode> getAttributeNames() {
return attributeNames;
}
@Override
public String toQueryString() {
return String.format(
"KEEP(%s, %s)",
this.aqlObjectExpression.toQueryString(),
this.attributeNames.stream().map(AqlNode::toQueryString).collect(Collectors.joining(", "))
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/functions/AqlParseIdentifier.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
public class AqlParseIdentifier implements AqlNode {
private final AqlNode documentExpression;
public AqlParseIdentifier(AqlNode documentExpression) {
this.documentExpression = documentExpression;
}
public AqlNode getDocumentExpression() {
return documentExpression;
}
public AqlVariable getCollection() {
return new AqlVariable(this.toQueryString()).getField("collection");
}
@Override
public String toQueryString() {
return String.format("PARSE_IDENTIFIER(%s)", this.documentExpression.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/functions/AqlPush.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
public class AqlPush implements AqlNode {
private final AqlNode aqlListExpression;
private final AqlNode aqlNode;
public AqlPush(AqlNode aqlListExpression, AqlNode aqlNode) {
this.aqlListExpression = aqlListExpression;
this.aqlNode = aqlNode;
}
@Override
public String toQueryString() {
return String.format(
"PUSH(%s, %s)",
this.aqlListExpression.toQueryString(),
this.aqlNode.toQueryString()
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/functions/AqlUnion.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import java.util.List;
import java.util.stream.Collectors;
public class AqlUnion implements AqlNode {
private final List<AqlNode> aqlListExpressionList;
public AqlUnion(List<AqlNode> aqlListExpressionList) {
this.aqlListExpressionList = aqlListExpressionList;
}
public List<AqlNode> getAqlListExpressionList() {
return aqlListExpressionList;
}
@Override
public String toQueryString() {
return String.format(
"UNION(%s)",
this.aqlListExpressionList.stream().map(AqlNode::toQueryString)
.collect(Collectors.joining(", "))
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/AqlFilter.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
public class AqlFilter implements AqlNode {
private final AqlNode aqlBooleanExpression;
public AqlFilter(AqlNode aqlBooleanExpression) {
this.aqlBooleanExpression = aqlBooleanExpression;
}
public AqlNode getAqlBooleanExpression() {
return aqlBooleanExpression;
}
@Override
public String toQueryString() {
return String.format("FILTER %s", this.aqlBooleanExpression.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/AqlFor.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
public class AqlFor implements AqlNode {
private final AqlVariable aqlVariable;
private final AqlNode aqlList;
public AqlFor(AqlVariable aqlVariable, AqlNode aqlList) {
this.aqlVariable = aqlVariable;
this.aqlList = aqlList;
}
public AqlVariable getAqlVariable() {
return aqlVariable;
}
public AqlNode getAqlList() {
return aqlList;
}
@Override
public String toQueryString() {
return String.format("FOR %s IN %s", this.aqlVariable.toQueryString(),
this.aqlList.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/AqlGraphTraversalFor.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlInteger;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.jetbrains.annotations.Nullable;
public class AqlGraphTraversalFor implements AqlNode {
private final AqlVariable nodeVariable;
private final TraversalDirection traversalDirection;
private final AqlNode startNode;
private final List<AqlNode> edgeCollections;
@Nullable
private final AqlVariable edgeVariable;
@Nullable
private final AqlVariable pathVariable;
@Nullable
private final AqlInteger min;
@Nullable
private final AqlInteger max;
public AqlGraphTraversalFor(
AqlVariable nodeVariable,
TraversalDirection traversalDirection,
AqlNode startNode,
List<AqlNode> edgeCollections,
@Nullable AqlVariable edgeVariable,
@Nullable AqlVariable pathVariable,
@Nullable AqlInteger min,
@Nullable AqlInteger max
) {
this.nodeVariable = nodeVariable;
this.traversalDirection = traversalDirection;
this.startNode = startNode;
this.edgeCollections = edgeCollections;
this.edgeVariable = edgeVariable;
this.pathVariable = pathVariable;
this.min = min;
this.max = max;
}
public AqlVariable getNodeVariable() {
return nodeVariable;
}
public TraversalDirection getTraversalDirection() {
return traversalDirection;
}
public AqlNode getStartNode() {
return startNode;
}
public List<AqlNode> getEdgeCollections() {
return edgeCollections;
}
@Nullable
public AqlVariable getEdgeVariable() {
return edgeVariable;
}
@Nullable
public AqlVariable getPathVariable() {
return pathVariable;
}
@Nullable
public AqlInteger getMin() {
return min;
}
@Nullable
public AqlInteger getMax() {
return max;
}
@Override
public String toQueryString() {
return String.format(
"FOR %s IN %s %s %s %s",
this.createForVariables(),
this.createMinMax(),
this.traversalDirection,
this.startNode.toQueryString(),
this.edgeCollections.stream().map(AqlNode::toQueryString).collect(Collectors.joining(", "))
);
}
private String createForVariables() {
var variables = new ArrayList<String>();
variables.add(this.nodeVariable.toQueryString());
if (this.edgeVariable != null) {
variables.add(this.edgeVariable.toQueryString());
}
if (this.pathVariable != null) {
variables.add(this.pathVariable.toQueryString());
}
return String.join(", ", variables);
}
private String createMinMax() {
if (this.min == null) {
return "";
}
if (this.max == null) {
return this.min.toQueryString() + "";
}
return String.format("%s..%s", this.min.toQueryString(), this.max.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/AqlLet.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
public class AqlLet implements AqlNode {
private final AqlVariable variable;
private final AqlNode aqlNode;
public AqlLet(AqlVariable variable, AqlNode aqlNode) {
this.variable = variable;
this.aqlNode = aqlNode;
}
public AqlVariable getVariable() {
return variable;
}
public AqlNode getAqlNode() {
return aqlNode;
}
@Override
public String toQueryString() {
return String.format("LET %s = ( %s )", this.variable.toQueryString(),
this.aqlNode.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/AqlLimit.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import org.jetbrains.annotations.Nullable;
public class AqlLimit implements AqlNode {
private final AqlNode count;
@Nullable
private AqlNode offset;
public AqlLimit(AqlNode count) {
this.count = count;
}
public AqlLimit(AqlNode count, @Nullable AqlNode offset) {
this.count = count;
this.offset = offset;
}
public AqlNode getCount() {
return count;
}
@Nullable
public AqlNode getOffset() {
return offset;
}
@Override
public String toQueryString() {
if (this.offset == null) {
return String.format("LIMIT %s", this.count.toQueryString());
}
return String.format("LIMIT %s, %s", this.offset.toQueryString(), this.count.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/AqlParentheses.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
public class AqlParentheses implements AqlNode {
private final AqlNode aqlNode;
public AqlParentheses(AqlNode aqlNode) {
this.aqlNode = aqlNode;
}
public AqlNode getAqlNode() {
return aqlNode;
}
@Override
public String toQueryString() {
return String.format("( %s )", this.aqlNode.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/AqlQuestionMarkOperator.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlOperator;
import java.util.Objects;
import org.jetbrains.annotations.Nullable;
public class AqlQuestionMarkOperator implements AqlNode {
private final AqlOperator arrayComparisonOperator;
@Nullable
private AqlNode rightHandExpression;
public AqlQuestionMarkOperator(
@Nullable AqlNode rightHandExpression,
AqlOperator arrayComparisonOperator
) {
this.rightHandExpression = rightHandExpression;
this.arrayComparisonOperator = arrayComparisonOperator;
}
@Override
public String toQueryString() {
return String.format(
"[? %s FILTER CURRENT %s]",
this.arrayComparisonOperator.toQueryString(),
Objects.requireNonNull(this.rightHandExpression).toQueryString()
);
}
@Nullable
public AqlNode getRightHandExpression() {
return rightHandExpression;
}
public void setRightHandExpression(@Nullable AqlNode rightHandExpression) {
this.rightHandExpression = rightHandExpression;
}
@Nullable
public AqlNode getDeepestRightHandExpression() {
if (this.isDeepestRightHandExpressionSet()
&& (this.rightHandExpression instanceof AqlQuestionMarkOperator questionMarkOperator)) {
return questionMarkOperator.getDeepestRightHandExpression();
}
return rightHandExpression;
}
public void setDeepestRightHandExpression(AqlNode rightHandExpression) {
if (this.isRightHandExpressionSet()) {
if (this.rightHandExpression instanceof AqlQuestionMarkOperator questionMarkOperator) {
questionMarkOperator.setDeepestRightHandExpression(rightHandExpression);
} else {
this.rightHandExpression = rightHandExpression;
}
} else {
this.rightHandExpression = rightHandExpression;
}
}
public AqlOperator getArrayComparisonOperator() {
return arrayComparisonOperator;
}
public boolean isRightHandExpressionSet() {
return rightHandExpression != null;
}
public boolean isDeepestRightHandExpressionSet() {
if (!this.isRightHandExpressionSet()) {
return false;
}
if (this.rightHandExpression instanceof AqlQuestionMarkOperator questionMarkOperator) {
return questionMarkOperator.isDeepestRightHandExpressionSet();
}
return true;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/AqlReturn.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
public class AqlReturn implements AqlNode {
private final AqlNode expression;
public AqlReturn(AqlNode expression) {
this.expression = expression;
}
public AqlNode getExpression() {
return expression;
}
@Override
public String toQueryString() {
return String.format("RETURN %s", this.expression.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/AqlSort.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import java.util.List;
import java.util.stream.Collectors;
public class AqlSort implements AqlNode {
private final List<AqlSortOption> sortOptionList;
public AqlSort(List<AqlSortOption> sortOptionList) {
this.sortOptionList = sortOptionList;
}
public List<AqlSortOption> getSortOptionList() {
return sortOptionList;
}
@Override
public String toQueryString() {
return String.format(
"SORT %s",
this.sortOptionList.stream().map(AqlSortOption::toQueryString)
.collect(Collectors.joining(", "))
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/AqlSortOption.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
public class AqlSortOption implements AqlNode {
private final AqlNode expression;
private final String direction;
private AqlSortOption(AqlNode expression, String direction) {
this.expression = expression;
this.direction = direction;
}
public static AqlSortOption asc(AqlNode expression) {
return new AqlSortOption(expression, "ASC");
}
public static AqlSortOption desc(AqlNode expression) {
return new AqlSortOption(expression, "DESC");
}
@Override
public String toQueryString() {
return String.format("%s %s", this.expression.toQueryString(), this.direction);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/AqlTernaryOperator.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
public class AqlTernaryOperator implements AqlNode {
private final AqlNode booleanExpression;
private final AqlNode leftExpression;
private final AqlNode rightExpression;
public AqlTernaryOperator(AqlNode booleanExpression, AqlNode leftExpression,
AqlNode rightExpression) {
this.booleanExpression = booleanExpression;
this.leftExpression = leftExpression;
this.rightExpression = rightExpression;
}
public AqlNode getBooleanExpression() {
return booleanExpression;
}
public AqlNode getLeftExpression() {
return leftExpression;
}
public AqlNode getRightExpression() {
return rightExpression;
}
@Override
public String toQueryString() {
return String.format(
"%s ? ( %s ) : ( %s )",
this.booleanExpression.toQueryString(),
this.leftExpression.toQueryString(),
this.rightExpression.toQueryString()
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/highLevelOperations/TraversalDirection.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations;
public enum TraversalDirection {
OUTBOUND,
INBOUND,
ANY
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/logicalOperators/AqlAnd.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.logicalOperators;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
public class AqlAnd implements AqlNode {
private final AqlNode leftNode;
private final AqlNode rightNode;
public AqlAnd(AqlNode leftNode, AqlNode rightNode) {
this.leftNode = leftNode;
this.rightNode = rightNode;
}
public AqlNode getLeftNode() {
return leftNode;
}
public AqlNode getRightNode() {
return rightNode;
}
@Override
public String toQueryString() {
return String.format("%s AND %s", this.leftNode.toQueryString(),
this.rightNode.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/logicalOperators/AqlNot.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.logicalOperators;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
public class AqlNot implements AqlNode {
private final AqlNode aqlNode;
public AqlNot(AqlNode aqlNode) {
this.aqlNode = aqlNode;
}
public AqlNode getAqlNode() {
return aqlNode;
}
@Override
public String toQueryString() {
return String.format("NOT %s", this.aqlNode.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/ast/logicalOperators/AqlOr.java | package ai.stapi.arangograph.graphLoader.arangoQuery.ast.logicalOperators;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
public class AqlOr implements AqlNode {
private final AqlNode leftNode;
private final AqlNode rightNode;
public AqlOr(AqlNode leftNode, AqlNode rightNode) {
this.leftNode = leftNode;
this.rightNode = rightNode;
}
public AqlNode getLeftNode() {
return leftNode;
}
public AqlNode getRightNode() {
return rightNode;
}
@Override
public String toQueryString() {
return String.format("%s OR %s", this.leftNode.toQueryString(), this.rightNode.toQueryString());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/bindingObjects/ArangoEdgeFindDocument.java | package ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects;
import java.util.List;
public class ArangoEdgeFindDocument {
private List<Object> data;
private EdgeArangoFindGraphDocument graphResponse;
private ArangoEdgeFindDocument() {
}
public ArangoEdgeFindDocument(List<Object> data, EdgeArangoFindGraphDocument graphResponse) {
this.data = data;
this.graphResponse = graphResponse;
}
public List<Object> getData() {
return data;
}
public EdgeArangoFindGraphDocument getGraphResponse() {
return graphResponse;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/bindingObjects/ArangoEdgeGetDocument.java | package ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects;
public class ArangoEdgeGetDocument {
private Object data;
private EdgeArangoGetGraphDocument graphResponse;
private ArangoEdgeGetDocument() {
}
public ArangoEdgeGetDocument(Object data, EdgeArangoGetGraphDocument graphResponse) {
this.data = data;
this.graphResponse = graphResponse;
}
public Object getData() {
return data;
}
public EdgeArangoGetGraphDocument getGraphResponse() {
return graphResponse;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/bindingObjects/ArangoNodeFindDocument.java | package ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects;
import java.util.List;
public class ArangoNodeFindDocument {
private List<Object> data;
private NodeArangoFindGraphDocument graphResponse;
private ArangoNodeFindDocument() {
}
public ArangoNodeFindDocument(List<Object> data, NodeArangoFindGraphDocument graphResponse) {
this.data = data;
this.graphResponse = graphResponse;
}
public List<Object> getData() {
return data;
}
public NodeArangoFindGraphDocument getGraphResponse() {
return graphResponse;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/bindingObjects/ArangoNodeGetDocument.java | package ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects;
public class ArangoNodeGetDocument {
private Object data;
private NodeArangoGetGraphDocument graphResponse;
private ArangoNodeGetDocument() {
}
public ArangoNodeGetDocument(Object data, NodeArangoGetGraphDocument graphResponse) {
this.data = data;
this.graphResponse = graphResponse;
}
public Object getData() {
return data;
}
public NodeArangoGetGraphDocument getGraphResponse() {
return graphResponse;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/bindingObjects/EdgeArangoFindGraphDocument.java | package ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects;
import ai.stapi.graph.graphelements.Edge;
import ai.stapi.graph.graphelements.Node;
import java.util.List;
public class EdgeArangoFindGraphDocument {
List<Edge> mainGraphElements;
List<Edge> edges;
List<Node> nodes;
private EdgeArangoFindGraphDocument() {
}
public EdgeArangoFindGraphDocument(
List<Edge> mainGraphElements,
List<Edge> edges,
List<Node> nodes
) {
this.mainGraphElements = mainGraphElements;
this.edges = edges;
this.nodes = nodes;
}
public List<Edge> getMainGraphElements() {
return mainGraphElements;
}
public List<Edge> getEdges() {
return edges;
}
public List<Node> getNodes() {
return nodes;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/bindingObjects/EdgeArangoGetGraphDocument.java | package ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects;
import ai.stapi.graph.graphelements.Edge;
import ai.stapi.graph.graphelements.Node;
import java.util.List;
public class EdgeArangoGetGraphDocument {
Edge mainGraphElement;
List<Edge> edges;
List<Node> nodes;
private EdgeArangoGetGraphDocument() {
}
public EdgeArangoGetGraphDocument(
Edge mainGraphElement,
List<Edge> edges,
List<Node> nodes
) {
this.mainGraphElement = mainGraphElement;
this.edges = edges;
this.nodes = nodes;
}
public Edge getMainGraphElement() {
return mainGraphElement;
}
public List<Edge> getEdges() {
return edges;
}
public List<Node> getNodes() {
return nodes;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/bindingObjects/NodeArangoFindGraphDocument.java | package ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects;
import ai.stapi.graph.graphelements.Edge;
import ai.stapi.graph.graphelements.Node;
import java.util.List;
public class NodeArangoFindGraphDocument {
List<Node> mainGraphElements;
List<Edge> edges;
List<Node> nodes;
private NodeArangoFindGraphDocument() {
}
public NodeArangoFindGraphDocument(
List<Node> mainGraphElements,
List<Edge> edges,
List<Node> nodes
) {
this.mainGraphElements = mainGraphElements;
this.edges = edges;
this.nodes = nodes;
}
public List<Node> getMainGraphElements() {
return mainGraphElements;
}
public List<Edge> getEdges() {
return edges;
}
public List<Node> getNodes() {
return nodes;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/bindingObjects/NodeArangoGetGraphDocument.java | package ai.stapi.arangograph.graphLoader.arangoQuery.bindingObjects;
import ai.stapi.graph.graphelements.Edge;
import ai.stapi.graph.graphelements.Node;
import java.util.List;
public class NodeArangoGetGraphDocument {
Node mainGraphElement;
List<Edge> edges;
List<Node> nodes;
private NodeArangoGetGraphDocument() {
}
public NodeArangoGetGraphDocument(
Node mainGraphElement,
List<Edge> edges,
List<Node> nodes
) {
this.mainGraphElement = mainGraphElement;
this.edges = edges;
this.nodes = nodes;
}
public Node getMainGraphElement() {
return mainGraphElement;
}
public List<Edge> getEdges() {
return edges;
}
public List<Node> getNodes() {
return nodes;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoEdgeCollectionSubQueryBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlObject;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlFor;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import org.jetbrains.annotations.NotNull;
public class ArangoEdgeCollectionSubQueryBuilder extends ArangoEdgeSubQueryBuilder {
private ArangoEdgeCollectionSubQueryBuilder(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
String graphElementType,
String subQueryPostfix,
boolean isOutgoing
) {
super(searchOptionResolver, structureSchemaFinder, graphElementType, subQueryPostfix,
isOutgoing);
}
public static ArangoEdgeCollectionSubQueryBuilder ingoing(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
String graphElementType,
String subQueryPostfix
) {
return new ArangoEdgeCollectionSubQueryBuilder(
searchOptionResolver,
structureSchemaFinder,
graphElementType,
subQueryPostfix,
false
);
}
public static ArangoEdgeCollectionSubQueryBuilder outgoing(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
String graphElementType,
String subQueryPostfix
) {
return new ArangoEdgeCollectionSubQueryBuilder(
searchOptionResolver,
structureSchemaFinder,
graphElementType,
subQueryPostfix,
true
);
}
@Override
@NotNull
protected ArangoQuery createAqlBody(
ArangoQuery keptAttributes,
AqlObject graph,
GraphLoaderReturnType... returnTypes
) {
var collectionVariable =
this.createCollectionVariable(this.subQueryPostfix).markAsBindParameter();
var aqlFor = new AqlFor(
this.createEdgeDocumentName(this.subQueryPostfix),
collectionVariable.markAsBindParameter()
);
var aqlBody = this.createBaseAqlBody(keptAttributes, graph, aqlFor, returnTypes);
aqlBody.getBindParameters().put(collectionVariable.getVariableName(), this.graphElementType);
return aqlBody;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoEdgeGetSubQueryBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlObject;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlString;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions.AqlConcatSeparator;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions.AqlDocument;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlLet;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import ai.stapi.identity.UniqueIdentifier;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import org.jetbrains.annotations.NotNull;
public class ArangoEdgeGetSubQueryBuilder extends ArangoEdgeSubQueryBuilder {
private final UniqueIdentifier graphElementId;
public ArangoEdgeGetSubQueryBuilder(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
String graphElementType,
String subQueryPostfix,
boolean isOutgoing,
UniqueIdentifier graphElementId
) {
super(searchOptionResolver, structureSchemaFinder, graphElementType, subQueryPostfix,
isOutgoing);
this.graphElementId = graphElementId;
}
public static ArangoEdgeGetSubQueryBuilder ingoing(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
UniqueIdentifier graphElementUuid,
String graphElementType,
String subQueryPostfix
) {
return new ArangoEdgeGetSubQueryBuilder(
searchOptionResolver,
structureSchemaFinder,
graphElementType,
subQueryPostfix,
false,
graphElementUuid
);
}
public static ArangoEdgeGetSubQueryBuilder outgoing(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
UniqueIdentifier graphElementUuid,
String graphElementType,
String subQueryPostfix
) {
return new ArangoEdgeGetSubQueryBuilder(
searchOptionResolver,
structureSchemaFinder,
graphElementType,
subQueryPostfix,
true,
graphElementUuid
);
}
@NotNull
@Override
protected ArangoQuery createAqlBody(
ArangoQuery keptAttributes,
AqlObject graph,
GraphLoaderReturnType... returnTypes
) {
var collectionVariable = this.createCollectionVariable(this.subQueryPostfix);
var idVariable = this.createIdVariable(this.subQueryPostfix);
var aqlFor = new AqlLet(
this.createEdgeDocumentName(this.subQueryPostfix),
new AqlDocument(
new AqlConcatSeparator(
new AqlString("/"),
collectionVariable.markAsBindParameter(),
idVariable.markAsBindParameter()
)
)
);
var baseAqlBody = this.createBaseAqlBody(keptAttributes, graph, aqlFor, returnTypes);
baseAqlBody.getBindParameters()
.put(collectionVariable.getVariableName(), this.graphElementType);
baseAqlBody.getBindParameters().put(idVariable.getVariableName(), this.graphElementId.getId());
return baseAqlBody;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoEdgeKeptAttributesBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
public class ArangoEdgeKeptAttributesBuilder extends ArangoKeptAttributesBuilder {
protected static final String[] DEFAULT_META_ATTRIBUTES = {
"_id",
"_rev",
"_key",
"_from",
"_to",
"_metaData"
};
public ArangoEdgeKeptAttributesBuilder(
StructureSchemaFinder structureSchemaProvider,
AqlVariable documentName,
String subQueryPostfix,
String graphElementType
) {
super(structureSchemaProvider, documentName, subQueryPostfix, graphElementType);
}
@Override
protected String[] provideDefaultMetaAttributes() {
return ArangoEdgeKeptAttributesBuilder.DEFAULT_META_ATTRIBUTES;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoEdgeSubQueryBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQueryType;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlObject;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlRootNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlString;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions.AqlDocument;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions.AqlPush;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlLet;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
public abstract class ArangoEdgeSubQueryBuilder implements ArangoMainQueryBuilder {
protected final boolean isOutgoing;
protected final ArangoGenericSearchOptionResolver searchOptionResolver;
protected final StructureSchemaFinder structureSchemaFinder;
protected final ArangoQueryByNodeTypeBuilder arangoQueryByNodeTypeBuilder;
protected final ArangoEdgeKeptAttributesBuilder arangoEdgeKeptAttributesBuilder;
protected final ArangoMappedObjectBuilder arangoMappedObjectBuilder;
protected final ArangoSearchOptionsBuilder arangoSearchOptionsBuilder;
protected final String graphElementType;
protected final String subQueryPostfix;
private boolean isNodeFieldMapped = false;
public ArangoEdgeSubQueryBuilder(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
String graphElementType,
String subQueryPostfix,
boolean isOutgoing
) {
this.searchOptionResolver = searchOptionResolver;
this.structureSchemaFinder = structureSchemaFinder;
this.graphElementType = graphElementType;
this.subQueryPostfix = subQueryPostfix;
this.isOutgoing = isOutgoing;
this.arangoQueryByNodeTypeBuilder = new ArangoQueryByNodeTypeBuilder(
this.searchOptionResolver,
this.structureSchemaFinder,
this.createChildSubQueryPostfix(this.subQueryPostfix, 0),
this.buildJoinedNodeGetter()
);
var edgeDocumentName = this.createEdgeDocumentName(this.subQueryPostfix);
this.arangoEdgeKeptAttributesBuilder = new ArangoEdgeKeptAttributesBuilder(
this.structureSchemaFinder,
edgeDocumentName,
this.subQueryPostfix,
this.graphElementType
);
this.arangoMappedObjectBuilder = new ArangoMappedObjectBuilder(
this.arangoEdgeKeptAttributesBuilder,
this.structureSchemaFinder,
edgeDocumentName,
this.subQueryPostfix,
this.graphElementType
);
this.arangoSearchOptionsBuilder = new ArangoSearchOptionsBuilder(
this.searchOptionResolver,
edgeDocumentName,
this.isOutgoing ? ArangoQueryType.OUTGOING_EDGE : ArangoQueryType.INGOING_EDGE,
this.graphElementType,
this.subQueryPostfix
);
}
public ArangoEdgeKeptAttributesBuilder setKeptAttributes() {
return this.arangoEdgeKeptAttributesBuilder;
}
public ArangoMappedObjectBuilder setMappedScalars() {
return this.arangoMappedObjectBuilder;
}
public ArangoSearchOptionsBuilder setSearchOptions() {
return this.arangoSearchOptionsBuilder;
}
public ArangoNodeGetSubQueryBuilder joinNodeGetSubQuery(String nodeType) {
return this.arangoQueryByNodeTypeBuilder.addGetNodeOption(nodeType);
}
public ArangoNodeGetSubQueryBuilder mapNodeGetSubQuery(String nodeType) {
if (!this.isNodeFieldMapped) {
this.arangoMappedObjectBuilder.mapCustomField(
"node",
this.createSubQueryVariable(this.createChildSubQueryPostfix(this.subQueryPostfix, 0))
.getItem(0)
.getField("data")
);
this.isNodeFieldMapped = true;
}
return this.arangoQueryByNodeTypeBuilder.addGetNodeOption(nodeType);
}
@Override
public ArangoQuery build(GraphLoaderReturnType... returnTypes) {
var subQueryVariable =
this.createSubQueryVariable(this.createChildSubQueryPostfix(this.subQueryPostfix, 0));
var keptAttributes = this.arangoEdgeKeptAttributesBuilder.build();
var edges = this.createEdges(subQueryVariable, keptAttributes);
var nodes = this.createNodes(subQueryVariable);
var graph = this.createGraphObject(nodes, edges);
return this.createAqlBody(keptAttributes, graph, returnTypes);
}
@Override
public ArangoQuery buildAsMain(GraphLoaderReturnType... returnTypes) {
var subQueryVariable =
this.createSubQueryVariable(this.createChildSubQueryPostfix(this.subQueryPostfix, 0));
var keptAttributes = this.arangoEdgeKeptAttributesBuilder.build();
var main = keptAttributes.getAqlNode();
var nodes = this.createNodes(subQueryVariable);
var edges = this.getChildSubQueryEdges(subQueryVariable);
var graph = this.createMainGraphObject(main, nodes, edges);
return this.createAqlBody(keptAttributes, graph, returnTypes);
}
@NotNull
protected abstract ArangoQuery createAqlBody(
ArangoQuery keptAttributes,
AqlObject graph,
GraphLoaderReturnType... returnTypes
);
@NotNull
protected ArangoQuery createBaseAqlBody(
ArangoQuery keptAttributes,
AqlObject graph,
AqlNode getDocumentLine,
GraphLoaderReturnType... returnTypes
) {
var mappedObject = this.arangoMappedObjectBuilder.build();
var dataObject = new AqlObject(Map.of(
new AqlString("edges"), mappedObject.getAqlNode()
));
var childQuery = this.arangoQueryByNodeTypeBuilder.build(returnTypes);
var searchOptions = this.arangoSearchOptionsBuilder.build();
var letJoinedNode = new AqlLet(
this.createSubQueryVariable(this.createChildSubQueryPostfix(this.subQueryPostfix, 0)),
childQuery.getAqlNode()
);
var forQuery = new AqlRootNode(
getDocumentLine,
searchOptions.getAqlNode(),
letJoinedNode,
this.createOtherNodeLine(),
this.createReturnStatement(
graph,
dataObject,
returnTypes
)
);
var bindParameters = this.mergeBindParameters(
keptAttributes.getBindParameters(),
mappedObject.getBindParameters(),
childQuery.getBindParameters(),
searchOptions.getBindParameters()
);
return new ArangoQuery(
forQuery,
bindParameters
);
}
private AqlNode createEdges(AqlVariable subQueryVariable, ArangoQuery keptAttributes) {
return new AqlPush(
this.getChildSubQueryEdges(subQueryVariable),
keptAttributes.getAqlNode()
);
}
private AqlNode createNodes(AqlVariable subQueryVariable) {
return new AqlPush(
this.getChildSubQueryNodes(subQueryVariable),
new ArangoNodeKeptAttributesBuilder(
this.structureSchemaFinder,
this.createOtherNodeVariableName(),
"",
""
).build().getAqlNode()
);
}
protected AqlVariable buildJoinedNodeGetter() {
return this.createEdgeDocumentName(this.subQueryPostfix)
.getField(this.isOutgoing ? "_to" : "_from");
}
private AqlLet createOtherNodeLine() {
return new AqlLet(
this.createOtherNodeVariableName(),
new AqlDocument(
this.createEdgeDocumentName(this.subQueryPostfix)
.getField(this.isOutgoing ? "_from" : "_to")
)
);
}
@NotNull
private AqlVariable createOtherNodeVariableName() {
var childSubQueryPrefix = this.createChildSubQueryPostfix(this.subQueryPostfix, 0);
return new AqlVariable("otherNode_" + childSubQueryPrefix);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoGraphTraversalJoinable.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractEdgeDescription;
public interface ArangoGraphTraversalJoinable {
ArangoGraphTraversalSubQueryBuilder joinGraphTraversal(AbstractEdgeDescription edgeDescription);
ArangoGraphTraversalSubQueryBuilder mapGraphTraversal(
String fieldName,
AbstractEdgeDescription edgeDescription
);
ArangoGraphTraversalSubQueryBuilder mapGraphTraversalAsConnections(
String fieldName,
AbstractEdgeDescription edgeDescription
);
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoGraphTraversalNodeOptionBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlReturn;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractEdgeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.EdgeDescriptionParameters;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
public class ArangoGraphTraversalNodeOptionBuilder
implements ArangoGraphTraversalJoinable, ArangoSubQueryBuilder {
private final StructureSchemaFinder structureSchemaFinder;
private final ArangoGenericSearchOptionResolver searchOptionResolver;
private final ArangoNodeKeptAttributesBuilder keptAttributesBuilder;
private final ArangoMappedObjectBuilder mappedObjectBuilder;
private final String subQueryPostfix;
private final Map<String, ArangoGraphTraversalSubQueryBuilder> subQueryBuilders;
private final String nodeType;
private final AqlVariable nodeDocumentVariable;
public ArangoGraphTraversalNodeOptionBuilder(
StructureSchemaFinder structureSchemaFinder,
ArangoGenericSearchOptionResolver searchOptionResolver,
String graphElementType,
String subQueryPostfix,
AqlVariable nodeDocumentVariable
) {
this.structureSchemaFinder = structureSchemaFinder;
this.searchOptionResolver = searchOptionResolver;
this.subQueryPostfix = subQueryPostfix;
this.nodeType = graphElementType;
this.nodeDocumentVariable = nodeDocumentVariable;
this.keptAttributesBuilder = new ArangoNodeKeptAttributesBuilder(
this.structureSchemaFinder,
nodeDocumentVariable,
this.subQueryPostfix,
this.nodeType
);
this.mappedObjectBuilder = new ArangoMappedObjectBuilder(
this.keptAttributesBuilder,
this.structureSchemaFinder,
nodeDocumentVariable,
"node_" + this.subQueryPostfix,
graphElementType
);
this.subQueryBuilders = new HashMap<>();
}
@NotNull
private static String getSubQueryVariable(String childSubQueryPrefix) {
return BASE_SUB_QUERY_VARIABLE_NAME + "_graphTraverOption_" + childSubQueryPrefix;
}
public ArangoMappedObjectBuilder setMappedScalars() {
return this.mappedObjectBuilder;
}
public ArangoNodeKeptAttributesBuilder setKeptAttributes() {
return this.keptAttributesBuilder;
}
public ArangoGraphTraversalSubQueryBuilder joinGraphTraversal(
AbstractEdgeDescription edgeDescription) {
var childSubQueryPrefix = this.getChildSubQueryPostfix();
var subQueryBuilder = new ArangoGraphTraversalSubQueryBuilder(
this.searchOptionResolver,
this.structureSchemaFinder,
edgeDescription,
childSubQueryPrefix,
this.nodeDocumentVariable
);
this.subQueryBuilders.put(
getSubQueryVariable(childSubQueryPrefix),
subQueryBuilder
);
return subQueryBuilder;
}
@Override
public ArangoGraphTraversalSubQueryBuilder mapGraphTraversal(
String fieldName,
AbstractEdgeDescription edgeDescription
) {
var childSubQueryPrefix = this.getChildSubQueryPostfix();
var subQueryVariable = getSubQueryVariable(childSubQueryPrefix);
var edgeType = ((EdgeDescriptionParameters) edgeDescription.getParameters()).getEdgeType();
var fieldDefinition = this.structureSchemaFinder.getFieldDefinitionOrFallback(
this.nodeType,
edgeType
);
if (fieldDefinition.isList()) {
this.mappedObjectBuilder.mapCustomField(fieldName,
new AqlVariable(subQueryVariable + "[*].data"));
} else {
this.mappedObjectBuilder.mapCustomField(fieldName,
new AqlVariable(subQueryVariable + "[0].data"));
}
var subQueryBuilder = new ArangoGraphTraversalSubQueryBuilder(
this.searchOptionResolver,
this.structureSchemaFinder,
edgeDescription,
childSubQueryPrefix,
this.nodeDocumentVariable
);
this.subQueryBuilders.put(
subQueryVariable,
subQueryBuilder
);
return subQueryBuilder;
}
public ArangoGraphTraversalSubQueryBuilder mapGraphTraversalAsConnections(
String fieldName,
AbstractEdgeDescription edgeDescription
) {
var childSubQueryPrefix = this.getChildSubQueryPostfix();
var subQueryVariable = getSubQueryVariable(childSubQueryPrefix);
var edgeType = ((EdgeDescriptionParameters) edgeDescription.getParameters()).getEdgeType();
var fieldDefinition = this.structureSchemaFinder.getFieldDefinitionOrFallback(
this.nodeType,
edgeType
);
if (fieldDefinition.isList()) {
this.mappedObjectBuilder.mapCustomField(fieldName + "Connections",
new AqlVariable(subQueryVariable + "[*].data"));
} else {
this.mappedObjectBuilder.mapCustomField(fieldName + "Connections",
new AqlVariable(subQueryVariable + "[0].data"));
}
var subQueryBuilder = ArangoGraphTraversalSubQueryBuilder.asConnections(
this.searchOptionResolver,
this.structureSchemaFinder,
edgeDescription,
childSubQueryPrefix,
this.nodeDocumentVariable
);
this.subQueryBuilders.put(
subQueryVariable,
subQueryBuilder
);
return subQueryBuilder;
}
@Override
public ArangoQuery build(GraphLoaderReturnType... returnTypes) {
var buildSubQueries = this.buildSubQueries(returnTypes);
var keptAttributes = this.keptAttributesBuilder.build();
var mappedObject = this.mappedObjectBuilder.build();
Map<String, Object> finalBindParameters = new HashMap<>();
finalBindParameters.putAll(keptAttributes.getBindParameters());
finalBindParameters.putAll(mappedObject.getBindParameters());
buildSubQueries.values()
.forEach(query -> finalBindParameters.putAll(query.getBindParameters()));
return new ArangoQuery(
new AqlVariable(
this.buildQueryString(
buildSubQueries,
keptAttributes,
mappedObject,
returnTypes)
),
finalBindParameters
);
}
@NotNull
private String buildQueryString(
Map<String, ArangoQuery> subQueries,
ArangoQuery keptAttributes,
ArangoQuery mappedObject,
GraphLoaderReturnType... returnTypes
) {
var subQueryString = this.buildSubQueriesString(subQueries);
var set = Arrays.stream(returnTypes).collect(Collectors.toSet());
if (set.contains(GraphLoaderReturnType.SORT_OPTION)) {
if (this.keptAttributesBuilder.isExactlyOneAttributeSet()) {
return new AqlReturn(
this.keptAttributesBuilder.buildOneAttributeFirstValue()).toQueryString();
}
return String.format(
"%s RETURN %s[0]",
subQueryString,
this.subQueryBuilders.keySet().iterator().next()
);
}
if (set.contains(GraphLoaderReturnType.FILTER_OPTION)) {
if (this.keptAttributesBuilder.isExactlyOneAttributeSet()) {
return new AqlReturn(
this.keptAttributesBuilder.buildOneListOrLeafAttribute()
).toQueryString();
}
var graphTraversalBuilderEntry = this.subQueryBuilders.entrySet().iterator().next();
var fieldDefinition = this.structureSchemaFinder.getFieldDefinitionOrFallback(
this.nodeType,
graphTraversalBuilderEntry.getValue().getEdgeType()
);
return String.format(
"%s RETURN %s%s",
subQueryString,
graphTraversalBuilderEntry.getKey(),
fieldDefinition.isList() ? "" : "[0]"
);
}
var graph = String.format(
"{ edges: %s, nodes: PUSH(%s, %s) }",
this.buildJoinedEdges(),
this.buildJoinedNodes(),
keptAttributes.getQueryString()
);
return String.format(
"%s RETURN { data: %s, graphResponse: %s }",
subQueryString,
set.contains(GraphLoaderReturnType.OBJECT) ? mappedObject.getQueryString() : "{}",
set.contains(GraphLoaderReturnType.GRAPH) ? graph : "{}"
);
}
private Map<String, ArangoQuery> buildSubQueries(GraphLoaderReturnType... returnTypes) {
return this.subQueryBuilders.entrySet()
.stream()
.map(entry -> new AbstractMap.SimpleEntry<>(entry.getKey(),
entry.getValue().build(returnTypes)))
.collect(
Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
}
private String buildSubQueriesString(Map<String, ArangoQuery> subQueries) {
var strings = subQueries.entrySet().stream()
.map(entry -> this.buildSubQueryString(entry.getKey(), entry.getValue().getQueryString()))
.toList();
return String.join(" ", strings);
}
private String buildSubQueryString(String variableKey, String subQueryString) {
var variableAssignmentStatement = "LET " + variableKey + " = (";
var endStatement = ")";
return String.join(
" ",
variableAssignmentStatement,
subQueryString,
endStatement
);
}
protected String buildJoinedEdges() {
if (this.subQueryBuilders.size() == 0) {
return "[]";
}
if (this.subQueryBuilders.size() == 1) {
var key = String.join("", this.subQueryBuilders.keySet());
return key + "[*].graphResponse.edges[**]";
}
return "UNION("
+ this.subQueryBuilders.keySet().stream()
.map(key -> key + "[*].graphResponse.edges[**]")
.collect(Collectors.joining(", "))
+ ")";
}
protected String buildJoinedNodes() {
if (this.subQueryBuilders.size() == 0) {
return "[]";
}
if (this.subQueryBuilders.size() == 1) {
var key = String.join("", this.subQueryBuilders.keySet());
return key + "[*].graphResponse.nodes[**]";
}
return "UNION("
+ this.subQueryBuilders.keySet().stream()
.map(key -> key + "[*].graphResponse.nodes[**]")
.collect(Collectors.joining(", "))
+ ")";
}
private AqlVariable buildDocumentName() {
if (this.subQueryPostfix.isBlank()) {
return new AqlVariable(NODE_DOCUMENT_BASE_NAME);
}
return new AqlVariable(NODE_DOCUMENT_BASE_NAME + "_" + this.subQueryPostfix);
}
protected String getChildSubQueryPostfix() {
if (this.subQueryPostfix.isBlank()) {
return String.valueOf(this.subQueryBuilders.size());
}
return this.subQueryPostfix + "_" + this.subQueryBuilders.size();
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoGraphTraversalSubQueryBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQueryType;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlRootNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions.AqlPush;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlGraphTraversalFor;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlLet;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlReturn;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.TraversalDirection;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractEdgeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.EdgeDescriptionParameters;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
public class ArangoGraphTraversalSubQueryBuilder implements ArangoSubQueryBuilder {
private final ArangoGenericSearchOptionResolver searchOptionResolver;
private final StructureSchemaFinder structureSchemaFinder;
private final AqlVariable traversingStart;
private final AbstractEdgeDescription edgeDescription;
private final ArangoSearchOptionsBuilder edgeSearchOptionBuilder;
private final ArangoEdgeKeptAttributesBuilder edgeKeptAttributesBuilder;
private final ArangoMappedObjectBuilder edgeMappedObjectBuilder;
private final ArangoSearchOptionsBuilder nodeSearchOptionBuilder;
private final ArangoQueryByNodeTypeBuilder arangoQueryByNodeTypeBuilder;
private final String subQueryPostfix;
private boolean isNodeFieldMapped = false;
private boolean asConnections = false;
public ArangoGraphTraversalSubQueryBuilder(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
AbstractEdgeDescription edgeDescription,
String subQueryPostfix,
AqlVariable variableTraversingStart
) {
this.searchOptionResolver = searchOptionResolver;
this.structureSchemaFinder = structureSchemaFinder;
this.subQueryPostfix = subQueryPostfix;
var edgeType = ArangoGraphTraversalSubQueryBuilder.getEdgeType(edgeDescription);
this.traversingStart = variableTraversingStart;
this.edgeDescription = edgeDescription;
this.edgeSearchOptionBuilder = new ArangoSearchOptionsBuilder(
this.searchOptionResolver,
this.createEdgeDocumentName(this.subQueryPostfix),
ArangoQueryType.GRAPH_TRAVERSAL,
edgeType,
this.subQueryPostfix
);
this.nodeSearchOptionBuilder = new ArangoSearchOptionsBuilder(
this.searchOptionResolver,
this.createNodeDocumentName(this.subQueryPostfix),
ArangoQueryType.GRAPH_TRAVERSAL,
null,
this.subQueryPostfix
);
this.edgeKeptAttributesBuilder = new ArangoEdgeKeptAttributesBuilder(
this.structureSchemaFinder,
this.createEdgeDocumentName(this.subQueryPostfix),
this.subQueryPostfix,
edgeType
);
this.edgeMappedObjectBuilder = new ArangoMappedObjectBuilder(
this.edgeKeptAttributesBuilder,
this.structureSchemaFinder,
this.createEdgeDocumentName(this.subQueryPostfix),
"edge_" + this.subQueryPostfix,
edgeType
);
this.arangoQueryByNodeTypeBuilder = ArangoQueryByNodeTypeBuilder.asGraphTraversal(
searchOptionResolver,
this.structureSchemaFinder,
this.subQueryPostfix,
this.createNodeDocumentName(this.subQueryPostfix)
);
}
public static ArangoGraphTraversalSubQueryBuilder asConnections(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaProvider,
AbstractEdgeDescription edgeDescription,
String subQueryPostfix,
AqlVariable variableTraversingStart
) {
var arangoGraphTraversalSubQueryBuilder = new ArangoGraphTraversalSubQueryBuilder(
searchOptionResolver,
structureSchemaProvider,
edgeDescription,
subQueryPostfix,
variableTraversingStart
);
arangoGraphTraversalSubQueryBuilder.asConnections = true;
return arangoGraphTraversalSubQueryBuilder;
}
private static String getEdgeType(AbstractEdgeDescription edgeDescription) {
var parameters = (EdgeDescriptionParameters) edgeDescription.getParameters();
return parameters.getEdgeType();
}
public ArangoGraphTraversalNodeOptionBuilder setOtherNode(String nodeType) {
this.nodeSearchOptionBuilder.setGraphElementType(nodeType);
return this.arangoQueryByNodeTypeBuilder.addGraphTraversalNodeOption(nodeType);
}
public ArangoGraphTraversalNodeOptionBuilder mapOtherNode(String nodeType) {
if (!this.isNodeFieldMapped) {
this.nodeSearchOptionBuilder.setGraphElementType(nodeType);
this.edgeMappedObjectBuilder.mapCustomField(
"node",
this.createSubQueryVariable(this.createChildSubQueryPostfix(this.subQueryPostfix, 0))
.getItem(0)
.getField("data")
);
this.isNodeFieldMapped = true;
}
return this.arangoQueryByNodeTypeBuilder.addGraphTraversalNodeOption(nodeType);
}
public ArangoEdgeKeptAttributesBuilder setEdgeKeptAttributes() {
return this.edgeKeptAttributesBuilder;
}
public ArangoSearchOptionsBuilder setEdgeSearchOptions() {
return this.edgeSearchOptionBuilder;
}
public ArangoMappedObjectBuilder setEdgeMappedScalars() {
return this.edgeMappedObjectBuilder;
}
public ArangoSearchOptionsBuilder setNodeSearchOptions() {
return this.nodeSearchOptionBuilder;
}
@Override
public ArangoQuery build(GraphLoaderReturnType... returnTypes) {
var edgeSearchOptions = this.edgeSearchOptionBuilder.build();
var edgeKeptAttributes = this.edgeKeptAttributesBuilder.build();
var nodeSearchOptions = this.nodeSearchOptionBuilder.build();
var edgeMappedObject = this.edgeMappedObjectBuilder.build();
var queryByNodeType = this.arangoQueryByNodeTypeBuilder.build(returnTypes);
var finalBindParameters = this.buildBindParameters(
edgeSearchOptions,
edgeKeptAttributes,
nodeSearchOptions,
edgeMappedObject,
queryByNodeType
);
var aqlRootNode = this.buildAqlRootNode(
edgeSearchOptions,
edgeKeptAttributes,
nodeSearchOptions,
edgeMappedObject,
queryByNodeType,
returnTypes
);
return new ArangoQuery(aqlRootNode, finalBindParameters);
}
public String getEdgeType() {
return ArangoGraphTraversalSubQueryBuilder.getEdgeType(this.edgeDescription);
}
@NotNull
private HashMap<String, Object> buildBindParameters(
ArangoQuery edgeSearchOptions,
ArangoQuery edgeKeptAttributes,
ArangoQuery nodeSearchOptions,
ArangoQuery edgeMappedObject,
ArangoQuery queryByNodeType
) {
var finalBindParameters = new HashMap<String, Object>();
finalBindParameters.put(
this.createCollectionVariable(this.subQueryPostfix).markAsBindParameter().getVariableName(),
ArangoGraphTraversalSubQueryBuilder.getEdgeType(edgeDescription)
);
finalBindParameters.putAll(edgeSearchOptions.getBindParameters());
finalBindParameters.putAll(edgeKeptAttributes.getBindParameters());
finalBindParameters.putAll(nodeSearchOptions.getBindParameters());
finalBindParameters.putAll(queryByNodeType.getBindParameters());
finalBindParameters.putAll(edgeMappedObject.getBindParameters());
return finalBindParameters;
}
@NotNull
private AqlRootNode buildAqlRootNode(
ArangoQuery edgeSearchOptions,
ArangoQuery edgeKeptAttributes,
ArangoQuery nodeSearchOptions,
ArangoQuery edgeMappedObject,
ArangoQuery queryByNodeType,
GraphLoaderReturnType... returnTypes
) {
return new AqlRootNode(
this.buildBeginningStatement(),
nodeSearchOptions.getAqlNode(),
edgeSearchOptions.getAqlNode(),
new AqlLet(
this.createSubQueryVariable(this.createChildSubQueryPostfix(this.subQueryPostfix, 0)),
queryByNodeType.getAqlNode()
),
this.buildEndStatement(
edgeKeptAttributes,
edgeMappedObject,
returnTypes
)
);
}
private AqlNode buildBeginningStatement() {
return new AqlGraphTraversalFor(
this.createNodeDocumentName(this.subQueryPostfix),
this.edgeDescription.isOutgoing() ? TraversalDirection.OUTBOUND
: TraversalDirection.INBOUND,
this.traversingStart,
List.of(this.createCollectionVariable(this.subQueryPostfix).markAsBindParameter()
.markAsBindParameter()),
this.createEdgeDocumentName(this.subQueryPostfix),
null,
null,
null
);
}
private AqlNode buildEndStatement(
ArangoQuery edgeKeptAttributes,
ArangoQuery edgeMappedObject,
GraphLoaderReturnType... returnTypes
) {
var childSubQueryPostfix = this.createChildSubQueryPostfix(this.subQueryPostfix, 0);
var subQueryVariable = this.createSubQueryVariable(childSubQueryPostfix);
var set = Arrays.stream(returnTypes).collect(Collectors.toSet());
if (set.contains(GraphLoaderReturnType.SORT_OPTION)) {
if (this.edgeKeptAttributesBuilder.isExactlyOneAttributeSet()) {
return new AqlReturn(this.edgeKeptAttributesBuilder.buildOneAttributeFirstValue());
}
return new AqlReturn(subQueryVariable.getItem(0));
}
if (set.contains(GraphLoaderReturnType.FILTER_OPTION)) {
if (this.edgeKeptAttributesBuilder.isExactlyOneAttributeSet()) {
return new AqlReturn(this.edgeKeptAttributesBuilder.buildOneListOrLeafAttribute());
}
return new AqlReturn(subQueryVariable.getItem(0));
}
var edges = this.createEdges(subQueryVariable, edgeKeptAttributes);
var nodes = this.createNodes(subQueryVariable);
var graph = this.createGraphObject(nodes, edges);
if (this.asConnections) {
return this.createReturnStatement(
graph,
this.createConnectionObject(edgeMappedObject.getAqlNode()),
returnTypes
);
}
var mappedEdgeObjectVariable = new AqlVariable("mappedEdgeObject" + this.subQueryPostfix);
return new AqlRootNode(
new AqlLet(mappedEdgeObjectVariable, edgeMappedObject.getAqlNode()),
this.createReturnStatement(
graph,
mappedEdgeObjectVariable.getField("node"),
returnTypes
)
);
}
private AqlNode createEdges(AqlVariable subQueryVariable, ArangoQuery keptAttributes) {
return new AqlPush(
this.getChildSubQueryEdges(subQueryVariable),
keptAttributes.getAqlNode()
);
}
private AqlNode createNodes(AqlVariable subQueryVariable) {
return this.getChildSubQueryNodes(subQueryVariable);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoKeptAttributesBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlObject;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlString;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions.AqlKeep;
import ai.stapi.graphoperations.serializableGraph.GraphElementKeys;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import com.arangodb.internal.DocumentFields;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public abstract class ArangoKeptAttributesBuilder {
protected final AqlVariable documentName;
protected final String subQueryPostfix;
protected final Map<String, Object> bindParameters;
protected final List<AqlNode> attributesToKeep;
private final StructureSchemaFinder structureSchemaFinder;
private final String graphElementType;
private boolean keepAllAttributes = false;
private boolean keepId = false;
protected ArangoKeptAttributesBuilder(
StructureSchemaFinder structureSchemaFinder,
AqlVariable documentName,
String subQueryPostfix,
String graphElementType
) {
this.structureSchemaFinder = structureSchemaFinder;
this.documentName = documentName;
this.subQueryPostfix = subQueryPostfix;
this.graphElementType = graphElementType;
this.bindParameters = new HashMap<>();
this.attributesToKeep = new ArrayList<>();
}
protected abstract String[] provideDefaultMetaAttributes();
public ArangoKeptAttributesBuilder addId() {
this.keepId = true;
return this;
}
public ArangoKeptAttributesBuilder addAttribute(String attributeName) {
var postfix = this.subQueryPostfix.isBlank() ? "" : "__" + this.subQueryPostfix;
var placeHolder = "keptAttributeName_" + this.attributesToKeep.size() + postfix;
this.attributesToKeep.add(new AqlVariable("@" + placeHolder));
this.bindParameters.put(placeHolder, attributeName);
return this;
}
public ArangoKeptAttributesBuilder addAttribute(String attributeName, String placeholder) {
this.attributesToKeep.add(new AqlVariable("@" + placeholder));
this.bindParameters.put(placeholder, attributeName);
return this;
}
public ArangoKeptAttributesBuilder keepAllAttributes() {
this.keepAllAttributes = true;
return this;
}
protected ArangoQuery build() {
return new ArangoQuery(
this.buildAqlObject(),
this.bindParameters
);
}
public AqlNode buildOneAttributeFirstValue() {
if (this.keepId) {
return this.documentName.getField(DocumentFields.KEY);
}
return this.buildOneAttribute().getItem(0).getField("value");
}
public AqlNode buildOneListOrLeafAttribute() {
if (this.keepId) {
return this.documentName.getField(DocumentFields.KEY);
}
var attribute = this.buildOneAttribute();
var attributeName = (String) this.bindParameters.values().iterator().next();
var fieldDefinition = this.structureSchemaFinder.getFieldDefinitionOrFallback(
this.graphElementType,
attributeName
);
if (!fieldDefinition.isList()) {
return attribute.getItem(0).getField("value");
} else {
return attribute.getAllItems().getField("value");
}
}
private AqlNode buildOneAttribute() {
return this.documentName
.getField(GraphElementKeys.ATTRIBUTES)
.getField(this.attributesToKeep.get(0).toQueryString())
.getItem(0)
.getField("values");
}
private AqlNode buildAqlObject() {
if (this.keepAllAttributes) {
return this.documentName;
}
var fieldMap = new HashMap<AqlNode, AqlNode>();
Arrays.stream(this.provideDefaultMetaAttributes())
.forEach(
metaAttribute -> fieldMap.put(
new AqlString(metaAttribute),
this.documentName.getField(metaAttribute)
)
);
var keep = new AqlKeep(
this.documentName.getField(GraphElementKeys.ATTRIBUTES),
this.attributesToKeep
);
fieldMap.put(
new AqlString(GraphElementKeys.ATTRIBUTES),
this.attributesToKeep.isEmpty() ? new AqlObject(Map.of()) : keep
);
return new AqlObject(fieldMap);
}
public boolean isExactlyOneAttributeSet() {
return this.attributesToKeep.size() == 1 || this.keepId;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoMainQueryBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlObject;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlString;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import java.util.Map;
public interface ArangoMainQueryBuilder extends ArangoSubQueryBuilder {
ArangoQuery buildAsMain(GraphLoaderReturnType... returnTypes);
default AqlObject createMainGraphObject(AqlNode main, AqlNode nodes, AqlNode edges) {
return new AqlObject(Map.of(
new AqlString("mainGraphElement"), main,
new AqlString("nodes"), nodes,
new AqlString("edges"), edges
));
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoMappedObjectBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlObject;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions.AqlParseIdentifier;
import ai.stapi.graphoperations.serializableGraph.GraphElementKeys;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import java.util.HashMap;
import java.util.Map;
public class ArangoMappedObjectBuilder {
private final ArangoKeptAttributesBuilder keptAttributesBuilder;
private final StructureSchemaFinder structureSchemaFinder;
private final AqlVariable documentName;
private final String subQueryPostfix;
private final String graphElementType;
private final Map<String, Object> bindParameters;
private final Map<AqlNode, AqlNode> fields;
public ArangoMappedObjectBuilder(
ArangoKeptAttributesBuilder keptAttributesBuilder,
StructureSchemaFinder structureSchemaFinder,
AqlVariable documentName,
String subQueryPostfix,
String graphElementType
) {
this.keptAttributesBuilder = keptAttributesBuilder;
this.structureSchemaFinder = structureSchemaFinder;
this.documentName = documentName;
this.subQueryPostfix = subQueryPostfix;
this.graphElementType = graphElementType;
this.bindParameters = new HashMap<>();
this.fields = new HashMap<>();
}
public ArangoMappedObjectBuilder mapAttribute(String fieldName, String attributeName) {
var postfix = this.subQueryPostfix.isBlank() ? "" : "__" + this.subQueryPostfix;
var attributeNamePlaceHolder = "mappedAttributeName_" + this.fields.size() + postfix;
var fieldNamePlaceHolder = "mappedFieldName_" + this.fields.size() + postfix;
this.keptAttributesBuilder.addAttribute(attributeName, attributeNamePlaceHolder);
this.bindParameters.put(fieldNamePlaceHolder, fieldName);
var fieldDefinition = this.structureSchemaFinder.getFieldDefinitionOrFallback(
this.graphElementType,
attributeName
);
var getAttributeVariable = this.documentName
.getField(GraphElementKeys.ATTRIBUTES)
.getField("@" + attributeNamePlaceHolder)
.getItem(0)
.getField("values");
this.fields.put(
new AqlVariable("@" + fieldNamePlaceHolder),
fieldDefinition.isList()
? getAttributeVariable.getAllItems().getField("value")
: getAttributeVariable.getItem(0).getField("value")
);
return this;
}
public ArangoMappedObjectBuilder mapId(String fieldName) {
var postfix = this.subQueryPostfix.isBlank() ? "" : "__" + this.subQueryPostfix;
var fieldNamePlaceHolder = "mappedFieldName_" + this.fields.size() + postfix;
this.bindParameters.put(fieldNamePlaceHolder, fieldName);
this.fields.put(
new AqlVariable("@" + fieldNamePlaceHolder),
this.documentName.getField("_key")
);
return this;
}
public ArangoMappedObjectBuilder mapType(String fieldName) {
var postfix = this.subQueryPostfix.isBlank() ? "" : "__" + this.subQueryPostfix;
var fieldNamePlaceHolder = "mappedFieldName_" + this.fields.size() + postfix;
this.bindParameters.put(fieldNamePlaceHolder, fieldName);
this.fields.put(
new AqlVariable("@" + fieldNamePlaceHolder),
new AqlParseIdentifier(this.documentName).getCollection()
);
return this;
}
public ArangoMappedObjectBuilder mapCustomField(String fieldName, AqlNode fieldValue) {
var postfix = this.subQueryPostfix.isBlank() ? "" : "__" + this.subQueryPostfix;
var fieldNamePlaceHolder = "mappedFieldName_" + this.fields.size() + postfix;
this.bindParameters.put(fieldNamePlaceHolder, fieldName);
this.fields.put(
new AqlVariable("@" + fieldNamePlaceHolder),
fieldValue
);
return this;
}
protected ArangoQuery build() {
return new ArangoQuery(
new AqlObject(this.fields),
this.bindParameters
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoNodeCollectionSubQueryBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlObject;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlFor;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import org.jetbrains.annotations.NotNull;
public class ArangoNodeCollectionSubQueryBuilder extends ArangoNodeSubQueryBuilder {
public ArangoNodeCollectionSubQueryBuilder(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
String graphElementType,
String subQueryPostfix
) {
super(
searchOptionResolver,
structureSchemaFinder,
graphElementType,
subQueryPostfix
);
}
@NotNull
@Override
protected ArangoQuery createAqlBody(
ArangoQuery keptAttributes,
AqlObject graph,
GraphLoaderReturnType... returnTypes
) {
var collectionVariable =
this.createCollectionVariable(this.subQueryPostfix).markAsBindParameter();
var aqlFor = new AqlFor(
this.createNodeDocumentName(this.subQueryPostfix),
collectionVariable.markAsBindParameter()
);
var aqlBody = this.createBaseAqlBody(keptAttributes, graph, aqlFor, returnTypes);
aqlBody.getBindParameters().put(collectionVariable.getVariableName(), this.graphElementType);
return aqlBody;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoNodeGetSubQueryBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlObject;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlString;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions.AqlConcatSeparator;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions.AqlDocument;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlLet;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import ai.stapi.identity.UniqueIdentifier;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ArangoNodeGetSubQueryBuilder extends ArangoNodeSubQueryBuilder {
@Nullable
protected AqlVariable nodeDocumentKeyVariable;
@Nullable
private UniqueIdentifier graphElementId;
public ArangoNodeGetSubQueryBuilder(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
String graphElementType,
String subQueryPostfix,
UniqueIdentifier graphElementId
) {
super(searchOptionResolver, structureSchemaFinder, graphElementType, subQueryPostfix);
this.graphElementId = graphElementId;
}
public ArangoNodeGetSubQueryBuilder(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder graphElementSchemaProvider,
String graphElementType,
String subQueryPostfix,
AqlVariable nodeDocumentKeyVariable
) {
super(searchOptionResolver, graphElementSchemaProvider, graphElementType, subQueryPostfix);
this.nodeDocumentKeyVariable = nodeDocumentKeyVariable;
}
@NotNull
@Override
protected ArangoQuery createAqlBody(
ArangoQuery keptAttributes,
AqlObject graph,
GraphLoaderReturnType... returnTypes
) {
var collectionVariable = this.createCollectionVariable(this.subQueryPostfix);
var idVariable = this.createIdVariable(this.subQueryPostfix);
var documentKey = new AqlConcatSeparator(
new AqlString("/"),
collectionVariable.markAsBindParameter(),
idVariable.markAsBindParameter()
);
var aqlFor = new AqlLet(
this.createNodeDocumentName(this.subQueryPostfix),
new AqlDocument(
this.nodeDocumentKeyVariable != null ? this.nodeDocumentKeyVariable : documentKey)
);
var baseAqlBody = this.createBaseAqlBody(keptAttributes, graph, aqlFor, returnTypes);
if (this.graphElementId != null) {
baseAqlBody.getBindParameters()
.put(collectionVariable.getVariableName(), this.graphElementType);
baseAqlBody.getBindParameters()
.put(idVariable.getVariableName(), this.graphElementId.getId());
}
return baseAqlBody;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoNodeKeptAttributesBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
public class ArangoNodeKeptAttributesBuilder extends ArangoKeptAttributesBuilder {
protected static final String[] DEFAULT_META_ATTRIBUTES = {"_id", "_rev", "_key", "_metaData"};
public ArangoNodeKeptAttributesBuilder(
StructureSchemaFinder structureSchemaFinder,
AqlVariable documentName,
String subQueryPostfix,
String graphElementType
) {
super(structureSchemaFinder, documentName, subQueryPostfix, graphElementType);
}
@Override
protected String[] provideDefaultMetaAttributes() {
return ArangoNodeKeptAttributesBuilder.DEFAULT_META_ATTRIBUTES;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoNodeSubQueryBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQueryType;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlList;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlObject;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlRootNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.functions.AqlUnion;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlLet;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlReturn;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.AbstractEdgeDescription;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.positive.EdgeDescriptionParameters;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
public abstract class ArangoNodeSubQueryBuilder
implements ArangoMainQueryBuilder, ArangoGraphTraversalJoinable {
protected final ArangoGenericSearchOptionResolver searchOptionResolver;
protected final StructureSchemaFinder structureSchemaFinder;
protected final ArangoNodeKeptAttributesBuilder arangoNodeKeptAttributesBuilder;
protected final ArangoMappedObjectBuilder arangoMappedObjectBuilder;
protected final ArangoSearchOptionsBuilder arangoSearchOptionsBuilder;
protected final String graphElementType;
protected final String subQueryPostfix;
protected final Map<String, ArangoGraphTraversalSubQueryBuilder> subQueryBuilders;
protected final Map<String, Object> bindParameters;
public ArangoNodeSubQueryBuilder(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
String graphElementType,
String subQueryPostfix
) {
this.searchOptionResolver = searchOptionResolver;
this.structureSchemaFinder = structureSchemaFinder;
this.graphElementType = graphElementType;
this.subQueryPostfix = subQueryPostfix;
var nodeDocumentName = this.createNodeDocumentName(this.subQueryPostfix);
this.arangoNodeKeptAttributesBuilder = new ArangoNodeKeptAttributesBuilder(
this.structureSchemaFinder,
nodeDocumentName,
this.subQueryPostfix,
this.graphElementType
);
this.arangoMappedObjectBuilder = new ArangoMappedObjectBuilder(
this.arangoNodeKeptAttributesBuilder,
this.structureSchemaFinder,
nodeDocumentName,
this.subQueryPostfix,
this.graphElementType
);
this.arangoSearchOptionsBuilder = new ArangoSearchOptionsBuilder(
this.searchOptionResolver,
nodeDocumentName,
ArangoQueryType.NODE,
this.graphElementType,
this.subQueryPostfix
);
this.subQueryBuilders = new LinkedHashMap<>();
this.bindParameters = new HashMap<>();
}
public ArangoNodeKeptAttributesBuilder setKeptAttributes() {
return this.arangoNodeKeptAttributesBuilder;
}
public ArangoMappedObjectBuilder setMappedScalars() {
return this.arangoMappedObjectBuilder;
}
public ArangoSearchOptionsBuilder setSearchOptions() {
return this.arangoSearchOptionsBuilder;
}
public ArangoGraphTraversalSubQueryBuilder joinGraphTraversal(
AbstractEdgeDescription edgeDescription) {
var childSubQueryPrefix = this.getChildSubQueryPostfix();
var subQueryBuilder = new ArangoGraphTraversalSubQueryBuilder(
this.searchOptionResolver,
this.structureSchemaFinder,
edgeDescription,
childSubQueryPrefix,
this.createNodeDocumentName(this.subQueryPostfix)
);
this.subQueryBuilders.put(
this.createSubQueryVariable(childSubQueryPrefix).getVariableName(),
subQueryBuilder
);
return subQueryBuilder;
}
public ArangoGraphTraversalSubQueryBuilder mapGraphTraversal(
String fieldName,
AbstractEdgeDescription edgeDescription
) {
var childSubQueryPrefix = this.getChildSubQueryPostfix();
var subQueryVariable = this.createSubQueryVariable(childSubQueryPrefix);
this.mapGraphTraversalJoin(edgeDescription, fieldName, subQueryVariable);
var subQueryBuilder = new ArangoGraphTraversalSubQueryBuilder(
this.searchOptionResolver,
this.structureSchemaFinder,
edgeDescription,
childSubQueryPrefix,
this.createNodeDocumentName(this.subQueryPostfix)
);
this.subQueryBuilders.put(
subQueryVariable.getVariableName(),
subQueryBuilder
);
return subQueryBuilder;
}
public ArangoGraphTraversalSubQueryBuilder mapGraphTraversalAsConnections(
String fieldName,
AbstractEdgeDescription edgeDescription
) {
var connectionFieldName = fieldName + "Connections";
var childSubQueryPrefix = this.getChildSubQueryPostfix();
var subQueryVariable = this.createSubQueryVariable(childSubQueryPrefix);
this.mapGraphTraversalJoin(edgeDescription, connectionFieldName, subQueryVariable);
var subQueryBuilder = ArangoGraphTraversalSubQueryBuilder.asConnections(
this.searchOptionResolver,
this.structureSchemaFinder,
edgeDescription,
childSubQueryPrefix,
this.createNodeDocumentName(this.subQueryPostfix)
);
this.subQueryBuilders.put(
subQueryVariable.getVariableName(),
subQueryBuilder
);
return subQueryBuilder;
}
@Override
public ArangoQuery build(GraphLoaderReturnType... returnTypes) {
var keptAttributes = this.arangoNodeKeptAttributesBuilder.build();
var nodes = this.createNodes(keptAttributes);
var edges = this.createEdges();
var graph = this.createGraphObject(nodes, edges);
return this.createAqlBody(keptAttributes, graph, returnTypes);
}
@Override
public ArangoQuery buildAsMain(GraphLoaderReturnType... returnTypes) {
var keptAttributes = this.arangoNodeKeptAttributesBuilder.build();
var main = keptAttributes.getAqlNode();
var nodes = this.createNodes();
var edges = this.createEdges();
var graph = this.createMainGraphObject(main, nodes, edges);
return this.createAqlBody(keptAttributes, graph, returnTypes);
}
@NotNull
protected abstract ArangoQuery createAqlBody(
ArangoQuery keptAttributes,
AqlObject graph,
GraphLoaderReturnType... returnTypes
);
@NotNull
protected ArangoQuery createBaseAqlBody(
ArangoQuery keptAttributes,
AqlObject graph,
AqlNode getDocumentLine,
GraphLoaderReturnType... returnTypes
) {
var mappedObject = this.arangoMappedObjectBuilder.build();
var searchOptions = this.arangoSearchOptionsBuilder.build();
var subQueryStatements = new ArrayList<AqlLet>();
var subQueryBindParams = new ArrayList<Map<String, Object>>();
this.subQueryBuilders.forEach((key, value) -> {
var arangoQuery = value.build(returnTypes);
subQueryStatements.add(
new AqlLet(
new AqlVariable(key),
arangoQuery.getAqlNode()
)
);
subQueryBindParams.add(arangoQuery.getBindParameters());
});
var aqlNodes = new ArrayList<AqlNode>();
aqlNodes.add(getDocumentLine);
aqlNodes.add(searchOptions.getAqlNode());
aqlNodes.addAll(subQueryStatements);
var set = Arrays.stream(returnTypes).collect(Collectors.toSet());
if (set.contains(GraphLoaderReturnType.SORT_OPTION)) {
if (this.arangoNodeKeptAttributesBuilder.isExactlyOneAttributeSet()) {
aqlNodes.add(
new AqlReturn(this.arangoNodeKeptAttributesBuilder.buildOneAttributeFirstValue()));
} else {
aqlNodes.add(
new AqlReturn(new AqlVariable(this.subQueryBuilders.keySet().iterator().next())));
}
} else if (set.contains(GraphLoaderReturnType.FILTER_OPTION)) {
if (this.arangoNodeKeptAttributesBuilder.isExactlyOneAttributeSet()) {
aqlNodes.add(
new AqlReturn(this.arangoNodeKeptAttributesBuilder.buildOneListOrLeafAttribute()));
} else {
var graphTraversalBuilderEntry = this.subQueryBuilders.entrySet().iterator().next();
var isList = this.structureSchemaFinder.isList(
this.graphElementType,
graphTraversalBuilderEntry.getValue().getEdgeType()
);
var subQueryVariable = new AqlVariable(graphTraversalBuilderEntry.getKey());
if (!isList) {
aqlNodes.add(new AqlReturn(subQueryVariable).getItem(0));
} else {
aqlNodes.add(new AqlReturn(subQueryVariable));
}
}
} else {
aqlNodes.add(
this.createReturnStatement(
graph,
mappedObject.getAqlNode(),
returnTypes
)
);
}
var forQuery = new AqlRootNode(aqlNodes);
var bindParameters = this.mergeBindParameters(
keptAttributes.getBindParameters(),
mappedObject.getBindParameters(),
searchOptions.getBindParameters()
);
subQueryBindParams.forEach(bindParameters::putAll);
return new ArangoQuery(
forQuery,
bindParameters
);
}
private void mapGraphTraversalJoin(
AbstractEdgeDescription edgeDescription,
String connectionFieldName,
AqlVariable subQueryVariable
) {
var edgeType = ((EdgeDescriptionParameters) edgeDescription.getParameters()).getEdgeType();
var fieldDefinition = this.structureSchemaFinder.getFieldDefinitionOrFallback(
this.graphElementType,
edgeType
);
if (!fieldDefinition.isList()) {
this.arangoMappedObjectBuilder.mapCustomField(
connectionFieldName,
subQueryVariable.getItem(0).getField("data")
);
} else {
this.arangoMappedObjectBuilder.mapCustomField(
connectionFieldName,
subQueryVariable.getAllItems().getField("data")
);
}
}
private AqlNode createEdges() {
var unionList = new ArrayList<AqlNode>();
this.subQueryBuilders.keySet().forEach(key ->
unionList.add(this.getChildSubQueryEdges(new AqlVariable(key)))
);
if (this.subQueryBuilders.size() > 1) {
return new AqlUnion(unionList);
}
if (this.subQueryBuilders.size() == 1) {
return unionList.get(0);
}
return new AqlList();
}
private AqlNode createNodes(ArangoQuery keptAttributes) {
var mainElementList = new AqlList(keptAttributes.getAqlNode());
if (this.subQueryBuilders.size() > 0) {
var unionList = new ArrayList<AqlNode>();
this.subQueryBuilders.keySet().forEach(key ->
unionList.add(this.getChildSubQueryNodes(new AqlVariable(key)))
);
var finalList = new ArrayList<AqlNode>(List.of(mainElementList));
finalList.addAll(unionList);
return new AqlUnion(finalList);
}
return mainElementList;
}
private AqlNode createNodes() {
var unionList = new ArrayList<AqlNode>();
this.subQueryBuilders.keySet().forEach(key ->
unionList.add(this.getChildSubQueryNodes(new AqlVariable(key)))
);
if (this.subQueryBuilders.size() > 1) {
return new AqlUnion(unionList);
}
if (this.subQueryBuilders.size() == 1) {
return unionList.get(0);
}
return new AqlList();
}
private String getChildSubQueryPostfix() {
return this.createChildSubQueryPostfix(this.subQueryPostfix, this.subQueryBuilders.size());
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoQueryBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlList;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlObject;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlRootNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlString;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlLet;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlReturn;
import ai.stapi.arangograph.graphLoader.arangoQuery.exceptions.CannotBuildArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import ai.stapi.identity.UniqueIdentifier;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
public class ArangoQueryBuilder {
private final ArangoGenericSearchOptionResolver searchOptionResolver;
private final StructureSchemaFinder structureSchemaFinder;
private ArangoMainQueryBuilder mainQueryBuilder;
private boolean isMainCollection = false;
public ArangoQueryBuilder(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder
) {
this.searchOptionResolver = searchOptionResolver;
this.structureSchemaFinder = structureSchemaFinder;
}
public ArangoNodeCollectionSubQueryBuilder setFindNodesMainQuery(String graphElementType) {
var collectionSubQueryBuilder = new ArangoNodeCollectionSubQueryBuilder(
this.searchOptionResolver,
this.structureSchemaFinder,
graphElementType,
""
);
this.mainQueryBuilder = collectionSubQueryBuilder;
this.isMainCollection = true;
return collectionSubQueryBuilder;
}
public ArangoEdgeCollectionSubQueryBuilder setFindOutgoingEdgeMainQuery(String graphElementType) {
var collectionSubQueryBuilder = ArangoEdgeCollectionSubQueryBuilder.outgoing(
this.searchOptionResolver,
this.structureSchemaFinder,
graphElementType,
""
);
this.mainQueryBuilder = collectionSubQueryBuilder;
this.isMainCollection = true;
return collectionSubQueryBuilder;
}
public ArangoEdgeCollectionSubQueryBuilder setFindIngoingEdgeMainQuery(String graphElementType) {
var collectionSubQueryBuilder = ArangoEdgeCollectionSubQueryBuilder.ingoing(
this.searchOptionResolver,
this.structureSchemaFinder,
graphElementType,
""
);
this.mainQueryBuilder = collectionSubQueryBuilder;
this.isMainCollection = true;
return collectionSubQueryBuilder;
}
public ArangoNodeGetSubQueryBuilder setGetNodeMainQuery(
String graphElementType,
UniqueIdentifier mainNodeUuid
) {
var getSubQueryBuilder = new ArangoNodeGetSubQueryBuilder(
this.searchOptionResolver,
this.structureSchemaFinder,
graphElementType,
"",
mainNodeUuid
);
this.mainQueryBuilder = getSubQueryBuilder;
return getSubQueryBuilder;
}
public ArangoEdgeGetSubQueryBuilder setGetOutgoingEdgeMainQuery(
String graphElementType,
UniqueIdentifier mainEdgeUuid
) {
var subQueryBuilder = ArangoEdgeGetSubQueryBuilder.outgoing(
this.searchOptionResolver,
this.structureSchemaFinder,
mainEdgeUuid,
graphElementType,
""
);
this.mainQueryBuilder = subQueryBuilder;
return subQueryBuilder;
}
public ArangoEdgeGetSubQueryBuilder setGetIngoingEdgeMainQuery(
String graphElementType,
UniqueIdentifier mainEdgeUuid
) {
var subQueryBuilder = ArangoEdgeGetSubQueryBuilder.ingoing(
this.searchOptionResolver,
this.structureSchemaFinder,
mainEdgeUuid,
graphElementType,
""
);
this.mainQueryBuilder = subQueryBuilder;
return subQueryBuilder;
}
public ArangoQuery build(GraphLoaderReturnType... returnTypes) {
if (this.mainQueryBuilder == null) {
throw CannotBuildArangoQuery.becauseNoMainQuerySet();
}
if (this.isMainCollection) {
var findQuery = this.mainQueryBuilder.buildAsMain(returnTypes);
var letNode = new AqlLet(
new AqlVariable("mainSubQuery"),
findQuery.getAqlNode()
);
var rootNode = new AqlRootNode(
letNode,
this.buildFindMainQueryReturnStatement(letNode.getVariable(), returnTypes)
);
return new ArangoQuery(
rootNode,
findQuery.getBindParameters()
);
}
return this.mainQueryBuilder.buildAsMain(returnTypes);
}
private AqlReturn buildFindMainQueryReturnStatement(
AqlVariable mainQueryVariable,
GraphLoaderReturnType... returnTypes
) {
var set = Arrays.stream(returnTypes).collect(Collectors.toSet());
var graphObject = new AqlObject(Map.of(
new AqlString("mainGraphElements"), mainQueryVariable
.getAllItems()
.getField(ArangoSubQueryBuilder.GRAPH_RESPONSE)
.getField("mainGraphElement"),
new AqlString("edges"), mainQueryVariable
.getAllItems()
.getField(ArangoSubQueryBuilder.GRAPH_RESPONSE)
.getField("edges")
.getFlattenItems(),
new AqlString("nodes"), mainQueryVariable
.getAllItems()
.getField(ArangoSubQueryBuilder.GRAPH_RESPONSE)
.getField("nodes")
.getFlattenItems()
));
var dataVariable = set.contains(GraphLoaderReturnType.OBJECT)
? mainQueryVariable.getAllItems().getField("data").getFlattenItems()
: new AqlList();
var graphVariable =
set.contains(GraphLoaderReturnType.GRAPH) ? graphObject : new AqlObject(Map.of());
var mainObject = new AqlObject(Map.of(
new AqlString("data"), dataVariable,
new AqlString(ArangoSubQueryBuilder.GRAPH_RESPONSE), graphVariable
));
return new AqlReturn(mainObject);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoQueryBuilderProvider.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
public class ArangoQueryBuilderProvider {
private final ArangoGenericSearchOptionResolver searchOptionResolver;
private final StructureSchemaFinder structureSchemaFinder;
public ArangoQueryBuilderProvider(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder
) {
this.searchOptionResolver = searchOptionResolver;
this.structureSchemaFinder = structureSchemaFinder;
}
public ArangoQueryBuilder provide() {
return new ArangoQueryBuilder(this.searchOptionResolver, this.structureSchemaFinder);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoQueryByNodeTypeBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class ArangoQueryByNodeTypeBuilder implements ArangoSubQueryBuilder {
private final ArangoGenericSearchOptionResolver searchOptionResolver;
private final StructureSchemaFinder structureSchemaFinder;
private final String subQueryPostfix;
private final AqlVariable nodeDocumentVariableName;
private final Map<String, Object> nodeOptionsPlaceholders;
private final Map<String, ArangoSubQueryBuilder> subQueryBuilders;
private final Map<String, Object> bindParameters;
private boolean isUsedAsGraphTraversal = false;
public ArangoQueryByNodeTypeBuilder(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
String subQueryPostfix,
AqlVariable nodeDocumentVariableName
) {
this.searchOptionResolver = searchOptionResolver;
this.structureSchemaFinder = structureSchemaFinder;
this.subQueryPostfix = subQueryPostfix;
this.nodeDocumentVariableName = nodeDocumentVariableName;
this.nodeOptionsPlaceholders = new HashMap<>();
this.subQueryBuilders = new HashMap<>();
this.bindParameters = new HashMap<>();
}
public static ArangoQueryByNodeTypeBuilder asGraphTraversal(
ArangoGenericSearchOptionResolver searchOptionResolver,
StructureSchemaFinder structureSchemaFinder,
String subQueryPostfix,
AqlVariable nodeDocumentVariableName
) {
var builder = new ArangoQueryByNodeTypeBuilder(
searchOptionResolver,
structureSchemaFinder,
subQueryPostfix,
nodeDocumentVariableName
);
builder.isUsedAsGraphTraversal = true;
return builder;
}
public ArangoNodeGetSubQueryBuilder addGetNodeOption(
String nodeType
) {
var nodeTypePlaceholder = this.buildJoinedNodeTypePlaceholder();
var nodeGetSubQueryBuilder = new ArangoNodeGetSubQueryBuilder(
this.searchOptionResolver,
this.structureSchemaFinder,
nodeType,
this.getChildSubQueryPostfix(),
this.nodeDocumentVariableName
);
var subQueryVariableName = this.buildJoinedNodeSubQueryVariableName();
this.subQueryBuilders.put(
subQueryVariableName,
nodeGetSubQueryBuilder
);
this.nodeOptionsPlaceholders.put(
nodeTypePlaceholder,
subQueryVariableName
);
this.bindParameters.put(
nodeTypePlaceholder,
nodeType
);
return nodeGetSubQueryBuilder;
}
public ArangoGraphTraversalNodeOptionBuilder addGraphTraversalNodeOption(
String nodeType
) {
var nodeTypePlaceholder = this.buildJoinedNodeTypePlaceholder();
var nodeOptionBuilder = new ArangoGraphTraversalNodeOptionBuilder(
this.structureSchemaFinder,
this.searchOptionResolver,
nodeType,
this.subQueryPostfix,
this.nodeDocumentVariableName
);
var subQueryVariableName = this.buildJoinedNodeSubQueryVariableName();
this.subQueryBuilders.put(
subQueryVariableName,
nodeOptionBuilder
);
this.nodeOptionsPlaceholders.put(
nodeTypePlaceholder,
subQueryVariableName
);
this.bindParameters.put(
nodeTypePlaceholder,
nodeType
);
return nodeOptionBuilder;
}
public ArangoQuery build(GraphLoaderReturnType... returnTypes) {
var buildSubQueries = this.buildSubQueries(returnTypes);
var finalBindParameters = new HashMap<>(this.bindParameters);
buildSubQueries.values()
.forEach(query -> finalBindParameters.putAll(query.getBindParameters()));
return new ArangoQuery(
new AqlVariable(this.buildString(buildSubQueries, returnTypes)),
finalBindParameters
);
}
private String buildString(Map<String, ArangoQuery> subQueries,
GraphLoaderReturnType... returnTypes) {
var subQueriesStrings = this.nodeOptionsPlaceholders.entrySet().stream()
.map(entry -> {
String actualNodeTypeStatement;
if (this.isUsedAsGraphTraversal) {
actualNodeTypeStatement = String.format(
"PARSE_IDENTIFIER(%s._id).collection",
this.nodeDocumentVariableName.getVariableName()
);
} else {
actualNodeTypeStatement = String.format(
"PARSE_IDENTIFIER(%s).collection",
this.nodeDocumentVariableName.getVariableName()
);
}
var subQueryString = subQueries.get(entry.getValue()).getQueryString();
return String.format("%s == @%s ? ( %s )", actualNodeTypeStatement, entry.getKey(),
subQueryString);
}).collect(Collectors.toList());
subQueriesStrings.add(this.getDefaultValueIfNodeTypeNotPresent(returnTypes));
return String.join(" : ", subQueriesStrings);
}
private Map<String, ArangoQuery> buildSubQueries(GraphLoaderReturnType... returnTypes) {
return this.subQueryBuilders.entrySet()
.stream()
.map(entry -> new AbstractMap.SimpleEntry<>(
entry.getKey(),
entry.getValue().build(returnTypes)
)).collect(
Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)
);
}
private String buildJoinedNodeTypePlaceholder() {
var basePlaceholder = "joinedNodeCollection_" + this.nodeOptionsPlaceholders.size();
return this.subQueryPostfix.isBlank() ? basePlaceholder
: basePlaceholder + "__" + this.subQueryPostfix;
}
private String buildJoinedNodeSubQueryVariableName() {
return BASE_SUB_QUERY_VARIABLE_NAME + "_" + this.getChildSubQueryPostfix();
}
private String getChildSubQueryPostfix() {
if (this.subQueryPostfix.isBlank()) {
return "" + this.subQueryBuilders.size();
}
return this.subQueryPostfix + "_" + this.subQueryBuilders.size();
}
private String getDefaultValueIfNodeTypeNotPresent(GraphLoaderReturnType... returnTypes) {
var set = Arrays.stream(returnTypes).collect(Collectors.toSet());
if (set.contains(GraphLoaderReturnType.SORT_OPTION) || set.contains(
GraphLoaderReturnType.FILTER_OPTION)) {
return "( RETURN null )";
}
if (this.isUsedAsGraphTraversal) {
return String.format(
"( RETURN { graphResponse: { nodes: [ %s ], edges: [] }, data: {} } )",
new ArangoNodeKeptAttributesBuilder(
this.structureSchemaFinder,
this.nodeDocumentVariableName,
this.getChildSubQueryPostfix(),
""
).build().getQueryString()
);
}
return String.format(
"( %s )",
new ArangoNodeGetSubQueryBuilder(
this.searchOptionResolver,
this.structureSchemaFinder,
"",
this.getChildSubQueryPostfix(),
this.nodeDocumentVariableName
).build(GraphLoaderReturnType.GRAPH).getQueryString()
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoSearchOptionsBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQueryType;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlRootNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlFilter;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlLimit;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlSort;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlSortOption;
import ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers.ArangoGenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLoader.search.filterOption.FilterOption;
import ai.stapi.graphoperations.graphLoader.search.filterOption.LeafFilterOption;
import ai.stapi.graphoperations.graphLoader.search.paginationOption.PaginationOption;
import ai.stapi.graphoperations.graphLoader.search.sortOption.SortOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
public class ArangoSearchOptionsBuilder {
protected final Map<String, Object> bindParameters;
private final AqlVariable documentName;
private final ArangoQueryType originQueryType;
private final String subQueryPostfix;
private final List<AqlSortOption> resolvedSortParts;
private final List<AqlFilter> resolvedFilterParts;
private final ArangoGenericSearchOptionResolver searchOptionResolver;
private String graphElementType;
@Nullable
private AqlLimit resolvedPaginationPart;
public ArangoSearchOptionsBuilder(
ArangoGenericSearchOptionResolver searchOptionResolver,
AqlVariable documentName,
ArangoQueryType originQueryType,
String graphElementType,
String subQueryPostfix
) {
this.searchOptionResolver = searchOptionResolver;
this.documentName = documentName;
this.originQueryType = originQueryType;
this.graphElementType = graphElementType;
this.subQueryPostfix = subQueryPostfix;
this.resolvedSortParts = new ArrayList<>();
this.resolvedFilterParts = new ArrayList<>();
this.resolvedPaginationPart = null;
this.bindParameters = new HashMap<>();
}
public ArangoSearchOptionsBuilder addFilterOption(FilterOption<?> filterOption) {
ArangoQuery resolved;
if (filterOption instanceof LeafFilterOption<?>) {
resolved = this.searchOptionResolver.resolve(
filterOption,
new ArangoSearchResolvingContext(
this.documentName.getVariableName(),
this.originQueryType,
this.graphElementType,
String.valueOf(this.resolvedFilterParts.size()),
this.subQueryPostfix
)
);
} else {
resolved = this.searchOptionResolver.resolve(
filterOption,
new ArangoSearchResolvingContext(
this.documentName.getVariableName(),
this.originQueryType,
this.graphElementType
)
);
}
this.resolvedFilterParts.add(new AqlFilter(resolved.getAqlNode()));
this.bindParameters.putAll(resolved.getBindParameters());
return this;
}
public ArangoSearchOptionsBuilder addSortOption(SortOption sortOption) {
var resolved = this.searchOptionResolver.resolve(
sortOption,
new ArangoSearchResolvingContext(
this.documentName.getVariableName(),
this.originQueryType,
this.graphElementType,
String.valueOf(this.resolvedSortParts.size()),
this.subQueryPostfix
)
);
this.resolvedSortParts.add((AqlSortOption) resolved.getAqlNode());
this.bindParameters.putAll(resolved.getBindParameters());
return this;
}
public ArangoSearchOptionsBuilder setPaginationOption(PaginationOption<?> paginationOption) {
if (paginationOption == null) {
return this;
}
var resolved = this.searchOptionResolver.resolve(
paginationOption,
new ArangoSearchResolvingContext(
this.documentName.getVariableName(),
this.originQueryType,
this.graphElementType,
"",
this.subQueryPostfix
)
);
this.resolvedPaginationPart = (AqlLimit) resolved.getAqlNode();
this.bindParameters.putAll(resolved.getBindParameters());
return this;
}
public ArangoSearchOptionsBuilder addFilterOptions(List<FilterOption<?>> filterOptions) {
filterOptions.forEach(this::addFilterOption);
return this;
}
public ArangoSearchOptionsBuilder addSortOptions(
List<SortOption> sortOptions) {
sortOptions.forEach(this::addSortOption);
return this;
}
protected ArangoQuery build() {
return new ArangoQuery(
this.buildQueryBody(),
this.bindParameters
);
}
private AqlNode buildQueryBody() {
var queryLines = new ArrayList<AqlNode>(this.resolvedFilterParts);
if (!this.resolvedSortParts.isEmpty()) {
queryLines.add(new AqlSort(this.resolvedSortParts));
}
if (this.resolvedPaginationPart != null) {
queryLines.add(this.resolvedPaginationPart);
}
return new AqlRootNode(queryLines);
}
public void setGraphElementType(String graphElementType) {
this.graphElementType = graphElementType;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoSearchResolvingContext.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQueryType;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.graphoperations.graphLoader.search.SearchResolvingContext;
public class ArangoSearchResolvingContext implements SearchResolvingContext {
private final AqlVariable documentName;
private final ArangoQueryType originQueryType;
private final String graphElementType;
private final String placeholderPostfix;
private final String subQueryPostfix;
public ArangoSearchResolvingContext(
AqlVariable documentName,
ArangoQueryType originQueryType,
String graphElementType, String placeholderPostfix,
String subQueryPostfix
) {
this.documentName = documentName;
this.originQueryType = originQueryType;
this.graphElementType = graphElementType;
this.placeholderPostfix = placeholderPostfix;
this.subQueryPostfix = subQueryPostfix;
}
public ArangoSearchResolvingContext(
String documentName,
ArangoQueryType originQueryType,
String graphElementType,
String placeholderPostfix,
String subQueryPostfix
) {
this(new AqlVariable(documentName), originQueryType, graphElementType, placeholderPostfix,
subQueryPostfix);
}
public ArangoSearchResolvingContext(AqlVariable documentName, ArangoQueryType originQueryType,
String graphElementType) {
this(documentName, originQueryType, graphElementType, "", "");
}
public ArangoSearchResolvingContext(String documentName, ArangoQueryType originQueryType,
String graphElementType) {
this(documentName, originQueryType, graphElementType, "", "");
}
public String getPlaceholderPostfix() {
return placeholderPostfix;
}
public AqlVariable getDocumentName() {
return documentName;
}
public String getSubQueryPostfix() {
return subQueryPostfix;
}
public ArangoQueryType getOriginQueryType() {
return originQueryType;
}
public String getGraphElementType() {
return graphElementType;
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/builder/ArangoSubQueryBuilder.java | package ai.stapi.arangograph.graphLoader.arangoQuery.builder;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlObject;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlString;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlVariable;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlReturn;
import ai.stapi.graphoperations.graphLoader.GraphLoaderReturnType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public interface ArangoSubQueryBuilder {
String NODE_DOCUMENT_BASE_NAME = "nodeElement";
String EDGE_DOCUMENT_BASE_NAME = "edgeElement";
String BASE_SUB_QUERY_VARIABLE_NAME = "subQuery";
String NODES = "nodes";
String EDGES = "edges";
String GRAPH_RESPONSE = "graphResponse";
String DATA = "data";
ArangoQuery build(GraphLoaderReturnType... returnTypes);
default String createChildSubQueryPostfix(String subQueryPostfix, Integer index) {
if (subQueryPostfix.isBlank()) {
return "" + index;
}
return subQueryPostfix + "_" + index;
}
default AqlVariable createEdgeDocumentName(String subQueryPostfix) {
if (subQueryPostfix.isBlank()) {
return new AqlVariable(ArangoSubQueryBuilder.EDGE_DOCUMENT_BASE_NAME);
}
return new AqlVariable(ArangoSubQueryBuilder.EDGE_DOCUMENT_BASE_NAME + "_" + subQueryPostfix);
}
default AqlVariable createNodeDocumentName(String subQueryPostfix) {
if (subQueryPostfix.isBlank()) {
return new AqlVariable(ArangoSubQueryBuilder.NODE_DOCUMENT_BASE_NAME);
}
return new AqlVariable(ArangoSubQueryBuilder.NODE_DOCUMENT_BASE_NAME + "_" + subQueryPostfix);
}
default AqlVariable createSubQueryVariable(String subQueryPostfix) {
if (subQueryPostfix.isBlank()) {
return new AqlVariable(ArangoSubQueryBuilder.BASE_SUB_QUERY_VARIABLE_NAME);
}
return new AqlVariable(
String.format("%s_%s", ArangoSubQueryBuilder.BASE_SUB_QUERY_VARIABLE_NAME, subQueryPostfix)
);
}
default AqlObject createGraphObject(AqlNode nodes, AqlNode edges) {
return new AqlObject(Map.of(
new AqlString(NODES), nodes,
new AqlString(EDGES), edges
));
}
default AqlReturn createReturnStatement(AqlNode graph, AqlNode data,
GraphLoaderReturnType... returnTypes) {
var set = Arrays.stream(returnTypes).collect(Collectors.toSet());
return new AqlReturn(
new AqlObject(Map.of(
new AqlString(GRAPH_RESPONSE),
set.contains(GraphLoaderReturnType.GRAPH) ? graph : new AqlObject(Map.of()),
new AqlString(DATA),
set.contains(GraphLoaderReturnType.OBJECT) ? data : new AqlObject(Map.of())
))
);
}
default AqlVariable getChildSubQueryEdges(AqlVariable subQueryVariable) {
return subQueryVariable.getAllItems()
.getField(GRAPH_RESPONSE)
.getField(EDGES)
.getFlattenItems();
}
default AqlVariable getChildSubQueryNodes(AqlVariable subQueryVariable) {
return subQueryVariable.getAllItems()
.getField(GRAPH_RESPONSE)
.getField(NODES)
.getFlattenItems();
}
default Map<String, Object> mergeBindParameters(Map<String, Object>... bindParameters) {
var result = new HashMap<String, Object>();
Arrays.stream(bindParameters).forEach(result::putAll);
return result;
}
default AqlVariable createCollectionVariable(String subQueryPostfix) {
if (subQueryPostfix.isBlank()) {
return new AqlVariable("collection");
}
return new AqlVariable("collection_" + subQueryPostfix);
}
default AqlVariable createIdVariable(String subQueryPostfix) {
if (subQueryPostfix.isBlank()) {
return new AqlVariable("graphElementIdPlaceholder");
}
return new AqlVariable("graphElementIdPlaceholder" + subQueryPostfix);
}
default AqlObject createConnectionObject(AqlNode edge) {
return new AqlObject(Map.of(
new AqlString("edges"), edge
));
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/exceptions/CannotBuildArangoQuery.java | package ai.stapi.arangograph.graphLoader.arangoQuery.exceptions;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQueryType;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoSubQueryBuilder;
import ai.stapi.graphoperations.graphLanguage.graphDescription.GraphDescription;
public class CannotBuildArangoQuery extends RuntimeException {
private CannotBuildArangoQuery(String message) {
super("Cannot build arango query, because " + message);
}
public static CannotBuildArangoQuery becauseNoMainQuerySet() {
return new CannotBuildArangoQuery(
"there was no main query set."
);
}
public static CannotBuildArangoQuery becauseGraphTraversalCannotBeJoinedFromEdge() {
return new CannotBuildArangoQuery(
"graph traversal cannot be joined from edge."
);
}
public static CannotBuildArangoQuery becauseThereWereMoreSubQueryResolversForBuilder(
ArangoSubQueryBuilder builder,
GraphDescription graphDescription
) {
return new CannotBuildArangoQuery(
"there were more supporting resolvers for one builder."
+ "\nBuilder class: " + builder.getClass().getSimpleName()
+ "\nProvided Graph Description: " + graphDescription.getClass().getSimpleName()
);
}
public static CannotBuildArangoQuery becauseThereWasNoSubQueryResolversForBuilder(
ArangoSubQueryBuilder builder,
GraphDescription graphDescription
) {
return new CannotBuildArangoQuery(
"there was no supporting resolvers for builder."
+ "\nBuilder class: " + builder.getClass().getSimpleName()
+ "\nProvided Graph Description: " + graphDescription.getClass().getSimpleName()
);
}
public static CannotBuildArangoQuery becauseEncounteredNonExisitingOriginQueryType(
ArangoQueryType originQueryType) {
return new CannotBuildArangoQuery(
"unknown origin query type encountered when resolving deep search option."
+ "\nArango Query Type: " + originQueryType.name()
);
}
}
|
0 | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery | java-sources/ai/stapi/arango-graph/0.0.2/ai/stapi/arangograph/graphLoader/arangoQuery/searchOptionResolvers/AbstractArangoCompositeFilterOptionResolver.java | package ai.stapi.arangograph.graphLoader.arangoQuery.searchOptionResolvers;
import ai.stapi.arangograph.graphLoader.arangoQuery.ArangoQuery;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlOperator;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.AqlRootNode;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.arrayComparisonOperators.AqlAll;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.arrayComparisonOperators.AqlAny;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.arrayComparisonOperators.AqlNone;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlParentheses;
import ai.stapi.arangograph.graphLoader.arangoQuery.ast.highLevelOperations.AqlQuestionMarkOperator;
import ai.stapi.arangograph.graphLoader.arangoQuery.builder.ArangoSearchResolvingContext;
import ai.stapi.graphoperations.graphLanguage.graphDescription.specific.query.CollectionComparisonOperator;
import ai.stapi.graphoperations.graphLoader.search.GenericSearchOptionResolver;
import ai.stapi.graphoperations.graphLoader.search.filterOption.AbstractCompositeFilterOptionResolver;
import ai.stapi.graphoperations.graphLoader.search.filterOption.CompositeFilterOption;
import ai.stapi.schema.structureSchemaProvider.StructureSchemaFinder;
import org.jetbrains.annotations.NotNull;
public abstract class AbstractArangoCompositeFilterOptionResolver<S extends CompositeFilterOption>
extends AbstractCompositeFilterOptionResolver<S, ArangoSearchResolvingContext, ArangoQuery> {
protected AbstractArangoCompositeFilterOptionResolver(
StructureSchemaFinder structureSchemaFinder,
GenericSearchOptionResolver<ArangoQuery> genericSearchOptionResolver
) {
super(structureSchemaFinder, genericSearchOptionResolver);
}
@Override
protected ArangoQuery postProcessResolvedFilter(
ArangoQuery resolvedFilter,
ArangoSearchResolvingContext context
) {
return new ArangoQuery(
new AqlParentheses(resolvedFilter.getAqlNode()),
resolvedFilter.getBindParameters()
);
}
@NotNull
protected AqlNode getOperatorAndRightHand(
AqlOperator operator,
AqlNode rightExpression,
CollectionComparisonOperator collectionComparisonOperator
) {
if (operator.getOperatorName().equals(AqlOperator.like().getOperatorName())) {
return new AqlQuestionMarkOperator(
new AqlRootNode(
operator,
rightExpression
),
new AqlOperator(collectionComparisonOperator.name())
);
} else {
return new AqlRootNode(
collectionComparisonOperator.equals(CollectionComparisonOperator.ALL) ?
new AqlAll(operator) :
collectionComparisonOperator.equals(CollectionComparisonOperator.NONE) ?
new AqlNone(operator) :
new AqlAny(operator),
rightExpression
);
}
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.