org.jooq.util.mysql.MySQLDSL Maven / Gradle / Ivy
/**
* Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com)
* All rights reserved.
*
* This work is dual-licensed
* - under the Apache Software License 2.0 (the "ASL")
* - under the jOOQ License and Maintenance Agreement (the "jOOQ License")
* =============================================================================
* You may choose which license applies to you:
*
* - If you're using this work with Open Source databases, you may choose
* either ASL or jOOQ License.
* - If you're using this work with at least one commercial database, you must
* choose jOOQ License
*
* For more information, please visit http://www.jooq.org/licenses
*
* Apache Software License 2.0:
* -----------------------------------------------------------------------------
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* jOOQ License and Maintenance Agreement:
* -----------------------------------------------------------------------------
* Data Geekery grants the Customer the non-exclusive, timely limited and
* non-transferable license to install and use the Software under the terms of
* the jOOQ License and Maintenance Agreement.
*
* This library is distributed with a LIMITED WARRANTY. See the jOOQ License
* and Maintenance Agreement for more details: http://www.jooq.org/licensing
*/
package org.jooq.util.mysql;
import org.jooq.EnumType;
import org.jooq.Field;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
/**
* The {@link SQLDialect#MYSQL} specific DSL.
*
* @author Lukas Eder
*/
public class MySQLDSL extends DSL {
/**
* No instances
*/
private MySQLDSL() {
}
// -------------------------------------------------------------------------
// MySQL-specific compression and encryption functions
// -------------------------------------------------------------------------
/**
* Get the MySQL-specific DECODE()
function.
*
* Don't mix this up with the various {@link DSL#decode()} methods!
*/
public static Field decode(String cryptString, String keyString) {
return decode(val(cryptString), val(keyString));
}
/**
* Get the MySQL-specific DECODE()
function.
*
* Don't mix this up with the various {@link DSL#decode()} methods!
*/
public static Field decode(byte[] cryptString, byte[] keyString) {
return decode(val(cryptString), val(keyString));
}
/**
* Get the MySQL-specific DECODE()
function.
*
* Don't mix this up with the various {@link DSL#decode()} methods!
*/
public static Field decode(Field cryptString, Field keyString) {
return function("decode", cryptString.getType(), cryptString, keyString);
}
/**
* 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.
*/
public static Field encode(byte[] string, byte[] keyString) {
return encode(val(string), val(keyString));
}
/**
* 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.
*/
public static Field aesDecrypt(String cryptString, String keyString) {
return aesDecrypt(val(cryptString), val(keyString));
}
/**
* 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.
*/
public static Field aesDecrypt(Field cryptString, Field keyString) {
return function("aes_decrypt", cryptString.getType(), cryptString, keyString);
}
/**
* 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.
*/
public static Field aesEncrypt(byte[] string, byte[] keyString) {
return aesEncrypt(val(string), val(keyString));
}
/**
* 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.
*/
public static Field desDecrypt(String cryptString) {
return desDecrypt(val(cryptString));
}
/**
* Get the MySQL-specific DES_DECRYPT()
function.
*/
public static Field desDecrypt(byte[] cryptString) {
return desDecrypt(val(cryptString));
}
/**
* 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.
*/
public static Field desDecrypt(String cryptString, String keyString) {
return desDecrypt(val(cryptString), val(keyString));
}
/**
* 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.
*/
public static Field desDecrypt(Field cryptString, Field keyString) {
return function("des_decrypt", cryptString.getType(), cryptString, keyString);
}
/**
* Get the MySQL-specific DES_ENCRYPT()
function.
*/
public static Field desEncrypt(String string) {
return desEncrypt(val(string));
}
/**
* Get the MySQL-specific DES_ENCRYPT()
function.
*/
public static Field desEncrypt(byte[] string) {
return desEncrypt(val(string));
}
/**
* 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.
*/
public static Field desEncrypt(String string, String keyString) {
return desEncrypt(val(string), val(keyString));
}
/**
* 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.
*/
public static Field desEncrypt(Field string, Field keyString) {
return function("des_encrypt", string.getType(), string, keyString);
}
/**
* Get the MySQL-specific COMPRESS()
function.
*/
public static Field compress(String string) {
return compress(val(string));
}
/**
* Get the MySQL-specific COMPRESS()
function.
*/
public static Field compress(byte[] string) {
return compress(val(string));
}
/**
* Get the MySQL-specific COMPRESS()
function.
*/
public static Field compress(Field string) {
return function("compress", string.getType(), string);
}
/**
* Get the MySQL-specific UNCOMPRESS()
function.
*/
public static Field uncompress(String string) {
return uncompress(val(string));
}
/**
* Get the MySQL-specific UNCOMPRESS()
function.
*/
public static Field uncompress(byte[] string) {
return uncompress(val(string));
}
/**
* 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.
*/
public static Field uncompressedLength(String string) {
return uncompressedLength(val(string));
}
/**
* Get the MySQL-specific UNCOMPRESSED_LENGTH()
function.
*/
public static Field uncompressedLength(byte[] string) {
return uncompressedLength(val(string));
}
/**
* 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.
*/
public static Field sha1(String string) {
return sha1(val(string));
}
/**
* Get the MySQL-specific SHA1()
function.
*/
public static Field sha1(byte[] string) {
return sha1(val(string));
}
/**
* Get the MySQL-specific SHA1()
function.
*/
public static Field sha1(Field string) {
return function("sha1", string.getType(), string);
}
/**
* 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.
*/
public static Field sha2(byte[] string, int hashLength) {
return sha2(val(string), val(hashLength));
}
/**
* 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.
*/
public static Field password(String string) {
return password(val(string));
}
/**
* Get the MySQL-specific PASSWORD()
function.
*/
public static Field password(byte[] string) {
return password(val(string));
}
/**
* Get the MySQL-specific PASSWORD()
function.
*/
public static Field password(Field string) {
return function("password", string.getType(), string);
}
// -------------------------------------------------------------------------
// Other utilities
// -------------------------------------------------------------------------
/**
* Get a field based {@link EnumType} by its MySQL-specific index.
*
* If your MySQL enum type contains these three values: A, B, C
* , then this will be the mapping of indexes to values:
*
*
* Enum literal as in {@link Enum#name()}
* Enum ordinal as in {@link Enum#ordinal()}
* MySQL index
*
*
* null
* -
* 0
*
*
* A
* 0
* 1
*
*
* B
* 1
* 2
*
*
* C
* 2
* 3
*
*
*
* See dev.mysql.com/doc/
* refman/5.5/en/enum.html for more details about MySQL enum types
*/
public static & org.jooq.EnumType> E enumType(Class type, int index) {
if (index <= 0) {
return null;
}
E[] values = type.getEnumConstants();
if (index > values.length) {
return null;
}
return values[index - 1];
}
}