Skip to content

Commit 0b85966

Browse files
committed
kotlin: change :one to rely on null assertions
1 parent 8020662 commit 0b85966

File tree

20 files changed

+66
-66
lines changed

20 files changed

+66
-66
lines changed

examples/kotlin/src/main/kotlin/com/example/authors/mysql/Queries.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Queries {
1414
fun deleteAuthor(id: Long)
1515

1616
@Throws(SQLException::class)
17-
fun getAuthor(id: Long): Author
17+
fun getAuthor(id: Long): Author?
1818

1919
@Throws(SQLException::class)
2020
fun listAuthors(): List<Author>

examples/kotlin/src/main/kotlin/com/example/authors/mysql/QueriesImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ class QueriesImpl(private val conn: Connection) : Queries {
5757
}
5858

5959
@Throws(SQLException::class)
60-
override fun getAuthor(id: Long): Author {
60+
override fun getAuthor(id: Long): Author? {
6161
return conn.prepareStatement(getAuthor).use { stmt ->
6262
stmt.setLong(1, id)
6363

6464
val results = stmt.executeQuery()
6565
if (!results.next()) {
66-
throw SQLException("no rows in result set")
66+
return null
6767
}
6868
val ret = Author(
6969
results.getLong(1),

examples/kotlin/src/main/kotlin/com/example/authors/postgresql/Queries.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import java.sql.Statement
88

99
interface Queries {
1010
@Throws(SQLException::class)
11-
fun createAuthor(name: String, bio: String?): Author
11+
fun createAuthor(name: String, bio: String?): Author?
1212

1313
@Throws(SQLException::class)
1414
fun deleteAuthor(id: Long)
1515

1616
@Throws(SQLException::class)
17-
fun getAuthor(id: Long): Author
17+
fun getAuthor(id: Long): Author?
1818

1919
@Throws(SQLException::class)
2020
fun listAuthors(): List<Author>

examples/kotlin/src/main/kotlin/com/example/authors/postgresql/QueriesImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ ORDER BY name
3333
class QueriesImpl(private val conn: Connection) : Queries {
3434

3535
@Throws(SQLException::class)
36-
override fun createAuthor(name: String, bio: String?): Author {
36+
override fun createAuthor(name: String, bio: String?): Author? {
3737
return conn.prepareStatement(createAuthor).use { stmt ->
3838
stmt.setString(1, name)
3939
stmt.setString(2, bio)
4040

4141
val results = stmt.executeQuery()
4242
if (!results.next()) {
43-
throw SQLException("no rows in result set")
43+
return null
4444
}
4545
val ret = Author(
4646
results.getLong(1),
@@ -64,13 +64,13 @@ class QueriesImpl(private val conn: Connection) : Queries {
6464
}
6565

6666
@Throws(SQLException::class)
67-
override fun getAuthor(id: Long): Author {
67+
override fun getAuthor(id: Long): Author? {
6868
return conn.prepareStatement(getAuthor).use { stmt ->
6969
stmt.setLong(1, id)
7070

7171
val results = stmt.executeQuery()
7272
if (!results.next()) {
73-
throw SQLException("no rows in result set")
73+
return null
7474
}
7575
val ret = Author(
7676
results.getLong(1),

examples/kotlin/src/main/kotlin/com/example/booktest/mysql/Queries.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ interface Queries {
3434
fun deleteBook(bookId: Int)
3535

3636
@Throws(SQLException::class)
37-
fun getAuthor(authorId: Int): Author
37+
fun getAuthor(authorId: Int): Author?
3838

3939
@Throws(SQLException::class)
40-
fun getBook(bookId: Int): Book
40+
fun getBook(bookId: Int): Book?
4141

4242
@Throws(SQLException::class)
4343
fun updateBook(

examples/kotlin/src/main/kotlin/com/example/booktest/mysql/QueriesImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ class QueriesImpl(private val conn: Connection) : Queries {
197197
}
198198

199199
@Throws(SQLException::class)
200-
override fun getAuthor(authorId: Int): Author {
200+
override fun getAuthor(authorId: Int): Author? {
201201
return conn.prepareStatement(getAuthor).use { stmt ->
202202
stmt.setInt(1, authorId)
203203

204204
val results = stmt.executeQuery()
205205
if (!results.next()) {
206-
throw SQLException("no rows in result set")
206+
return null
207207
}
208208
val ret = Author(
209209
results.getInt(1),
@@ -217,13 +217,13 @@ class QueriesImpl(private val conn: Connection) : Queries {
217217
}
218218

219219
@Throws(SQLException::class)
220-
override fun getBook(bookId: Int): Book {
220+
override fun getBook(bookId: Int): Book? {
221221
return conn.prepareStatement(getBook).use { stmt ->
222222
stmt.setInt(1, bookId)
223223

224224
val results = stmt.executeQuery()
225225
if (!results.next()) {
226-
throw SQLException("no rows in result set")
226+
return null
227227
}
228228
val ret = Book(
229229
results.getInt(1),

examples/kotlin/src/main/kotlin/com/example/booktest/postgresql/Queries.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface Queries {
1616
fun booksByTitleYear(title: String, year: Int): List<Book>
1717

1818
@Throws(SQLException::class)
19-
fun createAuthor(name: String): Author
19+
fun createAuthor(name: String): Author?
2020

2121
@Throws(SQLException::class)
2222
fun createBook(
@@ -26,16 +26,16 @@ interface Queries {
2626
title: String,
2727
year: Int,
2828
available: OffsetDateTime,
29-
tags: List<String>): Book
29+
tags: List<String>): Book?
3030

3131
@Throws(SQLException::class)
3232
fun deleteBook(bookId: Int)
3333

3434
@Throws(SQLException::class)
35-
fun getAuthor(authorId: Int): Author
35+
fun getAuthor(authorId: Int): Author?
3636

3737
@Throws(SQLException::class)
38-
fun getBook(bookId: Int): Book
38+
fun getBook(bookId: Int): Book?
3939

4040
@Throws(SQLException::class)
4141
fun updateBook(

examples/kotlin/src/main/kotlin/com/example/booktest/postgresql/QueriesImpl.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ class QueriesImpl(private val conn: Connection) : Queries {
133133
}
134134

135135
@Throws(SQLException::class)
136-
override fun createAuthor(name: String): Author {
136+
override fun createAuthor(name: String): Author? {
137137
return conn.prepareStatement(createAuthor).use { stmt ->
138138
stmt.setString(1, name)
139139

140140
val results = stmt.executeQuery()
141141
if (!results.next()) {
142-
throw SQLException("no rows in result set")
142+
return null
143143
}
144144
val ret = Author(
145145
results.getInt(1),
@@ -160,7 +160,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
160160
title: String,
161161
year: Int,
162162
available: OffsetDateTime,
163-
tags: List<String>): Book {
163+
tags: List<String>): Book? {
164164
return conn.prepareStatement(createBook).use { stmt ->
165165
stmt.setInt(1, authorId)
166166
stmt.setString(2, isbn)
@@ -172,7 +172,7 @@ class QueriesImpl(private val conn: Connection) : Queries {
172172

173173
val results = stmt.executeQuery()
174174
if (!results.next()) {
175-
throw SQLException("no rows in result set")
175+
return null
176176
}
177177
val ret = Book(
178178
results.getInt(1),
@@ -201,13 +201,13 @@ class QueriesImpl(private val conn: Connection) : Queries {
201201
}
202202

203203
@Throws(SQLException::class)
204-
override fun getAuthor(authorId: Int): Author {
204+
override fun getAuthor(authorId: Int): Author? {
205205
return conn.prepareStatement(getAuthor).use { stmt ->
206206
stmt.setInt(1, authorId)
207207

208208
val results = stmt.executeQuery()
209209
if (!results.next()) {
210-
throw SQLException("no rows in result set")
210+
return null
211211
}
212212
val ret = Author(
213213
results.getInt(1),
@@ -221,13 +221,13 @@ class QueriesImpl(private val conn: Connection) : Queries {
221221
}
222222

223223
@Throws(SQLException::class)
224-
override fun getBook(bookId: Int): Book {
224+
override fun getBook(bookId: Int): Book? {
225225
return conn.prepareStatement(getBook).use { stmt ->
226226
stmt.setInt(1, bookId)
227227

228228
val results = stmt.executeQuery()
229229
if (!results.next()) {
230-
throw SQLException("no rows in result set")
230+
return null
231231
}
232232
val ret = Book(
233233
results.getInt(1),

examples/kotlin/src/main/kotlin/com/example/jets/Queries.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import java.sql.Statement
88

99
interface Queries {
1010
@Throws(SQLException::class)
11-
fun countPilots(): Long
11+
fun countPilots(): Long?
1212

1313
@Throws(SQLException::class)
1414
fun deletePilot(id: Int)

examples/kotlin/src/main/kotlin/com/example/jets/QueriesImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ SELECT id, name FROM pilots LIMIT 5
2121
class QueriesImpl(private val conn: Connection) : Queries {
2222

2323
@Throws(SQLException::class)
24-
override fun countPilots(): Long {
24+
override fun countPilots(): Long? {
2525
return conn.prepareStatement(countPilots).use { stmt ->
2626

2727
val results = stmt.executeQuery()
2828
if (!results.next()) {
29-
throw SQLException("no rows in result set")
29+
return null
3030
}
3131
val ret = results.getLong(1)
3232
if (results.next()) {

examples/kotlin/src/main/kotlin/com/example/ondeck/mysql/Queries.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ interface Queries {
2626
fun deleteVenue(slug: String, slug_2: String)
2727

2828
@Throws(SQLException::class)
29-
fun getCity(slug: String): City
29+
fun getCity(slug: String): City?
3030

3131
@Throws(SQLException::class)
32-
fun getVenue(slug: String, city: String): Venue
32+
fun getVenue(slug: String, city: String): Venue?
3333

3434
@Throws(SQLException::class)
3535
fun listCities(): List<City>

examples/kotlin/src/main/kotlin/com/example/ondeck/mysql/QueriesImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ class QueriesImpl(private val conn: Connection) : Queries {
147147
}
148148

149149
@Throws(SQLException::class)
150-
override fun getCity(slug: String): City {
150+
override fun getCity(slug: String): City? {
151151
return conn.prepareStatement(getCity).use { stmt ->
152152
stmt.setString(1, slug)
153153

154154
val results = stmt.executeQuery()
155155
if (!results.next()) {
156-
throw SQLException("no rows in result set")
156+
return null
157157
}
158158
val ret = City(
159159
results.getString(1),
@@ -167,14 +167,14 @@ class QueriesImpl(private val conn: Connection) : Queries {
167167
}
168168

169169
@Throws(SQLException::class)
170-
override fun getVenue(slug: String, city: String): Venue {
170+
override fun getVenue(slug: String, city: String): Venue? {
171171
return conn.prepareStatement(getVenue).use { stmt ->
172172
stmt.setString(1, slug)
173173
stmt.setString(2, city)
174174

175175
val results = stmt.executeQuery()
176176
if (!results.next()) {
177-
throw SQLException("no rows in result set")
177+
return null
178178
}
179179
val ret = Venue(
180180
results.getLong(1),

examples/kotlin/src/main/kotlin/com/example/ondeck/postgresql/Queries.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import java.time.LocalDateTime
1010

1111
interface Queries {
1212
@Throws(SQLException::class)
13-
fun createCity(name: String, slug: String): City
13+
fun createCity(name: String, slug: String): City?
1414

1515
@Throws(SQLException::class)
1616
fun createVenue(
@@ -20,16 +20,16 @@ interface Queries {
2020
spotifyPlaylist: String,
2121
status: Status,
2222
statuses: List<Status>,
23-
tags: List<String>): Int
23+
tags: List<String>): Int?
2424

2525
@Throws(SQLException::class)
2626
fun deleteVenue(slug: String)
2727

2828
@Throws(SQLException::class)
29-
fun getCity(slug: String): City
29+
fun getCity(slug: String): City?
3030

3131
@Throws(SQLException::class)
32-
fun getVenue(slug: String, city: String): Venue
32+
fun getVenue(slug: String, city: String): Venue?
3333

3434
@Throws(SQLException::class)
3535
fun listCities(): List<City>
@@ -41,7 +41,7 @@ interface Queries {
4141
fun updateCityName(name: String, slug: String)
4242

4343
@Throws(SQLException::class)
44-
fun updateVenueName(name: String, slug: String): Int
44+
fun updateVenueName(name: String, slug: String): Int?
4545

4646
@Throws(SQLException::class)
4747
fun venueCountByCity(): List<VenueCountByCityRow>

0 commit comments

Comments
 (0)