All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gorm.tools.utils.DbUtils.groovy Maven / Gradle / Ivy

There is a newer version: 7.3.74
Show newest version
/*
* Copyright 2022 Yak.Works - Licensed under the Apache License, Version 2.0 (the "License")
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
package gorm.tools.utils

import groovy.transform.CompileStatic

@CompileStatic
class DbUtils {

    /**
     * Builds an hql condition as "column is null " or "column = :column" based on the value.
     */
    static String nullSafeHqlCondition(String column, Object value) {
        if (value == null) {
            return "${column} is null "
        } else {
            return "${column} = :${column}"
        }
    }

    /**
     * Builds an hql condition as "column is null " or "column = :column" based on the value.
     */
    static String nullSafeSqlCondition(String column, Object value) {
        String condition
        if (value == null) {
            condition = "${column} is null "
        } else {
            if (value instanceof String) {
                condition = "${column} = '$value'"
            } else {
                condition = "${column} = $value"
            }
        }
        return condition
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy