Skip to content

Commit b3e37fe

Browse files
committed
#61 - Tidy internals - use accessor methods instead of getters
1 parent 9043a16 commit b3e37fe

9 files changed

Lines changed: 70 additions & 67 deletions

File tree

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public String toString() {
4646
return Arrays.toString(slots);
4747
}
4848

49-
int getCapacity() {
49+
int capacity() {
5050
return slots.length;
5151
}
5252

@@ -70,10 +70,10 @@ int add(PooledConnection pc) {
7070
}
7171

7272
boolean remove(PooledConnection pc) {
73-
int slotId = pc.getSlotId();
73+
int slotId = pc.slotId();
7474
if (slots[slotId] != pc) {
7575
PooledConnection heldBy = slots[slotId];
76-
Log.warn("Failed to remove from slot[{0}] PooledConnection[{1}] - HeldBy[{2}]", pc.getSlotId(), pc, heldBy);
76+
Log.warn("Failed to remove from slot[{0}] PooledConnection[{1}] - HeldBy[{2}]", pc.slotId(), pc, heldBy);
7777
return false;
7878
}
7979
slots[slotId] = null;
@@ -92,7 +92,7 @@ void closeBusyConnections(long leakTimeMinutes) {
9292
//tmp.add(slots[i]);
9393
PooledConnection pc = slots[i];
9494
//noinspection StatementWithEmptyBody
95-
if (pc.getLastUsedTime() > olderThanTime) {
95+
if (pc.lastUsedTime() > olderThanTime) {
9696
// PooledConnection has been used recently or
9797
// expected to be longRunning so not closing...
9898
} else {
@@ -106,28 +106,28 @@ void closeBusyConnections(long leakTimeMinutes) {
106106

107107
private void closeBusyConnection(PooledConnection pc) {
108108
try {
109-
Log.warn("DataSourcePool closing busy connection? {0}", pc.getFullDescription());
110-
System.out.println("CLOSING busy connection: " + pc.getFullDescription());
109+
Log.warn("DataSourcePool closing busy connection? {0}", pc.fullDescription());
110+
System.out.println("CLOSING busy connection: " + pc.fullDescription());
111111
pc.closeConnectionFully(false);
112112
} catch (Exception ex) {
113-
Log.error("Error when closing potentially leaked connection " + pc.getDescription(), ex);
113+
Log.error("Error when closing potentially leaked connection " + pc.description(), ex);
114114
}
115115
}
116116

117117
/**
118118
* Returns information describing connections that are currently being used.
119119
*/
120-
String getBusyConnectionInformation(boolean toLogger) {
120+
String busyConnectionInformation(boolean toLogger) {
121121
if (toLogger) {
122122
Log.info("Dumping [{0}] busy connections: (Use datasource.xxx.capturestacktrace=true ... to get stackTraces)", size());
123123
}
124124
StringBuilder sb = new StringBuilder();
125125
for (PooledConnection pc : slots) {
126126
if (pc != null) {
127127
if (toLogger) {
128-
Log.info("Busy Connection - {0}", pc.getFullDescription());
128+
Log.info("Busy Connection - {0}", pc.fullDescription());
129129
} else {
130-
sb.append(pc.getFullDescription()).append("\r\n");
130+
sb.append(pc.fullDescription()).append("\r\n");
131131
}
132132
}
133133
}

ebean-datasource/src/main/java/io/ebean/datasource/pool/ConnectionDelegator.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.ebean.datasource.pool;
22

33
import java.sql.*;
4-
import java.util.Map;
54
import java.util.Properties;
65
import java.util.concurrent.Executor;
76

@@ -17,7 +16,7 @@ abstract class ConnectionDelegator implements Connection {
1716
/**
1817
* Return the underlying connection.
1918
*/
20-
Connection getDelegate() {
19+
Connection delegate() {
2120
return delegate;
2221
}
2322

@@ -47,58 +46,71 @@ public final int getNetworkTimeout() throws SQLException {
4746
return delegate.getNetworkTimeout();
4847
}
4948

49+
@Override
5050
public final Clob createClob() throws SQLException {
5151
return delegate.createClob();
5252
}
5353

54+
@Override
5455
public final Blob createBlob() throws SQLException {
5556
return delegate.createBlob();
5657
}
5758

59+
@Override
5860
public final NClob createNClob() throws SQLException {
5961
return delegate.createNClob();
6062
}
6163

64+
@Override
6265
public final SQLXML createSQLXML() throws SQLException {
6366
return delegate.createSQLXML();
6467
}
6568

69+
@Override
6670
public final boolean isValid(int timeout) throws SQLException {
6771
return delegate.isValid(timeout);
6872
}
6973

74+
@Override
7075
public final void setClientInfo(String name, String value) throws SQLClientInfoException {
7176
delegate.setClientInfo(name, value);
7277
}
7378

79+
@Override
7480
public final void setClientInfo(Properties properties) throws SQLClientInfoException {
7581
delegate.setClientInfo(properties);
7682
}
7783

84+
@Override
7885
public final String getClientInfo(String name) throws SQLException {
7986
return delegate.getClientInfo(name);
8087
}
8188

89+
@Override
8290
public final Properties getClientInfo() throws SQLException {
8391
return delegate.getClientInfo();
8492
}
8593

94+
@Override
8695
public final Array createArrayOf(String typeName, Object[] elements) throws SQLException {
8796
return delegate.createArrayOf(typeName, elements);
8897
}
8998

99+
@Override
90100
public final Struct createStruct(String typeName, Object[] attributes) throws SQLException {
91101
return delegate.createStruct(typeName, attributes);
92102
}
93103

94104
@SuppressWarnings("unchecked")
105+
@Override
95106
public final <T> T unwrap(Class<T> iface) throws SQLException {
96107
if (iface.equals(java.sql.Connection.class)) {
97108
return (T) delegate;
98109
}
99110
return delegate.unwrap(iface);
100111
}
101112

113+
@Override
102114
public final boolean isWrapperFor(Class<?> iface) throws SQLException {
103115
return delegate.isWrapperFor(iface);
104116
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ boolean validateConnection(PooledConnection conn) {
560560
try {
561561
return testConnection(conn);
562562
} catch (Exception e) {
563-
Log.warn("Heartbeat test failed on connection:{0} message: {1}", conn.getName(), e.getMessage());
563+
Log.warn("Heartbeat test failed on connection:{0} message: {1}", conn.name(), e.getMessage());
564564
return false;
565565
}
566566
}

ebean-datasource/src/main/java/io/ebean/datasource/pool/ExtendedPreparedStatement.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,10 @@ ExtendedPreparedStatement reset() {
5151
/**
5252
* Return the key used to cache this on the Connection.
5353
*/
54-
String getCacheKey() {
54+
String cacheKey() {
5555
return cacheKey;
5656
}
5757

58-
/**
59-
* Return the SQL used to create this PreparedStatement.
60-
*/
61-
public String getSql() {
62-
return sql;
63-
}
64-
6558
/**
6659
* Fully close the underlying PreparedStatement. After this we can no longer
6760
* reuse the PreparedStatement.

ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnection.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ final class PooledConnection extends ConnectionDelegator {
135135
/**
136136
* Return the slot position in the busy buffer.
137137
*/
138-
int getSlotId() {
138+
int slotId() {
139139
return slotId;
140140
}
141141

@@ -149,25 +149,25 @@ void setSlotId(int slotId) {
149149
/**
150150
* Return a string to identify the connection.
151151
*/
152-
String getName() {
152+
String name() {
153153
return name;
154154
}
155155

156156
@Override
157157
public String toString() {
158-
return getDescription();
158+
return description();
159159
}
160160

161-
private long getBusySeconds() {
161+
private long busySeconds() {
162162
return (System.currentTimeMillis() - startUseTime) / 1000;
163163
}
164164

165-
String getDescription() {
166-
return "name[" + name + "] startTime[" + getStartUseTime() + "] busySeconds[" + getBusySeconds() + "] createdBy[" + getCreatedByMethod() + "] stmt[" + getLastStatement() + "]";
165+
String description() {
166+
return "name[" + name + "] startTime[" + startUseTime() + "] busySeconds[" + busySeconds() + "] createdBy[" + createdByMethod() + "] stmt[" + lastStatement() + "]";
167167
}
168168

169-
String getFullDescription() {
170-
return "name[" + name + "] startTime[" + getStartUseTime() + "] busySeconds[" + getBusySeconds() + "] stackTrace[" + getStackTraceAsString() + "] stmt[" + getLastStatement() + "]";
169+
String fullDescription() {
170+
return "name[" + name + "] startTime[" + startUseTime() + "] busySeconds[" + busySeconds() + "] stackTrace[" + stackTraceAsString() + "] stmt[" + lastStatement() + "]";
171171
}
172172

173173
/**
@@ -212,7 +212,7 @@ void closeConnectionFully(boolean logErrors) {
212212
pool.dec();
213213
} catch (SQLException ex) {
214214
if (logErrors || Log.isLoggable(System.Logger.Level.DEBUG)) {
215-
Log.error("Error when fully closing connection [" + getFullDescription() + "]", ex);
215+
Log.error("Error when fully closing connection [" + fullDescription() + "]", ex);
216216
}
217217
}
218218
}
@@ -471,7 +471,7 @@ boolean shouldTrim(long usedSince, long createdSince) {
471471
* <p>
472472
* Used to detect busy connections that could be leaks.
473473
*/
474-
private long getStartUseTime() {
474+
private long startUseTime() {
475475
return startUseTime;
476476
}
477477

@@ -480,14 +480,14 @@ private long getStartUseTime() {
480480
* <p>
481481
* Used to close connections that have been idle for some time. Typically 5 minutes.
482482
*/
483-
long getLastUsedTime() {
483+
long lastUsedTime() {
484484
return lastUseTime;
485485
}
486486

487487
/**
488488
* Returns the last sql statement executed.
489489
*/
490-
private String getLastStatement() {
490+
private String lastStatement() {
491491
return lastStatement;
492492
}
493493

@@ -804,7 +804,7 @@ public CallableStatement prepareCall(String s, int i, int x, int y) throws SQLEx
804804
* Used to help finding connection pool leaks.
805805
* </p>
806806
*/
807-
private String getCreatedByMethod() {
807+
private String createdByMethod() {
808808
if (createdByMethod != null) {
809809
return createdByMethod;
810810
}
@@ -839,8 +839,8 @@ void setStackTrace(StackTraceElement[] stackTrace) {
839839
/**
840840
* Return the stackTrace as a String for logging purposes.
841841
*/
842-
private String getStackTraceAsString() {
843-
StackTraceElement[] stackTrace = getStackTrace();
842+
private String stackTraceAsString() {
843+
StackTraceElement[] stackTrace = stackTrace();
844844
if (stackTrace == null) {
845845
return "";
846846
}
@@ -851,7 +851,7 @@ private String getStackTraceAsString() {
851851
* Return the full stack trace that got the connection from the pool. You
852852
* could use this if getCreatedByMethod() doesn't work for you.
853853
*/
854-
private StackTraceElement[] getStackTrace() {
854+
private StackTraceElement[] stackTrace() {
855855
if (stackTrace == null) {
856856
return null;
857857
}

ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private PooledConnection _obtainConnection() throws InterruptedException, SQLExc
234234
PooledConnection c = pool.createConnectionForQueue(connectionId++);
235235
int busySize = registerBusyConnection(c);
236236
if (Log.isLoggable(Level.DEBUG)) {
237-
Log.debug("DataSourcePool [{0}] grow; id[{1}] busy[{2}] max[{3}]", name, c.getName(), busySize, maxSize);
237+
Log.debug("DataSourcePool [{0}] grow; id[{1}] busy[{2}] max[{3}]", name, c.name(), busySize, maxSize);
238238
}
239239
checkForWarningSize();
240240
return c;
@@ -402,14 +402,12 @@ void closeBusyConnections(long leakTimeMinutes) {
402402
* This is called whenever the pool grows in size (towards the max limit).
403403
*/
404404
private void checkForWarningSize() {
405-
// the the total number of connections that we can add
405+
// the total number of connections that we can add
406406
// to the pool before it hits the maximum
407407
int availableGrowth = (maxSize - totalConnections());
408-
409408
if (availableGrowth < warningSize) {
410409
closeBusyConnections(leakTimeMinutes);
411-
String msg = "DataSourcePool [" + name + "] is [" + availableGrowth + "] connections from its maximum size.";
412-
pool.notifyWarning(msg);
410+
pool.notifyWarning("DataSourcePool [" + name + "] is [" + availableGrowth + "] connections from its maximum size.");
413411
}
414412
}
415413

@@ -427,7 +425,7 @@ void dumpBusyConnectionInformation() {
427425
private String getBusyConnectionInformation(boolean toLogger) {
428426
lock.lock();
429427
try {
430-
return busyList.getBusyConnectionInformation(toLogger);
428+
return busyList.busyConnectionInformation(toLogger);
431429
} finally {
432430
lock.unlock();
433431
}

ebean-datasource/src/main/java/io/ebean/datasource/pool/PstmtCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ long putCount() {
6363
* the statement to the cache and return true.
6464
*/
6565
boolean returnStatement(ExtendedPreparedStatement stmt) {
66-
ExtendedPreparedStatement alreadyInCache = super.get(stmt.getCacheKey());
66+
ExtendedPreparedStatement alreadyInCache = super.get(stmt.cacheKey());
6767
if (alreadyInCache != null) {
6868
return false;
6969
}
7070
// add the returning prepared statement to the cache.
7171
// Note that the LRUCache will automatically close fully old unused
7272
// statements when the cache has hit its maximum size.
73-
put(stmt.getCacheKey(), stmt);
73+
put(stmt.cacheKey(), stmt);
7474
return true;
7575
}
7676

0 commit comments

Comments
 (0)