"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java" between
spring-framework-5.3.7.tar.gz and spring-framework-5.3.8.tar.gz

About: Spring Framework is an application framework for the Java platform and .NET Framework. Community edition.

SingleConnectionFactory.java  (spring-framework-5.3.7):SingleConnectionFactory.java  (spring-framework-5.3.8)
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* https://www.apache.org/licenses/LICENSE-2.0 * https://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
skipping to change at line 39 skipping to change at line 39
import io.r2dbc.spi.Wrapped; import io.r2dbc.spi.Wrapped;
import org.reactivestreams.Publisher; import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* Implementation of {@link DelegatingConnectionFactory} that wraps a * Implementation of {@link DelegatingConnectionFactory} that wraps a
* single R2DBC Connection which is not closed after use. * single R2DBC {@link Connection} which is not closed after use.
* Obviously, this is not multi-threading capable. * Obviously, this is not multi-threading capable.
* *
* <p>Note that at shutdown, someone should close the underlying * <p>Note that at shutdown, someone should close the underlying
* Connection via the {@code close()} method. Client code will * {@code Connection} via the {@code close()} method. Client code will
* never call close on the Connection handle if it is * never call close on the {@code Connection} handle if it is
* SmartConnectionFactory-aware (e.g. uses * SmartConnectionFactory-aware (e.g. uses
* {@link ConnectionFactoryUtils#releaseConnection(Connection, ConnectionFactory )}). * {@link ConnectionFactoryUtils#releaseConnection(Connection, ConnectionFactory )}).
* *
* <p>If client code will call {@link Connection#close()} in the * <p>If client code will call {@link Connection#close()} in the
* assumption of a pooled Connection, like when using persistence tools, * assumption of a pooled {@code Connection}, like when using persistence tools,
* set "suppressClose" to "true". This will return a close-suppressing * set "suppressClose" to {@code true}. This will return a close-suppressing
* proxy instead of the physical Connection. * proxy instead of the physical Connection.
* *
* <p>This is primarily intended for testing and pipelining usage of connections . * <p>This is primarily intended for testing and pipelining usage of connections .
* For example, it enables easy testing outside an application server, for code * For example, it enables easy testing outside an application server for code
* that expects to work on a {@link ConnectionFactory}. * that expects to work on a {@link ConnectionFactory}.
* Note that this implementation does not act as a connection pool-like utility. * Note that this implementation does not act as a connection pool-like utility.
* Connection pooling requires a {@link ConnectionFactory} implemented by e.g. * Connection pooling requires a pooling {@link ConnectionFactory} such as one f rom
* {@code r2dbc-pool}. * {@code r2dbc-pool}.
* *
* @author Mark Paluch * @author Mark Paluch
* @since 5.3 * @since 5.3
* @see #create() * @see #create()
* @see Connection#close() * @see Connection#close()
* @see ConnectionFactoryUtils#releaseConnection(Connection, ConnectionFactory) * @see ConnectionFactoryUtils#releaseConnection(Connection, ConnectionFactory)
*/ */
public class SingleConnectionFactory extends DelegatingConnectionFactory public class SingleConnectionFactory extends DelegatingConnectionFactory
implements DisposableBean { implements DisposableBean {
skipping to change at line 92 skipping to change at line 92
/** /**
* Constructor for bean-style configuration. * Constructor for bean-style configuration.
*/ */
public SingleConnectionFactory(ConnectionFactory targetConnectionFactory) { public SingleConnectionFactory(ConnectionFactory targetConnectionFactory) {
super(targetConnectionFactory); super(targetConnectionFactory);
this.connectionEmitter = super.create().cache(); this.connectionEmitter = super.create().cache();
} }
/** /**
* Create a new {@link SingleConnectionFactory} using a R2DBC connection * Create a new {@code SingleConnectionFactory} using an R2DBC connection
URL. URL.
* @param url the R2DBC URL to use for accessing {@link ConnectionFactory * @param url the R2DBC URL to use for accessing {@link ConnectionFactory
} discovery. } discovery
* @param suppressClose if the returned {@link Connection} should be a cl * @param suppressClose if the returned {@link Connection} should be a
ose-suppressing proxy * close-suppressing proxy or the physical {@code Connection}
* or the physical {@link Connection}.
* @see ConnectionFactories#get(String) * @see ConnectionFactories#get(String)
*/ */
public SingleConnectionFactory(String url, boolean suppressClose) { public SingleConnectionFactory(String url, boolean suppressClose) {
super(ConnectionFactories.get(url)); super(ConnectionFactories.get(url));
this.suppressClose = suppressClose; this.suppressClose = suppressClose;
this.connectionEmitter = super.create().cache(); this.connectionEmitter = super.create().cache();
} }
/** /**
* Create a new {@link SingleConnectionFactory} with a given {@link Conne * Create a new {@code SingleConnectionFactory} with a given {@link Conne
ction} and ction}
* {@link ConnectionFactoryMetadata}. * and {@link ConnectionFactoryMetadata}.
* @param target underlying target {@link Connection}. * @param target underlying target {@code Connection}
* @param metadata {@link ConnectionFactory} metadata to be associated wi * @param metadata {@code ConnectionFactory} metadata to be associated wi
th this {@link ConnectionFactory}. th
* @param suppressClose if the {@link Connection} should be wrapped with * this {@code ConnectionFactory}
a {@link Connection} that suppresses * @param suppressClose {@code true} if the {@code Connection} should be
* @code close()} calls (to allow for normal {@code close()} usage in app wrapped
lications that expect a pooled * with a {@code Connection} that suppresses {@code close()} calls (to al
* @link Connection}). low
* for normal {@code close()} usage in applications that expect a pooled
* {@code Connection})
*/ */
public SingleConnectionFactory(Connection target, ConnectionFactoryMetada ta metadata, boolean suppressClose) { public SingleConnectionFactory(Connection target, ConnectionFactoryMetada ta metadata, boolean suppressClose) {
super(new ConnectionFactory() { super(new ConnectionFactory() {
@Override @Override
public Publisher<? extends Connection> create() { public Publisher<? extends Connection> create() {
return Mono.just(target); return Mono.just(target);
} }
@Override @Override
public ConnectionFactoryMetadata getMetadata() { public ConnectionFactoryMetadata getMetadata() {
return metadata; return metadata;
skipping to change at line 134 skipping to change at line 136
Assert.notNull(target, "Connection must not be null"); Assert.notNull(target, "Connection must not be null");
Assert.notNull(metadata, "ConnectionFactoryMetadata must not be n ull"); Assert.notNull(metadata, "ConnectionFactoryMetadata must not be n ull");
this.target.set(target); this.target.set(target);
this.connectionEmitter = Mono.just(target); this.connectionEmitter = Mono.just(target);
this.suppressClose = suppressClose; this.suppressClose = suppressClose;
this.connection = (suppressClose ? getCloseSuppressingConnectionP roxy(target) : target); this.connection = (suppressClose ? getCloseSuppressingConnectionP roxy(target) : target);
} }
/** /**
* Set whether the returned {@link Connection} should be a close-suppress ing proxy * Set whether the returned {@link Connection} should be a close-suppress ing proxy
* or the physical {@link Connection}. * or the physical {@code Connection}.
*/ */
public void setSuppressClose(boolean suppressClose) { public void setSuppressClose(boolean suppressClose) {
this.suppressClose = suppressClose; this.suppressClose = suppressClose;
} }
/** /**
* Return whether the returned {@link Connection} will be a close-suppres sing proxy * Return whether the returned {@link Connection} will be a close-suppres sing proxy
* or the physical {@link Connection}. * or the physical {@code Connection}.
*/ */
protected boolean isSuppressClose() { protected boolean isSuppressClose() {
return this.suppressClose; return this.suppressClose;
} }
/** /**
* Set whether the returned {@link Connection}'s "autoCommit" setting sho * Set whether the returned {@link Connection}'s "autoCommit" setting sho
uld be overridden. uld
* be overridden.
*/ */
public void setAutoCommit(boolean autoCommit) { public void setAutoCommit(boolean autoCommit) {
this.autoCommit = autoCommit; this.autoCommit = autoCommit;
} }
/** /**
* Return whether the returned {@link Connection}'s "autoCommit" setting * Return whether the returned {@link Connection}'s "autoCommit" setting
should be overridden. should
* be overridden.
* @return the "autoCommit" value, or {@code null} if none to be applied * @return the "autoCommit" value, or {@code null} if none to be applied
*/ */
@Nullable @Nullable
protected Boolean getAutoCommitValue() { protected Boolean getAutoCommitValue() {
return this.autoCommit; return this.autoCommit;
} }
@Override @Override
public Mono<? extends Connection> create() { public Mono<? extends Connection> create() {
Connection connection = this.target.get(); Connection connection = this.target.get();
skipping to change at line 207 skipping to change at line 211
if (this.target.compareAndSet(connection, null)) { if (this.target.compareAndSet(connection, null)) {
this.connection = null; this.connection = null;
return Mono.from(connection.close()); return Mono.from(connection.close());
} }
return Mono.empty(); return Mono.empty();
}); });
} }
/** /**
* Prepare the {@link Connection} before using it. * Prepare the {@link Connection} before using it.
* Applies {@link #getAutoCommitValue() auto-commit} settings if configur * Applies {@linkplain #getAutoCommitValue() auto-commit} settings if con
ed. figured.
* @param connection the requested {@link Connection}. * @param connection the requested {@code Connection}
* @return the prepared {@link Connection}. * @return the prepared {@code Connection}
*/ */
protected Mono<Connection> prepareConnection(Connection connection) { protected Mono<Connection> prepareConnection(Connection connection) {
Boolean autoCommit = getAutoCommitValue(); Boolean autoCommit = getAutoCommitValue();
if (autoCommit != null) { if (autoCommit != null) {
return Mono.from(connection.setAutoCommit(autoCommit)).th enReturn(connection); return Mono.from(connection.setAutoCommit(autoCommit)).th enReturn(connection);
} }
return Mono.just(connection); return Mono.just(connection);
} }
/** /**
* Wrap the given {@link Connection} with a proxy that delegates every me thod call to it * Wrap the given {@link Connection} with a proxy that delegates every me thod call to it
* but suppresses close calls. * but suppresses close calls.
* @param target the original {@link Connection} to wrap. * @param target the original {@code Connection} to wrap
* @return the wrapped Connection. * @return the wrapped Connection
*/ */
protected Connection getCloseSuppressingConnectionProxy(Connection target ) { protected Connection getCloseSuppressingConnectionProxy(Connection target ) {
return (Connection) Proxy.newProxyInstance(SingleConnectionFactor y.class.getClassLoader(), return (Connection) Proxy.newProxyInstance(SingleConnectionFactor y.class.getClassLoader(),
new Class<?>[] { Connection.class, Wrapped.class }, new CloseSuppressingInvocationHandler(target)); new Class<?>[] { Connection.class, Wrapped.class }, new CloseSuppressingInvocationHandler(target));
} }
/** /**
* Invocation handler that suppresses close calls on R2DBC Connections. * Invocation handler that suppresses close calls on R2DBC Connections.
* *
* @see Connection#close() * @see Connection#close()
 End of changes. 14 change blocks. 
38 lines changed or deleted 41 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)