Debian Codegraph @

src/main/org/h2/server/web/ConnectionInfo.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.server.web;
7
8 import org.h2.util.StringUtils;
9
10 /**
11 * The connection info object is a wrapper for database connection information
12 * such as the database URL, user name and password.
13 * This class is used by the H2 Console.
14 */
15 public class ConnectionInfo implements Comparable<ConnectionInfo> {
16 /**
17 * The driver class name.
18 */
19 public String driver;
20
21 /**
22 * The database URL.
23 */
24 public String url;
25
26 /**
27 * The user name.
28 */
29 public String user;
30
31 /**
32 * The connection display name.
33 */
34 String name;
35
36 /**
37 * The last time this connection was used.
38 */
39 int lastAccess;
40
41 ConnectionInfo() {
42 // nothing to do
43 }
44
45 public ConnectionInfo(String data) {
46 String[] array = StringUtils.arraySplit(data, '|', false);
47 name = get(array, 0);
48 driver = get(array, 1);
49 url = get(array, 2);
50 user = get(array, 3);
51 }
52
53 private static String get(String[] array, int i) {
54 return array != null && array.length > i ? array[i] : "";
55 }
56
57 String getString() {
58 return StringUtils.arrayCombine(new String[] { name, driver, url, user }, '|');
59 }
60
61 @Override
62 public int compareTo(ConnectionInfo o) {
63 return Integer.compare(o.lastAccess, lastAccess);
64 }
65
66 }