From f4b42b94ce92e31b6e4eea042f28f6bb6cabf47f Mon Sep 17 00:00:00 2001 From: Woonduk Kang Date: Mon, 10 Sep 2012 07:47:20 +0000 Subject: [PATCH] =?UTF-8?q?[=EA=B0=95=EC=9A=B4=EB=8D=95]=20[LUCYSUS-1744]?= =?UTF-8?q?=20bindvalue=20=EA=B4=80=EB=A0=A8=20util=20=EC=B6=94=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@615 84d0f5b1-2673-498c-a247-62c4ff18d310 --- .../util/bindvalue/BindValueConverter.java | 41 +++++++++++++++++++ .../com/profiler/util/bindvalue/Types.java | 32 +++++++++++++++ .../profiler/util/bindvalue/TypesTest.java | 17 ++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/main/java/com/profiler/util/bindvalue/BindValueConverter.java create mode 100644 src/main/java/com/profiler/util/bindvalue/Types.java create mode 100644 src/test/java/com/profiler/util/bindvalue/TypesTest.java diff --git a/src/main/java/com/profiler/util/bindvalue/BindValueConverter.java b/src/main/java/com/profiler/util/bindvalue/BindValueConverter.java new file mode 100644 index 000000000..753604a69 --- /dev/null +++ b/src/main/java/com/profiler/util/bindvalue/BindValueConverter.java @@ -0,0 +1,41 @@ +package com.profiler.util.bindvalue; + +import com.profiler.util.StringUtils; + +import java.util.HashMap; +import java.util.Map; + +public class BindValueConverter { + public static final Map convertermap = new HashMap() ; + + public String bindValueToString(String methodName, Object[] args) { + Converter converter = convertermap.get(methodName); + if (converter == null) { + return ""; + } + return converter.convert(args); + } + + interface Converter { + String convert(Object[] args); + } + + class CommonConverter implements Converter { + @Override + public String convert(Object[] args) { + if(args == null) { + return "null"; + } + if (args.length == 1) { + return StringUtils.toString(args[1]); + } + else if(args.length == 2) { + return StringUtils.toString(args[0]) + ":" + StringUtils.toString(args[1]); + } + else if(args.length == 3) { + return StringUtils.toString(args[0]) + ":" + StringUtils.toString(args[1]); + } + return "error"; + } + } +} diff --git a/src/main/java/com/profiler/util/bindvalue/Types.java b/src/main/java/com/profiler/util/bindvalue/Types.java new file mode 100644 index 000000000..058a92264 --- /dev/null +++ b/src/main/java/com/profiler/util/bindvalue/Types.java @@ -0,0 +1,32 @@ +package com.profiler.util.bindvalue; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +public class Types { + + private static final Map MAP; + + static { + MAP = inverse(); + } + + static Map inverse() { + Map map = new HashMap(); + Field[] fields = java.sql.Types.class.getFields(); + for (Field field : fields) { + String name = field.getName(); + try { + Integer value = (Integer) field.get(java.sql.Types.class); + map.put(value, name); + } catch (IllegalAccessException e) { + } + } + return map; + } + + public static String findType(int type) { + return MAP.get(type); + } +} diff --git a/src/test/java/com/profiler/util/bindvalue/TypesTest.java b/src/test/java/com/profiler/util/bindvalue/TypesTest.java new file mode 100644 index 000000000..af75327a2 --- /dev/null +++ b/src/test/java/com/profiler/util/bindvalue/TypesTest.java @@ -0,0 +1,17 @@ +package com.profiler.util.bindvalue; + +import org.junit.Assert; +import org.junit.Test; + +import java.lang.reflect.Field; +import java.util.Map; + +public class TypesTest { + + @Test + public void testInverse() throws Exception { + Map inverse = Types.inverse(); + Field[] fields = java.sql.Types.class.getFields(); + Assert.assertEquals(inverse.size(), fields.length); + } +}