• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / ibatis-2 / 586

26 May 2025 08:47PM UTC coverage: 65.53% (+0.02%) from 65.509%
586

push

github

web-flow
Merge pull request #290 from hazendaz/master

Minor code cleanup

1606 of 2810 branches covered (57.15%)

15 of 24 new or added lines in 13 files covered. (62.5%)

5072 of 7740 relevant lines covered (65.53%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/ibatis/sqlmap/engine/datasource/JndiDataSourceFactory.java
1
/*
2
 * Copyright 2004-2025 the original author or authors.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *    https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.ibatis.sqlmap.engine.datasource;
17

18
import com.ibatis.sqlmap.client.SqlMapException;
19

20
import java.util.Iterator;
21
import java.util.Map;
22
import java.util.Properties;
23

24
import javax.naming.Context;
25
import javax.naming.InitialContext;
26
import javax.naming.NamingException;
27
import javax.sql.DataSource;
28

29
/**
30
 * DataSourceFactory implementation for JNDI.
31
 */
32
public class JndiDataSourceFactory implements DataSourceFactory {
×
33

34
  /** The data source. */
35
  private DataSource dataSource;
36

37
  public void initialize(Map properties) {
38
    try {
39
      InitialContext initCtx = null;
×
NEW
40
      Properties context = getContextProperties(properties);
×
41

42
      if (context == null) {
×
43
        initCtx = new InitialContext();
×
44
      } else {
45
        initCtx = new InitialContext(context);
×
46
      }
47

48
      if (properties.containsKey("DataSource")) {
×
49
        dataSource = (DataSource) initCtx.lookup((String) properties.get("DataSource"));
×
50
      } else if (properties.containsKey("DBJndiContext")) { // LEGACY --Backward compatibility
×
51
        dataSource = (DataSource) initCtx.lookup((String) properties.get("DBJndiContext"));
×
52
      } else if (properties.containsKey("DBFullJndiContext")) { // LEGACY --Backward
×
53
                                                                // compatibility
54
        dataSource = (DataSource) initCtx.lookup((String) properties.get("DBFullJndiContext"));
×
NEW
55
      } else if (properties.containsKey("DBInitialContext") && properties.containsKey("DBLookup")) {
×
56
        // LEGACY - Backward compatibility
57
        Context ctx = (Context) initCtx.lookup((String) properties.get("DBInitialContext"));
×
58
        dataSource = (DataSource) ctx.lookup((String) properties.get("DBLookup"));
×
59
      }
60

61
    } catch (NamingException e) {
×
62
      throw new SqlMapException("There was an error configuring JndiDataSourceTransactionPool. Cause: " + e, e);
×
63
    }
×
64
  }
×
65

66
  public DataSource getDataSource() {
67
    return dataSource;
×
68
  }
69

70
  /**
71
   * Gets the context properties.
72
   *
73
   * @param allProps
74
   *          the all props
75
   *
76
   * @return the context properties
77
   */
78
  private static Properties getContextProperties(Map allProps) {
79
    final String PREFIX = "context.";
×
NEW
80
    Properties contextProperties = null;
×
81
    Iterator keys = allProps.keySet().iterator();
×
82
    while (keys.hasNext()) {
×
83
      String key = (String) keys.next();
×
84
      String value = (String) allProps.get(key);
×
85
      if (key.startsWith(PREFIX)) {
×
86
        if (contextProperties == null) {
×
87
          contextProperties = new Properties();
×
88
        }
89
        contextProperties.put(key.substring(PREFIX.length()), value);
×
90
      }
91
    }
×
92
    return contextProperties;
×
93
  }
94

95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc