Skip to content

Commit cddf6c0

Browse files
committed
#21 - Refactor tidy internals only - BusyConnectionBuffer - method access and for loops for
1 parent cd4a664 commit cddf6c0

2 files changed

Lines changed: 20 additions & 24 deletions

File tree

src/main/java/io/ebean/datasource/pool/BusyConnectionBuffer.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,36 @@ class BusyConnectionBuffer {
3737
* @param capacity the initial capacity
3838
* @param growBy the fixed amount to grow the buffer by.
3939
*/
40-
protected BusyConnectionBuffer(int capacity, int growBy) {
40+
BusyConnectionBuffer(int capacity, int growBy) {
4141
this.slots = new PooledConnection[capacity];
4242
this.growBy = growBy;
4343
}
4444

4545
/**
4646
* We can only grow (not shrink) the capacity.
4747
*/
48-
protected void setCapacity(int newCapacity) {
48+
void setCapacity(int newCapacity) {
4949
if (newCapacity > slots.length) {
5050
PooledConnection[] current = this.slots;
5151
this.slots = new PooledConnection[newCapacity];
5252
System.arraycopy(current, 0, this.slots, 0, current.length);
5353
}
5454
}
5555

56+
@Override
5657
public String toString() {
5758
return Arrays.toString(slots);
5859
}
5960

60-
protected int getCapacity() {
61+
int getCapacity() {
6162
return slots.length;
6263
}
6364

64-
protected int size() {
65+
int size() {
6566
return size;
6667
}
6768

68-
protected boolean isEmpty() {
69+
boolean isEmpty() {
6970
return size == 0;
7071
}
7172

@@ -80,7 +81,7 @@ protected int add(PooledConnection pc) {
8081
return ++size;
8182
}
8283

83-
protected boolean remove(PooledConnection pc) {
84+
boolean remove(PooledConnection pc) {
8485

8586
int slotId = pc.getSlotId();
8687
if (slots[slotId] != pc) {
@@ -98,9 +99,9 @@ protected boolean remove(PooledConnection pc) {
9899
*/
99100
void collectStatistics(PooledConnectionStatistics.LoadValues values, boolean reset) {
100101

101-
for (int i = 0; i < slots.length; i++) {
102-
if (slots[i] != null) {
103-
values.plus(slots[i].getStatistics().getValues(reset));
102+
for (PooledConnection slot : slots) {
103+
if (slot != null) {
104+
values.plus(slot.getStatistics().getValues(reset));
104105
}
105106
}
106107
}
@@ -156,9 +157,8 @@ String getBusyConnectionInformation(boolean toLogger) {
156157

157158
StringBuilder sb = new StringBuilder();
158159

159-
for (int i = 0; i < slots.length; i++) {
160-
if (slots[i] != null) {
161-
PooledConnection pc = slots[i];
160+
for (PooledConnection pc : slots) {
161+
if (pc != null) {
162162
if (toLogger) {
163163
logger.info("Busy Connection - {}", pc.getFullDescription());
164164
} else {

src/main/java/io/ebean/datasource/pool/ConnectionPool.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ private void initialiseDatabase() throws SQLException {
345345
* Returns false.
346346
*/
347347
@Override
348-
public boolean isWrapperFor(Class<?> arg0) throws SQLException {
348+
public boolean isWrapperFor(Class<?> arg0) {
349349
return false;
350350
}
351351

@@ -392,7 +392,6 @@ public SQLException getDataSourceDownReason() {
392392
* Called when the pool hits the warning level.
393393
*/
394394
protected void notifyWarning(String msg) {
395-
396395
if (inWarningMode.compareAndSet(false, true)) {
397396
// send an Error to the event log...
398397
logger.warn(msg);
@@ -505,7 +504,7 @@ private void initConnection(Connection conn) throws SQLException {
505504
conn.setTransactionIsolation(transactionIsolation);
506505
}
507506
if (readOnly) {
508-
conn.setReadOnly(readOnly);
507+
conn.setReadOnly(true);
509508
}
510509
if (initSql != null) {
511510
for (String query : initSql) {
@@ -791,16 +790,13 @@ PooledConnection createConnectionForQueue(int connId) throws SQLException {
791790

792791
/**
793792
* Close all the connections in the pool.
794-
* <p>
795793
* <ul>
796-
* <li>Checks that the database is up.
797-
* <li>Resets the Alert level.
798-
* <li>Closes busy connections that have not been used for some time (aka
799-
* leaks).
800-
* <li>This closes all the currently available connections.
801-
* <li>Busy connections are closed when they are returned to the pool.
794+
* <li>Checks that the database is up.</li>
795+
* <li>Resets the Alert level.</li>
796+
* <li>Closes busy connections that have not been used for some time (aka leaks).</li>
797+
* <li>This closes all the currently available connections.</li>
798+
* <li>Busy connections are closed when they are returned to the pool.</li>
802799
* </ul>
803-
* </p>
804800
*/
805801
public void reset() {
806802
queue.reset(leakTimeMinutes);
@@ -1042,7 +1038,7 @@ public static class Status implements PoolStatus {
10421038
private final int waitCount;
10431039
private final int hitCount;
10441040

1045-
protected Status(int minSize, int maxSize, int free, int busy, int waiting, int highWaterMark, int waitCount, int hitCount) {
1041+
Status(int minSize, int maxSize, int free, int busy, int waiting, int highWaterMark, int waitCount, int hitCount) {
10461042
this.minSize = minSize;
10471043
this.maxSize = maxSize;
10481044
this.free = free;

0 commit comments

Comments
 (0)