Skip to content

Commit

Permalink
deps: Added slf4j-jdk14
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Ruaux committed Aug 15, 2022
1 parent 4795148 commit 75d986e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 77 deletions.
1 change: 0 additions & 1 deletion connectors/riot-db/riot-db.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dependencies {
implementation 'org.postgresql:postgresql'
implementation group: 'org.xerial', name: 'sqlite-jdbc', version: sqliteVersion
testImplementation project(':riot-test')
testImplementation 'org.slf4j:slf4j-simple'
testImplementation group: 'org.testcontainers', name: 'postgresql', version: testcontainersVersion
testImplementation group: 'org.testcontainers', name: 'oracle-xe', version: testcontainersVersion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Tool to run database scripts
*/
public class ScriptRunner {

private static final Logger log = LoggerFactory.getLogger(ScriptRunner.class);
private static final Logger log = Logger.getLogger(ScriptRunner.class.getName());

private static final String DEFAULT_DELIMITER = ";";

Expand Down Expand Up @@ -84,7 +83,7 @@ private void runScript(Connection conn, Reader reader) throws IOException, SQLEx
}
String trimmedLine = line.trim();
if (trimmedLine.startsWith("--")) {
log.debug(trimmedLine);
log.fine(trimmedLine);
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("//")) {
// Do nothing
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("--")) {
Expand All @@ -95,7 +94,7 @@ private void runScript(Connection conn, Reader reader) throws IOException, SQLEx
command.append(" ");
Statement statement = conn.createStatement();

log.debug(command.toString());
log.fine(command.toString());

boolean hasResults = false;
if (stopOnError) {
Expand All @@ -104,7 +103,7 @@ private void runScript(Connection conn, Reader reader) throws IOException, SQLEx
try {
statement.execute(command.toString());
} catch (SQLException e) {
log.error("Error executing: {}", command, e);
log.log(Level.SEVERE, "Error executing: " + command, e);
}
}

Expand Down
1 change: 0 additions & 1 deletion connectors/riot-file/riot-file.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies {
implementation (group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-storage', version: gcpVersion) {
exclude group: 'javax.annotation', module: 'javax.annotation-api'
}
testImplementation 'org.slf4j:slf4j-simple'
testImplementation project(':riot-test')
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.redis.riot.file.resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.logging.Logger;

import org.springframework.batch.item.ItemStreamReader;
import org.springframework.batch.item.file.ResourceAwareItemReaderItemStream;
import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader;
Expand All @@ -10,7 +10,8 @@
import org.springframework.util.Assert;

/**
* {@link ItemStreamReader} implementation that reads XML objects from a {@link Resource} having the following format:
* {@link ItemStreamReader} implementation that reads XML objects from a
* {@link Resource} having the following format:
*
* <pre>
* {@code
Expand All @@ -28,81 +29,83 @@
* @author Julien Ruaux
*/
public class XmlItemReader<T> extends AbstractItemCountingItemStreamItemReader<T>
implements ResourceAwareItemReaderItemStream<T> {
implements ResourceAwareItemReaderItemStream<T> {

private static final Log LOGGER = LogFactory.getLog(XmlItemReader.class);
private static final Logger LOGGER = Logger.getLogger(XmlItemReader.class.getName());

private Resource resource;
private Resource resource;

private XmlObjectReader<T> xmlObjectReader;
private XmlObjectReader<T> xmlObjectReader;

private boolean strict = true;
private boolean strict = true;

/**
* Create a new {@link XmlItemReader} instance.
*
* @param resource the input XML resource
* @param xmlObjectReader the XML object reader to use
*/
public XmlItemReader(Resource resource, XmlObjectReader<T> xmlObjectReader) {
Assert.notNull(resource, "The resource must not be null.");
Assert.notNull(xmlObjectReader, "The XML object reader must not be null.");
this.resource = resource;
this.xmlObjectReader = xmlObjectReader;
}
/**
* Create a new {@link XmlItemReader} instance.
*
* @param resource the input XML resource
* @param xmlObjectReader the XML object reader to use
*/
public XmlItemReader(Resource resource, XmlObjectReader<T> xmlObjectReader) {
Assert.notNull(resource, "The resource must not be null.");
Assert.notNull(xmlObjectReader, "The XML object reader must not be null.");
this.resource = resource;
this.xmlObjectReader = xmlObjectReader;
}

/**
* Set the {@link XmlObjectReader} to use to read and map XML elements to domain objects.
*
* @param xmlObjectReader the XML object reader to use
*/
public void setXmlObjectReader(XmlObjectReader<T> xmlObjectReader) {
this.xmlObjectReader = xmlObjectReader;
}
/**
* Set the {@link XmlObjectReader} to use to read and map XML elements to domain
* objects.
*
* @param xmlObjectReader the XML object reader to use
*/
public void setXmlObjectReader(XmlObjectReader<T> xmlObjectReader) {
this.xmlObjectReader = xmlObjectReader;
}

/**
* In strict mode the reader will throw an exception on {@link #open(org.springframework.batch.item.ExecutionContext)} if
* the input resource does not exist.
*
* @param strict true by default
*/
public void setStrict(boolean strict) {
this.strict = strict;
}
/**
* In strict mode the reader will throw an exception on
* {@link #open(org.springframework.batch.item.ExecutionContext)} if the input
* resource does not exist.
*
* @param strict true by default
*/
public void setStrict(boolean strict) {
this.strict = strict;
}

@Override
public void setResource(Resource resource) {
this.resource = resource;
}
@Override
public void setResource(Resource resource) {
this.resource = resource;
}

@Nullable
@Override
protected T doRead() throws Exception {
return xmlObjectReader.read();
}
@Nullable
@Override
protected T doRead() throws Exception {
return xmlObjectReader.read();
}

@Override
protected void doOpen() throws Exception {
if (!this.resource.exists()) {
if (this.strict) {
throw new IllegalStateException("Input resource must exist (reader is in 'strict' mode)");
}
LOGGER.warn("Input resource does not exist " + this.resource.getDescription());
return;
}
if (!this.resource.isReadable()) {
if (this.strict) {
throw new IllegalStateException("Input resource must be readable (reader is in 'strict' mode)");
}
LOGGER.warn("Input resource is not readable " + this.resource.getDescription());
return;
}
this.xmlObjectReader.open(this.resource);
}
@Override
protected void doOpen() throws Exception {
if (!this.resource.exists()) {
if (this.strict) {
throw new IllegalStateException("Input resource must exist (reader is in 'strict' mode)");
}
LOGGER.warning("Input resource does not exist " + this.resource.getDescription());
return;
}
if (!this.resource.isReadable()) {
if (this.strict) {
throw new IllegalStateException("Input resource must be readable (reader is in 'strict' mode)");
}
LOGGER.warning("Input resource is not readable " + this.resource.getDescription());
return;
}
this.xmlObjectReader.open(this.resource);
}

@Override
protected void doClose() throws Exception {
this.xmlObjectReader.close();
}
@Override
protected void doClose() throws Exception {
this.xmlObjectReader.close();
}

}
1 change: 1 addition & 0 deletions core/riot-core/riot-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ dependencies {
implementation group: 'me.tongfei', name: 'progressbar', version: progressbarVersion
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
implementation group: 'org.awaitility', name: 'awaitility', version: awaitilityVersion
runtimeOnly 'org.slf4j:slf4j-jdk14'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
}

0 comments on commit 75d986e

Please sign in to comment.