Skip to content

Commit

Permalink
Usages of setLinkedException replaced by standard "cause"
Browse files Browse the repository at this point in the history
- obsoleted and deprecated code

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Apr 11, 2023
1 parent fb0d288 commit b6a16eb
Show file tree
Hide file tree
Showing 6 changed files with 516 additions and 476 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,52 +17,52 @@

package com.sun.connector.cciblackbox;

import java.sql.SQLException;

import jakarta.resource.ResourceException;
import jakarta.resource.cci.ConnectionMetaData;
import jakarta.resource.spi.EISSystemException;

import java.sql.SQLException;

/**
* @author Sheetal Vartak
*/
public class CciConnectionMetaDataImpl implements ConnectionMetaData {

private CciManagedConnection mc;

public CciConnectionMetaDataImpl(CciManagedConnection mc) {
this.mc = mc;
}
private final CciManagedConnection mc;

public String getEISProductName() throws ResourceException {
try {
java.sql.Connection con = mc.getJdbcConnection();
return con.getMetaData().getDatabaseProductName();
public CciConnectionMetaDataImpl(CciManagedConnection mc) {
this.mc = mc;
}
catch (SQLException ex) {
ResourceException re = new EISSystemException(ex.getMessage());
re.setLinkedException(ex);
throw re;
}
}

public String getEISProductVersion() throws ResourceException {
try {
java.sql.Connection con = mc.getJdbcConnection();
return con.getMetaData().getDatabaseProductVersion();

@Override
public String getEISProductName() throws ResourceException {
try {
java.sql.Connection con = mc.getJdbcConnection();
return con.getMetaData().getDatabaseProductName();
} catch (SQLException ex) {
throw new EISSystemException(ex.getMessage(), ex);
}
}
catch (SQLException ex) {
ResourceException re = new EISSystemException(ex.getMessage());
re.setLinkedException(ex);
throw re;


@Override
public String getEISProductVersion() throws ResourceException {
try {
java.sql.Connection con = mc.getJdbcConnection();
return con.getMetaData().getDatabaseProductVersion();
} catch (SQLException ex) {
throw new EISSystemException(ex.getMessage(), ex);
}
}
}

public String getUserName() throws ResourceException {
if (mc.isDestroyed()) {
throw new ResourceException("ManagedConnection has been destroyed");

@Override
public String getUserName() throws ResourceException {
if (mc.isDestroyed()) {
throw new ResourceException("ManagedConnection has been destroyed");
}
return mc.getPasswordCredential().getUserName();
}
return mc.getPasswordCredential().getUserName();
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,118 +17,127 @@

package com.sun.connector.cciblackbox;

import jakarta.resource.ResourceException;
import jakarta.resource.spi.ConnectionManager;
import jakarta.resource.spi.ConnectionRequestInfo;
import jakarta.resource.spi.EISSystemException;
import jakarta.resource.spi.ManagedConnection;
import jakarta.resource.spi.ManagedConnectionFactory;
import jakarta.resource.spi.security.PasswordCredential;

import java.io.PrintWriter;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;

import jakarta.resource.ResourceException;
import jakarta.resource.spi.ConnectionManager;
import jakarta.resource.spi.ConnectionRequestInfo;
import jakarta.resource.spi.EISSystemException;
import jakarta.resource.spi.ManagedConnection;
import jakarta.resource.spi.ManagedConnectionFactory;
import jakarta.resource.spi.security.PasswordCredential;
import javax.security.auth.Subject;

/**
*
* @author Sheetal Vartak
*/
public class CciLocalTxManagedConnectionFactory implements ManagedConnectionFactory, Serializable {

private String url;
private String url;

public CciLocalTxManagedConnectionFactory() {
}


public CciLocalTxManagedConnectionFactory() {
}
@Override
public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException {
return new CciConnectionFactory(this, cxManager);
}

public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException {

return new CciConnectionFactory(this, cxManager);
}
@Override
public Object createConnectionFactory() throws ResourceException {
return new CciConnectionFactory(this, null);
}

public Object createConnectionFactory() throws ResourceException {
return new CciConnectionFactory(this, null);
}

public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo info)
throws ResourceException {
@Override
public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo info)
throws ResourceException {
try {
Connection con = null;
String userName = null;

PasswordCredential pc = Util.getPasswordCredential(this, subject, info);
if (pc == null) {
con = DriverManager.getConnection(url);
} else {
userName = pc.getUserName();
con = DriverManager.getConnection(url, userName, new String(pc.getPassword()));
}
return new CciManagedConnection(this, pc, null, con, false, true);
} catch (SQLException ex) {
throw new EISSystemException("SQLException: " + ex.getMessage(), ex);
}

}

try {
Connection con = null;
String userName = null;

PasswordCredential pc = Util.getPasswordCredential(this, subject, info);
if (pc == null) {
con = DriverManager.getConnection(url);
} else {
userName = pc.getUserName();
con = DriverManager.getConnection(url, userName, new String(pc.getPassword()));
}
return new CciManagedConnection(this, pc, null, con, false, true);
@Override
public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo info)
throws ResourceException {
PasswordCredential pc = Util.getPasswordCredential(this, subject, info);
Iterator it = connectionSet.iterator();
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof CciManagedConnection) {
CciManagedConnection mc = (CciManagedConnection) obj;
ManagedConnectionFactory mcf = mc.getManagedConnectionFactory();
if (Util.isPasswordCredentialEqual(mc.getPasswordCredential(), pc) && mcf.equals(this)) {
return mc;
}
}
}
return null;
}
catch (SQLException ex) {
ResourceException re = new EISSystemException("SQLException: " + ex.getMessage());
re.setLinkedException(ex);
throw re;


@Override
public void setLogWriter(PrintWriter out) throws ResourceException {
DriverManager.setLogWriter(out);
}

}

public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject,
ConnectionRequestInfo info) throws ResourceException {
@Override
public PrintWriter getLogWriter() throws ResourceException {
return DriverManager.getLogWriter();
}

PasswordCredential pc = Util.getPasswordCredential(this, subject, info);
Iterator it = connectionSet.iterator();
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof CciManagedConnection) {
CciManagedConnection mc = (CciManagedConnection) obj;
ManagedConnectionFactory mcf = mc.getManagedConnectionFactory();
if (Util.isPasswordCredentialEqual(mc.getPasswordCredential(), pc) && mcf.equals(this)) {
return mc;
}
}

public String getConnectionURL() {
return url;
}
return null;
}

public void setLogWriter(PrintWriter out) throws ResourceException {

DriverManager.setLogWriter(out);
}

public PrintWriter getLogWriter() throws ResourceException {
return DriverManager.getLogWriter();
}

public String getConnectionURL() {
return url;
}

public void setConnectionURL(String url) {
this.url = url;
}

public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof CciLocalTxManagedConnectionFactory) {
String v1 = ((CciLocalTxManagedConnectionFactory) obj).url;
String v2 = this.url;
return (v1 == null) ? (v2 == null) : (v1.equals(v2));
} else {
return false;


public void setConnectionURL(String url) {
this.url = url;
}
}

public int hashCode() {
if (url == null) {
return (new String("")).hashCode();
} else {
return url.hashCode();

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj instanceof CciLocalTxManagedConnectionFactory) {
String v1 = ((CciLocalTxManagedConnectionFactory) obj).url;
String v2 = this.url;
return v1 == null ? v2 == null : v1.equals(v2);
}
return false;
}


@Override
public int hashCode() {
return Objects.hashCode(url);
}
}
}
Loading

0 comments on commit b6a16eb

Please sign in to comment.