New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WFLY-30 SFSB containing injected DataSource fails to passivate/serialize #6925
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2014, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.jboss.as.connector.subsystems.datasources; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.io.Serializable; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.sql.SQLFeatureNotSupportedException; | ||
import java.util.logging.Logger; | ||
|
||
import javax.naming.InitialContext; | ||
import javax.sql.DataSource; | ||
|
||
/** | ||
* WildFly DataSource implementation | ||
* | ||
* @author <a href="jesper.pedersen@redhat.com">Jesper Pedersen</a> | ||
*/ | ||
public class WildFlyDataSource implements DataSource, Serializable { | ||
|
||
/** The serialVersionUID */ | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** DataSource */ | ||
private transient DataSource delegate; | ||
|
||
/** Service name */ | ||
private transient String jndiName; | ||
|
||
|
||
/** | ||
* Constructor | ||
* @param delegate The datasource | ||
* @param jndiName The service name | ||
*/ | ||
public WildFlyDataSource(DataSource delegate, String jndiName) { | ||
this.delegate = delegate; | ||
this.jndiName = jndiName; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public Connection getConnection() throws SQLException { | ||
return delegate.getConnection(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public Connection getConnection(String username, String password) throws SQLException { | ||
return delegate.getConnection(username, password); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public <T> T unwrap(Class<T> iface) throws SQLException { | ||
throw new SQLException("Unwrap not supported"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not delegate this method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Becose delegate isn't wrapper for interface, as next method is saying |
||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public boolean isWrapperFor(Class<?> iface) throws SQLException { | ||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public PrintWriter getLogWriter() throws SQLException { | ||
return delegate.getLogWriter(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public void setLogWriter(PrintWriter out) throws SQLException { | ||
delegate.setLogWriter(out); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public void setLoginTimeout(int seconds) throws SQLException { | ||
delegate.setLoginTimeout(seconds); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public int getLoginTimeout() throws SQLException { | ||
return delegate.getLoginTimeout(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public Logger getParentLogger() throws SQLFeatureNotSupportedException { | ||
return delegate.getParentLogger(); | ||
} | ||
|
||
private void writeObject(java.io.ObjectOutputStream out) throws IOException { | ||
out.defaultWriteObject(); | ||
out.writeObject(jndiName); | ||
} | ||
|
||
|
||
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { | ||
in.defaultReadObject(); | ||
jndiName = (String) in.readObject(); | ||
|
||
|
||
try { | ||
InitialContext context = new InitialContext(); | ||
|
||
DataSource originalDs = (DataSource) context.lookup(jndiName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't really work if the DS jndi name is not global and the entry is deserialised outside the scope of a deployment. Probably not going to be a big issue in practice, but it could be an issue with datasources that are embedded in a deployment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but at least this solution fix almost cases. W/o this patch it's not working at all in a cluster. This is a corner case, I would suggest to just ignore this, at least if you haven't any hint for a general solution covering also corner case. |
||
this.delegate = originalDs; | ||
} catch (Exception e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance use code could rely on the datasource being assignable to some other class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not