jdbc

simple jdbc classes implementation

License

License

Categories

Categories

Ant Build Tools
GroupId

GroupId

com.github.antonsjava
ArtifactId

ArtifactId

jdbc
Last Version

Last Version

1.1
Release Date

Release Date

Type

Type

jar
Description

Description

jdbc
simple jdbc classes implementation
Project URL

Project URL

https://github.com/antonsjava/jdbc
Source Code Management

Source Code Management

https://github.com/antonsjava/jdbc

Download jdbc

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.antonsjava/jdbc/ -->
<dependency>
    <groupId>com.github.antonsjava</groupId>
    <artifactId>jdbc</artifactId>
    <version>1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.antonsjava/jdbc/
implementation 'com.github.antonsjava:jdbc:1.1'
// https://jarcasting.com/artifacts/com.github.antonsjava/jdbc/
implementation ("com.github.antonsjava:jdbc:1.1")
'com.github.antonsjava:jdbc:jar:1.1'
<dependency org="com.github.antonsjava" name="jdbc" rev="1.1">
  <artifact name="jdbc" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.antonsjava', module='jdbc', version='1.1')
)
libraryDependencies += "com.github.antonsjava" % "jdbc" % "1.1"
[com.github.antonsjava/jdbc "1.1"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

jdbc

Simple DataSource implementation and DataSource wrapper with log capabilities.

DriverManagerDataSource

DataSource implementation which creates connections using DriverManager class. It makes no pooling. Creates new Connection instance each time when getConnection is called.

It is usefull for testing jdbc code which uses DataSource instance independently of environment which creates such instance.

Example of h2 DataSource instance creation

	DataSource ds = DriverManagerDataSource.instance(
			"org.h2.Driver"
			, "jdbc:h2:./target/databasefilename.h2;MODE=PostgreSQL"
			, "user"
			, "pass"
	);

LogDataSource

Wraps DataSource instance with some log capabilities. It logs

  • connection commits/rollbacks
  • statement executions
  • prepared statement executions with params
  • result set counts

Example of wrapping DataSource instance

	ds = LogDataSource.wrap(ds, 
			LogConfig.instance(
					() -> jdbclog.isDebugEnabled()
					, (message) -> jdbclog.debug(message))
		);

LogConfig

This class cumulates configuration of logging.

  • Consumer consumer - provides connection to logging real api
  • ConsumerStatus consumerStatus - provides connection to logging real api
  • boolean logStatement = true - enables loging of statement execution
  • boolean logResultSet = true - enables loging of result set counts (on close)
  • boolean logTransaction = true - enables loging of transaction boundaries

Log examples

connection boundary with connection identity 10

jdbc [10] commit time: 0

statement with connection identity 10 and statement identity 8

jdbc [10][8] statement: select vs, description from mytable where vs = '1111111111' time: 0

prepared statement with connection identity 10 and statement identity 9

jdbc [10][9] statement: update mytable set vs=?, description=? where vs = '1111111111' params:  ?1:1111111111 ?2:22222  result: 1 time: 1

result set with connection identity 10 and statement identity 8

jdbc [10][8] resultset row count: 2 first row time: 0 all row time: 2 close time: 0

Maven usage

   <dependency>
      <groupId>com.github.antonsjava</groupId>
      <artifactId>jdbc</artifactId>
      <version>1.0</version>
   </dependency>

Versions

Version
1.1
1.0