Skip to content

Instantly share code, notes, and snippets.

View juarezjuniorgithub's full-sized avatar

Juarez Barbosa Junior juarezjuniorgithub

View GitHub Profile
@juarezjuniorgithub
juarezjuniorgithub / OracleAIVectorSearchWithJava.java
Created May 4, 2024 11:27
OracleAIVectorSearchWithJava.java
/*
Copyright (c) 2024, Oracle and/or its affiliates.
This software is dual-licensed to you under the Universal Permissive License
(UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License
2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
either license.
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
https://www.apache.org/licenses/LICENSE-2.0
@juarezjuniorgithub
juarezjuniorgithub / application.properties
Created January 18, 2024 14:03
Oracle Autonomous Database connection details
spring.datasource.url=<YOUR_JDBC_CONNECTION_URL>
spring.datasource.username=<YOUR_DB_USERNAME>
spring.datasource.password=<YOUR_DB_PASSWORD>
@juarezjuniorgithub
juarezjuniorgithub / application.properties
Created January 18, 2024 14:01
Properties for UCP - Universal Connection Pool (UCP). Spring Boot 2.4.0 or above is required - application.properties
spring.datasource.type=oracle.ucp.jdbc.PoolDataSource
spring.datasource.oracleucp.connection-pool-name=connectionPoolName1
spring.datasource.oracleucp.initial-pool-size=1
spring.datasource.oracleucp.min-pool-size=1
spring.datasource.oracleucp.max-pool-size=2
spring.datasource.oracleucp.connection-factory-class-name=oracle.jdbc.pool.OracleDataSource
@juarezjuniorgithub
juarezjuniorgithub / Pool metrics mappings.csv
Created January 17, 2024 13:24
Pool metrics mappings
HikariCP metrics UCP Metrics
Number of active connections BorrowedConnectionsCount
Number of pending connection requests PendingRequestsCount
Total number of timed-out requests CumulativeFailedConnectionWaitCount
Time taken to get a connection PeakConnectionWaitTime / AverageConnectionWaitTime
Current total number of connections TotalConnectionsCount
Number of idle connections AvailableConnectionsCount
Max number of connections PeakConnectionsCount
@juarezjuniorgithub
juarezjuniorgithub / UCP knobs that don't exist in Hikari.csv
Last active January 19, 2024 08:59
UCP knobs that don't exist in Hikari
UCP Knob Description
UCP[XA]ConnectionBuilder.user().password() or PoolDataSource.getConnection(user + password) UCP's single pool can hold connections from more than one database accounts and can borrow a connection to a given account.
UCP[XA]ConnectionBuilder.shardingKey().superShardingKey() It is possible to establish a connection with a given sharding key/super key.
UCP[XA]ConnectionBuilder.connectionWaitTimeout() or UCP[XA]ConnectionBuilder.connectionWaitDuration() UCP can set connection wait timeout (either in seconds or in Duration - supporting milliseconds) for a separate borrow request as well as for a whole PoolDataSource.
UCP[XA]ConnectionBuilder.service() It is possible to borrow a connection to a selected database service (a pool can hold connections from different services.
UCP[XA]ConnectionBuilder..labels() or PoolDataSource.getConnection(labels) UCP connections can be labeled and per-label connection cost can be assigned. Then a connection can be borrowed based on its label(s) and cost.
@juarezjuniorgithub
juarezjuniorgithub / HikariCP properties that don’t have identical UCP properties to match but do have other mechanisms like driver properties or UCP APIs.csv
Last active January 17, 2024 17:00
HikariCP properties that don’t have identical UCP properties to match but do have other mechanisms like driver properties or UCP APIs
HikariCP Comments
autoCommit Use Oracle JDBC driver connection property autoCommit.
registerMbeans UCP always attempts registration.
threadFactory UCP supports setTaskManager instead (setter API only).
scheduledExecutor UCP supports setTaskManager instead (setter API only).
keepaliveTime Closest is to use driver connection properties oracle.net.keepAlive + oracle.net.TCP_KEEPIDLE which apply to all connections borrowed/available. The HikariCP property applies only to idle/available connections and uses isValid/query to keep alive. Another option is to add async validation in UCP for available connections.
minimumIdle Controls the minimum number of idle connections HikariCP tries to maintain in the pool.
@juarezjuniorgithub
juarezjuniorgithub / HikariCP properties that have exact UCP equivalences.csv
Last active January 17, 2024 11:37
HikariCP properties that have exact UCP equivalences
HikariCP UCP Comments
dataSourceClassName ConnectionFactoryClassName (1) ConnectionFactoryClassName also covers java.sql.DriverManager cases.(2) HikariCP doesn't support XA.
jdbcUrl URL
username User
password Password
connectionTimeout (ms) ConnectionWaitTimeout UCP 23.2 supports ms and pre-23.2 supports sec. HikariCP lowest acceptable value 250ms.
idleTimeout InactiveConnectionTimeout HikariCP won't drop below minimumIdle.
maxLifeTime MaxConnectionReuseTime
connectionTestQuery SQLForValidateConnection
maximumPoolSize MaxPoolSize
@juarezjuniorgithub
juarezjuniorgithub / OracleR2dbcProjectReactor.java
Created November 14, 2023 14:33
OracleR2dbcProjectReactor.java
package com.oracle.dev.jdbc.r2dbc;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public class OracleR2dbcProjectReactor {
private static final String QUERY = "SELECT * FROM CUSTOMERS";
@juarezjuniorgithub
juarezjuniorgithub / SQLStatementWithAsynchronousJDBC.java
Last active November 14, 2023 12:12
SQLStatementWithAsynchronousJDBC.java
package com.oracle.jdbc.reactive;
import java.sql.SQLException;
import java.util.concurrent.Flow;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OraclePreparedStatement;
import oracle.jdbc.pool.OracleDataSource;
public class SQLStatementWithAsynchronousJDBC {
@juarezjuniorgithub
juarezjuniorgithub / 23c-SpringBoot-JPA_Hibernate-UCP.sql
Created November 13, 2023 12:56
23c-SpringBoot-JPA_Hibernate-UCP.sql
CREATE USER ORACLE_23C_USER IDENTIFIED BY <YOUR_PASSWORD>;
GRANT DB_DEVELOPER_ROLE TO ORACLE_23C_USER;
GRANT CREATE SESSION TO ORACLE_23C_USER;
GRANT UNLIMITED TABLESPACE TO ORACLE_23C_USER;
CREATE TABLE Employee
(id NUMBER(10) CONSTRAINT pk_employee PRIMARY KEY,
name VARCHAR2(20),
job VARCHAR2(20),
salary NUMBER(10),