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  import javax.xml.bind.JAXBContext;
20  import javax.xml.bind.JAXBException;
21  import javax.xml.bind.Unmarshaller;
22  
23  import org.kuali.common.impex.model.DataType;
24  import org.kuali.common.impex.model.Schema;
25  import org.kuali.common.impex.model.Table;
26  import org.kuali.common.util.LocationUtils;
27  
28  
29  
30  
31  public class ProducerUtils {
32  
33  	
34  	public static final String NEWLINE = "\n";
35  	public static final String COMMA = ",";
36  	public static final String DOT = ".";
37  	public static final String SPACE = " ";
38  
39  	
40  
41  
42  
43  
44  	private static final int MAX_TABLE_NAME_SNIPPET_SIZE_FOR_PK = 27;
45  
46  	private static final String PRIMARY_KEY_SUFFIX = "P1";
47  	public static final char SINGLE_QUOTE = '\'';
48  	public static final String TYPE_SIZE_PREFIX = "(";
49  	public static final String TYPE_SIZE_SUFFIX = ")";
50  	public static final String NOT_NULL = "NOT NULL";
51  	public static final String NEWLINE_TAB = "\n\t";
52  
53  	public static String generatePrimaryKeyName(Table t) {
54  		StringBuilder sb = new StringBuilder();
55  
56  		
57  		String truncated = t.getName();
58  		if (truncated.length() > MAX_TABLE_NAME_SNIPPET_SIZE_FOR_PK) {
59  			truncated = truncated.substring(0, MAX_TABLE_NAME_SNIPPET_SIZE_FOR_PK);
60  		}
61  
62  		sb.append(truncated).append(PRIMARY_KEY_SUFFIX);
63  
64  		return sb.toString();
65  	}
66  
67  	public static boolean isDateType(DataType dataType) {
68  		if (dataType == null) {
69  			return false;
70  		}
71  
72  		return dataType == DataType.DATE || dataType == DataType.TIMESTAMP;
73  	}
74  
75  	
76  
77  
78  
79  
80  
81  
82  
83  
84  	public static Schema unmarshalSchema(String xmlLocation) throws JAXBException, IOException {
85  		JAXBContext context = JAXBContext.newInstance(Schema.class);
86  		Unmarshaller unmarshaller = context.createUnmarshaller();
87  
88  		return (Schema) unmarshaller.unmarshal(LocationUtils.getBufferedReader(xmlLocation));
89  	}
90  }