/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *
*/ package org.apache.tomcat.dbcp.dbcp2;
/** * Clones the given char[] if not null. * * @param value may be null. * @return a cloned char[] or null.
*/ publicstaticchar[] clone(finalchar[] value) { return value == null ? null : value.clone();
}
/** * Clones the given {@link Properties} without the standard "user" or "password" entries. * * @param properties may be null * @return a clone of the input without the standard "user" or "password" entries. * @since 2.8.0
*/ publicstatic Properties cloneWithoutCredentials(final Properties properties) { if (properties != null) { final Properties temp = (Properties) properties.clone();
temp.remove(Constants.KEY_USER);
temp.remove(Constants.KEY_PASSWORD); return temp;
} return properties;
}
/** * Closes the given {@link AutoCloseable} and if an exception is caught, then calls {@code exceptionHandler}. * * @param autoCloseable The resource to close. * @param exceptionHandler Consumes exception thrown closing this resource. * @since 2.10.0
*/ publicstaticvoid close(AutoCloseable autoCloseable, final Consumer<Exception> exceptionHandler) { if (autoCloseable != null) { try {
autoCloseable.close();
} catch (final Exception e) { if (exceptionHandler != null) {
exceptionHandler.accept(e);
}
}
}
}
/** * Closes the AutoCloseable (which may be null). * * @param autoCloseable an AutoCloseable, may be {@code null} * @since 2.6.0
*/ publicstaticvoid closeQuietly(final AutoCloseable autoCloseable) {
close(autoCloseable, null);
}
/** * Closes the Connection (which may be null). * * @param connection a Connection, may be {@code null} * @deprecated Use {@link #closeQuietly(AutoCloseable)}.
*/
@Deprecated publicstaticvoid closeQuietly(final Connection connection) {
closeQuietly((AutoCloseable) connection);
}
/** * Closes the ResultSet (which may be null). * * @param resultSet a ResultSet, may be {@code null} * @deprecated Use {@link #closeQuietly(AutoCloseable)}.
*/
@Deprecated publicstaticvoid closeQuietly(final ResultSet resultSet) {
closeQuietly((AutoCloseable) resultSet);
}
/** * Closes the Statement (which may be null). * * @param statement a Statement, may be {@code null}. * @deprecated Use {@link #closeQuietly(AutoCloseable)}.
*/
@Deprecated publicstaticvoid closeQuietly(final Statement statement) {
closeQuietly((AutoCloseable) statement);
}
/** * Gets the correct i18n message for the given key. * * @param key The key to look up an i18n message. * @return The i18n message.
*/ publicstatic String getMessage(final String key) { return getMessage(key, (Object[]) null);
}
/** * Gets the correct i18n message for the given key with placeholders replaced by the supplied arguments. * * @param key A message key. * @param args The message arguments. * @return An i18n message.
*/ publicstatic String getMessage(final String key, final Object... args) { final String msg = messages.getString(key); if (args == null || args.length == 0) { return msg;
} final MessageFormat mf = new MessageFormat(msg); return mf.format(args, new StringBuffer(), null).toString();
}
/** * Converts the given String to a char[]. * * @param value may be null. * @return a char[] or null.
*/ publicstaticchar[] toCharArray(final String value) { return value != null ? value.toCharArray() : null;
}
/** * Converts the given char[] to a String. * * @param value may be null. * @return a String or null.
*/ publicstatic String toString(finalchar[] value) { return value == null ? null : String.valueOf(value);
}
publicstaticvoid validateLifetime(final PooledObject<?> p, final Duration maxDuration) throws LifetimeExceededException { if (maxDuration.compareTo(Duration.ZERO) > 0) { final Duration lifetimeDuration = Duration.between(p.getCreateInstant(), Instant.now()); if (lifetimeDuration.compareTo(maxDuration) > 0) { thrownew LifetimeExceededException(Utils.getMessage("connectionFactory.lifetimeExceeded", lifetimeDuration, maxDuration));
}
}
}
private Utils() { // not instantiable
}
}
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.