Inspector | Message | Severity | Location |
---|---|---|---|
Java Inspector 031 | Switch statement case without 'break' | 1 | 51:17 |
Java Inspector 048 | Copyrights information should be present in each file. | 1 | |
Java Inspector 049 | Use a Collection instead of arrays Object[] | 2 | 24:9 |
Java Inspector 089 | Constructor documentation is too short. It is only 1 words. Should be at least 3 words. | 2 | 30:9 |
Java Inspector 089 | Undocumented method | 2 | 42:9 |
Java Inspector 025 | Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] | 3 | 37:30 |
Java Inspector 025 | Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] | 3 | 51:22 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 18:22 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 31:21 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 33:44 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 46:36 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 57:57 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 60:69 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 60:85 |
Java Inspector 051 | It is good practice to call in any case super() in a constructor. | 3 | 17:9 |
Java Inspector 051 | It is good practice to call in any case super() in a constructor. | 3 | 30:9 |
Java Inspector 054 | Discourage usage of instance variables like a, j by enforcing minimal variable name length (3). | 3 | 23:9 |
1package biz.hammurapi.sql;
2
3import java.sql.Connection;
4import java.sql.SQLException;
5import java.text.MessageFormat;
6
7/**
8 * Generates identities using SQLProcessor nextPK method
9 * @author Pavel Vlasov
10 *
11 */
12public class OracleSequenceIdentityGenerator implements IdentityGenerator {
13
14 /**
15 * Default constructor with "{0}_SEQ" pattern
16 */
17 public OracleSequenceIdentityGenerator() {
18 this("{0}_SEQ");
19 }
20
21 private int mode; // 0 - passthrough 1 - invariant 2 - format
22 private String seqName;
23 private MessageFormat mf;
24 private Object[] args=new Object[] {null};
25
26 /**
27 * Constructor
28 * @param pattern - Key name pattern. {0} stands for table name.
29 */
30 public OracleSequenceIdentityGenerator(String pattern) {
31 if ("{0}".equals(pattern)) {
32 mode=0;
33 } else if (pattern.indexOf("{0}")==-1) {
34 mode=1;
35 this.seqName=pattern;
36 } else {
37 mode=2;
38 mf=new MessageFormat(pattern);
39 }
40 }
41
42 public int generate(Connection con, String name) throws SQLException {
43 String ename;
44 switch (mode) {
45 case 0:
46 ename=name+"_SEQ";
47 break;
48 case 1:
49 ename=seqName;
50 break;
51 case 2:
52 synchronized (mf) {
53 args[0]=name;
54 ename=mf.format(args, new StringBuffer(), null).toString();
55 }
56 default:
57 throw new IllegalStateException("Invalid mode: "+mode);
58 }
59
60 return new SQLProcessor(con, null).projectSingleInt("SELECT "+ename+".NEXTVAL FROM DUAL", null);
61 }
62
63}
64