"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcAppender.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

JdbcAppender.java  (apache-log4j-2.11.1-src):JdbcAppender.java  (apache-log4j-2.11.2-src)
skipping to change at line 31 skipping to change at line 31
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.Core;
import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.appender.AbstractAppender; import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender; import org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender;
import org.apache.logging.log4j.core.appender.db.ColumnMapping; import org.apache.logging.log4j.core.appender.db.ColumnMapping;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.convert.TypeConverter; import org.apache.logging.log4j.core.config.plugins.convert.TypeConverter;
import org.apache.logging.log4j.core.config.plugins.validation.constraints.Requi red; import org.apache.logging.log4j.core.config.plugins.validation.constraints.Requi red;
import org.apache.logging.log4j.core.util.Assert; import org.apache.logging.log4j.core.util.Assert;
import org.apache.logging.log4j.core.util.Booleans; import org.apache.logging.log4j.core.util.Booleans;
/** /**
skipping to change at line 55 skipping to change at line 56
* A {@link ConnectionSource} plugin instance instructs the appender (and {@link JdbcDatabaseManager}) how to connect to * A {@link ConnectionSource} plugin instance instructs the appender (and {@link JdbcDatabaseManager}) how to connect to
* the database. This appender can be reconfigured at run time. * the database. This appender can be reconfigured at run time.
* *
* @see ColumnConfig * @see ColumnConfig
* @see ColumnMapping * @see ColumnMapping
* @see ConnectionSource * @see ConnectionSource
*/ */
@Plugin(name = "JDBC", category = Core.CATEGORY_NAME, elementType = Appender.ELE MENT_TYPE, printObject = true) @Plugin(name = "JDBC", category = Core.CATEGORY_NAME, elementType = Appender.ELE MENT_TYPE, printObject = true)
public final class JdbcAppender extends AbstractDatabaseAppender<JdbcDatabaseMan ager> { public final class JdbcAppender extends AbstractDatabaseAppender<JdbcDatabaseMan ager> {
private final String description; public static class Builder<B extends Builder<B>> extends AbstractDatabaseAp
pender.Builder<B>
private JdbcAppender(final String name, final Filter filter, final Layout<?
extends Serializable> layout,
final boolean ignoreExceptions, final JdbcDatabaseManager manager) {
super(name, filter, layout, ignoreExceptions, manager);
this.description = this.getName() + "{ manager=" + this.getManager() + "
}";
}
@Override
public String toString() {
return this.description;
}
/**
* Factory method for creating a JDBC appender within the plugin manager.
*
* @see Builder
* @deprecated use {@link #newBuilder()}
*/
@Deprecated
public static <B extends Builder<B>> JdbcAppender createAppender(final Strin
g name, final String ignore,
final Filte
r filter,
final Conne
ctionSource connectionSource,
final Strin
g bufferSize, final String tableName,
final Colum
nConfig[] columnConfigs) {
Assert.requireNonEmpty(name, "Name cannot be empty");
Objects.requireNonNull(connectionSource, "ConnectionSource cannot be nul
l");
Assert.requireNonEmpty(tableName, "Table name cannot be empty");
Assert.requireNonEmpty(columnConfigs, "ColumnConfigs cannot be empty");
final int bufferSizeInt = AbstractAppender.parseInt(bufferSize, 0);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
return JdbcAppender.<B>newBuilder()
.setBufferSize(bufferSizeInt)
.setColumnConfigs(columnConfigs)
.setConnectionSource(connectionSource)
.setTableName(tableName)
.withName(name)
.withIgnoreExceptions(ignoreExceptions)
.withFilter(filter)
.build();
}
@PluginBuilderFactory
public static <B extends Builder<B>> B newBuilder() {
return new Builder<B>().asBuilder();
}
public static class Builder<B extends Builder<B>> extends AbstractAppender.B
uilder<B>
implements org.apache.logging.log4j.core.util.Builder<JdbcAppender> { implements org.apache.logging.log4j.core.util.Builder<JdbcAppender> {
@PluginElement("ConnectionSource") @PluginElement("ConnectionSource")
@Required(message = "No ConnectionSource provided") @Required(message = "No ConnectionSource provided")
private ConnectionSource connectionSource; private ConnectionSource connectionSource;
@PluginBuilderAttribute @PluginBuilderAttribute
private boolean immediateFail;
@PluginBuilderAttribute
private int bufferSize; private int bufferSize;
@PluginBuilderAttribute @PluginBuilderAttribute
@Required(message = "No table name provided") @Required(message = "No table name provided")
private String tableName; private String tableName;
@PluginElement("ColumnConfigs") @PluginElement("ColumnConfigs")
private ColumnConfig[] columnConfigs; private ColumnConfig[] columnConfigs;
@PluginElement("ColumnMappings") @PluginElement("ColumnMappings")
private ColumnMapping[] columnMappings; private ColumnMapping[] columnMappings;
/** @PluginBuilderAttribute
* The connections source from which database connections should be retr private boolean truncateStrings = true;
ieved.
* // TODO Consider moving up to AbstractDatabaseAppender.Builder.
* @return this @PluginBuilderAttribute
*/ private long reconnectIntervalMillis = DEFAULT_RECONNECT_INTERVAL_MILLIS
public B setConnectionSource(final ConnectionSource connectionSource) { ;
this.connectionSource = connectionSource;
return asBuilder(); @Override
public JdbcAppender build() {
if (Assert.isEmpty(columnConfigs) && Assert.isEmpty(columnMappings))
{
LOGGER.error("Cannot create JdbcAppender without any columns.");
return null;
}
final String managerName = "JdbcManager{name=" + getName() + ", buff
erSize=" + bufferSize + ", tableName="
+ tableName + ", columnConfigs=" + Arrays.toString(columnCon
figs) + ", columnMappings="
+ Arrays.toString(columnMappings) + '}';
final JdbcDatabaseManager manager = JdbcDatabaseManager.getManager(m
anagerName, bufferSize, getLayout(),
connectionSource, tableName, columnConfigs, columnMappings,
immediateFail, reconnectIntervalMillis,
truncateStrings);
if (manager == null) {
return null;
}
return new JdbcAppender(getName(), getFilter(), getLayout(), isIgnor
eExceptions(), getPropertyArray(),
manager);
}
public long getReconnectIntervalMillis() {
return reconnectIntervalMillis;
}
public boolean isImmediateFail() {
return immediateFail;
} }
/** /**
* If an integer greater than 0, this causes the appender to buffer log events and flush whenever the buffer * If an integer greater than 0, this causes the appender to buffer log events and flush whenever the buffer
* reaches this size. * reaches this size.
* *
* @param bufferSize buffer size.
*
* @return this * @return this
*/ */
public B setBufferSize(final int bufferSize) { public B setBufferSize(final int bufferSize) {
this.bufferSize = bufferSize; this.bufferSize = bufferSize;
return asBuilder(); return asBuilder();
} }
/** /**
* The name of the database table to insert log events into. * Information about the columns that log event data should be inserted
into and how to insert that data.
*
* @param columnConfigs Column configurations.
* *
* @return this * @return this
*/ */
public B setTableName(final String tableName) { public B setColumnConfigs(final ColumnConfig... columnConfigs) {
this.tableName = tableName; this.columnConfigs = columnConfigs;
return asBuilder();
}
public B setColumnMappings(final ColumnMapping... columnMappings) {
this.columnMappings = columnMappings;
return asBuilder(); return asBuilder();
} }
/** /**
* Information about the columns that log event data should be inserted * The connections source from which database connections should be retr
into and how to insert that data. ieved.
*
* @param connectionSource The connections source.
* *
* @return this * @return this
*/ */
public B setColumnConfigs(final ColumnConfig... columnConfigs) { public B setConnectionSource(final ConnectionSource connectionSource) {
this.columnConfigs = columnConfigs; this.connectionSource = connectionSource;
return asBuilder(); return asBuilder();
} }
public B setColumnMappings(final ColumnMapping... columnMappings) { public void setImmediateFail(final boolean immediateFail) {
this.columnMappings = columnMappings; this.immediateFail = immediateFail;
}
public void setReconnectIntervalMillis(final long reconnectIntervalMilli
s) {
this.reconnectIntervalMillis = reconnectIntervalMillis;
}
/**
* The name of the database table to insert log events into.
*
* @param tableName The database table name.
*
* @return this
*/
public B setTableName(final String tableName) {
this.tableName = tableName;
return asBuilder(); return asBuilder();
} }
@Override public B setTruncateStrings(final boolean truncateStrings) {
public JdbcAppender build() { this.truncateStrings = truncateStrings;
if (Assert.isEmpty(columnConfigs) && Assert.isEmpty(columnMappings)) return asBuilder();
{
LOGGER.error("Cannot create JdbcAppender without any columns.");
return null;
}
final String managerName = "JdbcManager{name=" + getName() + ", buff
erSize=" + bufferSize + ", tableName="
+ tableName + ", columnConfigs=" + Arrays.toString(columnCon
figs) + ", columnMappings="
+ Arrays.toString(columnMappings) + '}';
final JdbcDatabaseManager manager = JdbcDatabaseManager.getManager(m
anagerName, bufferSize, getLayout(),
connectionSource, tableName, columnConfigs, columnMappings);
if (manager == null) {
return null;
}
return new JdbcAppender(getName(), getFilter(), getLayout(), isIgnor
eExceptions(), manager);
} }
} }
/**
* Factory method for creating a JDBC appender within the plugin manager.
*
* @see Builder
* @deprecated use {@link #newBuilder()}
*/
@Deprecated
public static <B extends Builder<B>> JdbcAppender createAppender(final Strin
g name, final String ignore,
final Filte
r filter,
final Conne
ctionSource connectionSource,
final Strin
g bufferSize, final String tableName,
final Colum
nConfig[] columnConfigs) {
Assert.requireNonEmpty(name, "Name cannot be empty");
Objects.requireNonNull(connectionSource, "ConnectionSource cannot be nul
l");
Assert.requireNonEmpty(tableName, "Table name cannot be empty");
Assert.requireNonEmpty(columnConfigs, "ColumnConfigs cannot be empty");
final int bufferSizeInt = AbstractAppender.parseInt(bufferSize, 0);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
return JdbcAppender.<B>newBuilder()
.setBufferSize(bufferSizeInt)
.setColumnConfigs(columnConfigs)
.setConnectionSource(connectionSource)
.setTableName(tableName).setName(name).setIgnoreExceptions(ignoreExcepti
ons).setFilter(filter)
.build();
}
@PluginBuilderFactory
public static <B extends Builder<B>> B newBuilder() {
return new Builder<B>().asBuilder();
}
private final String description;
private JdbcAppender(final String name, final Filter filter, final Layout<?
extends Serializable> layout,
final boolean ignoreExceptions, final Property[] properties, final J
dbcDatabaseManager manager) {
super(name, filter, layout, ignoreExceptions, properties, manager);
this.description = this.getName() + "{ manager=" + this.getManager() + "
}";
}
@Override
public String toString() {
return this.description;
}
} }
 End of changes. 12 change blocks. 
97 lines changed or deleted 141 lines changed or added

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