1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.impex.schema.impl.mysql;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.kuali.common.impex.ProducerUtils;
22 import org.kuali.common.impex.model.View;
23 import org.kuali.common.util.CollectionUtils;
24
25 public class MySqlViewSqlProducer {
26
27 protected static final String DROP_PREFIX = "DROP VIEW IF EXISTS ";
28
29 protected static final String CREATE_PREFIX = "CREATE VIEW ";
30 protected static final String CREATE_AS_KEYWORD = " AS\n";
31
32
33 public List<String> getViewsSql(List<View> views) {
34 List<String> results = new ArrayList<String>();
35
36 for (View view : CollectionUtils.toEmptyList(views)) {
37 results.addAll(generateStatementsForView(view));
38 }
39
40 return results;
41 }
42
43 protected List<String> generateStatementsForView(View view) {
44 List<String> results = new ArrayList<String>(2);
45
46 StringBuilder sb = new StringBuilder();
47
48 sb.append(DROP_PREFIX);
49 sb.append(view.getName());
50 sb.append(ProducerUtils.NEWLINE);
51
52 results.add(sb.toString());
53 sb = new StringBuilder();
54
55 sb.append(CREATE_PREFIX);
56 sb.append(view.getName());
57 sb.append(CREATE_AS_KEYWORD);
58 sb.append(view.getQueryString());
59 sb.append(ProducerUtils.NEWLINE);
60 results.add(sb.toString());
61
62 return results;
63 }
64 }