Skip to content

Commit

Permalink
feat: allow using UUID in PreparedStatement (#365)
Browse files Browse the repository at this point in the history
Enables the usage of UUIDs as a parameter in PreparedStatements. UUIDs are
automatically translated to strings.

Fixes #364
  • Loading branch information
olavloite committed Mar 1, 2021
1 parent d8dfa32 commit 4cbee6d
Show file tree
Hide file tree
Showing 4 changed files with 424 additions and 496 deletions.
Expand Up @@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

/** This class handles the parameters of a {@link PreparedStatement}. */
class JdbcParameterStore {
Expand Down Expand Up @@ -507,6 +508,8 @@ private Builder setParamWithKnownType(ValueBinder<Builder> binder, Object value,
}
} else if (value instanceof URL) {
return binder.to(((URL) value).toString());
} else if (value instanceof UUID) {
return binder.to(((UUID) value).toString());
}
throw JdbcSqlExceptionFactory.of(value + " is not a valid string", Code.INVALID_ARGUMENT);
case Types.DATE:
Expand Down Expand Up @@ -649,6 +652,8 @@ private Builder setParamWithUnknownType(ValueBinder<Builder> binder, Object valu
return binder.to(String.valueOf((char[]) value));
} else if (URL.class.isAssignableFrom(value.getClass())) {
return binder.to(((URL) value).toString());
} else if (UUID.class.isAssignableFrom(value.getClass())) {
return binder.to(((UUID) value).toString());
} else if (byte[].class.isAssignableFrom(value.getClass())) {
return binder.to(ByteArray.copyFrom((byte[]) value));
} else if (InputStream.class.isAssignableFrom(value.getClass())) {
Expand Down

0 comments on commit 4cbee6d

Please sign in to comment.