Skip to content

Instantly share code, notes, and snippets.

@kapion
Created December 24, 2018 09:38
Show Gist options
  • Select an option

  • Save kapion/9f45f315dc3553815c7d06356e56f580 to your computer and use it in GitHub Desktop.

Select an option

Save kapion/9f45f315dc3553815c7d06356e56f580 to your computer and use it in GitHub Desktop.
getDbNetInfoFromOracleDriver
class OracleDialect(private val dbInfo: DbDialect.DbInfo, val jdbcTemplate: JdbcTemplate) : DbDialect {
private val log = LoggerFactory.getLogger(this.javaClass)
private val connection = jdbcTemplate.dataSource.connection
...
private fun getDbNetInfoFromOracleDriver() {
try {
//HikariProxyConnection@1025792385 wrapping oracle.jdbc.driver.T4CConnection
val delegate = FieldUtils.readField(connection, "delegate", true)
//спускаемся в черную дыру ораклового драйвера
val net = FieldUtils.readField(delegate, "net", true)
val sAtts = FieldUtils.readField(net, "sAtts", true)
val cOption = FieldUtils.readField(sAtts, "cOption", true)
dbInfo.db = FieldUtils.readField(cOption, "origSid", true).toString()
val nt = FieldUtils.readField(cOption, "nt", true)
val socket = FieldUtils.readField(nt, "socket", true)
val impl = FieldUtils.readField(socket, "impl", true)
val addressMethod = ReflectionUtils.findMethod(impl.javaClass, "getInetAddress")
addressMethod?.let {
ReflectionUtils.makeAccessible(it)
dbInfo.host = it.invoke(impl).toString()
}
val portMethod = ReflectionUtils.findMethod(impl.javaClass, "getPort")
portMethod?.let {
ReflectionUtils.makeAccessible(it)
dbInfo.port = it.invoke(impl).toString()
}
dbInfo.schema = getCurrentScheme()
} catch (e: Exception) {
log.error("Error get the Oracle driver data for dbInfo")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment