~ubuntu-branches/ubuntu/oneiric/postgresql-pljava/oneiric

« back to all changes in this revision

Viewing changes to src/java/examples/org/postgresql/pljava/example/Parameters.java

  • Committer: Bazaar Package Importer
  • Author(s): Peter Eisentraut
  • Date: 2006-06-26 10:44:55 UTC
  • mfrom: (1.1.1 upstream) (3.1.1 edgy)
  • Revision ID: james.westby@ubuntu.com-20060626104455-135i9wosat2k8vvt
Tags: 1.3.0-1
* New upstream release (closes: #375199)
* Built for postgresql 8.1 (closes: #339641)
* Rebuilt for new libgcj library (closes: #369986)
* Updated copyright file
* Updated standards version
* Made use of cdbs simple patchsys

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
import java.math.BigDecimal;
10
10
import java.sql.Date;
 
11
import java.sql.ResultSet;
 
12
import java.sql.SQLException;
11
13
import java.sql.Time;
12
14
import java.sql.Timestamp;
13
15
import java.text.DateFormat;
 
16
import java.text.SimpleDateFormat;
14
17
import java.util.TimeZone;
15
18
import java.util.logging.Logger;
16
19
 
74
77
        {
75
78
                return new Timestamp(System.currentTimeMillis());
76
79
        }
77
 
        
 
80
 
 
81
        public static int countNulls(ResultSet input) throws SQLException
 
82
        {
 
83
                int nullCount = 0;
 
84
                int top = input.getMetaData().getColumnCount();
 
85
                for(int idx = 1; idx <= top; ++idx)
 
86
                {
 
87
                        input.getObject(idx);
 
88
                        if(input.wasNull())
 
89
                                nullCount++;
 
90
                }
 
91
                return nullCount;
 
92
        }
 
93
 
 
94
        public static int countNulls(Integer[] intArray) throws SQLException
 
95
        {
 
96
                int nullCount = 0;
 
97
                int top = intArray.length;
 
98
                for(int idx = 0; idx < top; ++idx)
 
99
                {
 
100
                        if(intArray[idx] == null)
 
101
                                nullCount++;
 
102
                }
 
103
                return nullCount;
 
104
        }
 
105
 
 
106
        public static byte print(byte value)
 
107
        {
 
108
                log("byte " + value);
 
109
                return value;
 
110
        }
 
111
 
 
112
        public static byte[] print(byte[] byteArray)
 
113
        {
 
114
                StringBuffer buf = new StringBuffer();
 
115
                int top = byteArray.length;
 
116
                buf.append("byte[] of size " + top);
 
117
                if(top > 0)
 
118
                {
 
119
                        buf.append(" {");
 
120
                        buf.append(byteArray[0]);
 
121
                        for(int idx = 1; idx < top; ++idx)
 
122
                        {
 
123
                                buf.append(',');
 
124
                                buf.append(byteArray[idx]);
 
125
                        }
 
126
                        buf.append('}');
 
127
                }
 
128
                log(buf.toString());
 
129
                return byteArray;
 
130
        }
 
131
 
 
132
        public static short print(short value)
 
133
        {
 
134
                log("short " + value);
 
135
                return value;
 
136
        }
 
137
 
 
138
        public static short[] print(short[] shortArray)
 
139
        {
 
140
                StringBuffer buf = new StringBuffer();
 
141
                int top = shortArray.length;
 
142
                buf.append("short[] of size " + top);
 
143
                if(top > 0)
 
144
                {
 
145
                        buf.append(" {");
 
146
                        buf.append(shortArray[0]);
 
147
                        for(int idx = 1; idx < top; ++idx)
 
148
                        {
 
149
                                buf.append(',');
 
150
                                buf.append(shortArray[idx]);
 
151
                        }
 
152
                        buf.append('}');
 
153
                }
 
154
                log(buf.toString());
 
155
                return shortArray;
 
156
        }
 
157
 
 
158
        public static int print(int value)
 
159
        {
 
160
                log("int " + value);
 
161
                return value;
 
162
        }
 
163
 
 
164
        public static int[] print(int[] intArray)
 
165
        {
 
166
                StringBuffer buf = new StringBuffer();
 
167
                int top = intArray.length;
 
168
                buf.append("int[] of size " + top);
 
169
                if(top > 0)
 
170
                {
 
171
                        buf.append(" {");
 
172
                        buf.append(intArray[0]);
 
173
                        for(int idx = 1; idx < top; ++idx)
 
174
                        {
 
175
                                buf.append(',');
 
176
                                buf.append(intArray[idx]);
 
177
                        }
 
178
                        buf.append('}');
 
179
                }
 
180
                log(buf.toString());
 
181
                return intArray;
 
182
        }
 
183
 
 
184
        public static long print(long value)
 
185
        {
 
186
                log("long " + value);
 
187
                return value;
 
188
        }
 
189
 
 
190
        public static long[] print(long[] longArray)
 
191
        {
 
192
                StringBuffer buf = new StringBuffer();
 
193
                int top = longArray.length;
 
194
                buf.append("long[] of size " + top);
 
195
                if(top > 0)
 
196
                {
 
197
                        buf.append(" {");
 
198
                        buf.append(longArray[0]);
 
199
                        for(int idx = 1; idx < top; ++idx)
 
200
                        {
 
201
                                buf.append(',');
 
202
                                buf.append(longArray[idx]);
 
203
                        }
 
204
                        buf.append('}');
 
205
                }
 
206
                log(buf.toString());
 
207
                return longArray;
 
208
        }
 
209
 
 
210
        public static float print(float value)
 
211
        {
 
212
                log("float " + value);
 
213
                return value;
 
214
        }
 
215
 
 
216
        public static float[] print(float[] floatArray)
 
217
        {
 
218
                StringBuffer buf = new StringBuffer();
 
219
                int top = floatArray.length;
 
220
                buf.append("float[] of size " + top);
 
221
                if(top > 0)
 
222
                {
 
223
                        buf.append(" {");
 
224
                        buf.append(floatArray[0]);
 
225
                        for(int idx = 1; idx < top; ++idx)
 
226
                        {
 
227
                                buf.append(',');
 
228
                                buf.append(floatArray[idx]);
 
229
                        }
 
230
                        buf.append('}');
 
231
                }
 
232
                log(buf.toString());
 
233
                return floatArray;
 
234
        }
 
235
 
 
236
        public static double print(double value)
 
237
        {
 
238
                log("double " + value);
 
239
                return value;
 
240
        }
 
241
 
 
242
        public static double[] print(double[] doubleArray)
 
243
        {
 
244
                StringBuffer buf = new StringBuffer();
 
245
                int top = doubleArray.length;
 
246
                buf.append("double[] of size " + top);
 
247
                if(top > 0)
 
248
                {
 
249
                        buf.append(" {");
 
250
                        buf.append(doubleArray[0]);
 
251
                        for(int idx = 1; idx < top; ++idx)
 
252
                        {
 
253
                                buf.append(',');
 
254
                                buf.append(doubleArray[idx]);
 
255
                        }
 
256
                        buf.append('}');
 
257
                }
 
258
                log(buf.toString());
 
259
                return doubleArray;
 
260
        }
 
261
 
 
262
        public static Integer[] print(Integer[] intArray)
 
263
        {
 
264
                StringBuffer buf = new StringBuffer();
 
265
                int top = intArray.length;
 
266
                buf.append("Integer[] of size " + top);
 
267
                if(top > 0)
 
268
                {
 
269
                        buf.append(" {");
 
270
                        buf.append(intArray[0]);
 
271
                        for(int idx = 1; idx < top; ++idx)
 
272
                        {
 
273
                                buf.append(',');
 
274
                                buf.append(intArray[idx]);
 
275
                        }
 
276
                        buf.append('}');
 
277
                }
 
278
                log(buf.toString());
 
279
                return intArray;
 
280
        }
 
281
 
78
282
        public static void print(Date time)
79
283
        {
80
284
                DateFormat p = DateFormat.getDateInstance(DateFormat.FULL);
 
285
                log("Local Date is " + p.format(time));
81
286
                p.setTimeZone(TimeZone.getTimeZone("UTC"));
82
 
                log("Date is " + p.format(time));
 
287
                log("UTC Date is " + p.format(time));
 
288
                log("TZ =  " + TimeZone.getDefault().getDisplayName());
83
289
        }
84
290
 
85
291
        public static void print(Time time)
86
292
        {
87
 
                DateFormat p = DateFormat.getTimeInstance(DateFormat.FULL);
 
293
                DateFormat p = new SimpleDateFormat("HH:mm:ss z Z");
 
294
                log("Local Time is " + p.format(time));
88
295
                p.setTimeZone(TimeZone.getTimeZone("UTC"));
89
 
                log("Time is " + p.format(time));
 
296
                log("UTC Time is " + p.format(time));
 
297
                log("TZ =  " + TimeZone.getDefault().getDisplayName());
90
298
        }
91
299
 
92
300
        public static void print(Timestamp time)
93
301
        {
94
302
                DateFormat p = DateFormat.getDateTimeInstance(
95
303
                                DateFormat.FULL, DateFormat.FULL);
 
304
                log("Local Timestamp is " + p.format(time));
96
305
                p.setTimeZone(TimeZone.getTimeZone("UTC"));
97
 
                log("Timestamp is " + p.format(time));
 
306
                log("UTC Timestamp is " + p.format(time));
 
307
                log("TZ =  " + TimeZone.getDefault().getDisplayName());
98
308
        }
99
309
}