Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
48c32a3744 | |||
fc521d2287 | |||
15125e2d6d | |||
6f1dd991c5 | |||
009831f5db | |||
1bcdb1df8c | |||
7ae948bb79 | |||
29402fc27e | |||
eca28292d5 | |||
aef4cdabc3 | |||
04114aa0cf | |||
575102fbfa | |||
19fa13849e | |||
9ffebf1d1d | |||
e35a1ae879 | |||
9c9cf85f92 | |||
1a2302f548 | |||
808784889b | |||
f394254f38 | |||
0574d5da82 |
21
.classpath
21
.classpath
@@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry including="**/*.java" kind="src" output="out/maven/classes" path="src">
|
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="out/maven/test-classes" path="test/src">
|
<classpathentry kind="src" output="target/test-classes" path="test/src">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
@@ -18,17 +18,28 @@
|
|||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry excluding="**" kind="src" output="out/maven/test-classes" path="test/resources">
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="test/resources">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="output" path="out/maven/classes"/>
|
<classpathentry kind="src" path="target/generated-sources/annotations">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
4
.island/release.bash
Executable file
4
.island/release.bash
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
mvn versions:set -DnewVersion=$(cat version.txt)
|
||||||
|
|
@@ -84,7 +84,6 @@ Reformat XML file like the pom.xml
|
|||||||
XMLLINT_INDENT=" " xmllint --format "back/pom.xml" -o "back/pom.xml"
|
XMLLINT_INDENT=" " xmllint --format "back/pom.xml" -o "back/pom.xml"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Enable the pre-commit checker
|
Enable the pre-commit checker
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
@@ -94,6 +93,8 @@ Enable the pre-commit checker
|
|||||||
|
|
||||||
> **_Note_**: You can change the code in `.git/hooks/pre-commit` by replacing `formatter:verify` with `formatter:format` to auto format the code @ every commit
|
> **_Note_**: You can change the code in `.git/hooks/pre-commit` by replacing `formatter:verify` with `formatter:format` to auto format the code @ every commit
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Add Gitea in the dependency for the registry:
|
Add Gitea in the dependency for the registry:
|
||||||
=============================================
|
=============================================
|
||||||
|
|
||||||
|
28
pom.xml
28
pom.xml
@@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>kangaroo-and-rabbit</groupId>
|
<groupId>kangaroo-and-rabbit</groupId>
|
||||||
<artifactId>archidata</artifactId>
|
<artifactId>archidata</artifactId>
|
||||||
<version>0.6.0</version>
|
<version>0.6.3</version>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.version>3.1</maven.compiler.version>
|
<maven.compiler.version>3.1</maven.compiler.version>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
@@ -107,7 +107,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.16.0</version>
|
<version>2.16.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
|
<artifactId>jackson-dataformat-csv</artifactId>
|
||||||
|
<version>2.16.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.servlet</groupId>
|
<groupId>jakarta.servlet</groupId>
|
||||||
@@ -158,9 +163,20 @@
|
|||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>5.10.1</version>
|
<version>5.10.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.revelc.code.formatter</groupId>
|
||||||
|
<artifactId>formatter-maven-plugin</artifactId>
|
||||||
|
<version>2.23.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
<testSourceDirectory>test/src</testSourceDirectory>
|
<testSourceDirectory>test/src</testSourceDirectory>
|
||||||
@@ -241,7 +257,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.3.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<configLocation>CheckStyle.xml</configLocation>
|
<configLocation>CheckStyle.xml</configLocation>
|
||||||
<consoleOutput>true</consoleOutput>
|
<consoleOutput>true</consoleOutput>
|
||||||
@@ -253,7 +269,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>net.revelc.code.formatter</groupId>
|
<groupId>net.revelc.code.formatter</groupId>
|
||||||
<artifactId>formatter-maven-plugin</artifactId>
|
<artifactId>formatter-maven-plugin</artifactId>
|
||||||
<version>2.12.2</version>
|
<version>2.23.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<encoding>UTF-8</encoding>
|
<encoding>UTF-8</encoding>
|
||||||
<lineEnding>LF</lineEnding>
|
<lineEnding>LF</lineEnding>
|
||||||
|
@@ -5,6 +5,9 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.QueryOption;
|
||||||
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
|
import org.kar.archidata.dataAccess.options.DBInterfaceOption;
|
||||||
import org.kar.archidata.db.DBEntry;
|
import org.kar.archidata.db.DBEntry;
|
||||||
import org.kar.archidata.model.User;
|
import org.kar.archidata.model.User;
|
||||||
|
|
||||||
@@ -12,21 +15,22 @@ public class UserDB {
|
|||||||
|
|
||||||
public UserDB() {}
|
public UserDB() {}
|
||||||
|
|
||||||
public static User getUsers(final long userId) throws Exception {
|
public static User getUsers(final long userId, QueryOption... option) throws Exception {
|
||||||
return DataAccess.get(User.class, userId);
|
return DataAccess.get(User.class, userId, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static User getUserOrCreate(final long userId, final String userLogin) throws Exception {
|
public static User getUserOrCreate(final long userId, final String userLogin, QueryOption... option) throws Exception {
|
||||||
final User user = getUsers(userId);
|
final User user = getUsers(userId);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
createUsersInfoFromOAuth(userId, userLogin);
|
createUsersInfoFromOAuth(userId, userLogin, option);
|
||||||
return getUsers(userId);
|
return getUsers(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createUsersInfoFromOAuth(final long userId, final String login) throws IOException {
|
private static void createUsersInfoFromOAuth(final long userId, final String login, QueryOption... option) throws IOException {
|
||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
QueryOptions options = new QueryOptions(option);
|
||||||
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
final String query = "INSERT INTO `user` (`id`, `login`, `lastConnection`, `admin`, `blocked`, `removed`) VALUE (?,?,now(3),'0','0','0')";
|
final String query = "INSERT INTO `user` (`id`, `login`, `lastConnection`, `admin`, `blocked`, `removed`) VALUE (?,?,now(3),'0','0','0')";
|
||||||
try {
|
try {
|
||||||
final PreparedStatement ps = entry.connection.prepareStatement(query);
|
final PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||||
|
@@ -364,4 +364,17 @@ public class AnnotationTools {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Field getFieldNamed(final Class<?> clazz, final String name) throws Exception {
|
||||||
|
for (final Field field : clazz.getFields()) {
|
||||||
|
// static field is only for internal global declaration ==> remove it ..
|
||||||
|
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (AnnotationTools.getFieldName(field).equals(name)) {
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,7 @@ import jakarta.ws.rs.core.StreamingOutput;
|
|||||||
@Path("/data")
|
@Path("/data")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public class DataResource {
|
public class DataResource {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(MediaType.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DataResource.class);
|
||||||
private final static int CHUNK_SIZE = 1024 * 1024; // 1MB chunks
|
private final static int CHUNK_SIZE = 1024 * 1024; // 1MB chunks
|
||||||
private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks
|
private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks
|
||||||
/** Upload some datas */
|
/** Upload some datas */
|
||||||
|
@@ -22,7 +22,7 @@ public class JacksonCatcher implements ExceptionMapper<JsonProcessingException>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RestErrorResponse build(final Exception exception) {
|
private RestErrorResponse build(final Exception exception) {
|
||||||
return new RestErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Catch Unknown Exception", exception.getMessage());
|
return new RestErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Catch JSON Exception", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import java.lang.reflect.Constructor;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
@@ -15,7 +16,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.GlobalConfiguration;
|
|
||||||
import org.kar.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
import org.kar.archidata.annotation.CreationTimestamp;
|
import org.kar.archidata.annotation.CreationTimestamp;
|
||||||
import org.kar.archidata.annotation.DataDefault;
|
import org.kar.archidata.annotation.DataDefault;
|
||||||
@@ -26,6 +26,8 @@ import org.kar.archidata.dataAccess.addOn.AddOnManyToOne;
|
|||||||
import org.kar.archidata.dataAccess.addOn.AddOnSQLTableExternalForeinKeyAsList;
|
import org.kar.archidata.dataAccess.addOn.AddOnSQLTableExternalForeinKeyAsList;
|
||||||
import org.kar.archidata.dataAccess.options.CheckFunction;
|
import org.kar.archidata.dataAccess.options.CheckFunction;
|
||||||
import org.kar.archidata.dataAccess.options.Condition;
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
|
import org.kar.archidata.dataAccess.options.DBInterfaceOption;
|
||||||
|
import org.kar.archidata.dataAccess.options.DBInterfaceRoot;
|
||||||
import org.kar.archidata.dataAccess.options.FilterValue;
|
import org.kar.archidata.dataAccess.options.FilterValue;
|
||||||
import org.kar.archidata.dataAccess.options.TransmitKey;
|
import org.kar.archidata.dataAccess.options.TransmitKey;
|
||||||
import org.kar.archidata.db.DBEntry;
|
import org.kar.archidata.db.DBEntry;
|
||||||
@@ -41,12 +43,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import jakarta.ws.rs.InternalServerErrorException;
|
import jakarta.ws.rs.InternalServerErrorException;
|
||||||
|
|
||||||
/* TODO list:
|
/* TODO list:
|
||||||
- useful code to manage external query: List<T> query<T>(class<T> clazz, String query, List<Object> parameters);
|
|
||||||
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
|
|
||||||
ResultSetMetaData rsmd = rs.getMetaData();
|
|
||||||
String name = rsmd.getColumnName(1);
|
|
||||||
- Manage to group of SQL action to permit to commit only at the end.
|
- Manage to group of SQL action to permit to commit only at the end.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Data access is an abstraction class that permit to access on the DB with a function wrapping that permit to minimize the SQL writing of SQL code. This interface support the SQL and SQLite
|
/** Data access is an abstraction class that permit to access on the DB with a function wrapping that permit to minimize the SQL writing of SQL code. This interface support the SQL and SQLite
|
||||||
@@ -73,7 +70,8 @@ public class DataAccess {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDBExist(final String name) throws InternalServerErrorException {
|
public static boolean isDBExist(final String name, final QueryOption... option) throws InternalServerErrorException {
|
||||||
|
final QueryOptions options = new QueryOptions(option);
|
||||||
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
|
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||||
// no base manage in sqLite ...
|
// no base manage in sqLite ...
|
||||||
// TODO: check if the file exist or not ...
|
// TODO: check if the file exist or not ...
|
||||||
@@ -81,7 +79,7 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
DBEntry entry;
|
DBEntry entry;
|
||||||
try {
|
try {
|
||||||
entry = DBEntry.createInterface(GlobalConfiguration.dbConfig, true);
|
entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
} catch (final IOException ex) {
|
} catch (final IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
LOGGER.error("Can not check if the DB exist!!! {}", ex.getMessage());
|
LOGGER.error("Can not check if the DB exist!!! {}", ex.getMessage());
|
||||||
@@ -124,7 +122,7 @@ public class DataAccess {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return 1 == DataAccess.executeSimpleQuerry("CREATE DATABASE `" + name + "`;", true);
|
return 1 == DataAccess.executeSimpleQuerry("CREATE DATABASE `" + name + "`;", new DBInterfaceRoot(true));
|
||||||
} catch (final SQLException | IOException ex) {
|
} catch (final SQLException | IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
LOGGER.error("Can not check if the DB exist!!! {}", ex.getMessage());
|
LOGGER.error("Can not check if the DB exist!!! {}", ex.getMessage());
|
||||||
@@ -132,7 +130,8 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isTableExist(final String name) throws InternalServerErrorException {
|
public static boolean isTableExist(final String name, final QueryOption... option) throws InternalServerErrorException {
|
||||||
|
final QueryOptions options = new QueryOptions(option);
|
||||||
try {
|
try {
|
||||||
String request = "";
|
String request = "";
|
||||||
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
|
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||||
@@ -143,14 +142,14 @@ public class DataAccess {
|
|||||||
AND name = ?;
|
AND name = ?;
|
||||||
""";
|
""";
|
||||||
// PreparedStatement ps = entry.connection.prepareStatement("show tables");
|
// PreparedStatement ps = entry.connection.prepareStatement("show tables");
|
||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
final PreparedStatement ps = entry.connection.prepareStatement(request);
|
final PreparedStatement ps = entry.connection.prepareStatement(request);
|
||||||
ps.setString(1, name);
|
ps.setString(1, name);
|
||||||
final ResultSet ret = ps.executeQuery();
|
final ResultSet ret = ps.executeQuery();
|
||||||
final int count = ret.getInt("total");
|
final int count = ret.getInt("total");
|
||||||
return count == 1;
|
return count == 1;
|
||||||
} else {
|
} else {
|
||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
// TODO : Maybe connect with a temporary not specified connection interface to a db ...
|
// TODO : Maybe connect with a temporary not specified connection interface to a db ...
|
||||||
final PreparedStatement ps = entry.connection.prepareStatement("show tables");
|
final PreparedStatement ps = entry.connection.prepareStatement("show tables");
|
||||||
final ResultSet rs = ps.executeQuery();
|
final ResultSet rs = ps.executeQuery();
|
||||||
@@ -447,6 +446,196 @@ public class DataAccess {
|
|||||||
count.inc();
|
count.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: this function will replace the previous one !!!
|
||||||
|
protected static RetreiveFromDB createSetValueFromDbCallback(final int count, final Field field) throws Exception {
|
||||||
|
final Class<?> type = field.getType();
|
||||||
|
if (type == Long.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final Long tmp = rs.getLong(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.set(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == long.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final Long tmp = rs.getLong(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
// field.set(data, null);
|
||||||
|
} else {
|
||||||
|
field.setLong(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == Integer.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final Integer tmp = rs.getInt(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.set(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == int.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final Integer tmp = rs.getInt(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
// field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.setInt(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == Float.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final Float tmp = rs.getFloat(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.set(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == float.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final Float tmp = rs.getFloat(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
// field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.setFloat(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == Double.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final Double tmp = rs.getDouble(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.set(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == double.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final Double tmp = rs.getDouble(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
// field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.setDouble(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == Boolean.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final Boolean tmp = rs.getBoolean(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.set(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == boolean.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final Boolean tmp = rs.getBoolean(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
// field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.setBoolean(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == Timestamp.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final Timestamp tmp = rs.getTimestamp(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.set(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == Date.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
try {
|
||||||
|
final Timestamp tmp = rs.getTimestamp(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.set(obj, Date.from(tmp.toInstant()));
|
||||||
|
}
|
||||||
|
} catch (final SQLException ex) {
|
||||||
|
final String tmp = rs.getString(count);
|
||||||
|
LOGGER.error("Fail to parse the SQL time !!! {}", tmp);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
final Date date = DateTools.parseDate(tmp);
|
||||||
|
LOGGER.error("Fail to parse the SQL time !!! {}", date);
|
||||||
|
field.set(obj, date);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == LocalDate.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final java.sql.Date tmp = rs.getDate(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.set(obj, tmp.toLocalDate());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == LocalTime.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final java.sql.Time tmp = rs.getTime(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.set(obj, tmp.toLocalTime());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type == String.class) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final String tmp = rs.getString(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
field.set(obj, tmp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (type.isEnum()) {
|
||||||
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
|
final String tmp = rs.getString(count);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
field.set(obj, null);
|
||||||
|
} else {
|
||||||
|
boolean find = false;
|
||||||
|
final Object[] arr = type.getEnumConstants();
|
||||||
|
for (final Object elem : arr) {
|
||||||
|
if (elem.toString().equals(tmp)) {
|
||||||
|
field.set(obj, elem);
|
||||||
|
find = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!find) {
|
||||||
|
throw new DataAccessException("Enum value does not exist in the Model: '" + tmp + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
throw new DataAccessException("Unknown Field Type");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isAddOnField(final Field field) {
|
public static boolean isAddOnField(final Field field) {
|
||||||
return findAddOnforField(field) != null;
|
return findAddOnforField(field) != null;
|
||||||
}
|
}
|
||||||
@@ -480,7 +669,7 @@ public class DataAccess {
|
|||||||
check.getChecker().check("", data, AnnotationTools.getFieldsNames(clazz));
|
check.getChecker().check("", data, AnnotationTools.getFieldsNames(clazz));
|
||||||
}
|
}
|
||||||
|
|
||||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
final List<Field> asyncFieldUpdate = new ArrayList<>();
|
final List<Field> asyncFieldUpdate = new ArrayList<>();
|
||||||
Long uniqueSQLID = null;
|
Long uniqueSQLID = null;
|
||||||
final String tableName = AnnotationTools.getTableName(clazz, options);
|
final String tableName = AnnotationTools.getTableName(clazz, options);
|
||||||
@@ -622,7 +811,6 @@ public class DataAccess {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
entry.close();
|
entry.close();
|
||||||
entry = null;
|
|
||||||
}
|
}
|
||||||
final List<LazyGetter> asyncActions = new ArrayList<>();
|
final List<LazyGetter> asyncActions = new ArrayList<>();
|
||||||
for (final Field field : asyncFieldUpdate) {
|
for (final Field field : asyncFieldUpdate) {
|
||||||
@@ -734,9 +922,9 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final List<LazyGetter> asyncActions = new ArrayList<>();
|
final List<LazyGetter> asyncActions = new ArrayList<>();
|
||||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
// real add in the BDD:
|
// real add in the BDD:
|
||||||
try {
|
try (entry) {
|
||||||
final String tableName = AnnotationTools.getTableName(clazz, options);
|
final String tableName = AnnotationTools.getTableName(clazz, options);
|
||||||
// boolean createIfNotExist = clazz.getDeclaredAnnotationsByType(SQLIfNotExists.class).length != 0;
|
// boolean createIfNotExist = clazz.getDeclaredAnnotationsByType(SQLIfNotExists.class).length != 0;
|
||||||
final StringBuilder query = new StringBuilder();
|
final StringBuilder query = new StringBuilder();
|
||||||
@@ -830,9 +1018,6 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
} catch (final SQLException ex) {
|
} catch (final SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} finally {
|
|
||||||
entry.close();
|
|
||||||
entry = null;
|
|
||||||
}
|
}
|
||||||
for (final LazyGetter action : asyncActions) {
|
for (final LazyGetter action : asyncActions) {
|
||||||
action.doRequest();
|
action.doRequest();
|
||||||
@@ -885,26 +1070,20 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int executeSimpleQuerry(final String query, final boolean root) throws SQLException, IOException {
|
public static int executeSimpleQuerry(final String query, final QueryOption... option) throws SQLException, IOException {
|
||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig, root);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
final Statement stmt = entry.connection.createStatement();
|
final Statement stmt = entry.connection.createStatement();
|
||||||
return stmt.executeUpdate(query);
|
return stmt.executeUpdate(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int executeSimpleQuerry(final String query) throws SQLException, IOException {
|
public static boolean executeQuerry(final String query, final QueryOption... option) throws SQLException, IOException {
|
||||||
return executeSimpleQuerry(query, false);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
}
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
|
|
||||||
public static boolean executeQuerry(final String query, final boolean root) throws SQLException, IOException {
|
|
||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig, root);
|
|
||||||
final Statement stmt = entry.connection.createStatement();
|
final Statement stmt = entry.connection.createStatement();
|
||||||
return stmt.execute(query);
|
return stmt.execute(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean executeQuerry(final String query) throws SQLException, IOException {
|
|
||||||
return executeQuerry(query, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T getWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
|
public static <T> T getWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
options.add(new Limit(1));
|
options.add(new Limit(1));
|
||||||
@@ -915,8 +1094,6 @@ public class DataAccess {
|
|||||||
return values.get(0);
|
return values.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* public static <T> List<T> getsWhere(final Class<T> clazz, final QueryItem condition) throws Exception { return getsWhere(clazz, condition, null); } */
|
|
||||||
|
|
||||||
public static void generateSelectField(final StringBuilder querySelect, final StringBuilder query, final Class<?> clazz, final QueryOptions options, final CountInOut count) throws Exception {
|
public static void generateSelectField(final StringBuilder querySelect, final StringBuilder query, final Class<?> clazz, final QueryOptions options, final CountInOut count) throws Exception {
|
||||||
final boolean readAllfields = QueryOptions.readAllColomn(options);
|
final boolean readAllfields = QueryOptions.readAllColomn(options);
|
||||||
final String tableName = AnnotationTools.getTableName(clazz, options);
|
final String tableName = AnnotationTools.getTableName(clazz, options);
|
||||||
@@ -960,10 +1137,13 @@ public class DataAccess {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryOptions options) throws Exception {
|
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryOptions options) throws Exception {
|
||||||
final Condition condition = options.get(Condition.class);
|
Condition condition = options.get(Condition.class);
|
||||||
|
if (condition == null) {
|
||||||
|
condition = new Condition();
|
||||||
|
}
|
||||||
final List<LazyGetter> lazyCall = new ArrayList<>();
|
final List<LazyGetter> lazyCall = new ArrayList<>();
|
||||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
final List<T> outs = new ArrayList<>();
|
final List<T> outs = new ArrayList<>();
|
||||||
// real add in the BDD:
|
// real add in the BDD:
|
||||||
try {
|
try {
|
||||||
@@ -979,9 +1159,7 @@ public class DataAccess {
|
|||||||
generateSelectField(querySelect, query, clazz, options, count);
|
generateSelectField(querySelect, query, clazz, options, count);
|
||||||
querySelect.append(query.toString());
|
querySelect.append(query.toString());
|
||||||
query = querySelect;
|
query = querySelect;
|
||||||
if (condition != null) {
|
condition.whereAppendQuery(query, tableName, options, deletedFieldName);
|
||||||
condition.whereAppendQuery(query, tableName, options, deletedFieldName);
|
|
||||||
}
|
|
||||||
final OrderBy orders = options.get(OrderBy.class);
|
final OrderBy orders = options.get(OrderBy.class);
|
||||||
if (orders != null) {
|
if (orders != null) {
|
||||||
orders.generateQuerry(query, tableName);
|
orders.generateQuerry(query, tableName);
|
||||||
@@ -994,9 +1172,7 @@ public class DataAccess {
|
|||||||
// prepare the request:
|
// prepare the request:
|
||||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
||||||
final CountInOut iii = new CountInOut(1);
|
final CountInOut iii = new CountInOut(1);
|
||||||
if (condition != null) {
|
condition.injectQuerry(ps, iii);
|
||||||
condition.injectQuerry(ps, iii);
|
|
||||||
}
|
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
limit.injectQuerry(ps, iii);
|
limit.injectQuerry(ps, iii);
|
||||||
}
|
}
|
||||||
@@ -1020,7 +1196,6 @@ public class DataAccess {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
entry.close();
|
entry.close();
|
||||||
entry = null;
|
|
||||||
}
|
}
|
||||||
return outs;
|
return outs;
|
||||||
}
|
}
|
||||||
@@ -1066,9 +1241,12 @@ public class DataAccess {
|
|||||||
|
|
||||||
public static long countWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
public static long countWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
final Condition condition = options.get(Condition.class);
|
Condition condition = options.get(Condition.class);
|
||||||
|
if (condition == null) {
|
||||||
|
condition = new Condition();
|
||||||
|
}
|
||||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
long count = 0;
|
long count = 0;
|
||||||
// real add in the BDD:
|
// real add in the BDD:
|
||||||
try {
|
try {
|
||||||
@@ -1077,9 +1255,7 @@ public class DataAccess {
|
|||||||
query.append("SELECT COUNT(*) AS count FROM `");
|
query.append("SELECT COUNT(*) AS count FROM `");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
query.append("` ");
|
query.append("` ");
|
||||||
if (condition != null) {
|
condition.whereAppendQuery(query, tableName, options, deletedFieldName);
|
||||||
condition.whereAppendQuery(query, tableName, options, deletedFieldName);
|
|
||||||
}
|
|
||||||
final Limit limit = options.get(Limit.class);
|
final Limit limit = options.get(Limit.class);
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
limit.generateQuerry(query, tableName);
|
limit.generateQuerry(query, tableName);
|
||||||
@@ -1088,9 +1264,7 @@ public class DataAccess {
|
|||||||
// prepare the request:
|
// prepare the request:
|
||||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
||||||
final CountInOut iii = new CountInOut(1);
|
final CountInOut iii = new CountInOut(1);
|
||||||
if (condition != null) {
|
condition.injectQuerry(ps, iii);
|
||||||
condition.injectQuerry(ps, iii);
|
|
||||||
}
|
|
||||||
if (limit != null) {
|
if (limit != null) {
|
||||||
limit.injectQuerry(ps, iii);
|
limit.injectQuerry(ps, iii);
|
||||||
}
|
}
|
||||||
@@ -1174,8 +1348,7 @@ public class DataAccess {
|
|||||||
final String tableName = AnnotationTools.getTableName(clazz, options);
|
final String tableName = AnnotationTools.getTableName(clazz, options);
|
||||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||||
// find the deleted field
|
// find the deleted field
|
||||||
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
|
||||||
final StringBuilder query = new StringBuilder();
|
final StringBuilder query = new StringBuilder();
|
||||||
query.append("DELETE FROM `");
|
query.append("DELETE FROM `");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
@@ -1189,7 +1362,6 @@ public class DataAccess {
|
|||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} finally {
|
} finally {
|
||||||
entry.close();
|
entry.close();
|
||||||
entry = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1209,8 +1381,7 @@ public class DataAccess {
|
|||||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||||
/* String updateFieldName = null; if ("sqlite".equalsIgnoreCase(ConfigBaseVariable.getDBType())) { updateFieldName = AnnotationTools.getUpdatedFieldName(clazz); } */
|
/* String updateFieldName = null; if ("sqlite".equalsIgnoreCase(ConfigBaseVariable.getDBType())) { updateFieldName = AnnotationTools.getUpdatedFieldName(clazz); } */
|
||||||
// find the deleted field
|
// find the deleted field
|
||||||
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
|
||||||
final StringBuilder query = new StringBuilder();
|
final StringBuilder query = new StringBuilder();
|
||||||
query.append("UPDATE `");
|
query.append("UPDATE `");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
@@ -1228,7 +1399,6 @@ public class DataAccess {
|
|||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} finally {
|
} finally {
|
||||||
entry.close();
|
entry.close();
|
||||||
entry = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1253,7 +1423,7 @@ public class DataAccess {
|
|||||||
if (deletedFieldName == null) {
|
if (deletedFieldName == null) {
|
||||||
throw new DataAccessException("The class " + clazz.getCanonicalName() + " has no deleted field");
|
throw new DataAccessException("The class " + clazz.getCanonicalName() + " has no deleted field");
|
||||||
}
|
}
|
||||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
final StringBuilder query = new StringBuilder();
|
final StringBuilder query = new StringBuilder();
|
||||||
query.append("UPDATE `");
|
query.append("UPDATE `");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
@@ -1270,14 +1440,13 @@ public class DataAccess {
|
|||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} finally {
|
} finally {
|
||||||
entry.close();
|
entry.close();
|
||||||
entry = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drop(final Class<?> clazz, final QueryOption... option) throws Exception {
|
public static void drop(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
final String tableName = AnnotationTools.getTableName(clazz, options);
|
final String tableName = AnnotationTools.getTableName(clazz, options);
|
||||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
final StringBuilder query = new StringBuilder();
|
final StringBuilder query = new StringBuilder();
|
||||||
query.append("DROP TABLE IF EXISTS `");
|
query.append("DROP TABLE IF EXISTS `");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
@@ -1303,14 +1472,13 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
entry.close();
|
entry.close();
|
||||||
entry = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanAll(final Class<?> clazz, final QueryOption... option) throws Exception {
|
public static void cleanAll(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
final String tableName = AnnotationTools.getTableName(clazz, options);
|
final String tableName = AnnotationTools.getTableName(clazz, options);
|
||||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
final StringBuilder query = new StringBuilder();
|
final StringBuilder query = new StringBuilder();
|
||||||
query.append("DELETE FROM `");
|
query.append("DELETE FROM `");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
@@ -1340,4 +1508,87 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* - useful code to manage external query: List<T> query<T>(class<T> clazz, ); ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2"); */
|
||||||
|
public static <TYPE> List<TYPE> query(final Class<TYPE> clazz, final String query, final List<Object> parameters, final QueryOption... option) throws Exception {
|
||||||
|
final QueryOptions options = new QueryOptions(option);
|
||||||
|
return query(clazz, query, parameters, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <TYPE> List<TYPE> query(final Class<TYPE> clazz, final String queryBase, final List<Object> parameters, final QueryOptions options) throws Exception {
|
||||||
|
final List<LazyGetter> lazyCall = new ArrayList<>();
|
||||||
|
// TODO ... final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||||
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
|
|
||||||
|
Condition condition = options.get(Condition.class);
|
||||||
|
if (condition == null) {
|
||||||
|
condition = new Condition();
|
||||||
|
}
|
||||||
|
final StringBuilder query = new StringBuilder(queryBase);
|
||||||
|
final List<TYPE> outs = new ArrayList<>();
|
||||||
|
// real add in the BDD:
|
||||||
|
try {
|
||||||
|
final CountInOut count = new CountInOut();
|
||||||
|
condition.whereAppendQuery(query, null, options, null);
|
||||||
|
LOGGER.warn("generate the query: '{}'", query.toString());
|
||||||
|
// prepare the request:
|
||||||
|
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
||||||
|
final CountInOut iii = new CountInOut(1);
|
||||||
|
if (parameters != null) {
|
||||||
|
for (final Object elem : parameters) {
|
||||||
|
DataAccess.addElement(ps, elem, iii);
|
||||||
|
}
|
||||||
|
iii.inc();
|
||||||
|
}
|
||||||
|
condition.injectQuerry(ps, iii);
|
||||||
|
// execute the request
|
||||||
|
final ResultSet rs = ps.executeQuery();
|
||||||
|
final ResultSetMetaData rsmd = rs.getMetaData();
|
||||||
|
final List<RetreiveFromDB> actionToRetreive = new ArrayList<>();
|
||||||
|
for (int jjj = 0; jjj < rsmd.getColumnCount(); jjj++) {
|
||||||
|
final String name = rsmd.getColumnName(jjj + 1);
|
||||||
|
// find field name ...
|
||||||
|
final Field field = AnnotationTools.getFieldNamed(clazz, name);
|
||||||
|
if (field == null) {
|
||||||
|
throw new DataAccessException("Querry with unknown field: '" + name + "'");
|
||||||
|
}
|
||||||
|
// create the callback...
|
||||||
|
final RetreiveFromDB element = createSetValueFromDbCallback(jjj + 1, field);
|
||||||
|
actionToRetreive.add(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
count.value = 1;
|
||||||
|
final CountInOut countNotNull = new CountInOut(0);
|
||||||
|
Object data = null;
|
||||||
|
for (final Constructor<?> contructor : clazz.getConstructors()) {
|
||||||
|
if (contructor.getParameterCount() == 0) {
|
||||||
|
data = contructor.newInstance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (data == null) {
|
||||||
|
// TODO...
|
||||||
|
} else {
|
||||||
|
for (final RetreiveFromDB action : actionToRetreive) {
|
||||||
|
action.doRequest(rs, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final TYPE out = (TYPE) data;
|
||||||
|
outs.add(out);
|
||||||
|
}
|
||||||
|
LOGGER.info("Async calls: {}", lazyCall.size());
|
||||||
|
for (final LazyGetter elem : lazyCall) {
|
||||||
|
elem.doRequest();
|
||||||
|
}
|
||||||
|
} catch (final SQLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
throw ex;
|
||||||
|
} catch (final Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
entry.close();
|
||||||
|
}
|
||||||
|
return outs;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -17,6 +17,10 @@ public class QueryAnd implements QueryItem {
|
|||||||
Collections.addAll(this.childs, items);
|
Collections.addAll(this.childs, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void add(final QueryItem... items) {
|
||||||
|
Collections.addAll(this.childs, items);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||||
if (this.childs.size() >= 1) {
|
if (this.childs.size() >= 1) {
|
||||||
@@ -43,4 +47,8 @@ public class QueryAnd implements QueryItem {
|
|||||||
elem.injectQuerry(ps, iii);
|
elem.injectQuerry(ps, iii);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return this.childs.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,8 +15,10 @@ public class QueryCondition implements QueryItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||||
query.append(tableName);
|
if (tableName != null) {
|
||||||
query.append(".");
|
query.append(tableName);
|
||||||
|
query.append(".");
|
||||||
|
}
|
||||||
query.append(this.key);
|
query.append(this.key);
|
||||||
query.append(" ");
|
query.append(" ");
|
||||||
query.append(this.comparator);
|
query.append(this.comparator);
|
||||||
|
@@ -24,8 +24,10 @@ public class QueryInList<T> implements QueryItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||||
query.append(tableName);
|
if (tableName != null) {
|
||||||
query.append(".");
|
query.append(tableName);
|
||||||
|
query.append(".");
|
||||||
|
}
|
||||||
query.append(this.key);
|
query.append(this.key);
|
||||||
query.append(" ");
|
query.append(" ");
|
||||||
query.append(this.comparator);
|
query.append(this.comparator);
|
||||||
|
24
src/org/kar/archidata/dataAccess/QueryNotNull.java
Normal file
24
src/org/kar/archidata/dataAccess/QueryNotNull.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
|
||||||
|
public class QueryNotNull implements QueryItem {
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
public QueryNotNull(final String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||||
|
if (tableName != null) {
|
||||||
|
query.append(tableName);
|
||||||
|
query.append(".");
|
||||||
|
}
|
||||||
|
query.append(this.key);
|
||||||
|
query.append(" IS NOT NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {}
|
||||||
|
}
|
24
src/org/kar/archidata/dataAccess/QueryNull.java
Normal file
24
src/org/kar/archidata/dataAccess/QueryNull.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
|
||||||
|
public class QueryNull implements QueryItem {
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
public QueryNull(final String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||||
|
if (tableName != null) {
|
||||||
|
query.append(tableName);
|
||||||
|
query.append(".");
|
||||||
|
}
|
||||||
|
query.append(this.key);
|
||||||
|
query.append(" IS NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {}
|
||||||
|
}
|
@@ -64,5 +64,4 @@ public class QueryOptions {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
7
src/org/kar/archidata/dataAccess/RetreiveFromDB.java
Normal file
7
src/org/kar/archidata/dataAccess/RetreiveFromDB.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
|
||||||
|
public interface RetreiveFromDB {
|
||||||
|
void doRequest(final ResultSet rs, Object obj) throws Exception;
|
||||||
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
package org.kar.archidata.dataAccess.addOn;
|
package org.kar.archidata.dataAccess.addOn;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
@@ -17,6 +18,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
@@ -85,6 +87,40 @@ public class AddOnDataJson implements DataAccessAddOn {
|
|||||||
count.inc();
|
count.inc();
|
||||||
if (!rs.wasNull()) {
|
if (!rs.wasNull()) {
|
||||||
final ObjectMapper objectMapper = new ObjectMapper();
|
final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
if (field.getType() == List.class) {
|
||||||
|
ParameterizedType listType = (ParameterizedType) field.getGenericType();
|
||||||
|
Class<?> listClass = (Class<?>) listType.getActualTypeArguments()[0];
|
||||||
|
if (listClass == Long.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Long>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Float.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Float>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Double.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Double>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Integer.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Integer>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Short.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Short>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == String.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<String>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
final Object dataParsed = objectMapper.readValue(jsonData, field.getType());
|
final Object dataParsed = objectMapper.readValue(jsonData, field.getType());
|
||||||
field.set(data, dataParsed);
|
field.set(data, dataParsed);
|
||||||
}
|
}
|
||||||
|
@@ -73,7 +73,7 @@ public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(final Field field) {
|
public boolean canInsert(final Field field) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,7 +83,7 @@ public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRetrieve(final Field field) {
|
public boolean canRetrieve(final Field field) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -0,0 +1,48 @@
|
|||||||
|
package org.kar.archidata.dataAccess.options;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.kar.archidata.GlobalConfiguration;
|
||||||
|
import org.kar.archidata.dataAccess.QueryOption;
|
||||||
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
|
import org.kar.archidata.db.DBConfig;
|
||||||
|
import org.kar.archidata.db.DBEntry;
|
||||||
|
|
||||||
|
public class DBInterfaceOption extends QueryOption {
|
||||||
|
private DBEntry entry = null;
|
||||||
|
private final DBConfig config;
|
||||||
|
private final boolean root;
|
||||||
|
|
||||||
|
public DBInterfaceOption(final DBConfig config) {
|
||||||
|
this.config = config;
|
||||||
|
this.root = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DBInterfaceOption(final DBConfig config, boolean root) {
|
||||||
|
this.config = config;
|
||||||
|
this.root = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DBEntry getEntry(QueryOptions options) throws IOException {
|
||||||
|
if (this.entry == null) {
|
||||||
|
final DBInterfaceRoot isRoot = options.get(DBInterfaceRoot.class);
|
||||||
|
this.entry = DBEntry.createInterface(this.config, isRoot != null && isRoot.getRoot());
|
||||||
|
}
|
||||||
|
return this.entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getRoot() {
|
||||||
|
return this.root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DBEntry getAutoEntry(QueryOptions options) throws IOException {
|
||||||
|
final DBInterfaceOption dbOption = options.get(DBInterfaceOption.class);
|
||||||
|
if (dbOption == null) {
|
||||||
|
final DBInterfaceRoot isRoot = options.get(DBInterfaceRoot.class);
|
||||||
|
return DBEntry.createInterface(GlobalConfiguration.dbConfig, isRoot != null && isRoot.getRoot());
|
||||||
|
} else {
|
||||||
|
return dbOption.getEntry(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,16 @@
|
|||||||
|
package org.kar.archidata.dataAccess.options;
|
||||||
|
|
||||||
|
import org.kar.archidata.dataAccess.QueryOption;
|
||||||
|
|
||||||
|
public class DBInterfaceRoot extends QueryOption {
|
||||||
|
private final boolean root;
|
||||||
|
|
||||||
|
public DBInterfaceRoot(boolean root) {
|
||||||
|
this.root = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getRoot() {
|
||||||
|
return this.root;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -52,7 +52,7 @@ public class DBEntry implements Closeable {
|
|||||||
try {
|
try {
|
||||||
this.connection = DriverManager.getConnection(this.config.getUrl(true), this.config.getLogin(), this.config.getPassword());
|
this.connection = DriverManager.getConnection(this.config.getUrl(true), this.config.getLogin(), this.config.getPassword());
|
||||||
} catch (final SQLException ex) {
|
} catch (final SQLException ex) {
|
||||||
throw new IOException("Connection db fail: " + ex.getMessage());
|
throw new IOException("Connection db fail: " + ex.getMessage() + " On URL: " + this.config.getUrl(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ public class DBEntry implements Closeable {
|
|||||||
try {
|
try {
|
||||||
this.connection = DriverManager.getConnection(this.config.getUrl(), this.config.getLogin(), this.config.getPassword());
|
this.connection = DriverManager.getConnection(this.config.getUrl(), this.config.getLogin(), this.config.getPassword());
|
||||||
} catch (final SQLException ex) {
|
} catch (final SQLException ex) {
|
||||||
throw new IOException("Connection db fail: " + ex.getMessage());
|
throw new IOException("Connection db fail: " + ex.getMessage() + " On URL: " + this.config.getUrl(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -43,8 +43,8 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
|||||||
private ResourceInfo resourceInfo;
|
private ResourceInfo resourceInfo;
|
||||||
protected final String applicationName;
|
protected final String applicationName;
|
||||||
|
|
||||||
private static final String AUTHENTICATION_SCHEME = "Yota";
|
public static final String AUTHENTICATION_SCHEME = "Bearer";
|
||||||
private static final String AUTHENTICATION_TOKEN_SCHEME = "Zota";
|
public static final String APIKEY = "ApiKey";
|
||||||
|
|
||||||
public AuthenticationFilter(final String applicationName) {
|
public AuthenticationFilter(final String applicationName) {
|
||||||
this.applicationName = applicationName;
|
this.applicationName = applicationName;
|
||||||
@@ -58,7 +58,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
|||||||
// Access denied for all
|
// Access denied for all
|
||||||
if (method.isAnnotationPresent(DenyAll.class)) {
|
if (method.isAnnotationPresent(DenyAll.class)) {
|
||||||
LOGGER.debug(" ==> deny all {}", requestContext.getUriInfo().getPath());
|
LOGGER.debug(" ==> deny all {}", requestContext.getUriInfo().getPath());
|
||||||
requestContext.abortWith(Response.status(Response.Status.FORBIDDEN).entity("Access blocked !!!").build());
|
abortWithForbidden(requestContext, "Access blocked !!!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,28 +71,28 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
|||||||
// this is a security guard, all the API must define their access level:
|
// this is a security guard, all the API must define their access level:
|
||||||
if (!method.isAnnotationPresent(RolesAllowed.class)) {
|
if (!method.isAnnotationPresent(RolesAllowed.class)) {
|
||||||
LOGGER.error(" ==> missing @RolesAllowed {}", requestContext.getUriInfo().getPath());
|
LOGGER.error(" ==> missing @RolesAllowed {}", requestContext.getUriInfo().getPath());
|
||||||
requestContext.abortWith(Response.status(Response.Status.FORBIDDEN).entity("Access ILLEGAL !!!").build());
|
abortWithForbidden(requestContext, "Access ILLEGAL !!!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Authorization header from the request
|
// Get the Authorization header from the request
|
||||||
String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
|
String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
|
||||||
|
String apikeyHeader = requestContext.getHeaderString(APIKEY);
|
||||||
// logger.debug("authorizationHeader: {}", authorizationHeader);
|
// logger.debug("authorizationHeader: {}", authorizationHeader);
|
||||||
if (authorizationHeader == null && method.isAnnotationPresent(PermitTokenInURI.class)) {
|
if (authorizationHeader == null && apikeyHeader == null && method.isAnnotationPresent(PermitTokenInURI.class)) {
|
||||||
final MultivaluedMap<String, String> quaryparam = requestContext.getUriInfo().getQueryParameters();
|
final MultivaluedMap<String, String> quaryparam = requestContext.getUriInfo().getQueryParameters();
|
||||||
for (final Entry<String, List<String>> item : quaryparam.entrySet()) {
|
for (final Entry<String, List<String>> item : quaryparam.entrySet()) {
|
||||||
if (item.getKey().equals(HttpHeaders.AUTHORIZATION)) {
|
if ((authorizationHeader == null && HttpHeaders.AUTHORIZATION.equals(item.getKey())) && !item.getValue().isEmpty()) {
|
||||||
if (!item.getValue().isEmpty()) {
|
authorizationHeader = item.getValue().get(0);
|
||||||
authorizationHeader = item.getValue().get(0);
|
}
|
||||||
}
|
if ((apikeyHeader == null && APIKEY.equals(item.getKey())) && !item.getValue().isEmpty()) {
|
||||||
break;
|
apikeyHeader = item.getValue().get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// logger.debug("authorizationHeader: {}", authorizationHeader);
|
// logger.debug("authorizationHeader: {}", authorizationHeader);
|
||||||
final boolean isApplicationToken = isApplicationTokenBasedAuthentication(authorizationHeader);
|
final boolean isApplicationToken = apikeyHeader != null;
|
||||||
final boolean isJwtToken = isTokenBasedAuthentication(authorizationHeader);
|
final boolean isJwtToken = isTokenBasedAuthentication(authorizationHeader);
|
||||||
// Validate the Authorization header data Model "Yota jwt.to.ken" "Zota tokenId:hash(token)"
|
|
||||||
if (!isApplicationToken && !isJwtToken) {
|
if (!isApplicationToken && !isJwtToken) {
|
||||||
LOGGER.warn("REJECTED unauthorized: {}", requestContext.getUriInfo().getPath());
|
LOGGER.warn("REJECTED unauthorized: {}", requestContext.getUriInfo().getPath());
|
||||||
abortWithUnauthorized(requestContext, "REJECTED unauthorized: " + requestContext.getUriInfo().getPath());
|
abortWithUnauthorized(requestContext, "REJECTED unauthorized: " + requestContext.getUriInfo().getPath());
|
||||||
@@ -100,7 +100,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
|||||||
}
|
}
|
||||||
UserByToken userByToken = null;
|
UserByToken userByToken = null;
|
||||||
if (isJwtToken) {
|
if (isJwtToken) {
|
||||||
// Extract the token from the Authorization header (Remove "Yota ")
|
// Extract the token from the Authorization header (Remove "Bearer ")
|
||||||
final String token = authorizationHeader.substring(AUTHENTICATION_SCHEME.length()).trim();
|
final String token = authorizationHeader.substring(AUTHENTICATION_SCHEME.length()).trim();
|
||||||
// logger.debug("token: {}", token);
|
// logger.debug("token: {}", token);
|
||||||
try {
|
try {
|
||||||
@@ -116,9 +116,7 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Extract the token from the Authorization header (Remove "Zota ")
|
final String token = apikeyHeader.trim();
|
||||||
final String token = authorizationHeader.substring(AUTHENTICATION_TOKEN_SCHEME.length()).trim();
|
|
||||||
// logger.debug("token: {}", token);
|
|
||||||
try {
|
try {
|
||||||
userByToken = validateToken(token);
|
userByToken = validateToken(token);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
@@ -164,13 +162,6 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
|||||||
return authorizationHeader != null && authorizationHeader.toLowerCase().startsWith(AUTHENTICATION_SCHEME.toLowerCase() + " ");
|
return authorizationHeader != null && authorizationHeader.toLowerCase().startsWith(AUTHENTICATION_SCHEME.toLowerCase() + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isApplicationTokenBasedAuthentication(final String authorizationHeader) {
|
|
||||||
// Check if the Authorization header is valid
|
|
||||||
// It must not be null and must be prefixed with "Bearer" plus a whitespace
|
|
||||||
// The authentication scheme comparison must be case-insensitive
|
|
||||||
return authorizationHeader != null && authorizationHeader.toLowerCase().startsWith(AUTHENTICATION_TOKEN_SCHEME.toLowerCase() + " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void abortWithUnauthorized(final ContainerRequestContext requestContext, final String message) {
|
private void abortWithUnauthorized(final ContainerRequestContext requestContext, final String message) {
|
||||||
|
|
||||||
// Abort the filter chain with a 401 status code response
|
// Abort the filter chain with a 401 status code response
|
||||||
@@ -182,6 +173,12 @@ public class AuthenticationFilter implements ContainerRequestFilter {
|
|||||||
.type(MediaType.APPLICATION_JSON).build());
|
.type(MediaType.APPLICATION_JSON).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void abortWithForbidden(final ContainerRequestContext requestContext, final String message) {
|
||||||
|
final RestErrorResponse ret = new RestErrorResponse(Response.Status.FORBIDDEN, "FORBIDDEN", message);
|
||||||
|
LOGGER.error("Error UUID={}", ret.uuid);
|
||||||
|
requestContext.abortWith(Response.status(ret.status).header(HttpHeaders.WWW_AUTHENTICATE, message).entity(ret).type(MediaType.APPLICATION_JSON).build());
|
||||||
|
}
|
||||||
|
|
||||||
protected UserByToken validateToken(final String authorization) throws Exception {
|
protected UserByToken validateToken(final String authorization) throws Exception {
|
||||||
LOGGER.info("Must be Override by the application implmentation, otherwise it dose not work");
|
LOGGER.info("Must be Override by the application implmentation, otherwise it dose not work");
|
||||||
return null;
|
return null;
|
||||||
|
@@ -35,13 +35,13 @@ class MySecurityContext implements SecurityContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSecure() {
|
public boolean isSecure() {
|
||||||
return this.sheme.equalsIgnoreCase("https");
|
return "https".equalsIgnoreCase(this.sheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAuthenticationScheme() {
|
public String getAuthenticationScheme() {
|
||||||
if (this.contextPrincipale.userByToken != null) {
|
if (this.contextPrincipale.userByToken != null) {
|
||||||
return "Zota";
|
return "Bearer";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
49
src/org/kar/archidata/serializer/CSVMessageBodyWriter.java
Normal file
49
src/org/kar/archidata/serializer/CSVMessageBodyWriter.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package org.kar.archidata.serializer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
|
||||||
|
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.Produces;
|
||||||
|
import jakarta.ws.rs.WebApplicationException;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.MultivaluedMap;
|
||||||
|
import jakarta.ws.rs.ext.MessageBodyWriter;
|
||||||
|
import jakarta.ws.rs.ext.Provider;
|
||||||
|
|
||||||
|
/** Body writer use in jersey with : In your main: ```java rc.register(new CSVMessageBodyWritter()); ```
|
||||||
|
*
|
||||||
|
* and in the produce element: ```java
|
||||||
|
* @GET
|
||||||
|
* @Produces(CSVMessageBodyWritter.CSV_TYPE) public List<Data> getData() {} ``` */
|
||||||
|
@Provider
|
||||||
|
@Produces("text/csv")
|
||||||
|
public class CSVMessageBodyWriter implements MessageBodyWriter<List<Object>> {
|
||||||
|
public static final String CSV_TYPE = "text/csv";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
|
||||||
|
return List.class.isAssignableFrom(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSize(final List<Object> data, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(final List<Object> data, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType,
|
||||||
|
final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException {
|
||||||
|
if (data != null && data.size() > 0) {
|
||||||
|
final CsvMapper mapper = new CsvMapper();
|
||||||
|
final Object o = data.get(0);
|
||||||
|
final CsvSchema schema = mapper.schemaFor(o.getClass()).withHeader();
|
||||||
|
mapper.writer(schema).writeValue(entityStream, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -14,6 +14,9 @@ public class ConfigBaseVariable {
|
|||||||
static public String ssoAdress;
|
static public String ssoAdress;
|
||||||
static public String ssoToken;
|
static public String ssoToken;
|
||||||
static public String testMode;
|
static public String testMode;
|
||||||
|
static public String eMailFrom;
|
||||||
|
static public String eMailLogin;
|
||||||
|
static public String eMailPassword;
|
||||||
|
|
||||||
// For test only
|
// For test only
|
||||||
public static void clearAllValue() {
|
public static void clearAllValue() {
|
||||||
@@ -30,6 +33,9 @@ public class ConfigBaseVariable {
|
|||||||
ssoAdress = System.getenv("SSO_ADDRESS");
|
ssoAdress = System.getenv("SSO_ADDRESS");
|
||||||
ssoToken = System.getenv("SSO_TOKEN");
|
ssoToken = System.getenv("SSO_TOKEN");
|
||||||
testMode = System.getenv("TEST_MODE");
|
testMode = System.getenv("TEST_MODE");
|
||||||
|
eMailFrom = System.getenv("EMAIL_FROM");
|
||||||
|
eMailLogin = System.getenv("EMAIL_LOGIN");
|
||||||
|
eMailPassword = System.getenv("EMAIL_PASSWORD");
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -120,4 +126,15 @@ public class ConfigBaseVariable {
|
|||||||
}
|
}
|
||||||
return Boolean.parseBoolean(testMode);
|
return Boolean.parseBoolean(testMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record EMailConfig(String from, String login, String password) {
|
||||||
|
};
|
||||||
|
|
||||||
|
public static EMailConfig getEMailConfig() {
|
||||||
|
if (eMailFrom == null || eMailLogin == null || eMailPassword == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new EMailConfig(eMailFrom, eMailLogin, eMailPassword);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ import org.kar.archidata.dataAccess.QueryAnd;
|
|||||||
import org.kar.archidata.dataAccess.QueryCondition;
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
||||||
import org.kar.archidata.dataAccess.options.Condition;
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
|
import org.kar.archidata.dataAccess.options.ReadAllColumn;
|
||||||
import org.kar.archidata.model.Data;
|
import org.kar.archidata.model.Data;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -76,7 +77,7 @@ public class DataTools {
|
|||||||
|
|
||||||
public static Data getWithSha512(final String sha512) {
|
public static Data getWithSha512(final String sha512) {
|
||||||
try {
|
try {
|
||||||
return DataAccess.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512)));
|
return DataAccess.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512)), new ReadAllColumn());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@@ -11,6 +11,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.kar.archidata.filter.AuthenticationFilter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ class TestSigner implements JWSSigner {
|
|||||||
public class JWTWrapper {
|
public class JWTWrapper {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(JWTWrapper.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(JWTWrapper.class);
|
||||||
|
|
||||||
private static RSAKey rsaJWK = null;;
|
private static RSAKey rsaJWK = null;
|
||||||
private static RSAKey rsaPublicJWK = null;
|
private static RSAKey rsaPublicJWK = null;
|
||||||
|
|
||||||
public static class PublicKey {
|
public static class PublicKey {
|
||||||
@@ -89,7 +90,7 @@ public class JWTWrapper {
|
|||||||
con.setRequestProperty("Accept", "application/json");
|
con.setRequestProperty("Accept", "application/json");
|
||||||
final String ssoToken = ConfigBaseVariable.ssoToken();
|
final String ssoToken = ConfigBaseVariable.ssoToken();
|
||||||
if (ssoToken != null) {
|
if (ssoToken != null) {
|
||||||
con.setRequestProperty("Authorization", "Zota " + ssoToken);
|
con.setRequestProperty(AuthenticationFilter.APIKEY, ssoToken);
|
||||||
}
|
}
|
||||||
final int responseCode = con.getResponseCode();
|
final int responseCode = con.getResponseCode();
|
||||||
|
|
||||||
@@ -244,9 +245,7 @@ public class JWTWrapper {
|
|||||||
// LOGGER.debug("JWT token is verified 'alice' =?= '" + signedJWT.getJWTClaimsSet().getSubject() + "'");
|
// LOGGER.debug("JWT token is verified 'alice' =?= '" + signedJWT.getJWTClaimsSet().getSubject() + "'");
|
||||||
// LOGGER.debug("JWT token isuer 'https://c2id.com' =?= '" + signedJWT.getJWTClaimsSet().getIssuer() + "'");
|
// LOGGER.debug("JWT token isuer 'https://c2id.com' =?= '" + signedJWT.getJWTClaimsSet().getIssuer() + "'");
|
||||||
return signedJWT.getJWTClaimsSet();
|
return signedJWT.getJWTClaimsSet();
|
||||||
} catch (final JOSEException ex) {
|
} catch (final JOSEException | ParseException e) {
|
||||||
ex.printStackTrace();
|
|
||||||
} catch (final ParseException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@@ -40,7 +40,7 @@ public class RESTApi {
|
|||||||
final HttpClient client = HttpClient.newHttpClient();
|
final HttpClient client = HttpClient.newHttpClient();
|
||||||
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1).uri(URI.create(this.baseUrl + urlOffset));
|
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1).uri(URI.create(this.baseUrl + urlOffset));
|
||||||
if (this.token != null) {
|
if (this.token != null) {
|
||||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Yota " + this.token);
|
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
|
||||||
}
|
}
|
||||||
final HttpRequest request = requestBuilding.GET().build();
|
final HttpRequest request = requestBuilding.GET().build();
|
||||||
final HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
final HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
@@ -111,7 +111,7 @@ public class RESTApi {
|
|||||||
LOGGER.trace("call {}: {}", model, URI.create(this.baseUrl + urlOffset));
|
LOGGER.trace("call {}: {}", model, URI.create(this.baseUrl + urlOffset));
|
||||||
LOGGER.trace("DATA: {}", body);
|
LOGGER.trace("DATA: {}", body);
|
||||||
if (this.token != null) {
|
if (this.token != null) {
|
||||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Yota " + this.token);
|
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
|
||||||
}
|
}
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
body = "";
|
body = "";
|
||||||
@@ -143,7 +143,7 @@ public class RESTApi {
|
|||||||
String body = null;
|
String body = null;
|
||||||
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1).uri(URI.create(this.baseUrl + urlOffset));
|
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1).uri(URI.create(this.baseUrl + urlOffset));
|
||||||
if (this.token != null) {
|
if (this.token != null) {
|
||||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Yota " + this.token);
|
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
|
||||||
}
|
}
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
body = "";
|
body = "";
|
||||||
@@ -171,7 +171,7 @@ public class RESTApi {
|
|||||||
final HttpClient client = HttpClient.newHttpClient();
|
final HttpClient client = HttpClient.newHttpClient();
|
||||||
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1).uri(URI.create(this.baseUrl + urlOffset));
|
Builder requestBuilding = HttpRequest.newBuilder().version(Version.HTTP_1_1).uri(URI.create(this.baseUrl + urlOffset));
|
||||||
if (this.token != null) {
|
if (this.token != null) {
|
||||||
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Yota " + this.token);
|
requestBuilding = requestBuilding.header(HttpHeaders.AUTHORIZATION, "Bearer " + this.token);
|
||||||
}
|
}
|
||||||
final HttpRequest request = requestBuilding.DELETE().build();
|
final HttpRequest request = requestBuilding.DELETE().build();
|
||||||
final HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
final HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
@@ -53,7 +53,7 @@ public class TestJson {
|
|||||||
final List<String> sqlCommand = DataFactory.createTable(SerializeAsJson.class);
|
final List<String> sqlCommand = DataFactory.createTable(SerializeAsJson.class);
|
||||||
for (final String elem : sqlCommand) {
|
for (final String elem : sqlCommand) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
DataAccess.executeSimpleQuerry(elem, false);
|
DataAccess.executeSimpleQuerry(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ public class TestListJson {
|
|||||||
final List<String> sqlCommand = DataFactory.createTable(SerializeListAsJson.class);
|
final List<String> sqlCommand = DataFactory.createTable(SerializeListAsJson.class);
|
||||||
for (final String elem : sqlCommand) {
|
for (final String elem : sqlCommand) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
DataAccess.executeSimpleQuerry(elem, false);
|
DataAccess.executeSimpleQuerry(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -57,7 +57,7 @@ public class TestManyToMany {
|
|||||||
sqlCommand.addAll(sqlCommand2);
|
sqlCommand.addAll(sqlCommand2);
|
||||||
for (final String elem : sqlCommand) {
|
for (final String elem : sqlCommand) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
DataAccess.executeSimpleQuerry(elem, false);
|
DataAccess.executeSimpleQuerry(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -56,7 +56,7 @@ public class TestManyToOne {
|
|||||||
sqlCommand.addAll(sqlCommand2);
|
sqlCommand.addAll(sqlCommand2);
|
||||||
for (final String elem : sqlCommand) {
|
for (final String elem : sqlCommand) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
DataAccess.executeSimpleQuerry(elem, false);
|
DataAccess.executeSimpleQuerry(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -51,7 +51,7 @@ public class TestOneToMany {
|
|||||||
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
||||||
for (final String elem : sqlCommand) {
|
for (final String elem : sqlCommand) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
DataAccess.executeSimpleQuerry(elem, false);
|
DataAccess.executeSimpleQuerry(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
121
test/src/test/kar/archidata/TestRawQuery.java
Normal file
121
test/src/test/kar/archidata/TestRawQuery.java
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
package test.kar.archidata;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.MethodOrderer;
|
||||||
|
import org.junit.jupiter.api.Order;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.kar.archidata.GlobalConfiguration;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
|
import org.kar.archidata.db.DBEntry;
|
||||||
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import test.kar.archidata.model.TypesTable;
|
||||||
|
|
||||||
|
@ExtendWith(StepwiseExtension.class)
|
||||||
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
|
public class TestRawQuery {
|
||||||
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypes.class);
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void configureWebServer() throws Exception {
|
||||||
|
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||||
|
ConfigBaseVariable.dbType = "sqlite";
|
||||||
|
ConfigBaseVariable.dbHost = "memory";
|
||||||
|
// for test we need to connect all time the DB
|
||||||
|
ConfigBaseVariable.dbKeepConnected = "true";
|
||||||
|
}
|
||||||
|
// Connect the dataBase...
|
||||||
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
|
entry.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
public static void removeDataBase() throws IOException {
|
||||||
|
LOGGER.info("Remove the test db");
|
||||||
|
DBEntry.closeAllForceMode();
|
||||||
|
ConfigBaseVariable.clearAllValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Order(1)
|
||||||
|
@Test
|
||||||
|
public void testCreateTable() throws Exception {
|
||||||
|
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
||||||
|
for (final String elem : sqlCommand) {
|
||||||
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
DataAccess.executeSimpleQuerry(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Order(2)
|
||||||
|
@Test
|
||||||
|
public void testGet() throws Exception {
|
||||||
|
|
||||||
|
final TypesTable test = new TypesTable();
|
||||||
|
test.intData = 95;
|
||||||
|
test.floatData = 1.0F;
|
||||||
|
DataAccess.insert(test);
|
||||||
|
test.intData = 96;
|
||||||
|
test.floatData = 2.0F;
|
||||||
|
DataAccess.insert(test);
|
||||||
|
test.intData = 97;
|
||||||
|
test.floatData = 3.0F;
|
||||||
|
DataAccess.insert(test);
|
||||||
|
test.intData = 98;
|
||||||
|
test.floatData = 4.0F;
|
||||||
|
DataAccess.insert(test);
|
||||||
|
test.intData = 99;
|
||||||
|
test.floatData = 5.0F;
|
||||||
|
DataAccess.insert(test);
|
||||||
|
test.intData = 99;
|
||||||
|
test.floatData = 6.0F;
|
||||||
|
DataAccess.insert(test);
|
||||||
|
test.intData = 99;
|
||||||
|
test.floatData = 7.0F;
|
||||||
|
DataAccess.insert(test);
|
||||||
|
{
|
||||||
|
String querry = """
|
||||||
|
SELECT *
|
||||||
|
FROM TypesTable
|
||||||
|
WHERE `intData` = ?
|
||||||
|
ORDER BY id DESC
|
||||||
|
""";
|
||||||
|
List<Object> parameters = List.of(Integer.valueOf(99));
|
||||||
|
// Try to retrieve all the data:
|
||||||
|
final List<TypesTable> retrieve = DataAccess.query(TypesTable.class, querry, parameters);
|
||||||
|
|
||||||
|
Assertions.assertNotNull(retrieve);
|
||||||
|
Assertions.assertEquals(3, retrieve.size());
|
||||||
|
Assertions.assertEquals(99, retrieve.get(0).intData);
|
||||||
|
Assertions.assertEquals(7.0F, retrieve.get(0).floatData);
|
||||||
|
Assertions.assertEquals(6.0F, retrieve.get(1).floatData);
|
||||||
|
Assertions.assertEquals(5.0F, retrieve.get(2).floatData);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
|
||||||
|
String querry = """
|
||||||
|
SELECT DISTINCT intData
|
||||||
|
FROM TypesTable
|
||||||
|
WHERE `intData` = ?
|
||||||
|
ORDER BY id DESC
|
||||||
|
""";
|
||||||
|
List<Object> parameters = List.of(Integer.valueOf(99));
|
||||||
|
// Try to retrieve all the data:
|
||||||
|
final List<TypesTable> retrieve = DataAccess.query(TypesTable.class, querry, parameters);
|
||||||
|
|
||||||
|
Assertions.assertNotNull(retrieve);
|
||||||
|
Assertions.assertEquals(1, retrieve.size());
|
||||||
|
Assertions.assertEquals(99, retrieve.get(0).intData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -65,7 +65,7 @@ public class TestSimpleTable {
|
|||||||
final List<String> sqlCommand = DataFactory.createTable(SimpleTable.class);
|
final List<String> sqlCommand = DataFactory.createTable(SimpleTable.class);
|
||||||
for (final String elem : sqlCommand) {
|
for (final String elem : sqlCommand) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
DataAccess.executeSimpleQuerry(elem, false);
|
DataAccess.executeSimpleQuerry(elem);
|
||||||
}
|
}
|
||||||
final SimpleTable test = new SimpleTable();
|
final SimpleTable test = new SimpleTable();
|
||||||
test.data = TestSimpleTable.DATA_INJECTED;
|
test.data = TestSimpleTable.DATA_INJECTED;
|
||||||
|
@@ -65,7 +65,7 @@ public class TestSimpleTableSoftDelete {
|
|||||||
final List<String> sqlCommand = DataFactory.createTable(SimpleTableSoftDelete.class);
|
final List<String> sqlCommand = DataFactory.createTable(SimpleTableSoftDelete.class);
|
||||||
for (final String elem : sqlCommand) {
|
for (final String elem : sqlCommand) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
DataAccess.executeSimpleQuerry(elem, false);
|
DataAccess.executeSimpleQuerry(elem);
|
||||||
}
|
}
|
||||||
final SimpleTableSoftDelete test = new SimpleTableSoftDelete();
|
final SimpleTableSoftDelete test = new SimpleTableSoftDelete();
|
||||||
test.data = TestSimpleTableSoftDelete.DATA_INJECTED;
|
test.data = TestSimpleTableSoftDelete.DATA_INJECTED;
|
||||||
|
@@ -53,7 +53,7 @@ public class TestTypeEnum1 {
|
|||||||
final List<String> sqlCommand = DataFactory.createTable(TypesEnum1.class);
|
final List<String> sqlCommand = DataFactory.createTable(TypesEnum1.class);
|
||||||
for (final String elem : sqlCommand) {
|
for (final String elem : sqlCommand) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
DataAccess.executeSimpleQuerry(elem, false);
|
DataAccess.executeSimpleQuerry(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ public class TestTypeEnum2 {
|
|||||||
final List<String> sqlCommand = DataFactory.createTable(TypesEnum2.class);
|
final List<String> sqlCommand = DataFactory.createTable(TypesEnum2.class);
|
||||||
for (final String elem : sqlCommand) {
|
for (final String elem : sqlCommand) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
DataAccess.executeSimpleQuerry(elem, false);
|
DataAccess.executeSimpleQuerry(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -57,7 +57,7 @@ public class TestTypes {
|
|||||||
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
||||||
for (final String elem : sqlCommand) {
|
for (final String elem : sqlCommand) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
DataAccess.executeSimpleQuerry(elem, false);
|
DataAccess.executeSimpleQuerry(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,5 +23,5 @@ function __run() #(step, name, cmd)
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
__run "1/1" "Check JAVA code format" "mvn formatter:verify"
|
__run "1/1" "Check JAVA code format" "mvn formatter:validate"
|
||||||
|
|
||||||
|
@@ -1 +1 @@
|
|||||||
0.6.0
|
0.6.3
|
||||||
|
Reference in New Issue
Block a user