Skip to content

Commit

Permalink
Singleton BooleanMySqlParameter (#212)
Browse files Browse the repository at this point in the history
Motivation:
Enhance resource management and consistency by adopting a singleton
pattern in `BooleanMySqlParameter`.

Modification:
Restructured BooleanMySqlParameter to allow only one instance, ensuring
efficient usage.

Result:
Optimized performance and uniformity in handling MySQL boolean
parameters with a singleton BooleanMySqlParameter.
  • Loading branch information
jchrys authored Jan 22, 2024
1 parent 073af3a commit 38dd8b4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/io/asyncer/r2dbc/mysql/codec/BooleanCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean canEncode(Object value) {

@Override
public MySqlParameter encode(Object value, CodecContext context) {
return new BooleanMySqlParameter((Boolean) value);
return (Boolean) value? BooleanMySqlParameter.TRUE : BooleanMySqlParameter.FALSE;
}

@Override
Expand All @@ -59,6 +59,10 @@ public boolean canPrimitiveDecode(MySqlColumnMetadata metadata) {

private static final class BooleanMySqlParameter extends AbstractMySqlParameter {

private static final BooleanMySqlParameter TRUE = new BooleanMySqlParameter(true);

private static final BooleanMySqlParameter FALSE = new BooleanMySqlParameter(false);

private final boolean value;

private BooleanMySqlParameter(boolean value) {
Expand Down

0 comments on commit 38dd8b4

Please sign in to comment.