| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
package org.melati; |
| 47 | |
|
| 48 | |
import java.io.IOException; |
| 49 | |
import java.util.Vector; |
| 50 | |
import java.util.Properties; |
| 51 | |
|
| 52 | |
import org.melati.poem.Database; |
| 53 | |
import org.melati.poem.PoemDatabaseFactory; |
| 54 | |
import org.melati.util.DatabaseInitException; |
| 55 | |
import org.melati.util.MelatiBugMelatiException; |
| 56 | |
import org.melati.util.PropertiesUtils; |
| 57 | |
import org.melati.util.PropertyException; |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
public final class LogicalDatabase { |
| 63 | |
|
| 64 | 0 | private LogicalDatabase() {} |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | 2 | private static Properties databaseDefs = null; |
| 69 | |
|
| 70 | |
private static final int MAX_TRANSACTIONS_DEFAULT = 8; |
| 71 | |
|
| 72 | |
private static synchronized Properties databaseDefs() { |
| 73 | 64 | if (databaseDefs == null) |
| 74 | |
try { |
| 75 | 6 | databaseDefs = |
| 76 | |
PropertiesUtils.fromResource(LogicalDatabase.class, |
| 77 | |
getPropertiesName()); |
| 78 | 0 | } catch (IOException e) { |
| 79 | 0 | throw new MelatiBugMelatiException("Cannot open database properties file " + getPropertiesName(), e); |
| 80 | 6 | } |
| 81 | 64 | return databaseDefs; |
| 82 | |
} |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
public static Vector<Database> initialisedDatabases() { |
| 90 | 4 | return PoemDatabaseFactory.initialisedDatabases(); |
| 91 | |
} |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
public static Vector<String> getInitialisedDatabaseNames() { |
| 103 | 122 | return PoemDatabaseFactory.getInitialisedDatabaseNames(); |
| 104 | |
} |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
public static Database getDatabase(String name) |
| 114 | |
throws DatabaseInitException { |
| 115 | 1269 | Database db = PoemDatabaseFactory.getDatabase(name); |
| 116 | 1267 | if (db == null) { |
| 117 | 64 | Properties defs = databaseDefs(); |
| 118 | 64 | String pref = LogicalDatabase.class.getName() + "." + name + "."; |
| 119 | 64 | String url = null; |
| 120 | 64 | String user = null; |
| 121 | 64 | String pass = null; |
| 122 | 64 | String clazz = null; |
| 123 | 64 | String dbmsClass = null; |
| 124 | 64 | String addConstraints = null; |
| 125 | 64 | String logSQL = null; |
| 126 | 64 | String logCommits = null; |
| 127 | |
int maxTrans; |
| 128 | |
try { |
| 129 | 64 | url = PropertiesUtils.getOrDie(defs, pref + "url"); |
| 130 | 58 | user = PropertiesUtils.getOrDie(defs, pref + "user"); |
| 131 | 58 | pass = PropertiesUtils.getOrDie(defs, pref + "pass"); |
| 132 | 58 | clazz = PropertiesUtils.getOrDie(defs, pref + "class"); |
| 133 | 58 | dbmsClass = PropertiesUtils.getOrDie(defs, pref + "dbmsclass"); |
| 134 | 58 | addConstraints = PropertiesUtils.getOrDefault(defs, pref + "addconstraints", "false"); |
| 135 | 58 | logSQL = PropertiesUtils.getOrDefault(defs, pref + "logsql", "false"); |
| 136 | 58 | logCommits = PropertiesUtils.getOrDefault(defs, pref + "logcommits", "false"); |
| 137 | 58 | maxTrans = PropertiesUtils. |
| 138 | |
getOrDefault_int(defs, pref + "maxtransactions", MAX_TRANSACTIONS_DEFAULT); |
| 139 | 6 | } catch (PropertyException e) { |
| 140 | 6 | throw new DatabaseInitException(getPropertiesName(),name, e); |
| 141 | 58 | } |
| 142 | 58 | db = PoemDatabaseFactory.getDatabase(name, url, user, pass, |
| 143 | |
clazz, dbmsClass, |
| 144 | |
new Boolean(addConstraints).booleanValue(), |
| 145 | |
new Boolean(logSQL).booleanValue(), |
| 146 | |
new Boolean(logCommits).booleanValue(), |
| 147 | |
maxTrans); |
| 148 | |
} |
| 149 | 1259 | return db; |
| 150 | |
} |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
public static void setDatabaseDefs(Properties databaseDefsIn) { |
| 155 | 8 | databaseDefs = databaseDefsIn; |
| 156 | 8 | } |
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
public static String getPropertiesName() { |
| 165 | 14 | return "org.melati.LogicalDatabase.properties"; |
| 166 | |
} |
| 167 | |
} |
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|