View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.common.impex.schema.impl;
17  
18  import java.util.Collections;
19  
20  import org.kuali.common.impex.model.Column;
21  import org.kuali.common.impex.model.DataType;
22  import org.kuali.common.impex.model.DataTypeSize;
23  import org.kuali.common.impex.model.ForeignKey;
24  import org.kuali.common.impex.model.ForeignKeyConstraintType;
25  import org.kuali.common.impex.model.Table;
26  import org.kuali.common.impex.model.UniqueConstraint;
27  import org.kuali.common.impex.model.View;
28  
29  public class MockDataUtil {
30  
31  	public static Table buildSimpleTable() {
32  
33  		Table result = new Table("FOO_T");
34  
35  		// id column
36  		Column idCol = new Column("ID", DataType.STRING);
37  		idCol.setSize(new DataTypeSize(36));
38  		idCol.setPrimaryKey(true);
39  
40  		result.getColumns().add(idCol);
41  
42  		// createtime column
43  		Column timeCol = new Column("CREATETIME", DataType.TIMESTAMP);
44  		timeCol.setNullable(false);
45  
46  		result.getColumns().add(timeCol);
47  
48  		// count column
49  		Column countCol = new Column("FOO_COUNT", DataType.FLOAT);
50  		countCol.setSize(new DataTypeSize(10));
51  
52  		result.getColumns().add(countCol);
53  
54  		// name column
55  		Column nameCol = new Column("NAME", DataType.STRING);
56  		nameCol.setSize(new DataTypeSize(255));
57  
58  		result.getColumns().add(nameCol);
59  
60  		// unique constraint on name
61  		UniqueConstraint nameIndex = new UniqueConstraint(Collections.singletonList(nameCol.getName()), "FOO_U1_NAME");
62  
63  		result.getUniqueConstraints().add(nameIndex);
64  
65  		return result;
66  	}
67  
68  	public static View buildSimpleView() {
69  
70  		String viewSql = "SELECT ID, NAME FROM FOO_T\n" + "WHERE NAME LIKE 'TEST%'";
71  
72  		return new View("TEST_V1", viewSql);
73  	}
74  
75  	public static ForeignKey buildSimpleForeignKey() {
76  		ForeignKey fk = new ForeignKey("FOO_FK_1", "FOO_T", "BAR_T");
77  
78  		fk.setOnDelete(ForeignKeyConstraintType.CASCADE);
79  		fk.setLocalColumnNames(Collections.singletonList("BAR_ID"));
80  		fk.setForeignColumnNames(Collections.singletonList("ID"));
81  
82  		return fk;
83  	}
84  }