This article is an article that releases the stress of one SE. Depending on the content, it may be useful for someone.
For RDBMS that failed to normalize, use ~~ reflection to refresh the source to relieve stress. I don't think about performance.
First of all, I would like to say that I do not want to criticize legacy technologies such as hosts. Segment at the host? It seems that you often add a suffix to. It seems that the number of host ⇛ Web downsizing cases is decreasing these days, but it is a personal stress release for the normalization failure that I recently saw in the downsizing case.
At the time of downsizing, items such as items 01 to 05 were brought into one table as the host thought, which is the root of all evil.
Example) TBL name Account management store table Column Store code (PK) Branch 01 Branch 02 Branch 03 Branch 04 Branch 05
I wanted to have a branch office hanging under the parent store that manages the account. However, it should be normalized properly to create a "branch table that hangs from the parent store code". It's very vulnerable to changes when the number of branches increases.
I am also an engineer. And since I am hired, I am an adult (mid 30) who tries to swallow what cannot be changed and aims to respond well.
First, prepare a getter with a suffix. It's just long, so fold it up.
suffixMethods.java
package suffixMethodsCall;
public class suffixMethods {
private static String RETURN_CODE_A = "A";
private static String RETURN_CODE_B = "B";
private static String RETURN_CODE_C = "C";
private static String RETURN_CODE_D = "D";
private static String RETURN_CODE_E = "E";
private static String RETURN_CODE_F = "F";
private static String RETURN_CODE_G = "G";
private static String RETURN_CODE_H = "H";
private static String RETURN_CODE_I = "I";
private static String RETURN_CODE_J = "J";
public String getReturnCode01() {
return RETURN_CODE_A;
}
public String getReturnCode02() {
return RETURN_CODE_B;
}
public String getReturnCode03() {
return RETURN_CODE_C;
}
public String getReturnCode04() {
return RETURN_CODE_D;
}
public String getReturnCode05() {
return RETURN_CODE_E;
}
public String getReturnCode06() {
return RETURN_CODE_F;
}
public String getReturnCode07() {
return RETURN_CODE_G;
}
public String getReturnCode08() {
return RETURN_CODE_H;
}
public String getReturnCode09() {
return RETURN_CODE_I;
}
public String getReturnCode10() {
return RETURN_CODE_J;
}
}
I made an execution class.
suffixMethodsCaller.java
package suffixMethodsCall;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class suffixMethodsCaller {
/**
* <pre>
*Execute all getters with suffix included in suffixMethods,
*Verify that the matchTargetCode at the beginning is included.
* </pre>
*/
public static void main(String[] args) {
//Matching string
String matchTargetCode = "J";
//Code list obtained from the method with suffix
List<String> codeList = new ArrayList<String>();
//Specify the class and method as a character string
suffixMethods sm = new suffixMethods();
String clazz = sm.getClass().getName();
String baseSuffixMethod = "getReturnCode";
int suffixPartStart = 1;
int suffixPartEnd = 10;
//Execute a method with suffix by using reflection
try {
Class<?> c = Class.forName(clazz);
Object myObj = c.newInstance();
//Loop the suffix part and plunge into the code list
for ( ; suffixPartStart <= suffixPartEnd; suffixPartStart++) {
//Execution method settings
Method m = c.getMethod(baseSuffixMethod + String.format("%02d", suffixPartStart));
//Stuff into code list
codeList.add(m.invoke(myObj).toString());
}
} catch(ReflectiveOperationException e) {
e.printStackTrace();
}
//Whether the character string to be matched is included in the execution result list of the method with suffix is output as bool
System.out.println(codeList.contains(matchTargetCode));
}
}
It's still a bit dirty, but I've achieved my goal for the time being.
In this case, I used 10 methods with suffix as an example, but if the number increases, performance will be a concern.
You can cut out the execution part to another method and make it more refreshing.
However, if you access the reflection API or hard-code it and match it all with String.equals
, which one is better?
I will verify it again.
This time I coded it for the purpose of relieving stress, but I haven't had many opportunities to use reflection so far, so it took longer than I expected.
Downsizing and migration PJs are always really annoying. You can do it honestly, but there are many things like that.
Recommended Posts