jdbc.psotgresql学习3

Connection Parameters:
PreapareThresHold: 确定PreparedStatement切换到使用服务器端预处理语句之前所需的执行次数。意思是在同一个PreparedStatement对象的第五次执行中使用服务器端预处理语句。设置为小于0是为1,表示每次都使用缓存中的。等于0的话为0,表示不使用缓存。缺省值是5。结果如下:

判断是否使用threshold:

PGConnection的构造方法中开始设置。

设置PrepareThreshold。

在PgStatement类的executeInternal 中调用isOnwShotQuery方法判断是否执行一次。

ForceBinary:如果threshold小于0forcebinarytransfer为true;

preferQueryMode = String指定使用哪种模式执行对数据库的查询:简单模式('Q'执行,不解析,不绑定,仅文本模式),扩展表示总是使用绑定/执行消息,extendedForPrepared表示仅扩展用于预处理语句,extendedCacheEverything表示使用扩展协议并尝试缓存查询缓存中的每个语句(包括Statement.execute(String sql))。扩展| extendedForPrepared | extendedCacheEverything | 简单默认是扩展的。
在QueryExcecutorBase中有:对queryexecutor进行初始化:

在PgConnection中有方法:

在QueryExcetorImp中有方法在execute中会提前调用:

在PgStatement中有:

loadBalanceHosts = Boolean: 需要先在url中加上loadBalanceHosts=true代表打开负载均衡。也就是如下配置url:
:postgresql://node1,node2,node3/accounting?targetServerType=preferSlave&loadBalanceHosts=true
在Driver类中parseURL方法首先会解析主机节点到参数properties中,此时info中有多个主机节点地址:

在Driver类的hostSpecs方法中,会将props配置文件中节点信息赋值给hostspc对象然后执行PGConnection构造方法:

在ConnectionFactoryImpl的openConnectionImpl方法中首先获取url参数中的targetServerType信息。没有的话赋值为any

在这个方法中创建HostChooser就是一个遍历主机的迭代器

集群的话需要加上servertype,在对象中加上要连接的目标主机的类型。

然后在while循环中开始对每个节点遍历建立PgStream:

判断目标主机的servertype:

目标主机和参数主机不一致抛异常:

最后在连接池中选出一个连接进行连接:返回一个queryexecuter

ssl:安全套接字连接:Connect using SSL. The driver must have been compiled with SSL support. This property does not need a value associated with it. The mere presence of it specifies a SSL connection. However, for compatibility with future versions, the value "true" is preferred. For more information see Chapter 4, Using SSL安全协议SSL,利用数据加密、身份验证和消息完整性验证机制,为网络上数据的传输提供安全性保证。支持各种应用层协议。SSL客户端必须验证SSL服务器的身份,SSL服务器是否验证SSL客户端的身份,则由SSL服务器决定。通过ca证书,服务器端向客户端发送证书,包含秘钥等服务器信息,客户端通过证书验证服务器身份,服务器端不必须验证客户端身份。

主要使用方式:https、sslvpn

在ConnectionFactoryImpl的openConnectionImpl方法中开始设置:

defaultRowFetchSize = int:默认行抓取大小,在PGConnection的构造函数中设置。默认为从服务器一次取出所有数据放在客户端内存中,fetch size参数不起作用。在core.v3包的QueryExecutorImp类的sendOneQuery方法中有:

得让(flags & QueryExecutor.QUERY_FORWARD_CURSOR) != 0为true。

如果connection是自动提交事务的,那么,fetchSize将失效statement不是TYPE_FORWARD_ONLY的,那么,fetchSize也将失效。

currentSchema = String:设置查询的search_path来决定查询那个schema下的表。
在ConnectionFactoryImpl的openConnectionImpl方法中设置只是在当前会话连接中将search_path改了连接断开后失效。使用psql连接也是一次会话,要是search_path真正修改需要修改配置文件。

cancelSignalTimeout = int(从9.4.1209开始)取消命令是通过自己的连接带外发送的,所以取消消息本身可能会卡住。该属性控制用于取消命令的“连接超时”和“套接字超时”。超时时间以秒为单位指定。默认值是10秒。
在ConnectionFactoryImpl的openConnectionImpl方法中设置:

tcpKeepAlive = boolean 启用或禁用TCP保持活动状态探测。默认是false。在ConnectionFactoryImpl的openConnectionImpl方法中设置

readOnly = Boolean Put the connection in read-only mode只读模式
在PgConnection构造函数中设置

loginTimeout=int:指定等待建立数据库连接的时间。超时时间以秒为单位指定。如果loginTimeout<=0,走在Driver类的connect方法中makeConnection()方法.反之,开启ConnectThread设置完计时线程,再调用makeConnection方法。

ConnctThread内部类实现了Runnable接口。在返回conn的时候加了锁保证线程安全。

用来返回result(Connection)对象。

targetServerType:主要在loadbalance中用到,用来说明客户端请求连接是master或slave。但是单机使用slave会报异常如下,具体参考loadbalancehost参数:

执行过程:
首先Class.forName(driver);
调用Driver类的静态代码块,进行初始化。

调用register方法将Driver进行注册

然后,调用获取连接
DriverManager.getConnection(url,user,pwd);
走的是

PgConnection的构造函数开始执行

创建QueryExecutor对象

用来实现集群

queryExecutor已经获取完毕,也就是连接获取成功现在开始执行操作。
Statement:
Connection调用createStatement方法获取Statement对象。

调用PgStatement的构造函数进行初始化

PgStatement对象获取成功,现在开始执行操作调用execute方法

IsOneShotQuery是threshold的方法

函数操作:
自定义函数:
参照https://jdbc.postgresql.org/d...
upper(””):将字符串转成大写

count():求记录数

Jdbc函数调用:
调用add方法可以通过call调用,也可以查询调用,如下:

CallableStatement执行过程:
继承了preparestatement所以preparestatement的方法都能执行。

conn执行prepareCall(sql)方法:

在创建CachedQuery之后,与PrepareStatement或Statement一致

注意事项:
1:通过AtomicInteger实现线程安全 reference是引用的意思。

2:Java安全权限机制,通过AccessController授予权限
    AccessController.doPrivileged()
3:maven的使用方法mvn + clean/build/install
4:ssl的使用方式

在centos6有的系统安装pg10会在配置加上OpenSSL编译make时出现如下错误,无法正确安装:

然后再make clean出现系统错误。这个错误可能是某个linux系统原因:在configure之前使用make clean 命令可以正确安装,configure之后,make错误在使用make clean出现系统错误。在其他系统中正常。

首先需要安装gcc,gcc-c++,zlib,realine,make等依赖包还有devel包。数据库打开ssl必须在数据库配置(configure)中加上OpenSSL才可以,命令为:

configure --prefix=address –with-openssl
数据库安装见地址:https://www.cnblogs.com/linhp...
然后,在正确安装之后,配置开始配置ssl,配置ssl地址:
http://blog.csdn.net/zhu46745...
此时,服务器已经配置成功。接下来,开始采用jdbc连接:
ssl有双向和单向验证,这里我们数据库采用单向验证也就是只有服务器数据库进行验证,客户端不用验证。采用jdbc连接数据库时只需要在url中加上ssl=true这条参数,开始连接但是你可能会遇到:
这条异常信息无法正确连接,因为客户端也就是jdbc需要验证服务器的证书。接写来我们可以加上这条命令跳过验证。当然,加上该条命令的话安全性肯定会降低。
&sslfactory=org.postgresql.ssl.NonValidatingFactory
如果不用跳过的验证的话我们就需要采用

    
5:readme.md文件包含了项目的解释和连接参数(properties),contributing.md主要解释如何分享项目
6:volatile在这里可以做到的作用是使得多个线程可以共享变量,但是问题在于使用volatile将使得VM优化失去作用,导致效率较低,
7:Driver类中的connect方法和DriverManager中的getConnection方法区别:DriverManager中的getConnection方法调用了Driver中的connect方法。
8:void setPrepareThreshold(int threshold):预处理设置阈值
9:MetaData(元数据):数据分为数据和元数据,数据主要是文件本身例如文本中的数据,元数据是针对于系统,例如文本的存放地址,大小等,系统通过    元数据管理文本数据。
10:osgi:open service gateway initial 面向Java的动态模型系统
11:SQLPermission 
12:setForceBinary:布尔类型的,
13:setPrepareThreshold :PrepareThreshold默认值为5,是PreparedStatement的sql语句执行超过5次之后,使用已经存在的匹配的一句执行,提高速度。当然,也可以设置为禁止模式。可以称之为临界值。
14:PgStatement类中execute和executeUpdate方法区别:

两者在底层调用的方法是一样的,只不过返回值不同,execute返回的是布尔型表示是否执行成功,executeUpdate表示更新解过返回最后改变的列数整形。使用executeUpdate进行增删改, execute用来生成表和删除表,

查询走的底层方法也一样:query返回的是resultset。

15java spi机制,简单说就是定义一个接口,和几个具体实现类。在classpath路径下建立service文件夹,文件夹了建立接口路径到类名字的文件,文件中定义实现类的路径到类名,然后,通过serviceloader就可以将接口的具体实现类全部获取出来。在jdbcDriver中有应用。

驱动加载和参数设置到实例化PGConnection对象过程:

Transaction: 事务应该具有4个属性:原子性、一致性、隔离性、持久性。这四个属性通常称为ACID特性。
原子性(atomicity)。一个事务是一个不可分割的工作单位,事务中包括的诸操作要么都做,要么都不做。
一致性(consistency)。事务必须是使数据库从一个一致性状态变到另一个一致性状态。一致性与原子性是密切相关的。
隔离性(isolation)。一个事务的执行不能被其他事务干扰。即一个事务内部的操作及使用的数据对并发的其他事务是隔离的,并发执行的各个事务之间不能互相干扰。
持久性(durability)。持续性也称永久性(permanence),指一个事务一旦提交,它对数据库中数据的改变就应该是永久性的。接下来的其他操作或故障不应该对其有任何影响。
autosave = String:指定查询失败时驱动程序应执行的操作
在autosave=always模式中,JDBC驱动程序在每个查询之前设置一个保存点,并在发生故障时回滚到该保存点。在autosave=never模式下(默认),没有保存点回滚。在autosave=conservative模式中,为每个查询设置保存点,但是只有在“缓存语句不能更改返回类型”或“语句XXX无效”这样的极少数情况下才执行回滚,因此JDBC驱动程序回滚并重试,默认是never,此操作一般在增删改中使用。
调用过程:
首先,设置autocommit为false;

在execute方法中:

2.5.2 外连接
外连接返回的查询结果集合中的不仅包含符合连接条件的行,而且还包括左表(左外连
接时)、右表(右外连接时)或两个边接表(全连接)中的所有数据行。
注意:对于外连接,oracle 可以使用“(+)”来表示。但 HighGo DB 数据库不支持,所
以在 oracle 向 HighGo DB 数据库迁移的时候,需要特别注意。

2.5.2 外连接
外连接返回的查询结果集合中的不仅包含符合连接条件的行,而且还包括左表(左外连
接时)、右表(右外连接时)或两个边接表(全连接)中的所有数据行。
注意:对于外连接,oracle 可以使用“(+)”来表示。但 HighGo DB 数据库不支持,所
以在 oracle 向 HighGo DB 数据库迁移的时候,需要特别注意。

except差集oracle中使用的是minux
select from student except select from user;

序列是 HighgoDB 的一种特殊计算器,它由用户创建,由系统管理。创建一个序列后,
可以将其作为某个字段的默认值。在 insert 命令的执行期间,序列的值会被自动生成,并作为
数据行的唯一性编号,存放在该数据行相应的字段中。

可以使用选项 config_file,hba_file,ident_file 分别声明配置文
件的路径。config_file 只能在 postgres 命令行上设置,但是其它的可以在主配置
文件里设置。如果明确设置了所有三个选项和 data_directory,那么就没必要声明
-D 或 PGDATA。

如果你发现有"Too many open files"这样的失败现象,那么就尝试
缩小这个设置。这个值只能在服务器启动的时候设置max_files_per_process(integer)

Postgresql配置远程连接
配置highgosql远程连接的时候,将postgres.conf打开监听为*;然后修改pg_hba.conf 将ipv4设置为0.0.0.0/0 md5。允许外部接入。重新启动服务。然后在bin目录下使用./psql –h address 登录验证是否成功。在配置完之后,配置防火墙,打开5432端口。

包结构分析以及maven打包:
jdbc.postgresql学习:首先看readme和contributing文件

Maven打jar包方式:jdbc通过maven进行jar包编译:详细见contributing.md文件,搜索mvn package在命令行中进入项目根目录下(包含pom文件的目录),使用mvn package命令进行打包,在打包的过程中会进行测试,如果测试不通过的话,使用mvn package -DskipTests或mvn package -Dmaven.test.skip=true命令跳过测试直接进行编译.即可成功。两个命令的区别是:前者只进行编译不进行检查,后者既不检查也不编译

进入jre7或6目录进行打包。
配置mvn库的toolchains文件:(不是项目的)

Jdbc.postgresql源码需要修改的地方:
1, 将端口改为: 5586

2, 驱动改为com.highgo.jdbc.

3, 包名改为:com.highgo.jdbc

4, 修改pom文件:

5, 改一下证书:

1加载驱动:

通过Class.forName("驱动(Driver类)")方法将Driver类加载进内存,Driver类中的静态代码块执行初始化操作。使用DriverManager(期望加载尽可能多的驱动)中的registerDriver()方法,将Driver类进行注册,每次注册之前先判断Driver是否已经注册,有的话抛出异常。没有正常注册

2分析外层类和外层包结构:
它们都是在org.postgresql目录下的,最外层有Driver、PGConnection,PGnotification,PGProperty,PGRefCursorResultSet,PGResultSetMetaData,PGstatement类和copy,core,ds,fastpath,geometric,gss,hostchosser,jdbc,jdbc2,jdbc3,largeobject,osgi,replication,ssl,sspi,translation,util,xa包
外层类:
Driver:
1.当使用Class.forName()将驱动加载进内存后,Driver类中的静态代码块开始执行register方法进行初始化操作,register方法先判断是否已经注册,有的话抛出异常返回,没有开始注册。并且赋值给自己的Driver方便验证是否已经注册。

2.其中用到SharedTimer类,进行数据库连接计数操作。
3.使用getDefaultProperties方法加载默认的配置文件,其中使用AccessController.doPrivileged意思是这个是特别的,不用做权限检查. 
4.loadDefaultProperties方法用来加载本地文件,
5.connect方法:首先检查主机地址是否正确错误返回。然后,获取本地参数文件并且做一个副本,遍历connect中info参数,将不为空的加到本地参数文件中,接着,使用parseURL方法将url地址解析然后添加到properties文件中,没问题的话,在执行timeout超时方法,小于0的话执行makeConnection进行连接,反之,执行ConnectionThread连接线程内部类。
 6.makeConnection方法:执行PGConnection的构造方法进行连接。
 7.deregister方法关闭连接
 8.ConnectionThread内部类实现了runnable:在连接超时的时候调用,通过构造函数进行初始化,将重连代码放到run方法中。

PGConnection:顶层Connection接口。主要是对sql.Connection接口方法的扩展。被BaseConnection接口所继承。

PGNotification[] getNotifications():获取通知
CopyManager getCopyAPI():copy管理者
LargeObjectManager getLargeObjectAPI() 大对象管理
Fastpath getFastpathAPI()    获取FastPath
void addDataType(String type, String className);添加数据类型
void setPrepareThreshold(int threshold);    设置阈值
void setDefaultFetchSize(int fetchSize)    :设置默认抓取大小
int getDefaultFetchSize();获得默认抓取大小
PGReplicationConnection getReplicationAPI();

PGNotification:顶层接口,This interface defines the public PostgreSQL extension for Notifications

String getName();获取通知名字
int getPID();获取通知线程id
String getParameter();    获取通知参数

PGProperty:本类是一个枚举类,主要是数据库的连接参数,例如(数据库名字,端口,主机地址,用户名,密码,ssl,连接超时,登录超时)等参数。
PGRefCursorResultSet: As of 8.0, this interface is only present for backwards- compatibility purposes. New code should call getString() on the ResultSet that contains the refcursor to obtain the underlying cursor name.

PGResultSetMetaData:一个顶级接口:元数据
String getBaseColumnName(int column) 获取基本列的名字

     String getBaseTableName(int column) 获取基本表的名字
     String getBaseSchemaName(int column) 获取基本模式的名字
     int getFormat(int column) 获取基本格式的名字

PGstatement:This interface defines the public PostgreSQL extensions to java.sql.Statement. All Statements constructed by the PostgreSQL driver implement PGStatement.
method:
long getLastOID() 返回上一个对象的 oid

void setPrepareThreshold(int threshold)
void setUseServerPrepare(boolean flag) 等同于void setPrepareThreshold(int threshold):设置阈值,
boolean isUseServerPrepare();    服务是不是使用了Prapare操作也就是threshold
int getPrepareThreshold();        预先获取阈值

外层包:
copy:
core:

Version: Get a machine-readable version number.
ServerVersion :enum 类Enumeration for PostgreSQL versions.实现了Version
ConnectionFactory:一个抽象类。Handles protocol-specific connection setup.
     public static QueryExecutor openConnection(HostSpec[] hostSpecs, String user,String database, Properties info) 获得查询执行者
     public abstract QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, String user,String database, Properties info) 

BaseConnection:Driver-internal connection interface. Application code should not use this interface. 继承了PGConnection 和 Connection接口。被jdbc包下的PgConnection类所实现。也就是访问PGConnection的对象最后将会转到PGConnection中去执行。其实就是将返回的Connection对象指向PGConnection对象来执行具体的操作。BaseConnection以及Connection都将被PGConnection所实现。

     void cancelQuery() :取消查询
     ResultSet execSQLQuery(String s)    执行查询
     void execSQLUpdate(String s) 执行修改
     QueryExecutor getQueryExecutor() 获得查询执行者
     ReplicationProtocol getReplicationProtocol() 获得副本协议
    Object getObject(String type, String value, byte[] byteValue)获得对象PGobject} instance is returned.
     Encoding getEncoding() 获得编码
     TypeInfo getTypeInfo(); 获得类型信息
     boolean haveMinimumServerVersion(int ver);    获得最小版本
     byte[] encodeString(String str) 编码字符串
     String escapeString(String str) 编译字符串
     boolean getStandardConformingStrings();是否获得正确的字符串
     TimestampUtils getTimestampUtils(); 获得时间戳工具
     boolean getStringVarcharFlag(); 是否获得varchar字符串标签
     TransactionState getTransactionState(); 获得事务的状态

SqlCommandType:Jdbc支持的sql命令。

     boolean binaryTransferSend(int oid);二进制转发
     boolean isColumnSanitiserDisabled();相同列消除
     void addTimerTask(TimerTask timerTask, long milliSeconds);添加时间任务
     void purgeTimerTasks();    肃清时间任务
     LruCache<FieldMetadata.Key, FieldMetadata> getFieldMetadataCache(); 获得元数据缓存,采用LRU(last least used)最近最少使用算法。                                 

CachedQuery createQuery(String sql, boolean escapeProcessing, boolean isParameterized,String... columnNames)有缓存的查询

     void setFlushCacheOnDeallocate(boolean flushCacheOnDeallocate); 设置解除分配内存的时候刷新缓存。

SocketFactoryFactory:Instantiates {@link SocketFactory} based on the {@link PGProperty#SOCKET_FACTORY}.获取SocketFactory实例
PGStream:In general, instances of PGStream are not threadsafe; the caller must ensure that only one thread at a time is accessing a particular PGStream instance.
PgStream的构造方法如下图:

PgStream中设置长度为4个字节的字节数组,将整数先右移24位也就是3个字节赋值给0,

BaseQueryKey:当ColumnNames

.v3:第3版本

ConnectionFactoryImpl:ConnectionFactory接口的实现类。ConnectionFactory implementation for version 3 (7.4+) connections.
private ISSPIClient createSSPI(PGStream pgStream, String spnServiceClass, boolean enableNegotiate) :
 public QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, String user, String database,Properties info):

QueryExecutorImpl:QueryExecutor implementation for the V3 protocol.继承了QueryExecutorBase

 public QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, String user, String database,Properties info)
 private PGStream enableSSL(PGStream pgStream, boolean requireSSL, Properties info, int connectTimeout)

 private void sendStartupPacket(PGStream pgStream, List<String[]> params)
 private void doAuthentication(PGStream pgStream, String host, String user, Properties info)

认证主要是对密码进行验证,数据库名和用户名等已经发送给数据库系统了,在数据库的data/pg_hbm.conf中对远程登录进行设置,trust为没有密码MD5为需要密码,从而在switch中走不同验证方式。

 private void runInitialQueries(QueryExecutor queryExecutor, Properties info)
 private boolean isMaster(QueryExecutor queryExecutor) 

QueryExecutor:一个借口查询执行者
QueryExecutorBase:实现了QueryExecutor接口


VisibleBufferedInputStream:A faster version of BufferedInputStream. Does no synchronisation and allows direct access to the used byte[] buffer.

Encoding:Representation of a particular character encoding.

SetupQueryRunner:Poor man's Statement & ResultSet, used for initial queries while we're still initializing the system.
Utils: Collection of utilities used by the protocol-level code.
Oid: Provides constants for well-known backend OIDs for the types we commonly use.
ReplicationProtocol:Abstracts the protocol-specific details of physic and logic replication. With each connection open with replication options associate own instance ReplicationProtocol.
Provider:Represents a provider of results.

QueryWithReturningColumnsKey:Cache key for a query that have some returning columns. should contain non-quoted column names. The parser will quote them automatically.There's a special case of {@code columnNames == new String[]{"*"}} that means all columns should be returned. {@link Parser} is aware of that and does not quote 

BaseQueryKey: This class is used as a cache key for simple statements that have no "returning columns". Prepared statements that have no returning columns use just {@code String sql} as a key. Simple and Prepared statements that have returning columns use {@link QueryWithReturningColumnsKey} as a cache key.
Query:
CachedQuery:Stores information on the parsed JDBC query. It is used to cut parsing overhead when executing the same query through {@link java.sql.Connection#prepareStatement(String)}.
TypeInfo:
ds(DataSource):

fastpath:这是从java应用程序中执行嵌入后端的函数的一种手段。It is based around the file src/interfaces/libpq/fe-exec.c

Fastpath:
    

geometric:

gss:

hostchosser:
HostChooser:接口 Lists connections in preferred order.

    Iterator<HostSpec> iterator();

HostChooserFactory:Chooses a {@link HostChooser} instance based on the number of hosts and properties.创建一个主机选择还是多个主机选择(负载均衡中用到应该是集群中的主备机)。

public static HostChooser createHostChooser(HostSpec[] hostSpecs,HostRequirement targetServerType, Properties info)

SingleHostChooser:实现了hostchooser接口 Host chooser that returns the single host.单一主机连接。

    public Iterator<HostSpec> iterator() 迭代主机
    public SingleHostChooser(HostSpec hostSpec)    构造函数进行初始化HostSpec集合使用Collections.singletonList()不可变链表存储,只能存储一个HostSpec对象,该对象包含主机地址和端口两个属性。

MultiHostChooser:实现了hostchooser接口 HostChooser that keeps track of known host statuses.多个主机进行连接区分master和slave主机用在负载均衡集群上面。

    private int rank(HostStatus status, HostRequirement targetServerType) 目标主机的等级
    class HostSpecByTargetServerTypeComparator implements Comparator<HostSpecStatus> 实现了Comparator进行比较目标主机的等级

private List<HostSpec> extractHostSpecs(List<HostSpecStatus> hostSpecStatuses) 提取主机

    private void sortCandidates(List<HostSpecStatus> candidates) 对候选主机进行排序
    private void shuffleGoodHosts(List<HostSpecStatus> candidates) 打乱让失去平衡。

GlobalHostStatusTracker :Keeps track of HostSpec targets in a global map.

private static final Map<HostSpec, HostSpecStatus> hostStatusMap = new HashMap<HostSpec, HostSpecStatus>(); 一个HostSpecMap。
    public static void reportHostStatus(HostSpec hostSpec, HostStatus hostStatus) :Store the actual observed host status.
    private static boolean updateStatusFromTo(HostStatus oldStatus, HostStatus newStatus) :验证主机状态是否为空或不是主或从机的话返回true,反之false;
    static List<HostSpecStatus> getCandidateHosts(HostSpec[] hostSpecs, HostRequirement targetServerType, long RecheckMillis) 获得候选主机。Returns a list of candidate hosts that have the required targetServerType.

static class HostSpecStatus :Immutable(不可变的) structure of known status of one HostSpec.
在连接之前要求的连接目的主机类型

jdbc:
 PgConnection:BaseConnection的实现类:实现了PGConnection和Connection接口
Driver类的connect方法new一个PGConnection对象,通过构造方法对象PgConnection进行初始化,

    public void setDefaultFetchSize(int fetchSize) 设置默认抓取数量
    public int getDefaultFetchSize() 获取默认抓取数量
public void setPrepareThreshold(int newThreshold) 设置预处理阈值临界值
    public boolean getForceBinary() 获取强制二进制
    public void setForceBinary(boolean newValue)设置强制二进制
    private final LruCache<FieldMetadata.Key, FieldMetadata> fieldMetadataCache; 
    public void execSQLUpdate(String s) :执行sql更新
    public java.sql.Statement createStatement() 创建statement通过PgStatement的构造函数初始化PgStatement,先调用checkClosed()方法
    public java.sql.PreparedStatement prepareStatement(String sql):通过重载调用PgPreparedStatement构造方法返回PreparedStatement实例。先调用checkClosed()方法。

Public CallableStatement prepareCall(String sql, int resultSetType, intresultSetConcurrency, int resultSetHoldability)

    public DatabaseMetaData getMetaData():获取数据库的元数据,先调用checkClosed();该方法用来验证ExecuterQuery是否已经关闭。
     
    private Set<Integer> getOidSet(String oidList):获取Oid集合

public void close():关闭已经建立的连接。

   public void setReadOnly(boolean readOnly)设置只读模式
 public void setAutoCommit(boolean autoCommit)设置是否自动提交。

手动提交:

public void rollback()设置回滚

public void setTransactionIsolation(int level):设置事务隔离。
设置查询模式。
public CachedQuery createQuery(String sql, boolean escapeProcessing, boolean isParameterized,String... columnNames);

public boolean haveMinimumServerVersion(Version ver):获取最小数量服务器版本
private String oidsToString(Set<Integer> oids):将属性名字变成字符串
private void initObjectTypes(Properties info):// This initialises the objectTypes hash map

enum StatementCancelState:含有4中状态。标志statement对象的状态。

  1. PgStatement:实现了BaseStatement和PGStatement接口。在PgConnection调用PgStatement的构造方法进行初始化对象获取PgConnection的ForceBinary变量,并赋值给本实例中的变量,设置并发,结果集的类型,设置获取值得大和PrepareThreadhold

FieldMetadata:This is an internal class to hold field metadata info like table name, column name, etc. This class is not meant to be used outside of pgjdbc.

TimestampUtils:Misc utils for handling time and date values.

TypeInfoCache:
public BaseConnection getPGConnection():获取Connection实例
public int getFetchSize()

AutoSave:enum类型NEVER,  ALWAYS,  CONSERVATIVE; 

查询执行:

public java.sql. ResultSet executeQuery(String p_sql):先执行executeWithFlags方法,在判断resultset是否存在,存在的话返回给用户。
Pgstatement执行过程:

Queryexecutor:在ConnectionFactory类的openConnection()方法中得到

connectionFactory.openConnectionImpl( hostSpecs, user, database, nfo);方法如下:在core.v3包中
首先判断是否使用ssl
目标服务主机类型

在之前都是配置参数,获取的socketfacroty。之后使用PgStream开始建立连接

jdbc2:

jdbc3:

largeobject:It provides methods that allow client code to create, open and delete large objects from the database. When opening an object, an instance of org.postgresql.largeobject.LargeObject is returned, and its methods then allow access to the object.

LargeObjectManager:

osgi:open service gateway initial 一个致力于解耦的模块控制使用jetty服务器
replication:
PGReplicationConnection:仅当连接创建时需要复制属性时,Api才可用PGProperty#REPLICATION}和PGProperty#ASSUME_MIN_SERVER_VERSION}。 没有它的财产建立复制流失败,例外。

public class MakeSSL extends ObjectFactory :converting regular socket connection to ssl
使用conver()将连接转换成SSL模式的连接

public class LibPQFactory extends WrappedFactory implements HostnameVerifier :位于jdbc4包下,

sspi:

ISSPIClient:只允许windows系统的登录方式
boolean isSSPISupported(); 是否支持SSPI
void continueSSPI(int msgLength)  继续使用SSPI
void startSSPI() 开始使用ssPI
void dispose(); 结束

translation(国际化):

util(工具包):

SharedTimer类: Incremented for each Timer created, this allows each to have a unique Timer name
其中使用到AtomicInteger(提供原子操作来进行Integer的使用,因此十分适合高并发情况下的使用)执行计数器。保证每个线程有自己的时间名字,它采用静态AtomicInteger进行计数。
PSQLState 枚举类:This class is used for holding SQLState codes.

ObjectFactory:Helper class to instantiate objects. 使用反射机制实例化对象,即通过Class调用getConstructor方法,然后newInstance获取实例,

CanEstimateSize:接口获得建立时的大小。主要是用于元数据的大小显示。
LruCache<Key, Value extends CanEstimateSize>:Caches values in simple least-recently-accessed order.
ServerErrorMessage:
UnixCrypt:Contains static methods to encrypt and compare passwords with Unix encrypted passwords.

• MD5Digest:对用户名和密码进行散列值运算生成信息摘要。Encodes user/password/salt information in the following way: MD5(MD5(password + user) + salt)

xa:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值