001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.util.dao.orm.hibernate;
016    
017    import java.sql.Timestamp;
018    
019    import org.hibernate.Query;
020    
021    /**
022     * @author         Brian Wing Shun Chan
023     * @deprecated This class has been repackaged at
024     *                         <code>com.liferay.portal.kernel.dao.orm</code>.
025     */
026    public class QueryPos {
027    
028            public static QueryPos getInstance(Query query) {
029                    return new QueryPos(query);
030            }
031    
032            public int getPos() {
033                    return _pos;
034            }
035    
036            public void add(boolean value) {
037                    _query.setBoolean(_pos++, value);
038            }
039    
040            public void add(Boolean value) {
041                    if (value != null) {
042                            _query.setBoolean(_pos++, value.booleanValue());
043                    }
044                    else {
045                            addNull();
046                    }
047            }
048    
049            public void add(double value) {
050                    _query.setDouble(_pos++, value);
051            }
052    
053            public void add(Double value) {
054                    if (value != null) {
055                            _query.setDouble(_pos++, value.doubleValue());
056                    }
057                    else {
058                            addNull();
059                    }
060            }
061    
062            public void add(float value) {
063                    _query.setFloat(_pos++, value);
064            }
065    
066            public void add(Float value) {
067                    if (value != null) {
068                            _query.setFloat(_pos++, value.intValue());
069                    }
070                    else {
071                            addNull();
072                    }
073            }
074    
075            public void add(int value) {
076                    _query.setInteger(_pos++, value);
077            }
078    
079            public void add(Integer value) {
080                    if (value != null) {
081                            _query.setInteger(_pos++, value.intValue());
082                    }
083                    else {
084                            addNull();
085                    }
086            }
087    
088            public void add(long value) {
089                    _query.setLong(_pos++, value);
090            }
091    
092            public void add(Long value) {
093                    if (value != null) {
094                            _query.setLong(_pos++, value.longValue());
095                    }
096                    else {
097                            addNull();
098                    }
099            }
100    
101            public void add(short value) {
102                    _query.setShort(_pos++, value);
103            }
104    
105            public void add(Short value) {
106                    if (value != null) {
107                            _query.setShort(_pos++, value.shortValue());
108                    }
109                    else {
110                            addNull();
111                    }
112            }
113    
114            public void add(String value) {
115                    _query.setString(_pos++, value);
116            }
117    
118            public void add(String[] values) {
119                    add(values, 1);
120            }
121    
122            public void add(String[] values, int count) {
123                    for (int i = 0; i < values.length; i++) {
124                            for (int j = 0; j < count; j++) {
125                                    add(values[i]);
126                            }
127                    }
128            }
129    
130            public void add(Timestamp value) {
131                    _query.setTimestamp(_pos++, value);
132            }
133    
134            private QueryPos(Query query) {
135                    _query = query;
136            }
137    
138            private void addNull() {
139                    _query.setSerializable(_pos++, null);
140            }
141    
142            private Query _query;
143            private int _pos;
144    
145    }