Here you can find the source of formatEJBQLObjectRangeRestriction(final String fieldName, final Object value1, final Object value2, final String paramName1, final String paramName2, List
public static String formatEJBQLObjectRangeRestriction(final String fieldName, final Object value1, final Object value2, final String paramName1, final String paramName2, List<String> paramsName, List<Object> paramsValue, boolean firstRestriction)
//package com.java2s; /*/* www . ja v a 2 s . c o m*/ * DatabaseUtils.java * * Copyright (c) 1998 - 2006 BusinessTechnology, Ltd. * All rights reserved * * This program is the proprietary and confidential information * of BusinessTechnology, Ltd. and may be used and disclosed only * as authorized in a license agreement authorizing and * controlling such use and disclosure * * Millennium ERP system. * */ import java.util.List; public class Main { public static String formatEJBQLObjectRangeRestriction(final String fieldName, final Object value1, final Object value2, final String paramName1, final String paramName2, List<String> paramsName, List<Object> paramsValue, boolean firstRestriction) { String result = ""; if (value1 != null && value1.equals(value2)) { result = String.format("(%s = :%s)", fieldName, paramName1); paramsName.add(paramName1); paramsValue.add(value1); } else if (value1 != null || value2 != null) { if (value1 == null) { result = String.format("(%s <= :%s)", fieldName, paramName2); paramsName.add(paramName2); paramsValue.add(value2); } else if (value2 == null) { result = String.format("(%s >= :%s)", fieldName, paramName1); paramsName.add(paramName1); paramsValue.add(value1); } else { result = String.format("(%s between :%s and :%s)", fieldName, paramName1, paramName2); paramsName.add(paramName1); paramsValue.add(value1); paramsName.add(paramName2); paramsValue.add(value2); } } if (!result.equals("")) result = generateRestrictionPrefix(result, firstRestriction); return result; } private static String generateRestrictionPrefix(final String restrictionText, boolean firstRestriction) { if (!firstRestriction) return " and ".concat(restrictionText); else return restrictionText; } }