Skip to content

Commit dda49bc

Browse files
committed
merge SPARK-2869 PR apache#1792
1 parent cd33a3b commit dda49bc

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

core/src/main/scala/org/apache/spark/rdd/JdbcRDD.scala

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ class JdbcRDD[T: ClassTag](
7474
}
7575

7676
def getSchema: Seq[(String, Int, Boolean)] = {
77-
if (null != schema) return schema
77+
if (null != schema) {
78+
return schema
79+
}
7880

7981
val conn = getConnection()
8082
val stmt = conn.prepareStatement(sql)
8183
val metadata = stmt.getMetaData
8284
try {
83-
if (null != stmt && ! stmt.isClosed()) stmt.close()
85+
if (null != stmt && ! stmt.isClosed()) {
86+
stmt.close()
87+
}
8488
} catch {
8589
case e: Exception => logWarning("Exception closing statement", e)
8690
}
@@ -110,8 +114,12 @@ class JdbcRDD[T: ClassTag](
110114
}
111115

112116
val parameterCount = stmt.getParameterMetaData.getParameterCount
113-
if (parameterCount > 0) stmt.setLong(1, part.lower)
114-
if (parameterCount > 1) stmt.setLong(2, part.upper)
117+
if (parameterCount > 0) {
118+
stmt.setLong(1, part.lower)
119+
}
120+
if (parameterCount > 1) {
121+
stmt.setLong(2, part.upper)
122+
}
115123

116124
val rs = stmt.executeQuery()
117125

@@ -126,17 +134,23 @@ class JdbcRDD[T: ClassTag](
126134

127135
override def close() {
128136
try {
129-
if (null != rs && ! rs.isClosed()) rs.close()
137+
if (null != rs && ! rs.isClosed()) {
138+
rs.close()
139+
}
130140
} catch {
131141
case e: Exception => logWarning("Exception closing resultset", e)
132142
}
133143
try {
134-
if (null != stmt && ! stmt.isClosed()) stmt.close()
144+
if (null != stmt && ! stmt.isClosed()) {
145+
stmt.close()
146+
}
135147
} catch {
136148
case e: Exception => logWarning("Exception closing statement", e)
137149
}
138150
try {
139-
if (null != conn && ! conn.isClosed()) conn.close()
151+
if (null != conn && ! conn.isClosed()) {
152+
conn.close()
153+
}
140154
logInfo("closed connection")
141155
} catch {
142156
case e: Exception => logWarning("Exception closing connection", e)
@@ -150,3 +164,4 @@ object JdbcRDD {
150164
Array.tabulate[Object](rs.getMetaData.getColumnCount)(i => rs.getObject(i + 1))
151165
}
152166
}
167+

0 commit comments

Comments
 (0)