ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/table/TableLinkConnection.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/table/TableLinkConnection.java
Status
scanned
Type
file
Name
TableLinkConnection.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
4562 (4.5 KB)
MD5
2de045e07e4e7a923a52139cdd5b776d
SHA1
2ef782904da47349e06fd94a2961e73156783703
SHA256
53e9460ab5f785ae0822f6aa9d04d72d6b9d27e2242e3213c8b14337c07eaeb7
SHA512

      
    
SHA1_git
ba984a034a6ea07c75605b8b02f346f3511b4d23
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TableLinkConnection.java | 4.5 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.table; import java.sql.Connection; import java.sql.SQLException; import java.util.HashMap; import java.util.Objects; import org.h2.message.DbException; import org.h2.util.JdbcUtils; /** * A connection for a linked table. The same connection may be used for multiple * tables, that means a connection may be shared. */ public class TableLinkConnection { /** * The map where the link is kept. */ private final HashMap<TableLinkConnection, TableLinkConnection> map; /** * The connection information. */ private final String driver, url, user, password; /** * The database connection. */ private Connection conn; /** * How many times the connection is used. */ private int useCounter; private boolean autocommit =true; private TableLinkConnection( HashMap<TableLinkConnection, TableLinkConnection> map, String driver, String url, String user, String password) { this.map = map; this.driver = driver; this.url = url; this.user = user; this.password = password; } /** * Open a new connection. * * @param map the map where the connection should be stored * (if shared connections are enabled). * @param driver the JDBC driver class name * @param url the database URL * @param user the user name * @param password the password * @param shareLinkedConnections if connections should be shared * @return a connection */ public static TableLinkConnection open( HashMap<TableLinkConnection, TableLinkConnection> map, String driver, String url, String user, String password, boolean shareLinkedConnections) { TableLinkConnection t = new TableLinkConnection(map, driver, url, user, password); if (!shareLinkedConnections) { t.open(); return t; } synchronized (map) { TableLinkConnection result = map.get(t); if (result == null) { t.open(); // put the connection in the map after is has been opened, // when we know it works map.put(t, t); result = t; } result.useCounter++; return result; } } private void open() { try { conn = JdbcUtils.getConnection(driver, url, user, password); } catch (SQLException e) { throw DbException.convert(e); } } @Override public int hashCode() { return Objects.hashCode(driver) ^ Objects.hashCode(url) ^ Objects.hashCode(user) ^ Objects.hashCode(password); } @Override public boolean equals(Object o) { if (o instanceof TableLinkConnection) { TableLinkConnection other = (TableLinkConnection) o; return Objects.equals(driver, other.driver) && Objects.equals(url, other.url) && Objects.equals(user, other.user) && Objects.equals(password, other.password); } return false; } /** * Get the connection. * This method and methods on the statement must be * synchronized on this object. * * @return the connection */ Connection getConnection() { return conn; } /** * Closes the connection if this is the last link to it. * * @param force if the connection needs to be closed even if it is still * used elsewhere (for example, because the connection is broken) */ void close(boolean force) { boolean actuallyClose = false; synchronized (map) { if (--useCounter <= 0 || force) { actuallyClose = true; map.remove(this); } } if (actuallyClose) { JdbcUtils.closeSilently(conn); } } /** * Specify if the autocommit mode is activated or not * * @param mode to set */ public void setAutoCommit(boolean mode) { this.autocommit= mode; } /** * The autocommit mode * @return true if autocommit is on */ public boolean getAutocommit(){ return autocommit; } }
Detected license expression
mpl-2.0 AND epl-1.0
Detected license expression (SPDX)
MPL-2.0 AND EPL-1.0
Percentage of license text
2.0
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License detections License expression License expression SPDX
mpl_2_0_and_epl_1_0-796bf8d7-f485-3520-923d-e6a4b1ecd2f3 mpl-2.0 AND epl-1.0 MPL-2.0 AND EPL-1.0
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220