• R/O
  • SSH

JdbcAcsess2: Commit

全てを再実装したJdbcAcsessです。


Commit MetaInfo

Revisión3564c6cff51719e2fce84d0aa452ad8e87e67509 (tree)
Tiempo2012-03-31 15:19:10
Autorshimakazuro
Commitershimakazuro

Log Message

パラメータの保存とりあえず完成

Cambiar Resumen

Diferencia incremental

diff -r 0f88dae1c9ae -r 3564c6cff517 src/jdbcacsess2/main/Config.java
--- a/src/jdbcacsess2/main/Config.java Mon Mar 26 14:02:57 2012 +0900
+++ b/src/jdbcacsess2/main/Config.java Sat Mar 31 15:19:10 2012 +0900
@@ -52,6 +52,8 @@
5252
5353 private final EntityManager entityManager;
5454
55+ public OptionValues optionValues;
56+
5557 /**
5658 * コンストラクタ
5759 *
@@ -122,6 +124,9 @@
122124 Jdbcacsess2.logger.info("Migrate end");
123125 setUpConfigDbms();
124126
127+ // プロパティの作成
128+ optionValues = new OptionValues(getEntityManager());
129+
125130 Jdbcacsess2.logger.info("Config end");
126131 }
127132
@@ -201,7 +206,7 @@
201206 {"Oracle(TYPE4:Pure Java)","oracle:thin","@%HostName%%PortNumber%:%DataBaseName%","oracle.jdbc.driver.OracleDriver","","00.0"},
202207 {"Oracle(TYPE2:NET)","oracle:oci","@%DataBaseName%","oracle.jdbc.driver.OracleDriver","","00.0"},
203208 {"Oracle(TYPE2:NET8)","oracle:oci8","@%DataBaseName%","oracle.jdbc.driver.OracleDriver","","00.0"},
204- {"DB2(TYPE4:Universal)","db2","//%HostName%%PortNumber%/%DataBaseName%","com.ibm.db2.jcc.DB2Driver","","00.1"},
209+ {"DB2(TYPE4:Universal)","db2","//%HostName%%PortNumber%/%DataBaseName%","com.ibm.db2.jcc.DB2Driver","","00.1"},
205210 {"DB2(TYPE2:Universal)","db2","%DataBaseName%","com.ibm.db2.jcc.DB2Driver","","00.0"},
206211 {"DB2(TYPE2:App)","db2","%DataBaseName%","COM.ibm.db2.jdbc.app.DB2Driver","","00.0"},
207212 {"DB2(TYPE3:Net)","db2","//%HostName%%PortNumber%/%DataBaseName%","COM.ibm.db2.jdbc.net.DB2Driver","","00.0"},
diff -r 0f88dae1c9ae -r 3564c6cff517 src/jdbcacsess2/main/ConfigProperty.java
--- a/src/jdbcacsess2/main/ConfigProperty.java Mon Mar 26 14:02:57 2012 +0900
+++ b/src/jdbcacsess2/main/ConfigProperty.java Sat Mar 31 15:19:10 2012 +0900
@@ -16,19 +16,17 @@
1616
1717 package jdbcacsess2.main;
1818
19-import jdbcacsess2.main.ConfigProperty.ConfigPropertyImpl;
2019 import net.java.ao.Entity;
21-import net.java.ao.Implementation;
2220 import net.java.ao.Preload;
23-import net.java.ao.schema.Ignore;
21+import net.java.ao.schema.NotNull;
2422 import net.java.ao.schema.Unique;
2523
24+
2625 /**
2726 * @author sima
2827 *
2928 */
3029 @Preload
31-@Implementation(ConfigPropertyImpl.class)
3230 public interface ConfigProperty extends Entity {
3331
3432 enum Type {
@@ -36,70 +34,16 @@
3634 }
3735
3836 @Unique
37+ @NotNull
3938 String getName();
4039 void setName(String name);
4140
41+ @NotNull
4242 Type getType();
4343 void setType(Type name);
4444
45+ @NotNull
4546 String getValue();
4647 void setValue(String value);
4748
48- @Ignore
49- public <T> T readProperty(Class<T> c);
50-
51- @Ignore
52- public void writeProperty(String name, String value);
53-
54- @Ignore
55- public void writeProperty(String name, Integer value);
56-
57- @Ignore
58- public void writeProperty(String name, Boolean value);
59-
60- public class ConfigPropertyImpl {
61- private final ConfigProperty configProperty;
62-
63- public ConfigPropertyImpl(ConfigProperty configProperty) {
64- this.configProperty = configProperty;
65- }
66-
67- @SuppressWarnings("unchecked")
68- public <T> T readProperty(Class<T> c) {
69- switch (configProperty.getType()) {
70- case STRING:
71- return (T) configProperty.getValue();
72- case NUMBER:
73- try {
74- return c.getConstructor().newInstance(configProperty.getValue());
75- } catch (Exception e) {
76- ShowDialog.errorMessage(e);
77- }
78- case BOOLEAN:
79- return (T) Boolean.valueOf(configProperty.getValue());
80- default:
81- break;
82- }
83- return null;
84- }
85-
86- public void writeProperty(String name, String value) {
87- writeProperty(name, Type.STRING, value);
88- }
89-
90- public void writeProperty(String name, Number value) {
91- writeProperty(name, Type.NUMBER, value.toString());
92- }
93-
94- public void writeProperty(String name, Boolean value) {
95- writeProperty(name, Type.BOOLEAN, value.toString());
96- }
97-
98- private void writeProperty(String name, Type type, String value) {
99- configProperty.setName(name);
100- configProperty.setType(type);
101- configProperty.setValue(value);
102- configProperty.save();
103- }
104- }
10549 }
diff -r 0f88dae1c9ae -r 3564c6cff517 src/jdbcacsess2/main/OptionValues.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdbcacsess2/main/OptionValues.java Sat Mar 31 15:19:10 2012 +0900
@@ -0,0 +1,91 @@
1+/*
2+ * Copyright 2012 Kazuhiro Shimada
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+package jdbcacsess2.main;
18+
19+import java.sql.SQLException;
20+
21+import jdbcacsess2.main.ConfigProperty.Type;
22+import net.java.ao.DBParam;
23+import net.java.ao.EntityManager;
24+import net.java.ao.Query;
25+
26+public class OptionValues {
27+ private final EntityManager entityManager;
28+
29+ public Prop<String> propString = new Prop<String>("STRING", "STR");
30+ public Prop<Integer> propInteger = new Prop<Integer>("INTEGER", 100);
31+ public Prop<Boolean> propBoolean = new Prop<Boolean>("BOOLEAN", true);
32+
33+ OptionValues(EntityManager entityManager) {
34+ this.entityManager = entityManager;
35+ }
36+
37+ public class Prop<T> {
38+ private final String name;
39+ private final T defaultValue;
40+ private final Class<? extends Object> c;
41+
42+ Prop(String name, T defaultValue) {
43+ this.name = name;
44+ c = defaultValue.getClass();
45+ this.defaultValue = defaultValue;
46+ }
47+
48+ public T getValue() throws SQLException {
49+ ConfigProperty[] e = entityManager.find(ConfigProperty.class, Query.select().where("NAME=?", name));
50+ if (e.length != 0) {
51+ switch (e[0].getType()) {
52+ case STRING:
53+ return (T) e[0].getValue();
54+ case NUMBER:
55+ try {
56+ return (T) c.getConstructor(String.class).newInstance(e[0].getValue());
57+ } catch (Exception ex) {
58+ ShowDialog.errorMessage(ex);
59+ break;
60+ }
61+ case BOOLEAN:
62+ return (T) Boolean.valueOf(e[0].getValue());
63+ default:
64+ break;
65+ }
66+ return null;
67+ }
68+ Type type = Type.NUMBER;
69+ if (c == String.class) {
70+ type = Type.STRING;
71+ }
72+ if (c == Boolean.class) {
73+ type = Type.BOOLEAN;
74+ }
75+ ConfigProperty rtn =
76+ entityManager.create(ConfigProperty.class,
77+ new DBParam("NAME", name),
78+ new DBParam("TYPE", type),
79+ new DBParam("VALUE", defaultValue));
80+ return defaultValue;
81+ }
82+
83+ public void setValue(T value) throws SQLException {
84+ ConfigProperty[] e = entityManager.find(ConfigProperty.class, Query.select().where("NAME=?", name));
85+ if (e.length != 0) {
86+ e[0].setValue(value.toString());
87+ e[0].save();
88+ }
89+ }
90+ }
91+}
Show on old repository browser