001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.util.dao.hibernate;
022:
023: import java.sql.Timestamp;
024:
025: import org.hibernate.Query;
026:
027: /**
028: * <a href="QueryPos.java.html"><b><i>View Source</i></b></a>
029: *
030: * @author Brian Wing Shun Chan
031: *
032: */
033: public class QueryPos {
034:
035: public static QueryPos getInstance(Query query) {
036: return new QueryPos(query);
037: }
038:
039: public int getPos() {
040: return _pos;
041: }
042:
043: public void add(boolean value) {
044: _query.setBoolean(_pos++, value);
045: }
046:
047: public void add(Boolean value) {
048: if (value != null) {
049: _query.setBoolean(_pos++, value.booleanValue());
050: } else {
051: addNull();
052: }
053: }
054:
055: public void add(double value) {
056: _query.setDouble(_pos++, value);
057: }
058:
059: public void add(Double value) {
060: if (value != null) {
061: _query.setDouble(_pos++, value.doubleValue());
062: } else {
063: addNull();
064: }
065: }
066:
067: public void add(int value) {
068: _query.setInteger(_pos++, value);
069: }
070:
071: public void add(Integer value) {
072: if (value != null) {
073: _query.setInteger(_pos++, value.intValue());
074: } else {
075: addNull();
076: }
077: }
078:
079: public void add(long value) {
080: _query.setLong(_pos++, value);
081: }
082:
083: public void add(Long value) {
084: if (value != null) {
085: _query.setLong(_pos++, value.longValue());
086: } else {
087: addNull();
088: }
089: }
090:
091: public void add(short value) {
092: _query.setShort(_pos++, value);
093: }
094:
095: public void add(Short value) {
096: if (value != null) {
097: _query.setShort(_pos++, value.shortValue());
098: } else {
099: addNull();
100: }
101: }
102:
103: public void add(String value) {
104: _query.setString(_pos++, value);
105: }
106:
107: public void add(String[] values) {
108: add(values, 1);
109: }
110:
111: public void add(String[] values, int count) {
112: for (int i = 0; i < values.length; i++) {
113: for (int j = 0; j < count; j++) {
114: add(values[i]);
115: }
116: }
117: }
118:
119: public void add(Timestamp value) {
120: _query.setTimestamp(_pos++, value);
121: }
122:
123: private QueryPos(Query query) {
124: _query = query;
125: }
126:
127: private void addNull() {
128: _query.setSerializable(_pos++, null);
129: }
130:
131: private Query _query;
132: private int _pos;
133:
134: }
|