全てを再実装したJdbcAcsessです。
Revisión | 3564c6cff51719e2fce84d0aa452ad8e87e67509 (tree) |
---|---|
Tiempo | 2012-03-31 15:19:10 |
Autor | shimakazuro |
Commiter | shimakazuro |
パラメータの保存とりあえず完成
@@ -52,6 +52,8 @@ | ||
52 | 52 | |
53 | 53 | private final EntityManager entityManager; |
54 | 54 | |
55 | + public OptionValues optionValues; | |
56 | + | |
55 | 57 | /** |
56 | 58 | * コンストラクタ |
57 | 59 | * |
@@ -122,6 +124,9 @@ | ||
122 | 124 | Jdbcacsess2.logger.info("Migrate end"); |
123 | 125 | setUpConfigDbms(); |
124 | 126 | |
127 | + // プロパティの作成 | |
128 | + optionValues = new OptionValues(getEntityManager()); | |
129 | + | |
125 | 130 | Jdbcacsess2.logger.info("Config end"); |
126 | 131 | } |
127 | 132 |
@@ -201,7 +206,7 @@ | ||
201 | 206 | {"Oracle(TYPE4:Pure Java)","oracle:thin","@%HostName%%PortNumber%:%DataBaseName%","oracle.jdbc.driver.OracleDriver","","00.0"}, |
202 | 207 | {"Oracle(TYPE2:NET)","oracle:oci","@%DataBaseName%","oracle.jdbc.driver.OracleDriver","","00.0"}, |
203 | 208 | {"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"}, | |
205 | 210 | {"DB2(TYPE2:Universal)","db2","%DataBaseName%","com.ibm.db2.jcc.DB2Driver","","00.0"}, |
206 | 211 | {"DB2(TYPE2:App)","db2","%DataBaseName%","COM.ibm.db2.jdbc.app.DB2Driver","","00.0"}, |
207 | 212 | {"DB2(TYPE3:Net)","db2","//%HostName%%PortNumber%/%DataBaseName%","COM.ibm.db2.jdbc.net.DB2Driver","","00.0"}, |
@@ -16,19 +16,17 @@ | ||
16 | 16 | |
17 | 17 | package jdbcacsess2.main; |
18 | 18 | |
19 | -import jdbcacsess2.main.ConfigProperty.ConfigPropertyImpl; | |
20 | 19 | import net.java.ao.Entity; |
21 | -import net.java.ao.Implementation; | |
22 | 20 | import net.java.ao.Preload; |
23 | -import net.java.ao.schema.Ignore; | |
21 | +import net.java.ao.schema.NotNull; | |
24 | 22 | import net.java.ao.schema.Unique; |
25 | 23 | |
24 | + | |
26 | 25 | /** |
27 | 26 | * @author sima |
28 | 27 | * |
29 | 28 | */ |
30 | 29 | @Preload |
31 | -@Implementation(ConfigPropertyImpl.class) | |
32 | 30 | public interface ConfigProperty extends Entity { |
33 | 31 | |
34 | 32 | enum Type { |
@@ -36,70 +34,16 @@ | ||
36 | 34 | } |
37 | 35 | |
38 | 36 | @Unique |
37 | + @NotNull | |
39 | 38 | String getName(); |
40 | 39 | void setName(String name); |
41 | 40 | |
41 | + @NotNull | |
42 | 42 | Type getType(); |
43 | 43 | void setType(Type name); |
44 | 44 | |
45 | + @NotNull | |
45 | 46 | String getValue(); |
46 | 47 | void setValue(String value); |
47 | 48 | |
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 | - } | |
105 | 49 | } |
@@ -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 | +} |