EMMA Coverage Report (generated Sun Mar 01 22:06:14 CET 2015)
[all classes][org.h2.jdbcx]

COVERAGE SUMMARY FOR SOURCE FILE [JdbcDataSourceFactory.java]

nameclass, %method, %block, %line, %
JdbcDataSourceFactory.java100% (1/1)100% (5/5)96%  (125/130)96%  (25/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JdbcDataSourceFactory100% (1/1)100% (5/5)96%  (125/130)96%  (25/26)
getTraceSystem (): TraceSystem 100% (1/1)84%  (27/32)83%  (5/6)
<static initializer> 100% (1/1)100% (3/3)100% (2/2)
JdbcDataSourceFactory (): void 100% (1/1)100% (8/8)100% (3/3)
getObjectInstance (Object, Name, Context, Hashtable): Object 100% (1/1)100% (84/84)100% (14/14)
getTrace (): Trace 100% (1/1)100% (3/3)100% (1/1)

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 */
6package org.h2.jdbcx;
7 
8import java.util.Hashtable;
9 
10import javax.naming.Context;
11import javax.naming.Name;
12import javax.naming.Reference;
13import javax.naming.spi.ObjectFactory;
14 
15import org.h2.engine.Constants;
16import org.h2.engine.SysProperties;
17import org.h2.message.Trace;
18import org.h2.message.TraceSystem;
19 
20/**
21 * This class is used to create new DataSource objects.
22 * An application should not use this class directly.
23 */
24public class JdbcDataSourceFactory implements ObjectFactory {
25 
26    private static TraceSystem cachedTraceSystem;
27    private final Trace trace;
28 
29    static {
30        org.h2.Driver.load();
31    }
32 
33    /**
34     * The public constructor to create new factory objects.
35     */
36    public JdbcDataSourceFactory() {
37        trace = getTraceSystem().getTrace("JDBCX");
38    }
39 
40    /**
41     * Creates a new object using the specified location or reference
42     * information.
43     *
44     * @param obj the reference (this factory only supports objects of type
45     *            javax.naming.Reference)
46     * @param name unused
47     * @param nameCtx unused
48     * @param environment unused
49     * @return the new JdbcDataSource, or null if the reference class name is
50     *         not JdbcDataSource.
51     */
52    @Override
53    public synchronized Object getObjectInstance(Object obj, Name name,
54            Context nameCtx, Hashtable<?, ?> environment) {
55        if (trace.isDebugEnabled()) {
56            trace.debug("getObjectInstance obj={0} name={1} " +
57                    "nameCtx={2} environment={3}", obj, name, nameCtx, environment);
58        }
59        if (obj instanceof Reference) {
60            Reference ref = (Reference) obj;
61            if (ref.getClassName().equals(JdbcDataSource.class.getName())) {
62                JdbcDataSource dataSource = new JdbcDataSource();
63                dataSource.setURL((String) ref.get("url").getContent());
64                dataSource.setUser((String) ref.get("user").getContent());
65                dataSource.setPassword((String) ref.get("password").getContent());
66                dataSource.setDescription((String) ref.get("description").getContent());
67                String s = (String) ref.get("loginTimeout").getContent();
68                dataSource.setLoginTimeout(Integer.parseInt(s));
69                return dataSource;
70            }
71        }
72        return null;
73    }
74 
75    /**
76     * INTERNAL
77     */
78    public static TraceSystem getTraceSystem() {
79        synchronized (JdbcDataSourceFactory.class) {
80            if (cachedTraceSystem == null) {
81                cachedTraceSystem = new TraceSystem(
82                        SysProperties.CLIENT_TRACE_DIRECTORY + "h2datasource" +
83                                Constants.SUFFIX_TRACE_FILE);
84                cachedTraceSystem.setLevelFile(SysProperties.DATASOURCE_TRACE_LEVEL);
85            }
86            return cachedTraceSystem;
87        }
88    }
89 
90    Trace getTrace() {
91        return trace;
92    }
93 
94}

[all classes][org.h2.jdbcx]
EMMA 2.0.5312 (C) Vladimir Roubtsov