{"id":76119,"date":"2020-01-20T14:22:41","date_gmt":"2020-01-20T08:52:41","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?p=76119"},"modified":"2024-04-12T14:34:07","modified_gmt":"2024-04-12T09:04:07","slug":"advanced-usage","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/","title":{"rendered":"Advanced usage"},"content":{"rendered":"<p><strong>JDBC interceptors<\/strong><\/p>\n<p>To see an example of how to use an interceptor, take a look atorg.apache.tomcat.jdbc.pool.interceptor.ConnectionState. This simple interceptor is a cache of three attributes, transaction isolation level, auto commit and read only state, in order for the system to avoid not needed roundtrips to the database.<\/p>\n<p>Further interceptors will be added to the core of the pool as the need arises. Contributions are always welcome!<\/p>\n<p>Interceptors are of course not limited to just java.sql.Connection but can be used to wrap any of the results from a method invocation as well. You could build query performance analyzer that provides JMX notifications when a query is running longer than the expected time.<\/p>\n<p>Configuring JDBC interceptors<\/p>\n<p>Configuring JDBC interceptors is done using the jdbcInterceptors property. The property contains a list of semicolon separated class names. If the classname is not fully qualified it will be prefixed with theorg.apache.tomcat.jdbc.pool.interceptor. prefix.<\/p>\n<p>Example:<\/p>\n<p>jdbcInterceptors=&#8221;org.apache.tomcat.jdbc.pool.interceptor.ConnectionState; org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer&#8221;<\/p>\n<p>is the same as<\/p>\n<p>jdbcInterceptors=&#8221;ConnectionState;StatementFinalizer&#8221;<\/p>\n<p>Interceptors can have properties as well. Properties for an interceptor are specified within parentheses after the class name. Several properties are separated by commas.<\/p>\n<p>Example:<\/p>\n<p>jdbcInterceptors=&#8221;ConnectionState;StatementFinalizer(useEquals=true)&#8221;<\/p>\n<p>Extra whitespace characters around class names, property names and values are ignored.<\/p>\n<p>org.apache.tomcat.jdbc.pool.JdbcInterceptor<\/p>\n<p>Abstract base class for all interceptors, can not be instantiated.<\/p>\n<table width=\"638\">\n<tbody>\n<tr>\n<td width=\"128\">Attribute<\/td>\n<td width=\"510\">Description<\/td>\n<\/tr>\n<tr>\n<td width=\"128\">useEquals<\/td>\n<td width=\"510\">(boolean) Set to true if you wish the\u00a0ProxyConnection\u00a0class to use\u00a0String.equals\u00a0and set to false\u00a0when you wish to use\u00a0==\u00a0when comparing method names. The default value is\u00a0true.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>org.apache.tomcat.jdbc.pool.interceptor.ConnectionState<\/p>\n<p>Caches the connection for the following attributes autoCommit, readOnly, transactionIsolation and catalog. It is a performance enhancement to avoid roundtrip to the database when getters are called or setters are called with an already set value.<\/p>\n<p>org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer<\/p>\n<p>Keeps track of all statements created using createStatement, prepareStatement or prepareCall and closes these statements when the connection is returned to the pool.<\/p>\n<p>org.apache.tomcat.jdbc.pool.interceptor.StatementCache<\/p>\n<p>Caches PreparedStatement and\/or CallableStatement instances on a connection.<\/p>\n<p>The statements are cached per connection. The count limit is counted globally for all connections that belong to the same pool. Once the count reaches max, subsequent statements are not returned to the cache and are closed immediately.<\/p>\n<p>&nbsp;<\/p>\n<table width=\"638\">\n<thead>\n<tr>\n<td width=\"128\">Attribute<\/td>\n<td width=\"510\">Description<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td width=\"128\">prepared<\/td>\n<td width=\"510\">(boolean as String) Enable caching of\u00a0PreparedStatement\u00a0instances created usingprepareStatement\u00a0calls. The default value is\u00a0true.<\/td>\n<\/tr>\n<tr>\n<td width=\"128\">callable<\/td>\n<td width=\"510\">(boolean as String) Enable caching of\u00a0CallableStatement\u00a0instances created usingprepareCall\u00a0calls. The default value is\u00a0false.<\/td>\n<\/tr>\n<tr>\n<td width=\"128\">max<\/td>\n<td width=\"510\">(int as String) Limit on the count of cached statements across the connection pool. The default value is\u00a050.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>org.apache.tomcat.jdbc.pool.interceptor.StatementDecoratorInterceptor<\/p>\n<p>&nbsp;<\/p>\n<ol start=\"48392\">\n<li>Interceptor to wrap statements and result sets in order to prevent access to the actual connection using the methods ResultSet.getStatement().getConnection() and Statement.getConnection()<\/li>\n<\/ol>\n<p>org.apache.tomcat.jdbc.pool.interceptor.QueryTimeoutInterceptor<\/p>\n<p>Automatically calls java.sql.Statement.setQueryTimeout(seconds) when a new statement is created. The pool itself doesn&#8217;t timeout the query, it is still up to the JDBC driver to enforce query timeouts.<\/p>\n<table width=\"504\">\n<tbody>\n<tr>\n<td width=\"128\">Attribute<\/td>\n<td width=\"376\">Description<\/td>\n<\/tr>\n<tr>\n<td width=\"128\">queryTimeout<\/td>\n<td width=\"376\">(int as String) The number of seconds to set for the query timeout The default value is\u00a01000milliseconds.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport<\/p>\n<p>Keeps track of query performance and issues log entries when queries exceed a time threshold of fail. The log level used is WARN<\/p>\n<table width=\"638\">\n<thead>\n<tr>\n<td width=\"128\">Attribute<\/td>\n<td width=\"510\">Description<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td width=\"128\">threshold<\/td>\n<td width=\"510\">(int as String) The number of milliseconds a query has to exceed before issuing a log alert. The default value is\u00a01000\u00a0milliseconds.<\/td>\n<\/tr>\n<tr>\n<td width=\"128\">maxQueries<\/td>\n<td width=\"510\">(int as String) The maximum number of queries to keep track of in order to preserve memory space The default value is\u00a01000.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx<\/p>\n<p>Extends the SlowQueryReport and in addition to log entries it issues JMX notification for monitoring tools to react to. Inherits all the attributes from its parent class. This class uses Tomcat&#8217;s JMX engine so it wont work outside of the Tomcat container. By default, JMX notifications are sent through the ConnectionPool mbean if it is enabled. The SlowQueryReportJmx can also register an MBean if notifyPool=false<\/p>\n<table>\n<thead>\n<tr>\n<td width=\"99\">Attribute<\/td>\n<td width=\"539\">Description<\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td width=\"99\">notifyPool<\/td>\n<td width=\"539\">(boolean as String) Set to false if you want JMX notifications to go to the\u00a0SlowQueryReportJmxMBean The default value is\u00a0true.<\/td>\n<\/tr>\n<tr>\n<td width=\"99\">objectName<\/td>\n<td width=\"539\">(String) Define a valid\u00a0javax.management.ObjectName\u00a0string that will be used to register this object with the platform mbean server The default value is\u00a0null\u00a0and the object will be registered using tomcat.jdbc:type=org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx,name=the-name-of-the-pool<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer<\/p>\n<p>The abandoned timer starts when a connection is checked out from the pool. This means if you have a 30second timeout and run 10x10second queries using the connection it will be marked abandoned and potentially reclaimed depending on the abandonWhenPercentageFull attribute. Using this interceptor it will reset the checkout timer every time you perform an operation on the connection or execute a query successfully.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JDBC interceptors To see an example of how to use an interceptor, take a look atorg.apache.tomcat.jdbc.pool.interceptor.ConnectionState. This simple interceptor is a cache of three attributes, transaction isolation level, auto commit and read only state, in order for the system to avoid not needed roundtrips to the database. Further interceptors will be added to the core&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[8678],"tags":[8913],"class_list":["post-76119","page","type-page","status-publish","hentry","category-tomcat","tag-advanced-usage"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Advanced usage - Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Advanced usage - Tutorial\" \/>\n<meta property=\"og:description\" content=\"JDBC interceptors To see an example of how to use an interceptor, take a look atorg.apache.tomcat.jdbc.pool.interceptor.ConnectionState. This simple interceptor is a cache of three attributes, transaction isolation level, auto commit and read only state, in order for the system to avoid not needed roundtrips to the database. Further interceptors will be added to the core...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T09:04:07+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/\",\"name\":\"Advanced usage - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2020-01-20T08:52:41+00:00\",\"dateModified\":\"2024-04-12T09:04:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Advanced usage\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Advanced usage - Tutorial","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/","og_locale":"en_US","og_type":"article","og_title":"Advanced usage - Tutorial","og_description":"JDBC interceptors To see an example of how to use an interceptor, take a look atorg.apache.tomcat.jdbc.pool.interceptor.ConnectionState. This simple interceptor is a cache of three attributes, transaction isolation level, auto commit and read only state, in order for the system to avoid not needed roundtrips to the database. Further interceptors will be added to the core...","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T09:04:07+00:00","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/","name":"Advanced usage - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2020-01-20T08:52:41+00:00","dateModified":"2024-04-12T09:04:07+00:00","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/advanced-usage\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Advanced usage"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/76119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=76119"}],"version-history":[{"count":3,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/76119\/revisions"}],"predecessor-version":[{"id":76582,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/76119\/revisions\/76582"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=76119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=76119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=76119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}