(no commit message)
[utils] / system / general / src / main / java / org / wamblee / system / components / ORMappingConfig.java
1 /*
2  * Copyright 2005-2010 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.system.components;
17
18 public class ORMappingConfig {
19
20     public enum DatabaseType {
21         MYSQL_INNO_DB, DERBY;
22
23         public static interface Switch<T> {
24             T handleMySqlInnoDb();
25
26             T handleDerby();
27         }
28
29         public <T> T handleCases(Switch<T> aSwitch) {
30
31             switch (this) {
32             case MYSQL_INNO_DB: {
33                 return aSwitch.handleMySqlInnoDb();
34             }
35             case DERBY: {
36                 return aSwitch.handleDerby();
37             }
38             default: {
39                 throw new RuntimeException("Unhandled case " + this);
40             }
41             }
42         }
43     };
44
45     private boolean schemaUpdate;
46     private DatabaseType type;
47
48     public ORMappingConfig(boolean aSchemaUpdate, DatabaseType aType) {
49         schemaUpdate = aSchemaUpdate;
50         type = aType;
51     }
52
53     public boolean isSchemaUpdate() {
54         return schemaUpdate;
55     }
56
57     public DatabaseType getType() {
58         return type;
59     }
60
61 }