org.neo4j.ogm.driver.AbstractConfigurableDriver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neo4j-ogm-api Show documentation
Show all versions of neo4j-ogm-api Show documentation
Neo4j-OGM's internal Api for connecting different transports.
The newest version!
/*
* Copyright (c) 2002-2024 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.neo4j.ogm.driver;
import static java.util.stream.Collectors.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.driver.ParameterConversion.DefaultParameterConversion;
import org.neo4j.ogm.spi.CypherModificationProvider;
/**
* The AbstractConfigurableDriver is used by all drivers to register themselves.
* The register method takes a generic {@link Configuration} object, which is used to register the
* driver appropriately. This object contains of one or more key-value
* pairs. Every driver configuration must contain a mandatory key "URI", whose corresponding value is
* a text representation of the driver uri, for example:
* setConfig("URI", "http://username:password@hostname:port")
* if credentials are not present the URI, they can be specified in one of
* two ways, either as a plain text username/password key-values pair in the configuration e.g.
* setConfig("username", "bilbo")
* setConfig("password", "hobbit")
* or, alternatively using the "credentials" key
* setConfig("credentials", new UsernamePasswordCredentials("bilbo", "hobbit")
*
* @author Vince Bickers
* @author Mark Angrish
* @author Michael J. Simons
*/
public abstract class AbstractConfigurableDriver implements Driver {
/**
* Set of classes that are supported natively without implicit or explicit (native type support) conversion.
* The set is not meant to be used outside this package, so it was put into the concrete driver class and not
* on the {@link TypeSystem} interface.
*
* The byte array ({@code byte[]} has been excluded here as OGM should use {@code org.neo4j.ogm.typeconversion.ByteArrayBase64Converter}
* by default.
*
* {@link List} and {@link Map} have both been excluded, as the {@link TypeSystemBasedParameterConversion} takes care of that.
*/
static final Set> DEFAULT_SUPPORTED_TYPES =
Stream.of(
List.class,
Map.class,
Boolean.class, boolean.class,
Long.class, long.class,
Double.class, double.class,
String.class
).collect(collectingAndThen(toSet(), Collections::unmodifiableSet));
private final ThreadLocal> cypherModificationProviderLoader =
ThreadLocal.withInitial(() -> ServiceLoader.load(CypherModificationProvider.class));
protected Configuration configuration;
protected TypeSystem typeSystem = Driver.super.getTypeSystem();
protected ParameterConversion parameterConversion = DefaultParameterConversion.INSTANCE;
/**
* Used for configuring the cypher modification providers. Defaults to {@link #getConfiguration()} and reads the
* custom properties from the common {@link Configuration}.
*/
protected final Supplier