From 889d42bc03d00185a9d1c44ea66c9fe33f66622d Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 28 May 2014 16:56:59 +0200 Subject: [PATCH] [#3286] [#3289] Overloading all MySQL specific DSL functions to accept BLOB arguments --- .../test/java/org/jooq/test/MySQLTest.java | 13 +-- .../java/org/jooq/util/mysql/MySQLDSL.java | 86 +++++++++---------- 2 files changed, 49 insertions(+), 50 deletions(-) diff --git a/jOOQ-test/src/test/java/org/jooq/test/MySQLTest.java b/jOOQ-test/src/test/java/org/jooq/test/MySQLTest.java index 67cc5969cc..db140a9ed4 100644 --- a/jOOQ-test/src/test/java/org/jooq/test/MySQLTest.java +++ b/jOOQ-test/src/test/java/org/jooq/test/MySQLTest.java @@ -63,6 +63,7 @@ import static org.jooq.util.mysql.MySQLDSL.sha1; import static org.jooq.util.mysql.MySQLDSL.sha2; import static org.jooq.util.mysql.MySQLDSL.uncompress; import static org.jooq.util.mysql.MySQLDSL.uncompressedLength; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -843,12 +844,12 @@ public class MySQLTest extends jOOQAbstractTest< assertNotNull(create().select(password(MESSAGE)).fetchOne(0)); assertNotNull(create().select(sha1(MESSAGE)).fetchOne(0)); assertNotNull(create().select(sha2(MESSAGE, 256)).fetchOne(0)); - assertEquals(MESSAGE, create().select(decode(encode(MESSAGE, SECRET), val(SECRET))).fetchOne(0)); - assertEquals(MESSAGE, create().select(aesDecrypt(aesEncrypt(MESSAGE, SECRET), val(SECRET))).fetchOne(0)); - assertEquals(MESSAGE, create().select(desDecrypt(desEncrypt(MESSAGE, SECRET), val(SECRET))).fetchOne(0)); - assertEquals(MESSAGE, create().select(desDecrypt(desEncrypt(MESSAGE))).fetchOne(0)); - assertEquals(MESSAGE, create().select(uncompress(compress(MESSAGE))).fetchOne(0)); - assertEquals(3, create().select(uncompressedLength(compress(MESSAGE))).fetchOne(0)); + assertArrayEquals(MESSAGE, create().select(decode(encode(MESSAGE, SECRET), val(SECRET))).fetchOne().value1()); + assertArrayEquals(MESSAGE, create().select(aesDecrypt(aesEncrypt(MESSAGE, SECRET), val(SECRET))).fetchOne().value1()); + assertArrayEquals(MESSAGE, create().select(desDecrypt(desEncrypt(MESSAGE, SECRET), val(SECRET))).fetchOne().value1()); + assertArrayEquals(MESSAGE, create().select(desDecrypt(desEncrypt(MESSAGE))).fetchOne().value1()); + assertArrayEquals(MESSAGE, create().select(uncompress(compress(MESSAGE))).fetchOne().value1()); + assertEquals(5, create().select(uncompressedLength(compress(MESSAGE))).fetchOne(0)); } @Test diff --git a/jOOQ/src/main/java/org/jooq/util/mysql/MySQLDSL.java b/jOOQ/src/main/java/org/jooq/util/mysql/MySQLDSL.java index fdd56e281e..e3e84c425e 100644 --- a/jOOQ/src/main/java/org/jooq/util/mysql/MySQLDSL.java +++ b/jOOQ/src/main/java/org/jooq/util/mysql/MySQLDSL.java @@ -44,7 +44,6 @@ import org.jooq.EnumType; import org.jooq.Field; import org.jooq.SQLDialect; import org.jooq.impl.DSL; -import static org.jooq.impl.DSL.val; /** * The {@link SQLDialect#MYSQL} specific DSL. @@ -64,7 +63,7 @@ public class MySQLDSL extends DSL { // ------------------------------------------------------------------------- /** - * Get the MySQL-specific DECODE() function + * Get the MySQL-specific DECODE() function. *

* Don't mix this up with the various {@link DSL#decode()} methods! */ @@ -73,7 +72,7 @@ public class MySQLDSL extends DSL { } /** - * Get the MySQL-specific DECODE() function + * Get the MySQL-specific DECODE() function. *

* Don't mix this up with the various {@link DSL#decode()} methods! */ @@ -82,7 +81,7 @@ public class MySQLDSL extends DSL { } /** - * Get the MySQL-specific DECODE() function + * Get the MySQL-specific DECODE() function. *

* Don't mix this up with the various {@link DSL#decode()} methods! */ @@ -91,274 +90,273 @@ public class MySQLDSL extends DSL { } /** - * Get the MySQL-specific ENCODE() function + * Get the MySQL-specific ENCODE() function. */ public static Field encode(String string, String keyString) { return encode(val(string), val(keyString)); } /** - * Get the MySQL-specific ENCODE() function + * Get the MySQL-specific ENCODE() function. */ public static Field encode(byte[] string, byte[] keyString) { return encode(val(string), val(keyString)); } /** - * Get the MySQL-specific ENCODE() function + * Get the MySQL-specific ENCODE() function. */ public static Field encode(Field string, Field keyString) { return function("encode", string.getType(), string, keyString); } /** - * Get the MySQL-specific AES_DECRYPT() function + * Get the MySQL-specific AES_DECRYPT() function. */ public static Field aesDecrypt(String cryptString, String keyString) { return aesDecrypt(val(cryptString), val(keyString)); } /** - * Get the MySQL-specific AES_DECRYPT() function + * Get the MySQL-specific AES_DECRYPT() function. */ public static Field aesDecrypt(byte[] cryptString, byte[] keyString) { return aesDecrypt(val(cryptString), val(keyString)); } /** - * Get the MySQL-specific AES_DECRYPT() function + * Get the MySQL-specific AES_DECRYPT() function. */ public static Field aesDecrypt(Field cryptString, Field keyString) { return function("aes_decrypt", cryptString.getType(), cryptString, keyString); } /** - * Get the MySQL-specific AES_ENCRYPT() function + * Get the MySQL-specific AES_ENCRYPT() function. */ public static Field aesEncrypt(String string, String keyString) { return aesEncrypt(val(string), val(keyString)); } /** - * Get the MySQL-specific AES_ENCRYPT() function + * Get the MySQL-specific AES_ENCRYPT() function. */ public static Field aesEncrypt(byte[] string, byte[] keyString) { return aesEncrypt(val(string), val(keyString)); } /** - * Get the MySQL-specific AES_ENCRYPT() function + * Get the MySQL-specific AES_ENCRYPT() function. */ public static Field aesEncrypt(Field string, Field keyString) { return function("aes_encrypt", string.getType(), string, keyString); } /** - * Get the MySQL-specific DES_DECRYPT() function + * Get the MySQL-specific DES_DECRYPT() function. */ public static Field desDecrypt(String cryptString) { return desDecrypt(val(cryptString)); } /** - * Get the MySQL-specific DES_DECRYPT() function + * Get the MySQL-specific DES_DECRYPT() function. */ public static Field desDecrypt(byte[] cryptString) { return desDecrypt(val(cryptString)); } /** - * Get the MySQL-specific DES_DECRYPT() function + * Get the MySQL-specific DES_DECRYPT() function. */ public static Field desDecrypt(Field cryptString) { return function("des_decrypt", cryptString.getType(), cryptString); } /** - * Get the MySQL-specific DES_DECRYPT() function + * Get the MySQL-specific DES_DECRYPT() function. */ public static Field desDecrypt(String cryptString, String keyString) { return desDecrypt(val(cryptString), val(keyString)); } /** - * Get the MySQL-specific DES_DECRYPT() function + * Get the MySQL-specific DES_DECRYPT() function. */ public static Field desDecrypt(byte[] cryptString, byte[] keyString) { return desDecrypt(val(cryptString), val(keyString)); } /** - * Get the MySQL-specific DES_DECRYPT() function + * Get the MySQL-specific DES_DECRYPT() function. */ public static Field desDecrypt(Field cryptString, Field keyString) { return function("des_decrypt", cryptString.getType(), cryptString, keyString); } /** - * Get the MySQL-specific DES_ENCRYPT() function + * Get the MySQL-specific DES_ENCRYPT() function. */ public static Field desEncrypt(String string) { return desEncrypt(val(string)); } /** - * Get the MySQL-specific DES_ENCRYPT() function + * Get the MySQL-specific DES_ENCRYPT() function. */ public static Field desEncrypt(byte[] string) { return desEncrypt(val(string)); } /** - * Get the MySQL-specific DES_ENCRYPT() function + * Get the MySQL-specific DES_ENCRYPT() function. */ public static Field desEncrypt(Field string) { return function("des_encrypt", string.getType(), string); } /** - * Get the MySQL-specific DES_ENCRYPT() function + * Get the MySQL-specific DES_ENCRYPT() function. */ public static Field desEncrypt(String string, String keyString) { return desEncrypt(val(string), val(keyString)); } /** - * Get the MySQL-specific DES_ENCRYPT() function + * Get the MySQL-specific DES_ENCRYPT() function. */ public static Field desEncrypt(byte[] string, byte[] keyString) { return desEncrypt(val(string), val(keyString)); } /** - * Get the MySQL-specific DES_ENCRYPT() function + * Get the MySQL-specific DES_ENCRYPT() function. */ public static Field desEncrypt(Field string, Field keyString) { return function("des_encrypt", string.getType(), string, keyString); } /** - * Get the MySQL-specific COMPRESS() function + * Get the MySQL-specific COMPRESS() function. */ public static Field compress(String string) { return compress(val(string)); } /** - * Get the MySQL-specific COMPRESS() function + * Get the MySQL-specific COMPRESS() function. */ public static Field compress(byte[] string) { return compress(val(string)); } /** - * Get the MySQL-specific COMPRESS() function + * Get the MySQL-specific COMPRESS() function. */ public static Field compress(Field string) { return function("compress", string.getType(), string); } /** - * Get the MySQL-specific UNCOMPRESS() function + * Get the MySQL-specific UNCOMPRESS() function. */ public static Field uncompress(String string) { return uncompress(val(string)); } /** - * Get the MySQL-specific UNCOMPRESS() function + * Get the MySQL-specific UNCOMPRESS() function. */ public static Field uncompress(byte[] string) { return uncompress(val(string)); } /** - * Get the MySQL-specific UNCOMPRESS() function + * Get the MySQL-specific UNCOMPRESS() function. */ public static Field uncompress(Field string) { return function("uncompress", string.getType(), string); } /** - * Get the MySQL-specific UNCOMPRESSED_LENGTH() function + * Get the MySQL-specific UNCOMPRESSED_LENGTH() function. */ public static Field uncompressedLength(String string) { return uncompressedLength(val(string)); } /** - * Get the MySQL-specific UNCOMPRESSED_LENGTH() function + * Get the MySQL-specific UNCOMPRESSED_LENGTH() function. */ public static Field uncompressedLength(byte[] string) { return uncompressedLength(val(string)); } /** - * Get the MySQL-specific UNCOMPRESSED_LENGTH() function + * Get the MySQL-specific UNCOMPRESSED_LENGTH() function. */ public static Field uncompressedLength(Field string) { return function("uncompressed_length", Integer.class, string); } /** - * Get the MySQL-specific SHA1() function + * Get the MySQL-specific SHA1() function. */ public static Field sha1(String string) { return sha1(val(string)); } /** - * Get the MySQL-specific SHA1() function + * Get the MySQL-specific SHA1() function. */ public static Field sha1(byte[] string) { return sha1(val(string)); } /** - * Get the MySQL-specific SHA1() function + * Get the MySQL-specific SHA1() function. */ public static Field sha1(Field string) { return function("sha1", string.getType(), string); } /** - * Get the MySQL-specific SHA2() function + * Get the MySQL-specific SHA2() function. */ public static Field sha2(String string, int hashLength) { return sha2(val(string), val(hashLength)); } - /** - * Get the MySQL-specific SHA2() function + * Get the MySQL-specific SHA2() function. */ public static Field sha2(byte[] string, int hashLength) { return sha2(val(string), val(hashLength)); } /** - * Get the MySQL-specific SHA2() function + * Get the MySQL-specific SHA2() function. */ public static Field sha2(Field string, Field hashLength) { return function("sha2", string.getType(), string, hashLength); } /** - * Get the MySQL-specific PASSWORD() function + * Get the MySQL-specific PASSWORD() function. */ public static Field password(String string) { return password(val(string)); } /** - * Get the MySQL-specific PASSWORD() function + * Get the MySQL-specific PASSWORD() function. */ public static Field password(byte[] string) { return password(val(string)); } /** - * Get the MySQL-specific PASSWORD() function + * Get the MySQL-specific PASSWORD() function. */ public static Field password(Field string) { return function("password", string.getType(), string);