Skip to content
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
1,250 changes: 1,250 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/junit.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: JUnit

on: [push]
on: [ push ]

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ QueryResult result = connection.insert()
This repository contains some basic rules specified in Code of Conduct file.<br>

<a href="https://github.com/ZorTik/AdvancedSQLClient/blob/master/CODE_OF_CONDUCT.md">Code of Conduct</a><br>
<a href="https://www.flaticon.com/free-icons/database" title="database icons">Database icons created by Freepik - Flaticon</a>
<a href="https://www.flaticon.com/free-icons/database" title="database icons">Database icons created by Freepik - Flaticon</a>
2 changes: 1 addition & 1 deletion api/src/main/java/me/zort/sqllib/api/Executive.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public interface Executive {

SQLConnection getConnection();
SQLConnection getConnection();

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.zort.sqllib.api;

public interface ISQLConnectionBuilder<C extends SQLConnection> {
C build(ISQLDatabaseOptions options);

C build(ISQLDatabaseOptions options);

}
30 changes: 19 additions & 11 deletions api/src/main/java/me/zort/sqllib/api/ISQLDatabaseOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@

public interface ISQLDatabaseOptions {

void setAutoReconnect(boolean autoReconnect);
void setDebug(boolean debug);
void setLogSqlErrors(boolean logSqlErrors);
void setNamingStrategy(NamingStrategy namingStrategy);
void setGson(Gson gson);

boolean isAutoReconnect();
boolean isDebug();
boolean isLogSqlErrors();
NamingStrategy getNamingStrategy();
Gson getGson();
void setAutoReconnect(boolean autoReconnect);

void setDebug(boolean debug);

void setLogSqlErrors(boolean logSqlErrors);

void setNamingStrategy(NamingStrategy namingStrategy);

void setGson(Gson gson);

boolean isAutoReconnect();

boolean isDebug();

boolean isLogSqlErrors();

NamingStrategy getNamingStrategy();

Gson getGson();

}
21 changes: 11 additions & 10 deletions api/src/main/java/me/zort/sqllib/api/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

public interface ObjectMapper {

void registerBackupValueResolver(@NotNull FieldValueResolver resolver);
<T> T assignValues(Row row, Class<T> typeClass);
void registerBackupValueResolver(@NotNull FieldValueResolver resolver);

interface FieldValueResolver {
Object obtainValue(SQLConnection connection,
AnnotatedElement element,
Row row,
String fieldName,
String convertedName,
Type type);
}
<T> T assignValues(Row row, Class<T> typeClass);

interface FieldValueResolver {
Object obtainValue(SQLConnection connection,
AnnotatedElement element,
Row row,
String fieldName,
String convertedName,
Type type);
}
}
29 changes: 16 additions & 13 deletions api/src/main/java/me/zort/sqllib/api/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@

/**
* This class represents a query.
*
* @author ZorTik
*/
public interface Query {

String buildQuery();
String buildQuery();

/**
* Returns the highest parent of this query
* tree.
* @return The parent.
*/
default Query getAncestor() {
return this;
}
/**
* Returns the highest parent of this query
* tree.
*
* @return The parent.
*/
default Query getAncestor() {
return this;
}

default boolean isAncestor() {
return getAncestor() == this;
}
default boolean isAncestor() {
return getAncestor() == this;
}

default void errorSignal(SQLException e) {}
default void errorSignal(SQLException e) {
}

}
50 changes: 25 additions & 25 deletions api/src/main/java/me/zort/sqllib/api/SQLConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@
*/
public interface SQLConnection {

/**
* Tries to connect to remote SQL server.
*
* @return True if connection was successful,
* otherwise false.
*/
boolean connect();

/**
* Tries to disconnect from remote SQL server.
*/
void disconnect();

/**
* Returns current running connection with
* SQL server.
*
* @return The connection.
*/
@Nullable
Connection getConnection();

default boolean isConnected() {
return getConnection() != null;
}
/**
* Tries to connect to remote SQL server.
*
* @return True if connection was successful,
* otherwise false.
*/
boolean connect();

/**
* Tries to disconnect from remote SQL server.
*/
void disconnect();

/**
* Returns current running connection with
* SQL server.
*
* @return The connection.
*/
@Nullable
Connection getConnection();

default boolean isConnected() {
return getConnection() != null;
}

}
14 changes: 8 additions & 6 deletions api/src/main/java/me/zort/sqllib/api/SQLEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

public interface SQLEndpoint {

String buildJdbc();
String getUsername();
String getPassword();
String buildJdbc();

default boolean isValid() {
return true;
}
String getUsername();

String getPassword();

default boolean isValid() {
return true;
}

}
16 changes: 8 additions & 8 deletions api/src/main/java/me/zort/sqllib/api/StatementFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
*/
public interface StatementFactory<T extends Statement> {

/**
* Prepares the statement for executing in {@link SQLConnection}.
*
* @param connection The connection to use.
* @return The prepared statement.
* @throws SQLException If an error occurs while preparing.
*/
T prepare(Connection connection) throws SQLException;
/**
* Prepares the statement for executing in {@link SQLConnection}.
*
* @param connection The connection to use.
* @return The prepared statement.
* @throws SQLException If an error occurs while preparing.
*/
T prepare(Connection connection) throws SQLException;

}
66 changes: 34 additions & 32 deletions api/src/main/java/me/zort/sqllib/api/cache/CacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,41 @@
*/
public interface CacheManager {

/**
* Sets a query result to the cache.
* If the query is already cached, it should be overwritten.
*
* @param query Query that was executed
* @param result Result
*/
void set(@NotNull Query query, @NotNull QueryResult result);
/**
* Sets a query result to the cache.
* If the query is already cached, it should be overwritten.
*
* @param query Query that was executed
* @param result Result
*/
void set(@NotNull Query query, @NotNull QueryResult result);

/**
* Returns a query result from the cache, or null if
* the query is not cached.
*
* @param query Query that was executed
* @param isExec Whether the query is an exec (no ResultSet) query
* @return The nullable query result
*/
@Nullable QueryResult get(@NotNull Query query, boolean isExec);
/**
* Returns a query result from the cache, or null if
* the query is not cached.
*
* @param query Query that was executed
* @param isExec Whether the query is an exec (no ResultSet) query
* @return The nullable query result
*/
@Nullable QueryResult get(@NotNull Query query, boolean isExec);

/**
* Returns a cache manager that does not cache anything.
*
* @return The cache manager
*/
static CacheManager noCache() {
return new CacheManager() {
@Override
public void set(@NotNull Query query, @NotNull QueryResult result) {}
@Override
public @Nullable QueryResult get(@NotNull Query query, boolean isExec) {
return null;
}
};
}
/**
* Returns a cache manager that does not cache anything.
*
* @return The cache manager
*/
static CacheManager noCache() {
return new CacheManager() {
@Override
public void set(@NotNull Query query, @NotNull QueryResult result) {
}

@Override
public @Nullable QueryResult get(@NotNull Query query, boolean isExec) {
return null;
}
};
}

}
38 changes: 20 additions & 18 deletions api/src/main/java/me/zort/sqllib/api/data/QueryResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@
*/
public interface QueryResult {

boolean isSuccessful();
@Nullable
String getRejectMessage();

QueryResult noChangesResult = successful();

static QueryResult successful() {
return new QueryResult() {
@Override
public boolean isSuccessful() {
return true;
}
@Override
public @Nullable String getRejectMessage() {
return null;
}
};
}
boolean isSuccessful();

@Nullable
String getRejectMessage();

QueryResult noChangesResult = successful();

static QueryResult successful() {
return new QueryResult() {
@Override
public boolean isSuccessful() {
return true;
}

@Override
public @Nullable String getRejectMessage() {
return null;
}
};
}

}
Loading