/*
* Copyright (c) 2004, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
/*
* Borrowed from PostgreSQL JDBC driver
*/
package net.bitnine.agensgraph.ds.common;
import net.bitnine.agensgraph.Driver;
import org.postgresql.PGProperty;
import org.postgresql.ds.common.PGObjectFactory;
import org.postgresql.jdbc.AutoSave;
import org.postgresql.jdbc.PreferQueryMode;
import org.postgresql.util.*;
import javax.naming.*;
import javax.sql.CommonDataSource;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.postgresql.util.internal.Nullness.castNonNull;
/**
* Base class for data sources and related classes.
*
* @author Aaron Mulder (ammulder@chariotsolutions.com)
*/
public abstract class BaseDataSource implements CommonDataSource, Referenceable {
private static final Logger LOGGER = Logger.getLogger(BaseDataSource.class.getName());
// Standard properties, defined in the JDBC 2.0 Optional Package spec
private String[] serverNames = new String[]{"localhost"};
private String databaseName = "";
private String user;
private String password;
private int[] portNumbers = new int[]{0};
// Map for all other properties
private Properties properties = new Properties();
/*
* Ensure the driver is loaded as JDBC Driver might be invisible to Java's ServiceLoader.
* Usually, {@code Class.forName(...)} is not required as {@link DriverManager} detects JDBC drivers
* via {@code META-INF/services/java.sql.Driver} entries. However there might be cases when the driver
* is located at the application level classloader, thus it might be required to perform manual
* registration of the driver.
*/
static {
try {
Class.forName("net.bitnine.agensgraph.Driver");
} catch (ClassNotFoundException e) {
throw new IllegalStateException(
"BaseDataSource is unable to load net.bitnine.agensgraph.Driver. Please check if you have proper AgensGraph JDBC Driver jar on the classpath",
e);
}
}
/**
* Gets a connection to the PostgreSQL database. The database is identified by the DataSource
* properties serverName, databaseName, and portNumber. The user to connect as is identified by
* the DataSource properties user and password.
*
* @return A valid database connection.
* @throws SQLException Occurs when the database connection cannot be established.
*/
public Connection getConnection() throws SQLException {
return getConnection(user, password);
}
/**
* Gets a connection to the PostgreSQL database. The database is identified by the DataSource
* properties serverName, databaseName, and portNumber. The user to connect as is identified by
* the arguments user and password, which override the DataSource properties by the same name.
*
* @param user user
* @param password password
* @return A valid database connection.
* @throws SQLException Occurs when the database connection cannot be established.
*/
public Connection getConnection(String user, String password)
throws SQLException {
try {
Connection con = DriverManager.getConnection(getUrl(), user, password);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Created a {0} for {1} at {2}",
new Object[]{getDescription(), user, getUrl()});
}
return con;
} catch (SQLException e) {
LOGGER.log(Level.FINE, "Failed to create a {0} for {1} at {2}: {3}",
new Object[]{getDescription(), user, getUrl(), e});
throw e;
}
}
/**
* This implementation don't use a LogWriter.
*/
@Override
public PrintWriter getLogWriter() {
return null;
}
/**
* This implementation don't use a LogWriter.
*
* @param printWriter Not used
*/
@Override
public void setLogWriter(PrintWriter printWriter) {
// NOOP
}
/**
* Gets the name of the host the PostgreSQL database is running on.
*
* @return name of the host the PostgreSQL database is running on
* @deprecated use {@link #getServerNames()}
*/
@Deprecated
public String getServerName() {
return serverNames[0];
}
/**
* Gets the name of the host(s) the PostgreSQL database is running on.
*
* @return name of the host(s) the PostgreSQL database is running on
*/
public String[] getServerNames() {
return serverNames;
}
/**
* Sets the name of the host the PostgreSQL database is running on. If this is changed, it will
* only affect future calls to getConnection. The default value is {@code localhost}.
*
* @param serverName name of the host the PostgreSQL database is running on
* @deprecated use {@link #setServerNames(String[])}
*/
@Deprecated
public void setServerName(String serverName) {
this.setServerNames(new String[]{serverName});
}
/**
* Sets the name of the host(s) the PostgreSQL database is running on. If this is changed, it will
* only affect future calls to getConnection. The default value is {@code localhost}.
*
* @param serverNames name of the host(s) the PostgreSQL database is running on
*/
@SuppressWarnings("nullness")
public void setServerNames(String[] serverNames) {
if (serverNames == null || serverNames.length == 0) {
this.serverNames = new String[]{"localhost"};
} else {
serverNames = serverNames.clone();
for (int i = 0; i < serverNames.length; i++) {
String serverName = serverNames[i];
if (serverName == null || serverName.equals("")) {
serverNames[i] = "localhost";
}
}
this.serverNames = serverNames;
}
}
/**
* Gets the name of the PostgreSQL database, running on the server identified by the serverName
* property.
*
* @return name of the PostgreSQL database
*/
public String getDatabaseName() {
return databaseName;
}
/**
* Sets the name of the PostgreSQL database, running on the server identified by the serverName
* property. If this is changed, it will only affect future calls to getConnection.
*
* @param databaseName name of the PostgreSQL database
*/
public void setDatabaseName(String databaseName) {
this.databaseName = databaseName;
}
/**
* Gets a description of this DataSource-ish thing. Must be customized by subclasses.
*
* @return description of this DataSource-ish thing
*/
public abstract String getDescription();
/**
* Gets the user to connect as by default. If this is not specified, you must use the
* getConnection method which takes a user and password as parameters.
*
* @return user to connect as by default
*/
public String getUser() {
return user;
}
/**
* Sets the user to connect as by default. If this is not specified, you must use the
* getConnection method which takes a user and password as parameters. If this is changed, it will
* only affect future calls to getConnection.
*
* @param user user to connect as by default
*/
public void setUser(String user) {
this.user = user;
}
/**
* Gets the password to connect with by default. If this is not specified but a password is needed
* to log in, you must use the getConnection method which takes a user and password as parameters.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
AgensGraph JDBC Driver 基于 PostgreSQL JDBC Driver,并提供处理图形数据的附加功能。因此,当用户开发 Java 应用程序时,使用 AgensGraph JDBC Driver 和 PostgreSQL JDBC Driver 的 API 几乎没有区别。唯一的区别是 AgensGraph 使用 Cypher 查询语言而不是 SQL,并使用图形数据作为数据类型
资源推荐
资源详情
资源评论
收起资源包目录
agensgraph-jdbc-master.zip (47个子文件)
agensgraph-jdbc-master
gradle
wrapper
gradle-wrapper.jar 58KB
gradle-wrapper.properties 202B
.github
workflows
tests.yml 755B
src
test
java
net
bitnine
agensgraph
test
TestUtil.java 8KB
ds
AGPoolingDataSourceTest.java 4KB
graph
EdgeTest.java 3KB
PathTest.java 3KB
VertexTest.java 3KB
GraphIdTest.java 2KB
util
JsonbUtilTest.java 5KB
AgTokenizerTest.java 2KB
JsonbTest.java 20KB
jdbc
AgPreparedStatementTest.java 6KB
AgArrayTest.java 7KB
AgResultSetTest.java 17KB
AbstractAGDockerizedTest.java 2KB
main
resources
META-INF
services
java.sql.Driver 29B
java
net
bitnine
agensgraph
Driver.java 33KB
ds
AGConnectionPoolDataSource.java 3KB
AGPoolingDataSource.java 18KB
common
BaseDataSource.java 55KB
core
Oid.java 1KB
graph
Vertex.java 2KB
GraphId.java 2KB
Edge.java 3KB
GraphEntity.java 4KB
Path.java 2KB
util
AgTokenizer.java 4KB
JsonbObjectBuilder.java 6KB
JsonbArrayBuilder.java 4KB
Jsonb.java 18KB
DriverInfo.java 1KB
JsonbUtil.java 6KB
JsonbObject.java 4KB
jdbc
AgArray.java 7KB
AgResultSet.java 32KB
AgStatement.java 8KB
AgConnection.java 10KB
AgPreparedStatement.java 15KB
LICENSE 1KB
gradlew.bat 3KB
build.properties 165B
VERSION.md 2KB
gradlew 8KB
.gitignore 427B
settings.gradle.kts 169B
build.gradle.kts 4KB
共 47 条
- 1
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6797
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 斗音评论区关键词私信.apk
- Linux常用命令大全.pdf
- plantuml======资源
- 基于java开发的密码解锁APP,包含手势密码解锁+指纹密码解锁+源码+项目界面展示(毕业设计&课程设计&项目开发)
- 基于单片机的智能窗帘设计
- 基于STM32F103C8T6+LCD1602+MCP6S28的8通道模拟可编程增益放大器Proteus仿真
- 5G RAN NR TDD单用户峰值吞吐率计算过程.pptx
- 基于Objective-C开发的手势密码解锁和面容解锁(代码简洁高效通俗易懂)+源码+开发文档+源码解析(毕业设计&课程设计)
- LangChain学习之 Question And Answer的操作附带数据文件
- linux常用命令大全.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功