Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code formatting via Spotless with google java format #653

Merged
merged 3 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ on:
- '.github/workflows/*.yml'

jobs:
lint:
name: Check code formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: '11'
- name: spotless:check
run: mvn spotless:check

test:
name: test ${{ matrix.os }} jdk${{ matrix.java }}
strategy:
Expand Down
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,22 @@
</instructions>
</configuration>
</plugin>
</plugins>

<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.12.3</version>
<configuration>
<java>
<toggleOffOn />
<googleJavaFormat>
<version>1.11.0</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
</configuration>
</plugin>
</plugins>

<pluginManagement>
<plugins>
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/org/sqlite/BusyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,40 @@
import java.sql.Connection;
import java.sql.SQLException;

/**
*
* https://www.sqlite.org/c3ref/busy_handler.html
*/
/** https://www.sqlite.org/c3ref/busy_handler.html */
public abstract class BusyHandler {

/**
* commit the busy handler for the connection.
*
* @param conn the SQLite connection
* @param busyHandler the busyHandler
* @throws SQLException
*/
private static void commitHandler(Connection conn, BusyHandler busyHandler) throws SQLException {

private static void commitHandler(Connection conn, BusyHandler busyHandler)
throws SQLException {

if (conn == null || !(conn instanceof SQLiteConnection)) {
throw new SQLException("connection must be to an SQLite db");
}

if (conn.isClosed()) {
throw new SQLException("connection closed");
}

SQLiteConnection sqliteConnection = (SQLiteConnection) conn;
sqliteConnection.getDatabase().busy_handler(busyHandler);
}

/**
* Sets a busy handler for the connection.
*
* @param conn the SQLite connection
* @param busyHandler the busyHandler
* @throws SQLException
*/
public static final void setHandler(Connection conn, BusyHandler busyHandler) throws SQLException {
public static final void setHandler(Connection conn, BusyHandler busyHandler)
throws SQLException {
commitHandler(conn, busyHandler);
}

Expand All @@ -54,9 +53,12 @@ public static final void clearHandler(Connection conn) throws SQLException {
/**
* https://www.sqlite.org/c3ref/busy_handler.html
*
* @param nbPrevInvok number of times that the busy handler has been invoked previously for the same locking event
* @param nbPrevInvok number of times that the busy handler has been invoked previously for the
* same locking event
* @throws SQLException
* @return If the busy callback returns 0, then no additional attempts are made to access the database and SQLITE_BUSY is returned to the application. If the callback returns non-zero, then another attempt is made to access the database and the cycle repeats.
* @return If the busy callback returns 0, then no additional attempts are made to access the
* database and SQLITE_BUSY is returned to the application. If the callback returns
* non-zero, then another attempt is made to access the database and the cycle repeats.
*/
protected abstract int callback(int nbPrevInvok) throws SQLException;
}
39 changes: 18 additions & 21 deletions src/main/java/org/sqlite/Collation.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@
*/
package org.sqlite;

import org.sqlite.core.Codes;
import org.sqlite.core.DB;

import java.sql.Connection;
import java.sql.SQLException;
import org.sqlite.core.Codes;
import org.sqlite.core.DB;

/** Provides an interface for creating SQLite user-defined collations.
*
* <p>A subclass of <tt>org.sqlite.Collation</tt> can be registered with
* <tt>Collation.create()</tt> and called by the name it was given. All
* collations must implement <tt>xCompare(String, String)</tt>, which is called when SQLite
* compares two strings using the custom collation.</p>
/**
* Provides an interface for creating SQLite user-defined collations.
*
* Eg.
* <p>A subclass of <tt>org.sqlite.Collation</tt> can be registered with <tt>Collation.create()</tt>
* and called by the name it was given. All collations must implement <tt>xCompare(String,
* String)</tt>, which is called when SQLite compares two strings using the custom collation. Eg.
*
* <pre>
* Class.forName("org.sqlite.JDBC");
Expand All @@ -43,31 +40,30 @@
* conn.createStatement().execute("select c1 from t order by c1 collate REVERSE;");
* </pre>
*/
public abstract class Collation
{
public abstract class Collation {
private SQLiteConnection conn;
private DB db;

/**
* Registers a given collation with the connection.
*
* @param conn The connection.
* @param name The name of the collation.
* @param f The collation to register.
*/
public static final void create(Connection conn, String name, Collation f)
throws SQLException {
public static final void create(Connection conn, String name, Collation f) throws SQLException {
if (conn == null || !(conn instanceof SQLiteConnection)) {
throw new SQLException("connection must be to an SQLite db");
}
if (conn.isClosed()) {
throw new SQLException("connection closed");
}

f.conn = (SQLiteConnection)conn;
f.conn = (SQLiteConnection) conn;
f.db = f.conn.getDatabase();

if (name == null || name.length() > 255) {
throw new SQLException("invalid collation name: '"+name+"'");
throw new SQLException("invalid collation name: '" + name + "'");
}

if (f.db.create_collation(name, f) != Codes.SQLITE_OK) {
Expand All @@ -77,24 +73,25 @@ public static final void create(Connection conn, String name, Collation f)

/**
* Removes a named collation from the given connection.
*
* @param conn The connection to remove the collation from.
* @param name The name of the collation.
* @throws SQLException
*/
public static final void destroy(Connection conn, String name)
throws SQLException {
public static final void destroy(Connection conn, String name) throws SQLException {
if (conn == null || !(conn instanceof SQLiteConnection)) {
throw new SQLException("connection must be to an SQLite db");
}
((SQLiteConnection)conn).getDatabase().destroy_collation(name);
((SQLiteConnection) conn).getDatabase().destroy_collation(name);
}


/**
* Called by SQLite as a custom collation to compare two strings.
*
* @param str1 the first string in the comparison
* @param str2 the second string in the comparison
* @return an integer that is negative, zero, or positive if the first string is less than, equal to, or greater than the second, respectively
* @return an integer that is negative, zero, or positive if the first string is less than,
* equal to, or greater than the second, respectively
*/
protected abstract int xCompare(String str1, String str2);
}
Loading