Merge branch 'dev'
* dev: (26 commits) Add short-circuit to aliveness check if connection was used within the last second. Make slf4j-api scope ‘compile’ and slf4j-simple scope ‘compile’ + optional More testy stuff. Fixed iteration direction bug, forgot we were iterating backwards. Change javassist back from provided to compile so that maven-war-plugin can bundle it by default into the war. updated changes log Use execute() instead of executeQuery() for initSql. Fix isolation level dirty detection logic. Correct property name. Add the ability for the user to customize Connections before they are added to the pool. Implement proper connection unwrapping. No need to wrap methods that do not throw SQLException with our own try…catch checkException() logic. Remove tools.jar dependency now that instrumentation is gone. Fix other scopes. Added query timeout to test query. updated changes log Remove unnecessary casts in the generated proxies. Replace bound check with try..catch it is faster in the nominal case. Track current transaction isolation level so that we can reset it only when necessary (as it often requires a round trip to the server). Demote error log to warn. Conditionally reset the transaction isolation level based on whether the user has altered it or not. Turns out it is expensive for some databases. ...pull/30/head
commit
a92e25d436
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Brett Wooldridge
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.zaxxer.hikari;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface whose implementers can perform one-time customization of a
|
||||||
|
* Connection before it is added to the pool. Note the implemention
|
||||||
|
* of the <code>customize()</code> method must be multithread-safe as
|
||||||
|
* it may be called by multiple threads at one time.
|
||||||
|
*
|
||||||
|
* @author Brett Wooldridge
|
||||||
|
*/
|
||||||
|
public interface IConnectionCustomizer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The Connection object that is passed into this method is the "raw"
|
||||||
|
* Connection instance provided by the JDBC driver, not a wrapped
|
||||||
|
* HikariCP connection.
|
||||||
|
*
|
||||||
|
* @param connection a native JDBC driver Connection instance to customize
|
||||||
|
* @throws SQLException should be thrown if an error condition is encountered during customization
|
||||||
|
*/
|
||||||
|
void customize(Connection connection) throws SQLException;
|
||||||
|
}
|
@ -0,0 +1,132 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Brett Wooldridge
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.zaxxer.hikari.util;
|
||||||
|
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fast list without range checking.
|
||||||
|
*
|
||||||
|
* @author Brett Wooldridge
|
||||||
|
*/
|
||||||
|
public final class FastStatementList
|
||||||
|
{
|
||||||
|
private Statement[] elementData;
|
||||||
|
|
||||||
|
private int size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a FastList with a default size of 16.
|
||||||
|
*/
|
||||||
|
public FastStatementList()
|
||||||
|
{
|
||||||
|
this.elementData = new Statement[16];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a FastList with a specfied size.
|
||||||
|
*
|
||||||
|
* @param size the initial size of the FastList
|
||||||
|
*/
|
||||||
|
public FastStatementList(int size)
|
||||||
|
{
|
||||||
|
this.elementData = new Statement[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an element to the tail of the FastList.
|
||||||
|
*
|
||||||
|
* @param element the element to add
|
||||||
|
*/
|
||||||
|
public void add(Statement element)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
elementData[size++] = element;
|
||||||
|
}
|
||||||
|
catch (ArrayIndexOutOfBoundsException oob)
|
||||||
|
{
|
||||||
|
// overflow-conscious code
|
||||||
|
int oldCapacity = elementData.length;
|
||||||
|
int newCapacity = oldCapacity + (oldCapacity >> 1);
|
||||||
|
Statement[] newElementData = new Statement[newCapacity];
|
||||||
|
System.arraycopy(element, 0, newElementData, 0, oldCapacity);
|
||||||
|
newElementData[size++] = element;
|
||||||
|
elementData = newElementData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the element at the specified index.
|
||||||
|
*
|
||||||
|
* @param index the index of the element to get
|
||||||
|
* @return the element, or ArrayIndexOutOfBounds is thrown if the index is invalid
|
||||||
|
*/
|
||||||
|
public Statement get(int index)
|
||||||
|
{
|
||||||
|
return elementData[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This remove method is most efficient when the element being removed
|
||||||
|
* is the last element. Equality is identity based, not equals() based.
|
||||||
|
* Only the first matching element is removed.
|
||||||
|
*
|
||||||
|
* @param element the element to remove
|
||||||
|
*/
|
||||||
|
public void remove(Object element)
|
||||||
|
{
|
||||||
|
for (int index = size - 1; index >= 0; index--)
|
||||||
|
{
|
||||||
|
if (element == elementData[index])
|
||||||
|
{
|
||||||
|
int numMoved = size - index - 1;
|
||||||
|
if (numMoved > 0)
|
||||||
|
{
|
||||||
|
System.arraycopy(elementData, index + 1, elementData, index, numMoved);
|
||||||
|
}
|
||||||
|
elementData[--size] = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the FastList.
|
||||||
|
*/
|
||||||
|
public void clear()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
elementData[i] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current number of elements in the FastList.
|
||||||
|
*
|
||||||
|
* @return the number of current elements
|
||||||
|
*/
|
||||||
|
public int size()
|
||||||
|
{
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Brett Wooldridge
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.zaxxer.hikari;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.zaxxer.hikari.mocks.StubConnection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Brett Wooldridge
|
||||||
|
*/
|
||||||
|
public class UnwrapTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void testUnwrapConnection() throws SQLException
|
||||||
|
{
|
||||||
|
HikariConfig config = new HikariConfig();
|
||||||
|
config.setMinimumPoolSize(1);
|
||||||
|
config.setMaximumPoolSize(1);
|
||||||
|
config.setAcquireIncrement(1);
|
||||||
|
config.setConnectionTestQuery("VALUES 1");
|
||||||
|
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
|
||||||
|
|
||||||
|
HikariDataSource ds = new HikariDataSource(config);
|
||||||
|
|
||||||
|
Assert.assertSame("Idle connections not as expected", 1, ds.pool.getIdleConnections());
|
||||||
|
|
||||||
|
Connection connection = ds.getConnection();
|
||||||
|
Assert.assertNotNull(connection);
|
||||||
|
|
||||||
|
StubConnection unwrapped = connection.unwrap(StubConnection.class);
|
||||||
|
Assert.assertTrue("unwrapped connection is not instance of StubConnection: " + unwrapped, (unwrapped != null && unwrapped instanceof StubConnection));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue