Skip to content

Commit

Permalink
Merge 'bindings/java: Fix naming rules' from Kim Seon Woo
Browse files Browse the repository at this point in the history
## Purpose of this PR
- Set rules for java naming, maybe we can add tests to  automatically
test rules in the future
- For java methods, don't use underbar(IMO using camelcase for java
methods seems to be the common convention)
- If method names collide, append 0 at the back
## Reference
#615

Closes #645
  • Loading branch information
penberg committed Jan 13, 2025
2 parents 9d42a48 + 84c987d commit fa6a9ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bindings/java/rs_src/limbo_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ERROR_CODE_ETC: i32 = 9999;

#[no_mangle]
#[allow(clippy::arc_with_non_send_sync)]
pub extern "system" fn Java_org_github_tursodatabase_core_LimboDB__1open_1utf8<'local>(
pub extern "system" fn Java_org_github_tursodatabase_core_LimboDB_openUtf8<'local>(
mut env: JNIEnv<'local>,
obj: JObject<'local>,
file_name_byte_arr: JByteArray<'local>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.github.tursodatabase.core;

import org.github.tursodatabase.LimboErrorCode;
import org.github.tursodatabase.NativeInvocation;
import org.github.tursodatabase.exceptions.LimboException;

import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -19,7 +15,7 @@ public abstract class AbstractDB {
private final String fileName;
private final AtomicBoolean closed = new AtomicBoolean(true);

public AbstractDB(String url, String filaName) throws SQLException {
public AbstractDB(String url, String filaName) {
this.url = url;
this.fileName = filaName;
}
Expand Down Expand Up @@ -52,10 +48,10 @@ public final synchronized void exec(String sql, boolean autoCommit) throws SQLEx
* @throws SQLException if a database access error occurs.
*/
public final synchronized void open(int openFlags) throws SQLException {
_open(fileName, openFlags);
open0(fileName, openFlags);
}

protected abstract void _open(String fileName, int openFlags) throws SQLException;
protected abstract void open0(String fileName, int openFlags) throws SQLException;

/**
* Closes a database connection and finalizes any remaining statements before the closing
Expand Down Expand Up @@ -100,14 +96,14 @@ public synchronized int finalize(SafeStmtPtr safePtr, long ptr) throws SQLExcept
* @return pointer to database instance
* @throws SQLException if a database access error occurs.
*/
protected abstract long _open_utf8(byte[] fileName, int openFlags) throws SQLException;
protected abstract long openUtf8(byte[] fileName, int openFlags) throws SQLException;

/**
* Closes the SQLite interface to a database.
*
* @throws SQLException if a database access error occurs.
*/
protected abstract void _close() throws SQLException;
protected abstract void close0() throws SQLException;

/**
* Compiles, evaluates, executes and commits an SQL statement.
Expand All @@ -116,7 +112,7 @@ public synchronized int finalize(SafeStmtPtr safePtr, long ptr) throws SQLExcept
* @return Result code.
* @throws SQLException if a database access error occurs.
*/
public abstract int _exec(String sql) throws SQLException;
public abstract int exec(String sql) throws SQLException;

/**
* Compiles an SQL statement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public final class LimboDB extends AbstractDB {
}
}

// url example: "jdbc:sqlite:{fileName}

/**
* @param url e.g. "jdbc:sqlite:fileName
* @param fileName e.g. path to file
Expand All @@ -41,7 +39,7 @@ public static LimboDB create(String url, String fileName) throws SQLException {
}

// TODO: receive config as argument
private LimboDB(String url, String fileName) throws SQLException {
private LimboDB(String url, String fileName) {
super(url, fileName);
}

Expand All @@ -53,7 +51,6 @@ public void load() {

try {
System.loadLibrary("_limbo_java");

} finally {
isLoaded = true;
}
Expand All @@ -63,31 +60,31 @@ public void load() {

// TODO: add support for JNI
@Override
protected synchronized native long _open_utf8(byte[] file, int openFlags) throws SQLException;
protected synchronized native long openUtf8(byte[] file, int openFlags) throws SQLException;

// TODO: add support for JNI
@Override
protected synchronized native void _close() throws SQLException;
protected synchronized native void close0() throws SQLException;

@Override
public synchronized int _exec(String sql) throws SQLException {
public synchronized int exec(String sql) throws SQLException {
// TODO: add implementation
throw new SQLFeatureNotSupportedException();
}

// TODO: add support for JNI
synchronized native int _exec_utf8(byte[] sqlUtf8) throws SQLException;
synchronized native int execUtf8(byte[] sqlUtf8) throws SQLException;

// TODO: add support for JNI
@Override
public native void interrupt();

@Override
protected void _open(String fileName, int openFlags) throws SQLException {
protected void open0(String fileName, int openFlags) throws SQLException {
if (isOpen) {
throwLimboException(LimboErrorCode.UNKNOWN_ERROR.code, "Already opened");
}
dbPtr = _open_utf8(stringToUtf8ByteArray(fileName), openFlags);
dbPtr = openUtf8(stringToUtf8ByteArray(fileName), openFlags);
isOpen = true;
}

Expand Down

0 comments on commit fa6a9ed

Please sign in to comment.