@@ -33,7 +33,7 @@ trait AsyncDBSession extends LogSupport {
33
33
withListeners(statement, _parameters) {
34
34
queryLogging(statement, _parameters)
35
35
connection.sendPreparedStatement(statement, _parameters : _* ).map { result =>
36
- result.rowsAffected.map (_ > 0 ).getOrElse( false )
36
+ result.rowsAffected.exists (_ > 0 )
37
37
}
38
38
}
39
39
}
@@ -44,8 +44,8 @@ trait AsyncDBSession extends LogSupport {
44
44
queryLogging(statement, _parameters)
45
45
if (connection.isShared) {
46
46
// create local transaction because postgresql-async 0.2.4 seems not to be stable with PostgreSQL without transaction
47
- connection.toNonSharedConnection().map(c => TxAsyncDBSession (c)). flatMap { tx : TxAsyncDBSession =>
48
- tx .update(statement, _parameters : _* )
47
+ connection.toNonSharedConnection().flatMap { conn =>
48
+ AsyncTx .inTransaction( TxAsyncDBSession (conn), ( tx : TxAsyncDBSession ) => tx .update(statement, _parameters : _* ) )
49
49
}
50
50
} else {
51
51
connection.sendPreparedStatement(statement, _parameters : _* ).map { result =>
@@ -60,11 +60,12 @@ trait AsyncDBSession extends LogSupport {
60
60
withListeners(statement, _parameters) {
61
61
queryLogging(statement, _parameters)
62
62
connection.toNonSharedConnection().flatMap { conn =>
63
- conn.sendPreparedStatement(statement, _parameters : _* ).map { result =>
64
- result.generatedKey.getOrElse {
65
- throw new IllegalArgumentException (ErrorMessage .FAILED_TO_RETRIEVE_GENERATED_KEY + " SQL: '" + statement + " '" )
66
- }
67
- }
63
+ AsyncTx .inTransaction(TxAsyncDBSession (conn), (tx : TxAsyncDBSession ) =>
64
+ tx.connection.sendPreparedStatement(statement, _parameters : _* ).flatMap { result =>
65
+ result.generatedKey.map(_.getOrElse {
66
+ throw new IllegalArgumentException (ErrorMessage .FAILED_TO_RETRIEVE_GENERATED_KEY + " SQL: '" + statement + " '" )
67
+ })
68
+ })
68
69
}
69
70
}
70
71
}
@@ -88,7 +89,7 @@ trait AsyncDBSession extends LogSupport {
88
89
results match {
89
90
case Nil => None
90
91
case one :: Nil => Option (one)
91
- case _ => throw new TooManyRowsException (1 , results.size)
92
+ case _ => throw TooManyRowsException (1 , results.size)
92
93
}
93
94
}
94
95
}
@@ -106,10 +107,9 @@ trait AsyncDBSession extends LogSupport {
106
107
107
108
def processResultSet (oneToOne : (LinkedHashMap [A , Option [B ]]), rs : WrappedResultSet ): LinkedHashMap [A , Option [B ]] = {
108
109
val o = extractOne(rs)
109
- oneToOne.keys.find(_ == o).map {
110
- case Some (found) => throw new IllegalRelationshipException (ErrorMessage .INVALID_ONE_TO_ONE_RELATION )
111
- }.getOrElse {
112
- oneToOne += (o -> extractTo(rs))
110
+ oneToOne.keys.find(_ == o) match {
111
+ case Some (_) => throw IllegalRelationshipException (ErrorMessage .INVALID_ONE_TO_ONE_RELATION )
112
+ case _ => oneToOne += (o -> extractTo(rs))
113
113
}
114
114
}
115
115
connection.sendPreparedStatement(statement, _parameters : _* ).map { result =>
@@ -338,7 +338,7 @@ trait AsyncDBSession extends LogSupport {
338
338
protected def ensureAndNormalizeParameters (parameters : Seq [Any ]): Seq [Any ] = {
339
339
parameters.map {
340
340
case withValue : ParameterBinderWithValue [_] => withValue.value
341
- case binder : ParameterBinder => throw new IllegalArgumentException (" ParameterBinder is unsupported" )
341
+ case _ : ParameterBinder => throw new IllegalArgumentException (" ParameterBinder is unsupported" )
342
342
case rawValue => rawValue
343
343
}
344
344
}
0 commit comments