| 50 | | public EmdrosDatabase(EmdrosEnv env, String username, String userhost, |
|---|
| 51 | | String database, Connection conn) |
|---|
| 52 | | { |
|---|
| 53 | | this.env = env; |
|---|
| 54 | | this.conn = conn; |
|---|
| 55 | | this.username = username; |
|---|
| 56 | | this.userhost = userhost; |
|---|
| 57 | | this.database = database; |
|---|
| 58 | | } |
|---|
| 59 | | |
|---|
| 60 | | public void setLogDatabaseHandle(Connection conn) |
|---|
| 61 | | { |
|---|
| 62 | | try |
|---|
| 63 | | { |
|---|
| 64 | | this.conn.close(); |
|---|
| 65 | | } |
|---|
| 66 | | catch (SQLException e) |
|---|
| 67 | | { |
|---|
| 68 | | m_LOG.error("Failed to close old database connection: "+e); |
|---|
| 69 | | } |
|---|
| 70 | | this.conn = conn; |
|---|
| 71 | | } |
|---|
| 72 | | |
|---|
| | 52 | public EmdrosDatabase(String dbHost, String dbName, String dbUser, |
|---|
| | 53 | String dbPass, String logUser, String logFrom, Connection logDb) |
|---|
| | 54 | throws DatabaseException |
|---|
| | 55 | { |
|---|
| | 56 | env = new EmdrosEnv(eOutputKind.kOKConsole, |
|---|
| | 57 | eCharsets.kCSISO_8859_1, dbHost, dbUser, dbPass, dbName); |
|---|
| | 58 | |
|---|
| | 59 | if (!env.connectionOk()) |
|---|
| | 60 | { |
|---|
| | 61 | throw new DatabaseException("Failed to connect to database", |
|---|
| | 62 | new Exception(env.getDBError())); |
|---|
| | 63 | } |
|---|
| | 64 | |
|---|
| | 65 | this.conn = logDb; |
|---|
| | 66 | this.username = logUser; |
|---|
| | 67 | this.userhost = logUser + "@" + logFrom; |
|---|
| | 68 | this.database = dbName; |
|---|
| | 69 | } |
|---|
| | 70 | |
|---|
| | 71 | public boolean isAlive() |
|---|
| | 72 | { |
|---|
| | 73 | return env.connectionOk(); |
|---|
| | 74 | } |
|---|
| | 75 | |
|---|
| 146 | | Table min_m_table = getTable("SELECT MIN_M"); |
|---|
| 147 | | try |
|---|
| 148 | | { |
|---|
| 149 | | return Integer.parseInt |
|---|
| 150 | | ( |
|---|
| 151 | | min_m_table.iterator().next().iterator().next() |
|---|
| 152 | | ); |
|---|
| 153 | | } |
|---|
| 154 | | catch (TableException e) |
|---|
| 155 | | { |
|---|
| 156 | | throw new DatabaseException("Failed to get MIN_M", e, |
|---|
| 157 | | "SELECT MIN_M"); |
|---|
| 158 | | } |
|---|
| 159 | | } |
|---|
| 160 | | |
|---|
| 161 | | public int getMaxM() throws DatabaseException |
|---|
| 162 | | { |
|---|
| 163 | | Table max_m_table = getTable("SELECT MAX_M"); |
|---|
| 164 | | |
|---|
| 165 | | try |
|---|
| 166 | | { |
|---|
| 167 | | return Integer.parseInt |
|---|
| 168 | | ( |
|---|
| 169 | | max_m_table.iterator().next().iterator().next() |
|---|
| 170 | | ); |
|---|
| 171 | | } |
|---|
| 172 | | catch (TableException e) |
|---|
| 173 | | { |
|---|
| 174 | | throw new DatabaseException("Failed to get MAX_M", e, |
|---|
| 175 | | "SELECT MAX_M"); |
|---|
| 176 | | } |
|---|
| 177 | | } |
|---|
| 178 | | |
|---|
| | 152 | int [] min_m = new int[1]; |
|---|
| | 153 | |
|---|
| | 154 | if (!env.getMin_m(min_m)) |
|---|
| | 155 | { |
|---|
| | 156 | throw new DatabaseException("Failed to get MIN_M", |
|---|
| | 157 | new Exception(env.getDBError())); |
|---|
| | 158 | } |
|---|
| | 159 | |
|---|
| | 160 | return min_m[0]; |
|---|
| | 161 | } |
|---|
| | 162 | |
|---|
| | 163 | public int getMaxM() throws DatabaseException |
|---|
| | 164 | { |
|---|
| | 165 | int [] max_m = new int[1]; |
|---|
| | 166 | |
|---|
| | 167 | if (!env.getMax_m(max_m)) |
|---|
| | 168 | { |
|---|
| | 169 | throw new DatabaseException("Failed to get MAX_M", |
|---|
| | 170 | new Exception(env.getDBError())); |
|---|
| | 171 | } |
|---|
| | 172 | |
|---|
| | 173 | return max_m[0]; |
|---|
| | 174 | } |
|---|
| | 175 | |
|---|
| 433 | | public String getVisibleMonadString() |
|---|
| 434 | | throws SQLException |
|---|
| 435 | | { |
|---|
| 436 | | PreparedStatement stmt = conn.prepareStatement |
|---|
| 437 | | ( |
|---|
| 438 | | "SELECT Monad_First, Monad_Last " + |
|---|
| 439 | | "FROM user_text_access " + |
|---|
| 440 | | "WHERE (User_Name = ? OR User_Name = 'anonymous')" |
|---|
| 441 | | ); |
|---|
| 442 | | stmt.setString(1, username); |
|---|
| 443 | | |
|---|
| 444 | | ResultSet rs = stmt.executeQuery(); |
|---|
| 445 | | StringBuffer result = new StringBuffer(); |
|---|
| 446 | | result.append("{"); |
|---|
| 447 | | boolean haveMonads = false; |
|---|
| 448 | | |
|---|
| 449 | | while (rs.next()) |
|---|
| 450 | | { |
|---|
| 451 | | haveMonads = true; |
|---|
| 452 | | String first = rs.getString(1); |
|---|
| 453 | | String last = rs.getString(2); |
|---|
| 454 | | result.append(first+"-"+last); |
|---|
| 455 | | if (!rs.isLast()) |
|---|
| 456 | | { |
|---|
| 457 | | result.append(","); |
|---|
| 458 | | } |
|---|
| 459 | | } |
|---|
| 460 | | |
|---|
| 461 | | result.append("}"); |
|---|
| 462 | | |
|---|
| 463 | | stmt.close(); |
|---|
| 464 | | rs.close(); |
|---|
| 465 | | |
|---|
| 466 | | if (!haveMonads) |
|---|
| 467 | | { |
|---|
| 468 | | return null; |
|---|
| 469 | | } |
|---|
| 470 | | |
|---|
| 471 | | return result.toString(); |
|---|
| 472 | | } |
|---|
| 473 | | |
|---|