Set JDBC properties on play-framework application.config - jdbc

I'd like to set some JDBC properties on the application.config.
For example: useLegacyDatetimeCode=false&useUnicode=true&serverTimezone=UTC
And this is my application.config.
play {
db.prototype.hikaricp {
connectionTimeout = 30 seconds
maximumPoolSize = 5
}
}
db {
default {
driver="org.mariadb.jdbc.Driver"
url="jdbc:mariadb://host:port"
username="user"
password="password"
}
}
However, my program need to access multiple databases so that I cannot combine the url, username, password and properties in the url property.
Is it possible to configure it?
I've tried this, but it does not work.
db {
default {
driver="org.mariadb.jdbc.Driver"
url="jdbc:mariadb://host:port"
username="user"
password="password"
useLegacyDatetimeCode=false
}
}
Thanks.

So, in order to set the JDBC driver specific properties in play configuration you have to configure them through the connection pool implementation.
It will then initiate connections with the given properties to the connection driver.
For example with default connection pool implementation in play (HikariCP)
# SQLServer driver properties, timeout In seconds
db.default.hikaricp.dataSource.queryTimeout = 15
This will map any property to the driver props

Related

How to configure rest client in quarkus microprofile case

When using Quarkus microprofile as a rest client, how can I configure underlying HttpClient?
Like number of retries, connection pool size per host and so on?
Also is it possible to force client restart somehow (so connections pool will be restarted)?
https://download.eclipse.org/microprofile/microprofile-rest-client-2.0-RC2/microprofile-rest-client-2.0-RC2.html#_configuration_keys outlines the full set of configuration keys that can be used.
The ones you're looking for are:
{packageName}.{interfaceName}/mp-rest/connectTimeout
{packageName}.{interfaceName}/mp-rest/readTimeout
The RestClientBuilder also has methods for setting those properties if you're using the programmatic API instead of the CDI approach.
I'm not aware of any means of restarting the underlying HTTP client connection pool. What would be the use case for such a situation that doesn't require the whole application to be restarted?
So... After a lot of digging, here is a solution I've found so far. It is not obvious apparently:
To make it work in pure Java (no native)
Under resources/META-INF/services directory add file named org.eclipse.microprofile.rest.client.spi.RestClientBuilderListener containing class name of your implementation of RestClientBuilderListener interface. For example my.test.MyBuilderListener. This will allow ServiceLocator to execute your listener
Refer a property you want to modify from ResteasyClientBuilder, for example to set your custom value to connectionTTL code will looks like this:
public void onNewBuilder(RestClientBuilder builder) {
log.info("Changing TTL for connections");
builder.property("resteasy.connectionTTL", List.of(2L, TimeUnit.SECONDS));
}
Ie. add a resteasy. prefix to a property name
Profit
Now native support:
After steps above:
Set both MyBuildListener and ResteasyClientBuilder available for reflection by creating a file reflection-config.json:
[
{
"name": "org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true,
"allDeclaredFields": true,
"allPublicFields": true
}, {
"name": "my.test.MyBuilderListener",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true,
"allDeclaredFields": true,
"allPublicFields": true
}
]
Add service registration file to resources. Create a file named resources-config.json with content
{
"resources": [
{
"pattern": "META-INF/services/org\\.eclipse\\.microprofile\\.rest\\.client\\.spi\\.RestClientBuilderListener$"
}
]
}
register both files in application.yaml:
quarkus:
native:
additional-build-args: -H:ResourceConfigurationFiles=resources-config.json, -H:ReflectionConfigurationFiles=reflection-config.json
Native profit
Have fun

Connection not established after database backup

Deployed web application in weblogic 12c server and it has data source configure to make use of connection pool.
Database is Oracle 12,
Usecase: when application is alive up and running, for a min database backup script has been run(stop db, backup, start db), after that when trying to access application(session got established) then got SQL error (connection already closed). What could be an issue?
Temporary solution: after restarting application it was working fine with out any issue. Still wondering how it got worked?
Datasource configuration :
**dataSource {
configClass = GrailsAnnotationConfiguration.class
dialect = "org.hibernate.dialect.Oracle10gDialect"
loggingSql = false
jmxExport = false
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
hbm2ddl.auto = null
show_sql = false
// naming_strategy = "org.hibernate.cfg.ImprovedNamingStrategy"
dialect = "org.hibernate.dialect.Oracle10gDialect"
config.location = [
"classpath:hibernate-core.cfg.xml",
"classpath:hibernate-utility.cfg.xml"
]
}
// environment specific settings
environments {
development {
dataSource {
}
}
test {
dataSource {
}
}
production {
dataSource {
}
}
}**

Exception when Implementing RPC Security Management in corda using spring webserver

Spring Web server not started when we specify RPC Security Management configuration in node.conf file.
Getting error as Unresolved reference: proxy, while running PartyAServer.
Below is my server configuration for PartyA node :-
task runPartyAServer(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.example.server.Server'
environment "server.port", "10022"
environment "config.rpc.host", "localhost"
environment "config.rpc.port", "10006"
}
I am able to start the node with following node A configuration, but facing error while running PartyA server.
node {
name "O=PartyA,L=London,C=GB"
advertisedServices = ["com.example"]
p2pPort 10005
rpcPort 10006
cordapps = ["$corda_release_group:corda-finance:$corda_release_version",
"com.example:java-source:$version",
"com.example:base:$version"]
}
Below is my node.conf for PartyA node :-
extraAdvertisedServiceIds=[
"com.example"
]
myLegalName="O=PartyA,L=London,C=GB"
networkMapService {
address="localhost:10002"
legalName="O=Controller,L=London,C=GB"
}
p2pAddress="localhost:10005"
rpcAddress="localhost:10006"
rpcUsers=[]
security = {
authService = {
dataSource = {
type = "DB",
passwordEncryption = "SHIRO_1_CRYPT",
connection = {
jdbcUrl = "jdbc:oracle:thin:#172.16.105.21:1521:SFMS"
username = "abinay"
password = "abinay"
driverClassName = "oracle.jdbc.OracleDriver"
}
}
options = {
cache = {
expireAfterSecs = 120
maxEntries = 10000
}
}
}
}
Without having username and password how nodeRPCConnection(proxy) will be established with following code,
#PostConstruct
public void initialiseNodeRPCConnection() {
NetworkHostAndPort rpcAddress = new NetworkHostAndPort(host,rpcPort);
CordaRPCClient rpcClient = new CordaRPCClient(rpcAddress);
rpcConnection = rpcClient.start(username, password);
proxy = rpcConnection.getProxy();
staticMap.put("proxy",proxy);
}
This strikes me as more likely to be an oracle connection issue.
I'd start by writing some java code just to ensure that you can connect to the oracle DB, and then focus on getting that to work in the cordapp environment.
There's a good developer example on this (in both java and kotlin: https://github.com/corda/samples-java/tree/master/Basic/flow-database-access ; https://github.com/corda/samples-kotlin/tree/master/Basic/flow-database-access)
Best of luck on this!

Retrieving Datasource JDBC connection string via JMX from IBM Websphere

I would like to know if it is possible to retrieve a Datasource's JDBC connection String from IBM Websphere Application Server. I already have access to the datasource's JMX Bean but no attribute or operation (see below) seems to expose the JDBC connection URL String. Does anybody know how to retrieve this information?
Attributes:
dbcDriver: WebSphere:name=...
connectionFactoryType: interface javax.sql.DataSource
dataSourceName:
dataStoreHelperClass: description: New JDBC Datasource
loginTimeout: statementCacheSize: 10
jtaEnabled: true
testConnection: true
testConnectionInterval: 180
objectName: WebSphere:name=...
stateManageable: false
statisticsProvider: false
eventProvider: false
authMechanismPreference: 0
stuckTimerTime: 0
stuckTime: 0
stuckThreshold: 0
surgeThreshhold: -1
surgeCreationInterval: 0
connectionTimeout: 180
maxConnections: 10
minConnections: 1
purgePolicy: FailingConnectionOnly
reapTime: 180
unusedTimeout: 1800
agedTimeout: 0
freePoolDistributionTableSize: 5
freePoolPartitions: 1
sharedPoolPartitions: 200
holdTimeLimit: 10
diagnosticProviderName: ...
name: TaggingDatenquelle
Description: New JDBC Datasource
jndiName: jdbc/name
category:
Operations:
getJdbcDriver:
getConnectionFactoryClass:
getDataSourceName:
getDataStoreHelperClass:
getDescription:
getLoginTimeout:
getStatementCacheSize:
isJTAEnabled:
getProperty:
getTestConnection:
setTestConnection:
getTestConnectionInterval:
setTestConnectionInterval:
getObjectNameStr:
isStateManageable:
isStatisticsProvider:
isEventProvider:
getAuthMechanismPreference:
getStuckTimerTime:
setStuckTimerTime:
getStuckTime:
setStuckTime:
getStuckThreshold:
setStuckThreshold:
getSurgeThreshhold:
setSurgeThreshhold:
getSurgeCreationInterval:
setSurgeCreationInterval:
getConnectionTimeout:
setConnectionTimeout:
getMaxConnections:
setMaxConnections:
getMinConnections:
setMinConnections:
getPurgePolicy:
setPurgePolicy:
getReapTime:
setReapTime:
getUnusedTimeout:
setUnusedTimeout:
getAgedTimeout:
setAgedTimeout:
getFreePoolDistributionTableSize:
getFreePoolPartitions:
getSharedPoolPartitions:
getHoldTimeLimit:
setHoldTimeLimit:
showPoolContents:
showAllPoolContents:
purgePoolContents:
purgePoolContents:
purgePoolContents:
getPoolContents:
getAllPoolContents:
showAllocationHandleList:
pause:
resume:
getStatus:
getDiagnosticProviderName:
getDiagnosticProviderId:
getRegisteredDiagnostics:
configDump:
stateDump:
selfDiagnostic:
localize:
getName:
getDescription:
getJndiName:
getCategory:
=====================================
In short, no you can not get the connection URL from any of the currently provided JMX beans.
The only way that WebSphere Liberty exposes the JDBC connection URL is thorugh the java.sql.DatabaseMetaData.getURL() API. If you can get a reference to a DataSource object (via JNDI lookup or #Resource injection), you can get a connection from that, get the DatabaseMetaData and then call getURL().
DataSource ds = (DataSource) new InitialContext().lookup("jdbc/name");
String url = ds.getConnection().getMetaData().getURL();

Grails - Connection Closed message in Tomcat 7

I have a grails application that connects to an Oracle database over the firewall. I run into "Connection Closed" message.
I am not sure as to why it's happening. My production datasource is configured as follows:
production {
datasource {
dbCreate = "update"
url = ${datasource.url}
}
}
This isn't valid syntax: url = ${datasource.url}. It should be url = "${datasource.url}". Where is datasource.url coming from? If it's a string, you can just use url = datasource.url

Resources