Skip to content

Commit

Permalink
perf: remove use of DriverManager.println
Browse files Browse the repository at this point in the history
Closes: #984
  • Loading branch information
gotson committed Oct 3, 2023
1 parent 21c77a4 commit 75ce563
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/org/sqlite/core/NativeDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sqlite.BusyHandler;
import org.sqlite.Collation;
import org.sqlite.Function;
Expand All @@ -29,6 +30,7 @@

/** This class provides a thin JNI layer over the SQLite3 C API. */
public final class NativeDB extends DB {
private static final Logger logger = LoggerFactory.getLogger(NativeDB.class);
private static final int DEFAULT_BACKUP_BUSY_SLEEP_TIME_MILLIS = 100;
private static final int DEFAULT_BACKUP_NUM_BUSY_BEFORE_FAIL = 3;
private static final int DEFAULT_PAGES_PER_BACKUP_STEP = 100;
Expand Down Expand Up @@ -88,8 +90,11 @@ protected synchronized void _open(String file, int openFlags) throws SQLExceptio
/** @see org.sqlite.core.DB#_exec(java.lang.String) */
@Override
public synchronized int _exec(String sql) throws SQLException {
DriverManager.println(
"DriverManager [" + Thread.currentThread().getName() + "] [SQLite EXEC] " + sql);
logger.atTrace()
.setMessage("DriverManager [{}] [SQLite EXEC] {}")
.addArgument(() -> Thread.currentThread().getName())
.addArgument(sql)
.log();
return _exec_utf8(stringToUtf8ByteArray(sql));
}

Expand Down Expand Up @@ -121,8 +126,11 @@ public synchronized int _exec(String sql) throws SQLException {
/** @see org.sqlite.core.DB#prepare(java.lang.String) */
@Override
protected synchronized SafeStmtPtr prepare(String sql) throws SQLException {
DriverManager.println(
"DriverManager [" + Thread.currentThread().getName() + "] [SQLite PREP] " + sql);
logger.atTrace()
.setMessage("DriverManager [{}] [SQLite EXEC] {}")
.addArgument(() -> Thread.currentThread().getName())
.addArgument(sql)
.log();
return new SafeStmtPtr(this, prepare_utf8(stringToUtf8ByteArray(sql)));
}

Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/sqlite/architecture/CodingRulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import static com.tngtech.archunit.base.DescribedPredicate.not;
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.equivalentTo;
import static com.tngtech.archunit.lang.conditions.ArchPredicates.are;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static com.tngtech.archunit.library.GeneralCodingRules.*;

import com.tngtech.archunit.core.domain.JavaCall;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.domain.properties.HasName;
import com.tngtech.archunit.core.domain.properties.HasOwner;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.conditions.ArchConditions;
import java.sql.DriverManager;
import org.sqlite.util.OSInfo;

@AnalyzeClasses(
Expand All @@ -30,4 +37,18 @@ void no_access_to_standard_streams(JavaClasses importedClasses) {
@ArchTest private final ArchRule no_jodatime = NO_CLASSES_SHOULD_USE_JODATIME;

@ArchTest private final ArchRule no_java_util_logging = NO_CLASSES_SHOULD_USE_JAVA_UTIL_LOGGING;

@ArchTest
private final ArchRule no_driver_manager_println =
noClasses()
.should(
ArchConditions.callMethodWhere(
JavaCall.Predicates.target(HasName.Predicates.name("println"))
.and(
JavaCall.Predicates.target(
HasOwner.Predicates.With.owner(
JavaClass.Predicates
.assignableTo(
DriverManager
.class))))));
}

0 comments on commit 75ce563

Please sign in to comment.