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

mybatis / ibatis-2 / 678

27 Dec 2025 01:13AM UTC coverage: 65.584% (+0.05%) from 65.532%
678

push

github

hazendaz
Merge remote-tracking branch 'upstream/master' into support-javax

1606 of 2810 branches covered (57.15%)

167 of 305 new or added lines in 90 files covered. (54.75%)

6 existing lines in 4 files now uncovered.

5067 of 7726 relevant lines covered (65.58%)

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
  @Override
38
  public void initialize(Map properties) {
39
    try {
40
      InitialContext initCtx = null;
×
NEW
41
      Properties context = getContextProperties(properties);
×
42

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

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

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

67
  @Override
68
  public DataSource getDataSource() {
69
    return dataSource;
×
70
  }
71

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

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

© 2026 Coveralls, Inc