Skip to content

Commit 141d803

Browse files
BB8DBB8D
authored andcommitted
Finish JavaDoc and README
1 parent 6edeb24 commit 141d803

File tree

2 files changed

+165
-25
lines changed

2 files changed

+165
-25
lines changed

README.md

Lines changed: 164 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,164 @@
1-
# NORDSTROM COMMON
2-
3-
**Nordstrom Common** is a small collection of general-purpose utility classes with wide applicability.
4-
5-
## UncheckedThrow
6-
7-
The **UncheckedThrow** class uses type erasure to enable client code to throw checked exceptions as unchecked. This allows methods to throw checked exceptions without requiring clients to handle or declare them. It should be sparingly, as this exempts client code from handling or declaring exceptions created by their own actions. The target use case for this facility is to throw exceptions that were serialized in responses from a remote system. Although the compiler won't require clients of methods using this technique to handle or declare the suppressed exception, the JavaDoc for such methods should include a `@throws` declaration for implementers who might want to handle or declare it voluntarily.
8-
9-
10-
```java
11-
...
12-
13-
String value;
14-
try {
15-
value = URLDecoder.decode(keyVal[1], "UTF-8");
16-
} catch (UnsupportedEncodingException e) {
17-
UncheckedThrow.throwUnchecked(e);
18-
}
19-
20-
...
21-
```
22-
23-
## DatabaseUtils
24-
1+
# NORDSTROM COMMON
2+
3+
**Nordstrom Common** is a small collection of general-purpose utility classes with wide applicability.
4+
5+
## UncheckedThrow
6+
7+
The **UncheckedThrow** class uses type erasure to enable client code to throw checked exceptions as unchecked. This allows methods to throw checked exceptions without requiring clients to handle or declare them. It should be sparingly, as this exempts client code from handling or declaring exceptions created by their own actions. The target use case for this facility is to throw exceptions that were serialized in responses from a remote system. Although the compiler won't require clients of methods using this technique to handle or declare the suppressed exception, the JavaDoc for such methods should include a `@throws` declaration for implementers who might want to handle or declare it voluntarily.
8+
9+
10+
```java
11+
...
12+
13+
String value;
14+
try {
15+
value = URLDecoder.decode(keyVal[1], "UTF-8");
16+
} catch (UnsupportedEncodingException e) {
17+
UncheckedThrow.throwUnchecked(e);
18+
}
19+
20+
...
21+
```
22+
23+
## DatabaseUtils
24+
25+
The **DatabaseUtils** class provides facilities that enable you to define collections of Oracle database queries and execute them easily. Query collections are defined as Java enumeration that implement the `QueryAPI` interface:
26+
* `getQueryStr` - Get the query string for this constant. This is the actual query that's sent to the database.
27+
* `getArgNames` - Get the names of the arguments for this query. This provides diagnostic information if the incorrect number of arguments is specified by the client.
28+
* `getArgCount` - Get the number of arguments required by this query. This enables **DatabaseUtils** to verify that the correct number of arguments has been specified by the client.
29+
* `getConnection` - Get the connection string associated with this query. This eliminates the need for the client to provide this information.
30+
* `getEnum` - Get the enumeration to which this query belongs. This enables **DatabaseUtils** to retrieve the name of the query's enumerated constant for diagnostic messages.
31+
32+
To maximize usability and configurability, we recommend the following implementation strategy for your query collections:
33+
* Define your query collection as an enumeration that implements `QueryAPI`.
34+
* Define each query constant with a property name and a name for each argument (if any).
35+
* To assist users of your queries, preface their names with a type indicator (**GET** or **UPDATE**).
36+
* Back the query collection with a configuration that implements the `Settings API`:
37+
* groupId: com.nordstrom.test-automation.tools
38+
* artifactId: settings
39+
* className: com.nordstrom.automation.settings.SettingsCore
40+
* To support execution on multiple endpoints, implement `getConnection` with sub-configurations or other dynamic data sources (e.g. - web service).
41+
42+
##### Query Collection Example
43+
44+
```java
45+
public class OpctConfig extends SettingsCore<OpctConfig.OpctValues> {
46+
47+
private static final String SETTINGS_FILE = "OpctConfig.properties";
48+
49+
private OpctConfig() throws ConfigurationException, IOException {
50+
super(OpctValues.class);
51+
}
52+
53+
public enum OpctValues implements SettingsCore.SettingsAPI, QueryAPI {
54+
/** args: [ ] */
55+
GET_RULE_HEAD_DETAILS("opct.query.getRuleHeadDetails"),
56+
/** args: [ name, zone_id, priority, rule_type ] */
57+
GET_RULE_COUNT("opct.query.getRuleCount", "name", "zone_id", "priority", "rule_type"),
58+
/** args: [ role_id, user_id ] */
59+
UPDATE_USER_ROLE("opct.query.updateRsmUserRole", "role_id", "user_id"),
60+
/** MST connection string */
61+
MST_CONNECT("opct.connect.mst"),
62+
/** RMS connection string */
63+
RMS_CONNECT("opct.connect.rms");
64+
65+
private String key;
66+
private String[] args;
67+
private String query;
68+
69+
private static OpctConfig config;
70+
private static String mstConnect;
71+
private static String rmsConnect;
72+
73+
private static EnumSet<OpctValues> rmsQueries = EnumSet.of(UPDATE_USER_ROLE);
74+
75+
static {
76+
try {
77+
config = new OpctConfig();
78+
} catch (ConfigurationException | IOException e) {
79+
throw new RuntimeException("Unable to instantiate OPCT configuration object", e);
80+
}
81+
}
82+
83+
OpctValues(String key, String... args) {
84+
this.key = key;
85+
this.args = args;
86+
}
87+
88+
@Override
89+
public String key() {
90+
return key;
91+
}
92+
93+
@Override
94+
public String getQueryStr() {
95+
if (query == null) {
96+
query = config.getString(key);
97+
}
98+
return query;
99+
}
100+
101+
@Override
102+
public String[] getArgNames() {
103+
return args;
104+
}
105+
106+
@Override
107+
public int getArgCount() {
108+
return args.length;
109+
}
110+
111+
@Override
112+
public String getConnection() {
113+
if (rmsQueries.contains(this)) {
114+
return getRmsConnect();
115+
} else {
116+
return getMstConnect();
117+
}
118+
}
119+
120+
@Override
121+
public Enum<OpctValues> getEnum() {
122+
return this;
123+
}
124+
125+
/**
126+
* Get MST connection string.
127+
*
128+
* @return MST connection string
129+
*/
130+
public static String getMstConnect() {
131+
if (mstConnect == null) {
132+
mstConnect = config.getString(OpctValues.MST_CONNECT.key());
133+
}
134+
return mstConnect;
135+
}
136+
137+
/**
138+
* Get RMS connection string.
139+
*
140+
* @return RMS connection string
141+
*/
142+
public static String getRmsConnect() {
143+
if (rmsConnect == null) {
144+
rmsConnect = config.getString(OpctValues.RMS_CONNECT.key());
145+
}
146+
return rmsConnect;
147+
}
148+
}
149+
150+
@Override
151+
public String getSettingsPath() {
152+
return SETTINGS_FILE;
153+
}
154+
155+
/**
156+
* Get OPCT configuration object.
157+
*
158+
* @return OPCT configuration object
159+
*/
160+
public static OpctConfig getConfig() {
161+
return OpctValues.config;
162+
}
163+
}
164+
```

src/main/java/com/nordstrom/common/jdbc/DatabaseUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* collections: <ul>
3333
* <li>Define your query collection as an enumeration that implements {@link QueryAPI}.</li>
3434
* <li>Define each query constant with a property name and a name for each argument (if any).</li>
35-
* <li>To assist users of your queries, preface their names with a type indicator (GET or UPDATE).</li>
35+
* <li>To assist users of your queries, preface their names with a type indicator (<b>GET</b> or <b>UPDATE</b>).</li>
3636
* <li>Back the query collection with a configuration that implements the <b>{@code Settings API}</b>: <ul>
3737
* <li>groupId: com.nordstrom.test-automation.tools</li>
3838
* <li>artifactId: settings</li>

0 commit comments

Comments
 (0)