Skip to content

Commit

Permalink
remove neo4j.driver
Browse files Browse the repository at this point in the history
  • Loading branch information
liubingyelby authored and tugraph committed Jul 13, 2023
1 parent a52d16b commit 2ca12d5
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 67 deletions.
5 changes: 0 additions & 5 deletions ogm/tugraph-db-rpc-driver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<artifactId>tugraph-db-ogm-api</artifactId>
<version>${ogm.api.version}</version>
</dependency>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>4.4.5</version>
</dependency>
<dependency>
<groupId>com.antgroup.tugraph</groupId>
<artifactId>tugraph-db-java-rpc-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@

import java.net.URI;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.BiFunction;
import java.util.function.Function;

import com.antgroup.tugraph.ogm.drivers.rpc.request.RpcRequest;
import com.antgroup.tugraph.ogm.drivers.rpc.transaction.RpcTransaction;
import com.antgroup.tugraph.TuGraphDbRpcClient;

import org.neo4j.driver.*;
import org.neo4j.driver.exceptions.ServiceUnavailableException;
import com.antgroup.tugraph.ogm.drivers.rpc.exception.ServiceUnavailableException;
import com.antgroup.tugraph.ogm.config.Configuration;
import com.antgroup.tugraph.ogm.config.Credentials;
import com.antgroup.tugraph.ogm.config.UsernamePasswordCredentials;
Expand Down Expand Up @@ -59,7 +56,6 @@ public class RpcDriver extends AbstractConfigurableDriver {

private TuGraphDbRpcClient rpcClient;
private Credentials credentials;
private Config driverConfig;
/**
* The database to use (Use Tugraph default).
*/
Expand All @@ -80,7 +76,6 @@ public void configure(Configuration newConfiguration) {

super.configure(newConfiguration);

this.driverConfig = buildDriverConfig();
this.credentials = this.configuration.getCredentials();
this.database = this.configuration.getDatabase();

Expand Down Expand Up @@ -161,55 +156,4 @@ public Request request(Transaction transaction) {
return new RpcRequest(rpcClient, this.parameterConversion, getCypherModification(), database);
}

public <T> T unwrap(Class<T> clazz) {

if (clazz == Driver.class) {
return (T) rpcClient;
} else {
return super.unwrap(clazz);
}
}

private Optional<Logging> getRpcLogging() {

Object possibleLogging = customPropertiesSupplier.get().get(CONFIG_PARAMETER_RPC_LOGGING);
if (possibleLogging != null && !(possibleLogging instanceof Logging)) {
LOGGER.warn("Invalid object of type {} for {}, not changing log.", possibleLogging.getClass(),
CONFIG_PARAMETER_RPC_LOGGING);
possibleLogging = null;
}

LOGGER.debug("Using {} for rpc logging.", possibleLogging == null ? "default" : possibleLogging.getClass());

return Optional.ofNullable((Logging) possibleLogging);
}

private Config buildDriverConfig() {

// Done outside the try/catch and explicity catch the illegalargument exception of singleURI
// so that exception semantics are not changed since we introduced that feature.

URI singleUri = getSingleURI(configuration.getURI());
if (!isCorrectScheme(singleUri.getScheme())) {
throw new IllegalArgumentException(
"Rpc uri is incorrect!");
}

try {
Config.ConfigBuilder configBuilder = Config.builder();
configBuilder.withMaxConnectionPoolSize(configuration.getConnectionPoolSize());

if (configuration.getConnectionLivenessCheckTimeout() != null) {
configBuilder.withConnectionLivenessCheckTimeout(configuration.getConnectionLivenessCheckTimeout(),
TimeUnit.MILLISECONDS);
}

getRpcLogging().ifPresent(configBuilder::withLogging);

return configBuilder.build();
} catch (Exception e) {
throw new ConnectionException("Unable to build driver configuration", e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package com.antgroup.tugraph.ogm.drivers.rpc.driver;

import org.neo4j.driver.exceptions.ServiceUnavailableException;
import com.antgroup.tugraph.ogm.drivers.rpc.exception.ServiceUnavailableException;
import com.antgroup.tugraph.ogm.driver.ExceptionTranslator;
import com.antgroup.tugraph.ogm.exception.ConnectionException;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Modifications Copyright 2022 "Ant Group"
* Copyright (c) 2002-2022 "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 com.antgroup.tugraph.ogm.drivers.rpc.exception;

public class ClientException extends TuGraphException {
public ClientException(String message) {
super(message);
}

public ClientException(String message, Throwable cause) {
super(message, cause);
}

public ClientException(String code, String message) {
super(code, message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Modifications Copyright 2022 "Ant Group"
* Copyright (c) 2002-2022 "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 com.antgroup.tugraph.ogm.drivers.rpc.exception;

public class DatabaseException extends TuGraphException {
public DatabaseException(String code, String message) {
super(code, message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Modifications Copyright 2022 "Ant Group"
* Copyright (c) 2002-2022 "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 com.antgroup.tugraph.ogm.drivers.rpc.exception;

public class ServiceUnavailableException extends TuGraphException {
public ServiceUnavailableException(String message) {
super(message);
}

public ServiceUnavailableException(String message, Throwable throwable) {
super(message, throwable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Modifications Copyright 2022 "Ant Group"
* Copyright (c) 2002-2022 "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 com.antgroup.tugraph.ogm.drivers.rpc.exception;

public class TransientException extends TuGraphException {
public TransientException(String code, String message) {
super(code, message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Modifications Copyright 2022 "Ant Group"
* Copyright (c) 2002-2022 "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 com.antgroup.tugraph.ogm.drivers.rpc.exception;

public class TuGraphException extends RuntimeException {
private static final long serialVersionUID = -80579062276712566L;
private final String code;

public TuGraphException(String message) {
this("N/A", message);
}

public TuGraphException(String message, Throwable cause) {
this("N/A", message, cause);
}

public TuGraphException(String code, String message) {
this(code, message, (Throwable) null);
}

public TuGraphException(String code, String message, Throwable cause) {
super(message, cause);
this.code = code;
}

/** @deprecated */
@Deprecated
public String tugraphErrorCode() {
return this.code;
}

public String code() {
return this.code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import com.antgroup.tugraph.ogm.drivers.rpc.response.RowModelResponse;
import com.antgroup.tugraph.TuGraphDbRpcClient;

import org.neo4j.driver.exceptions.ClientException;
import org.neo4j.driver.exceptions.DatabaseException;
import org.neo4j.driver.exceptions.TransientException;
import com.antgroup.tugraph.ogm.drivers.rpc.exception.ClientException;
import com.antgroup.tugraph.ogm.drivers.rpc.exception.DatabaseException;
import com.antgroup.tugraph.ogm.drivers.rpc.exception.TransientException;
import com.antgroup.tugraph.ogm.driver.ParameterConversion;
import com.antgroup.tugraph.ogm.exception.CypherException;
import com.antgroup.tugraph.ogm.model.GraphModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.util.ArrayList;

import org.neo4j.driver.exceptions.ClientException;
import com.antgroup.tugraph.ogm.drivers.rpc.exception.ClientException;

import com.antgroup.tugraph.ogm.exception.CypherException;
import com.antgroup.tugraph.ogm.response.Response;
Expand Down

0 comments on commit 2ca12d5

Please sign in to comment.