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