Overloading all MySQL specific DSL functions to accept BLOB arguments
This commit is contained in:
parent
cf6d060d67
commit
fbe6650cee
@ -822,7 +822,7 @@ public class MySQLTest extends jOOQAbstractTest<
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMySQLEncryptionFunctions() throws Exception {
|
||||
public void testMySQLStringEncryptionFunctions() throws Exception {
|
||||
assertNotNull(create().select(password("abc")).fetchOne(0));
|
||||
assertNotNull(create().select(md5("abc")).fetchOne(0));
|
||||
assertNotNull(create().select(sha1("abc")).fetchOne(0));
|
||||
@ -835,6 +835,22 @@ public class MySQLTest extends jOOQAbstractTest<
|
||||
assertEquals(3, create().select(uncompressedLength(compress("abc"))).fetchOne(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMySQLByteArrayEncryptionFunctions() throws Exception {
|
||||
final byte[] MESSAGE = new byte[] {-74, 71, -79, -124, -58};
|
||||
final byte[] SECRET = new byte[] {-122, -123, 4, -12, -37};
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMySQLJavaKeywordEnums() throws Exception {
|
||||
reset = false;
|
||||
|
||||
@ -44,6 +44,7 @@ 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.
|
||||
@ -76,8 +77,17 @@ public class MySQLDSL extends DSL {
|
||||
* <p>
|
||||
* Don't mix this up with the various {@link DSL#decode()} methods!
|
||||
*/
|
||||
public static Field<String> decode(Field<String> cryptString, Field<String> keyString) {
|
||||
return function("decode", String.class, cryptString, keyString);
|
||||
public static Field<byte[]> decode(byte[] cryptString, byte[] keyString) {
|
||||
return decode(val(cryptString), val(keyString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>DECODE()</code> function
|
||||
* <p>
|
||||
* Don't mix this up with the various {@link DSL#decode()} methods!
|
||||
*/
|
||||
public static <T> Field<T> decode(Field<T> cryptString, Field<T> keyString) {
|
||||
return function("decode", cryptString.getType(), cryptString, keyString);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,8 +100,15 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>ENCODE()</code> function
|
||||
*/
|
||||
public static Field<String> encode(Field<String> string, Field<String> keyString) {
|
||||
return function("encode", String.class, string, keyString);
|
||||
public static Field<byte[]> encode(byte[] string, byte[] keyString) {
|
||||
return encode(val(string), val(keyString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>ENCODE()</code> function
|
||||
*/
|
||||
public static <T> Field<T> encode(Field<T> string, Field<T> keyString) {
|
||||
return function("encode", string.getType(), string, keyString);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,8 +121,15 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>AES_DECRYPT()</code> function
|
||||
*/
|
||||
public static Field<String> aesDecrypt(Field<String> cryptString, Field<String> keyString) {
|
||||
return function("aes_decrypt", String.class, cryptString, keyString);
|
||||
public static Field<byte[]> aesDecrypt(byte[] cryptString, byte[] keyString) {
|
||||
return aesDecrypt(val(cryptString), val(keyString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>AES_DECRYPT()</code> function
|
||||
*/
|
||||
public static <T> Field<T> aesDecrypt(Field<T> cryptString, Field<T> keyString) {
|
||||
return function("aes_decrypt", cryptString.getType(), cryptString, keyString);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,8 +142,15 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>AES_ENCRYPT()</code> function
|
||||
*/
|
||||
public static Field<String> aesEncrypt(Field<String> string, Field<String> keyString) {
|
||||
return function("aes_encrypt", String.class, string, keyString);
|
||||
public static Field<byte[]> aesEncrypt(byte[] string, byte[] keyString) {
|
||||
return aesEncrypt(val(string), val(keyString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>AES_ENCRYPT()</code> function
|
||||
*/
|
||||
public static <T> Field<T> aesEncrypt(Field<T> string, Field<T> keyString) {
|
||||
return function("aes_encrypt", string.getType(), string, keyString);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,8 +163,15 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>DES_DECRYPT()</code> function
|
||||
*/
|
||||
public static Field<String> desDecrypt(Field<String> cryptString) {
|
||||
return function("des_decrypt", String.class, cryptString);
|
||||
public static Field<byte[]> desDecrypt(byte[] cryptString) {
|
||||
return desDecrypt(val(cryptString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>DES_DECRYPT()</code> function
|
||||
*/
|
||||
public static <T> Field<T> desDecrypt(Field<T> cryptString) {
|
||||
return function("des_decrypt", cryptString.getType(), cryptString);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,8 +184,15 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>DES_DECRYPT()</code> function
|
||||
*/
|
||||
public static Field<String> desDecrypt(Field<String> cryptString, Field<String> keyString) {
|
||||
return function("des_decrypt", String.class, cryptString, keyString);
|
||||
public static Field<byte[]> desDecrypt(byte[] cryptString, byte[] keyString) {
|
||||
return desDecrypt(val(cryptString), val(keyString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>DES_DECRYPT()</code> function
|
||||
*/
|
||||
public static <T> Field<T> desDecrypt(Field<T> cryptString, Field<T> keyString) {
|
||||
return function("des_decrypt", cryptString.getType(), cryptString, keyString);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,8 +205,15 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>DES_ENCRYPT()</code> function
|
||||
*/
|
||||
public static Field<String> desEncrypt(Field<String> string) {
|
||||
return function("des_encrypt", String.class, string);
|
||||
public static Field<byte[]> desEncrypt(byte[] string) {
|
||||
return desEncrypt(val(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>DES_ENCRYPT()</code> function
|
||||
*/
|
||||
public static <T> Field<T> desEncrypt(Field<T> string) {
|
||||
return function("des_encrypt", string.getType(), string);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,8 +226,15 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>DES_ENCRYPT()</code> function
|
||||
*/
|
||||
public static Field<String> desEncrypt(Field<String> string, Field<String> keyString) {
|
||||
return function("des_encrypt", String.class, string, keyString);
|
||||
public static Field<byte[]> desEncrypt(byte[] string, byte[] keyString) {
|
||||
return desEncrypt(val(string), val(keyString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>DES_ENCRYPT()</code> function
|
||||
*/
|
||||
public static <T> Field<T> desEncrypt(Field<T> string, Field<T> keyString) {
|
||||
return function("des_encrypt", string.getType(), string, keyString);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -188,8 +247,15 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>COMPRESS()</code> function
|
||||
*/
|
||||
public static Field<String> compress(Field<String> string) {
|
||||
return function("compress", String.class, string);
|
||||
public static Field<byte[]> compress(byte[] string) {
|
||||
return compress(val(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>COMPRESS()</code> function
|
||||
*/
|
||||
public static <T> Field<T> compress(Field<T> string) {
|
||||
return function("compress", string.getType(), string);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,8 +268,15 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>UNCOMPRESS()</code> function
|
||||
*/
|
||||
public static Field<String> uncompress(Field<String> string) {
|
||||
return function("uncompress", String.class, string);
|
||||
public static Field<byte[]> uncompress(byte[] string) {
|
||||
return uncompress(val(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>UNCOMPRESS()</code> function
|
||||
*/
|
||||
public static <T> Field<T> uncompress(Field<T> string) {
|
||||
return function("uncompress", string.getType(), string);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,7 +289,14 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>UNCOMPRESSED_LENGTH()</code> function
|
||||
*/
|
||||
public static Field<Integer> uncompressedLength(Field<String> string) {
|
||||
public static Field<Integer> uncompressedLength(byte[] string) {
|
||||
return uncompressedLength(val(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>UNCOMPRESSED_LENGTH()</code> function
|
||||
*/
|
||||
public static <T> Field<Integer> uncompressedLength(Field<T> string) {
|
||||
return function("uncompressed_length", Integer.class, string);
|
||||
}
|
||||
|
||||
@ -230,8 +310,15 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>SHA1()</code> function
|
||||
*/
|
||||
public static Field<String> sha1(Field<String> string) {
|
||||
return function("sha1", String.class, string);
|
||||
public static Field<byte[]> sha1(byte[] string) {
|
||||
return sha1(val(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>SHA1()</code> function
|
||||
*/
|
||||
public static <T> Field<T> sha1(Field<T> string) {
|
||||
return function("sha1", string.getType(), string);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,11 +328,19 @@ public class MySQLDSL extends DSL {
|
||||
return sha2(val(string), val(hashLength));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>SHA2()</code> function
|
||||
*/
|
||||
public static Field<String> sha2(Field<String> string, Field<Integer> hashLength) {
|
||||
return function("sha2", String.class, string, hashLength);
|
||||
public static Field<byte[]> sha2(byte[] string, int hashLength) {
|
||||
return sha2(val(string), val(hashLength));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>SHA2()</code> function
|
||||
*/
|
||||
public static <T> Field<T> sha2(Field<T> string, Field<Integer> hashLength) {
|
||||
return function("sha2", string.getType(), string, hashLength);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -258,8 +353,15 @@ public class MySQLDSL extends DSL {
|
||||
/**
|
||||
* Get the MySQL-specific <code>PASSWORD()</code> function
|
||||
*/
|
||||
public static Field<String> password(Field<String> string) {
|
||||
return function("password", String.class, string);
|
||||
public static Field<byte[]> password(byte[] string) {
|
||||
return password(val(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the MySQL-specific <code>PASSWORD()</code> function
|
||||
*/
|
||||
public static <T> Field<T> password(Field<T> string) {
|
||||
return function("password", string.getType(), string);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user