01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: */
05: /*
06: * Licensed to the Apache Software Foundation (ASF) under one or more
07: * contributor license agreements. See the NOTICE file distributed with
08: * this work for additional information regarding copyright ownership.
09: * The ASF licenses this file to You under the Apache License, Version 2.0
10: * (the "License"); you may not use this file except in compliance with
11: * the License. You may obtain a copy of the License at
12: *
13: * http://www.apache.org/licenses/LICENSE-2.0
14: *
15: * Unless required by applicable law or agreed to in writing, software
16: * distributed under the License is distributed on an "AS IS" BASIS,
17: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18: * See the License for the specific language governing permissions and
19: * limitations under the License.
20: */
21: package org.h2.test.trace;
22:
23: import java.math.BigDecimal;
24:
25: import org.h2.util.StringUtils;
26:
27: /**
28: * An argument of a statement.
29: */
30: class Arg {
31: private Class clazz;
32: private Object obj;
33: private Statement stat;
34:
35: Arg(Player player, Class clazz, Object obj) {
36: this .clazz = clazz;
37: this .obj = obj;
38: }
39:
40: Arg(Statement stat) {
41: this .stat = stat;
42: }
43:
44: public String toString() {
45: if (stat != null) {
46: return stat.toString();
47: } else {
48: return quote(clazz, getValue());
49: }
50: }
51:
52: void execute() throws Exception {
53: if (stat != null) {
54: obj = stat.execute();
55: clazz = stat.getReturnClass();
56: stat = null;
57: }
58: }
59:
60: Class getValueClass() {
61: return clazz;
62: }
63:
64: Object getValue() {
65: return obj;
66: }
67:
68: String quote(Class clazz, Object value) {
69: if (value == null) {
70: return null;
71: } else if (clazz == String.class) {
72: return StringUtils.quoteJavaString(value.toString());
73: } else if (clazz == BigDecimal.class) {
74: return "new BigDecimal(\"" + value.toString() + "\")";
75: } else if (clazz.isArray()) {
76: if (clazz == String[].class) {
77: return StringUtils
78: .quoteJavaStringArray((String[]) value);
79: } else if (clazz == int[].class) {
80: return StringUtils.quoteJavaIntArray((int[]) value);
81: }
82: }
83: return value.toString();
84: }
85:
86: }
|