File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\server\web\ConnectionInfo.java.html

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