1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.impex;
17
18 import java.io.IOException;
19
20 import javax.xml.bind.JAXBContext;
21 import javax.xml.bind.JAXBException;
22 import javax.xml.bind.Unmarshaller;
23
24 import org.kuali.common.impex.model.DataType;
25 import org.kuali.common.impex.model.Schema;
26 import org.kuali.common.impex.model.Table;
27 import org.kuali.common.util.LocationUtils;
28
29
30
31
32 public class ProducerUtils {
33
34
35 public static final String NEWLINE = "\n";
36 public static final String COMMA = ",";
37 public static final String DOT = ".";
38 public static final String SPACE = " ";
39 public static final String STATEMENT_SEPARATOR = "/";
40
41
42
43
44
45
46 private static final int MAX_TABLE_NAME_SNIPPET_SIZE_FOR_PK = 27;
47
48 private static final String PRIMARY_KEY_SUFFIX = "P1";
49 public static final char SINGLE_QUOTE = '\'';
50 public static final String TYPE_SIZE_PREFIX = "(";
51 public static final String TYPE_SIZE_SUFFIX = ")";
52 public static final String NOT_NULL = "NOT NULL";
53 public static final String NEWLINE_TAB = "\n\t";
54
55 public static String generatePrimaryKeyName(Table t) {
56 StringBuilder sb = new StringBuilder();
57
58
59 String truncated = t.getName();
60 if (truncated.length() > MAX_TABLE_NAME_SNIPPET_SIZE_FOR_PK) {
61 truncated = truncated.substring(0, MAX_TABLE_NAME_SNIPPET_SIZE_FOR_PK);
62 }
63
64 sb.append(truncated).append(PRIMARY_KEY_SUFFIX);
65
66 return sb.toString();
67 }
68
69 public static boolean isDateType(DataType dataType) {
70 if (dataType == null) {
71 return false;
72 }
73
74 return dataType == DataType.DATE || dataType == DataType.TIMESTAMP;
75 }
76
77 public static boolean isTextType(DataType dataType) {
78 if (dataType == null) {
79 return false;
80 }
81
82 return dataType == DataType.STRING || dataType == DataType.CLOB;
83 }
84
85
86
87
88
89
90
91
92
93
94 public static Schema unmarshalSchema(String xmlLocation) throws JAXBException, IOException {
95 JAXBContext context = JAXBContext.newInstance(Schema.class);
96 Unmarshaller unmarshaller = context.createUnmarshaller();
97
98 return (Schema) unmarshaller.unmarshal(LocationUtils.getBufferedReader(xmlLocation));
99 }
100 }