1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.common.database.model;
21
22 import org.waarp.common.database.DbAdmin;
23 import org.waarp.common.database.exception.WaarpDatabaseNoConnectionException;
24
25 import java.util.ArrayList;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.Set;
29
30
31
32
33 public class DbModelFactory {
34
35
36
37
38 public static final Set<String> classLoaded = new HashSet<String>();
39
40
41
42 public static final List<DbModel> dbModels = new ArrayList<DbModel>();
43
44
45
46
47
48
49
50
51
52
53
54
55 public static DbAdmin initialize(final String dbdriver, final String dbserver,
56 final String dbuser, final String dbpasswd,
57 final boolean write)
58 throws WaarpDatabaseNoConnectionException {
59 final DbType type = DbType.getFromDriver(dbdriver);
60 final DbModel dbModel = null;
61 switch (type) {
62 case H2:
63
64 break;
65 case Oracle:
66
67 break;
68 case PostGreSQL:
69
70 break;
71 case MySQL:
72
73 break;
74 case MariaDB:
75
76 break;
77 default:
78 throw new WaarpDatabaseNoConnectionException(
79 "TypeDriver unknown: " + type);
80 }
81 if (dbModel == null) {
82 throw new WaarpDatabaseNoConnectionException(
83 "TypeDriver not allocated: " + type);
84 }
85 dbModels.add(dbModel);
86 return new DbAdmin(dbModel, dbserver, dbuser, dbpasswd, write);
87 }
88
89
90
91
92
93
94
95
96 public static boolean containsDbType(final DbType... types) {
97 for (final DbModel dbModel : dbModels) {
98 for (final DbType dbType : types) {
99 if (dbModel.getDbType() == dbType) {
100 return true;
101 }
102 }
103 }
104 return false;
105 }
106 }