Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 009831f5db | |||
| 1bcdb1df8c | |||
| 7ae948bb79 | |||
| 29402fc27e | |||
| eca28292d5 | |||
| aef4cdabc3 | |||
| 04114aa0cf | |||
| 575102fbfa | |||
| 19fa13849e | |||
| 9ffebf1d1d | |||
| e35a1ae879 | |||
| 9c9cf85f92 | |||
| 1a2302f548 | |||
| 808784889b | |||
| f394254f38 | |||
| 0574d5da82 |
10
.classpath
10
.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,17 @@
|
|||||||
<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="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.2</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,28 +5,32 @@ 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;
|
||||||
|
|
||||||
public class UserDB {
|
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);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import jakarta.validation.constraints.Size;
|
|||||||
|
|
||||||
public class AnnotationTools {
|
public class AnnotationTools {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(AnnotationTools.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(AnnotationTools.class);
|
||||||
|
|
||||||
public static String getTableName(final Class<?> clazz, final QueryOptions options) throws Exception {
|
public static String getTableName(final Class<?> clazz, final QueryOptions options) throws Exception {
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
final OverrideTableName data = options.get(OverrideTableName.class);
|
final OverrideTableName data = options.get(OverrideTableName.class);
|
||||||
@@ -35,7 +35,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return AnnotationTools.getTableName(clazz);
|
return AnnotationTools.getTableName(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTableName(final Class<?> element) throws Exception {
|
public static String getTableName(final Class<?> element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Table.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Table.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -51,7 +51,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSchemedescription(final Field element) throws Exception {
|
public static String getSchemedescription(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Schema.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Schema.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -62,7 +62,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return ((Schema) annotation[0]).description();
|
return ((Schema) annotation[0]).description();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getComment(final Field element) throws Exception {
|
public static String getComment(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DataComment.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DataComment.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -73,7 +73,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return ((DataComment) annotation[0]).value();
|
return ((DataComment) annotation[0]).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDefault(final Field element) throws Exception {
|
public static String getDefault(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DataDefault.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DataDefault.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -84,7 +84,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return ((DataDefault) annotation[0]).value();
|
return ((DataDefault) annotation[0]).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ManyToOne getManyToOne(final Field element) throws Exception {
|
public static ManyToOne getManyToOne(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ManyToOne.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(ManyToOne.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -95,7 +95,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return (ManyToOne) annotation[0];
|
return (ManyToOne) annotation[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataJson getDataJson(final Field element) throws Exception {
|
public static DataJson getDataJson(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DataJson.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DataJson.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -106,7 +106,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return (DataJson) annotation[0];
|
return (DataJson) annotation[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Long getConstraintsMax(final Field element) throws Exception {
|
public static Long getConstraintsMax(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Max.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Max.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -117,7 +117,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return ((Max) annotation[0]).value();
|
return ((Max) annotation[0]).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Long getConstraintsMin(final Field element) throws Exception {
|
public static Long getConstraintsMin(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Min.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Min.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -128,7 +128,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return ((Min) annotation[0]).value();
|
return ((Min) annotation[0]).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getLimitSize(final Field element) throws Exception {
|
public static int getLimitSize(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -140,7 +140,7 @@ public class AnnotationTools {
|
|||||||
final int length = ((Column) annotation[0]).length();
|
final int length = ((Column) annotation[0]).length();
|
||||||
return length <= 0 ? 0 : length;
|
return length <= 0 ? 0 : length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Size getConstraintsSize(final Field element) throws Exception {
|
public static Size getConstraintsSize(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Size.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Size.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -151,7 +151,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return (Size) annotation[0];
|
return (Size) annotation[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getConstraintsPattern(final Field element) throws Exception {
|
public static String getConstraintsPattern(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Pattern.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Pattern.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -162,7 +162,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return ((Pattern) annotation[0]).regexp();
|
return ((Pattern) annotation[0]).regexp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAnnotationGroup(final Field field, final Class<?> annotationType) {
|
public static boolean isAnnotationGroup(final Field field, final Class<?> annotationType) {
|
||||||
try {
|
try {
|
||||||
final Annotation[] anns = field.getAnnotations();
|
final Annotation[] anns = field.getAnnotations();
|
||||||
@@ -185,7 +185,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFieldName(final Field element) throws Exception {
|
public static String getFieldName(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -200,7 +200,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getColumnNotNull(final Field element) throws Exception {
|
public static boolean getColumnNotNull(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -211,7 +211,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return !((Column) annotation[0]).nullable();
|
return !((Column) annotation[0]).nullable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getConstraintsNotNull(final Field element) throws Exception {
|
public static boolean getConstraintsNotNull(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(NotNull.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(NotNull.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -222,7 +222,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPrimaryKey(final Field element) throws Exception {
|
public static boolean isPrimaryKey(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Id.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Id.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -230,7 +230,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUnique(final Field element) throws Exception {
|
public static boolean isUnique(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -241,7 +241,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return ((Column) annotation[0]).unique();
|
return ((Column) annotation[0]).unique();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GenerationType getStrategy(final Field element) throws Exception {
|
public static GenerationType getStrategy(final Field element) throws Exception {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(GeneratedValue.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(GeneratedValue.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
@@ -252,27 +252,27 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return ((GeneratedValue) annotation[0]).strategy();
|
return ((GeneratedValue) annotation[0]).strategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDeletedField(final Field element) throws Exception {
|
public static boolean isDeletedField(final Field element) throws Exception {
|
||||||
return element.getDeclaredAnnotationsByType(DataDeleted.class).length != 0;
|
return element.getDeclaredAnnotationsByType(DataDeleted.class).length != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isCreatedAtField(final Field element) throws Exception {
|
public static boolean isCreatedAtField(final Field element) throws Exception {
|
||||||
return element.getDeclaredAnnotationsByType(CreationTimestamp.class).length != 0;
|
return element.getDeclaredAnnotationsByType(CreationTimestamp.class).length != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUpdateAtField(final Field element) throws Exception {
|
public static boolean isUpdateAtField(final Field element) throws Exception {
|
||||||
return element.getDeclaredAnnotationsByType(UpdateTimestamp.class).length != 0;
|
return element.getDeclaredAnnotationsByType(UpdateTimestamp.class).length != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isdefaultNotRead(final Field element) throws Exception {
|
public static boolean isdefaultNotRead(final Field element) throws Exception {
|
||||||
return element.getDeclaredAnnotationsByType(DataNotRead.class).length != 0;
|
return element.getDeclaredAnnotationsByType(DataNotRead.class).length != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isIdField(final Field element) throws Exception {
|
public static boolean isIdField(final Field element) throws Exception {
|
||||||
return element.getDeclaredAnnotationsByType(Id.class).length != 0;
|
return element.getDeclaredAnnotationsByType(Id.class).length != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDeletedFieldName(final Class<?> clazz) throws Exception {
|
public static String getDeletedFieldName(final Class<?> clazz) throws Exception {
|
||||||
try {
|
try {
|
||||||
for (final Field elem : clazz.getFields()) {
|
for (final Field elem : clazz.getFields()) {
|
||||||
@@ -289,7 +289,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUpdatedFieldName(final Class<?> clazz) throws Exception {
|
public static String getUpdatedFieldName(final Class<?> clazz) throws Exception {
|
||||||
try {
|
try {
|
||||||
for (final Field elem : clazz.getFields()) {
|
for (final Field elem : clazz.getFields()) {
|
||||||
@@ -306,7 +306,7 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Field getIdField(final Class<?> clazz) {
|
public static Field getIdField(final Class<?> clazz) {
|
||||||
try {
|
try {
|
||||||
for (final Field field : clazz.getFields()) {
|
for (final Field field : clazz.getFields()) {
|
||||||
@@ -323,15 +323,15 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getFieldsNames(final Class<?> clazz) throws Exception {
|
public static List<String> getFieldsNames(final Class<?> clazz) throws Exception {
|
||||||
return getFieldsNamesFilter(clazz, false);
|
return getFieldsNamesFilter(clazz, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getAllFieldsNames(final Class<?> clazz) throws Exception {
|
public static List<String> getAllFieldsNames(final Class<?> clazz) throws Exception {
|
||||||
return getFieldsNamesFilter(clazz, true);
|
return getFieldsNamesFilter(clazz, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> getFieldsNamesFilter(final Class<?> clazz, final boolean full) throws Exception {
|
private static List<String> getFieldsNamesFilter(final Class<?> clazz, final boolean full) throws Exception {
|
||||||
final List<String> out = new ArrayList<>();
|
final List<String> out = new ArrayList<>();
|
||||||
for (final Field field : clazz.getFields()) {
|
for (final Field field : clazz.getFields()) {
|
||||||
@@ -346,11 +346,11 @@ public class AnnotationTools {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isGenericField(final Field elem) throws Exception {
|
public static boolean isGenericField(final Field elem) throws Exception {
|
||||||
return AnnotationTools.isPrimaryKey(elem) || AnnotationTools.isCreatedAtField(elem) || AnnotationTools.isUpdateAtField(elem) || AnnotationTools.isDeletedField(elem);
|
return AnnotationTools.isPrimaryKey(elem) || AnnotationTools.isCreatedAtField(elem) || AnnotationTools.isUpdateAtField(elem) || AnnotationTools.isDeletedField(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Field getFieldOfId(final Class<?> clazz) throws Exception {
|
public static Field getFieldOfId(final Class<?> clazz) throws Exception {
|
||||||
for (final Field field : clazz.getFields()) {
|
for (final Field field : clazz.getFields()) {
|
||||||
// static field is only for internal global declaration ==> remove it ..
|
// static field is only for internal global declaration ==> remove it ..
|
||||||
@@ -363,5 +363,18 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -55,25 +52,26 @@ public class DataAccess {
|
|||||||
static final Logger LOGGER = LoggerFactory.getLogger(DataAccess.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(DataAccess.class);
|
||||||
// by default we manage some add-on that permit to manage non-native model (like json serialization, List of external key as String list...)
|
// by default we manage some add-on that permit to manage non-native model (like json serialization, List of external key as String list...)
|
||||||
static final List<DataAccessAddOn> addOn = new ArrayList<>();
|
static final List<DataAccessAddOn> addOn = new ArrayList<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
addOn.add(new AddOnManyToMany());
|
addOn.add(new AddOnManyToMany());
|
||||||
addOn.add(new AddOnManyToOne());
|
addOn.add(new AddOnManyToOne());
|
||||||
addOn.add(new AddOnSQLTableExternalForeinKeyAsList());
|
addOn.add(new AddOnSQLTableExternalForeinKeyAsList());
|
||||||
addOn.add(new AddOnDataJson());
|
addOn.add(new AddOnDataJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a new add-on on the current management.
|
/** Add a new add-on on the current management.
|
||||||
* @param addOn instantiate object on the Add-on */
|
* @param addOn instantiate object on the Add-on */
|
||||||
public static void addAddOn(final DataAccessAddOn addOn) {
|
public static void addAddOn(final DataAccessAddOn addOn) {
|
||||||
DataAccess.addOn.add(addOn);
|
DataAccess.addOn.add(addOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataAccess() {
|
public 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,13 +79,13 @@ 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());
|
||||||
|
|
||||||
// TODO: TO test
|
// TODO: TO test
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -116,7 +114,7 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
throw new InternalServerErrorException("Can Not manage the DB-access");
|
throw new InternalServerErrorException("Can Not manage the DB-access");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean createDB(final String name) {
|
public static boolean createDB(final String name) {
|
||||||
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
|
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||||
// no base manage in sqLite ...
|
// no base manage in sqLite ...
|
||||||
@@ -124,15 +122,16 @@ 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());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
@@ -171,7 +170,7 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
throw new InternalServerErrorException("Can Not manage the DB-access");
|
throw new InternalServerErrorException("Can Not manage the DB-access");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** extract a list of "-" separated element from a SQL input data.
|
/** extract a list of "-" separated element from a SQL input data.
|
||||||
* @param rs Result Set of the BDD
|
* @param rs Result Set of the BDD
|
||||||
* @param iii Id in the result set
|
* @param iii Id in the result set
|
||||||
@@ -190,7 +189,7 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static <T> void setValuedb(final Class<?> type, final T data, final CountInOut iii, final Field field, final PreparedStatement ps) throws Exception {
|
protected static <T> void setValuedb(final Class<?> type, final T data, final CountInOut iii, final Field field, final PreparedStatement ps) throws Exception {
|
||||||
if (type == Long.class) {
|
if (type == Long.class) {
|
||||||
final Object tmp = field.get(data);
|
final Object tmp = field.get(data);
|
||||||
@@ -447,10 +446,200 @@ 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 {
|
||||||
|
Class<?> type = field.getType();
|
||||||
|
if (type == Long.class) {
|
||||||
|
return (final ResultSet rs, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataAccessAddOn findAddOnforField(final Field field) {
|
public static DataAccessAddOn findAddOnforField(final Field field) {
|
||||||
for (final DataAccessAddOn elem : addOn) {
|
for (final DataAccessAddOn elem : addOn) {
|
||||||
if (elem.isCompatibleField(field)) {
|
if (elem.isCompatibleField(field)) {
|
||||||
@@ -459,7 +648,7 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: manage insert batch...
|
// TODO: manage insert batch...
|
||||||
public static <T> List<T> insertMultiple(final List<T> data, final QueryOption... options) throws Exception {
|
public static <T> List<T> insertMultiple(final List<T> data, final QueryOption... options) throws Exception {
|
||||||
final List<T> out = new ArrayList<>();
|
final List<T> out = new ArrayList<>();
|
||||||
@@ -469,18 +658,18 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T insert(final T data, final QueryOption... option) throws Exception {
|
public static <T> T insert(final T data, final QueryOption... option) throws Exception {
|
||||||
final Class<?> clazz = data.getClass();
|
final Class<?> clazz = data.getClass();
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
|
|
||||||
// External checker of data:
|
// External checker of data:
|
||||||
final CheckFunction check = options.get(CheckFunction.class);
|
final CheckFunction check = options.get(CheckFunction.class);
|
||||||
if (check != null) {
|
if (check != null) {
|
||||||
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);
|
||||||
@@ -491,7 +680,7 @@ public class DataAccess {
|
|||||||
query.append("INSERT INTO `");
|
query.append("INSERT INTO `");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
query.append("` (");
|
query.append("` (");
|
||||||
|
|
||||||
boolean firstField = true;
|
boolean firstField = true;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (final Field field : clazz.getFields()) {
|
for (final Field field : clazz.getFields()) {
|
||||||
@@ -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) {
|
||||||
@@ -634,7 +822,7 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// seems a good idea, but very dangerous if we not filter input data... if set an id it can be complicated...
|
// seems a good idea, but very dangerous if we not filter input data... if set an id it can be complicated...
|
||||||
public static <T> T insertWithJson(final Class<T> clazz, final String jsonData) throws Exception {
|
public static <T> T insertWithJson(final Class<T> clazz, final String jsonData) throws Exception {
|
||||||
final ObjectMapper mapper = new ObjectMapper();
|
final ObjectMapper mapper = new ObjectMapper();
|
||||||
@@ -642,7 +830,7 @@ public class DataAccess {
|
|||||||
final T data = mapper.readValue(jsonData, clazz);
|
final T data = mapper.readValue(jsonData, clazz);
|
||||||
return insert(data);
|
return insert(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <ID_TYPE> QueryCondition getTableIdCondition(final Class<?> clazz, final ID_TYPE idKey) throws Exception {
|
public static <ID_TYPE> QueryCondition getTableIdCondition(final Class<?> clazz, final ID_TYPE idKey) throws Exception {
|
||||||
// Find the ID field type ....
|
// Find the ID field type ....
|
||||||
final Field idField = AnnotationTools.getIdField(clazz);
|
final Field idField = AnnotationTools.getIdField(clazz);
|
||||||
@@ -662,7 +850,7 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
return new QueryCondition(AnnotationTools.getFieldName(idField), "=", idKey);
|
return new QueryCondition(AnnotationTools.getFieldName(idField), "=", idKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update an object with the inserted json data
|
/** Update an object with the inserted json data
|
||||||
*
|
*
|
||||||
* @param <T> Type of the object to insert
|
* @param <T> Type of the object to insert
|
||||||
@@ -682,7 +870,7 @@ public class DataAccess {
|
|||||||
options.add(new TransmitKey(id));
|
options.add(new TransmitKey(id));
|
||||||
return updateWhereWithJson(clazz, jsonData, options.getAllArray());
|
return updateWhereWithJson(clazz, jsonData, options.getAllArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> int updateWhereWithJson(final Class<T> clazz, final String jsonData, final QueryOption... option) throws Exception {
|
public static <T> int updateWhereWithJson(final Class<T> clazz, final String jsonData, final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
final Condition condition = options.get(Condition.class);
|
final Condition condition = options.get(Condition.class);
|
||||||
@@ -700,11 +888,11 @@ public class DataAccess {
|
|||||||
options.add(new FilterValue(keys));
|
options.add(new FilterValue(keys));
|
||||||
return updateWhere(data, options.getAllArray());
|
return updateWhere(data, options.getAllArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, ID_TYPE> int update(final T data, final ID_TYPE id) throws Exception {
|
public static <T, ID_TYPE> int update(final T data, final ID_TYPE id) throws Exception {
|
||||||
return update(data, id, AnnotationTools.getFieldsNames(data.getClass()));
|
return update(data, id, AnnotationTools.getFieldsNames(data.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param <T>
|
/** @param <T>
|
||||||
* @param data
|
* @param data
|
||||||
* @param id
|
* @param id
|
||||||
@@ -714,7 +902,7 @@ public class DataAccess {
|
|||||||
public static <T, ID_TYPE> int update(final T data, final ID_TYPE id, final List<String> updateColomn) throws Exception {
|
public static <T, ID_TYPE> int update(final T data, final ID_TYPE id, final List<String> updateColomn) throws Exception {
|
||||||
return updateWhere(data, new Condition(getTableIdCondition(data.getClass(), id)), new FilterValue(updateColomn), new TransmitKey(id));
|
return updateWhere(data, new Condition(getTableIdCondition(data.getClass(), id)), new FilterValue(updateColomn), new TransmitKey(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> int updateWhere(final T data, final QueryOption... option) throws Exception {
|
public static <T> int updateWhere(final T data, final QueryOption... option) throws Exception {
|
||||||
final Class<?> clazz = data.getClass();
|
final Class<?> clazz = data.getClass();
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
@@ -734,16 +922,16 @@ 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();
|
||||||
query.append("UPDATE `");
|
query.append("UPDATE `");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
query.append("` SET ");
|
query.append("` SET ");
|
||||||
|
|
||||||
boolean firstField = true;
|
boolean firstField = true;
|
||||||
for (final Field field : clazz.getFields()) {
|
for (final Field field : clazz.getFields()) {
|
||||||
// static field is only for internal global declaration ==> remove it ..
|
// static field is only for internal global declaration ==> remove it ..
|
||||||
@@ -790,7 +978,7 @@ public class DataAccess {
|
|||||||
query.append(" ");
|
query.append(" ");
|
||||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||||
condition.whereAppendQuery(query, tableName, null, deletedFieldName);
|
condition.whereAppendQuery(query, tableName, null, deletedFieldName);
|
||||||
|
|
||||||
// If the first field is not set, then nothing to update n the main base:
|
// If the first field is not set, then nothing to update n the main base:
|
||||||
if (!firstField) {
|
if (!firstField) {
|
||||||
LOGGER.debug("generate the query: '{}'", query.toString());
|
LOGGER.debug("generate the query: '{}'", query.toString());
|
||||||
@@ -830,16 +1018,13 @@ 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();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addElement(final PreparedStatement ps, final Object value, final CountInOut iii) throws Exception {
|
static void addElement(final PreparedStatement ps, final Object value, final CountInOut iii) throws Exception {
|
||||||
if (value instanceof final Long tmp) {
|
if (value instanceof final Long tmp) {
|
||||||
LOGGER.debug("Inject Long => {}", tmp);
|
LOGGER.debug("Inject Long => {}", tmp);
|
||||||
@@ -884,27 +1069,21 @@ public class DataAccess {
|
|||||||
throw new DataAccessException("Not manage type ==> need to add it ...");
|
throw new DataAccessException("Not manage type ==> need to add it ...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
||||||
@@ -914,14 +1093,12 @@ 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);
|
||||||
boolean firstField = true;
|
boolean firstField = true;
|
||||||
|
|
||||||
for (final Field elem : clazz.getFields()) {
|
for (final Field elem : clazz.getFields()) {
|
||||||
// static field is only for internal global declaration ==> remove it ..
|
// static field is only for internal global declaration ==> remove it ..
|
||||||
if (java.lang.reflect.Modifier.isStatic(elem.getModifiers())) {
|
if (java.lang.reflect.Modifier.isStatic(elem.getModifiers())) {
|
||||||
@@ -952,18 +1129,21 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
|
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
return getsWhere(clazz, options);
|
return getsWhere(clazz, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 {
|
||||||
@@ -975,13 +1155,11 @@ public class DataAccess {
|
|||||||
query.append(" FROM `");
|
query.append(" FROM `");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
query.append("` ");
|
query.append("` ");
|
||||||
|
|
||||||
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,11 +1196,10 @@ public class DataAccess {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
entry.close();
|
entry.close();
|
||||||
entry = null;
|
|
||||||
}
|
}
|
||||||
return outs;
|
return outs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object createObjectFromSQLRequest(final ResultSet rs, final Class<?> clazz, final CountInOut count, final CountInOut countNotNull, final QueryOptions options,
|
public static Object createObjectFromSQLRequest(final ResultSet rs, final Class<?> clazz, final CountInOut count, final CountInOut countNotNull, final QueryOptions options,
|
||||||
final List<LazyGetter> lazyCall) throws Exception {
|
final List<LazyGetter> lazyCall) throws Exception {
|
||||||
final boolean readAllfields = QueryOptions.readAllColomn(options);
|
final boolean readAllfields = QueryOptions.readAllColomn(options);
|
||||||
@@ -1059,16 +1234,19 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <ID_TYPE> long count(final Class<?> clazz, final ID_TYPE id) throws Exception {
|
public static <ID_TYPE> long count(final Class<?> clazz, final ID_TYPE id) throws Exception {
|
||||||
return DataAccess.countWhere(clazz, new Condition(getTableIdCondition(clazz, id)));
|
return DataAccess.countWhere(clazz, new Condition(getTableIdCondition(clazz, id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -1110,25 +1284,25 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, ID_TYPE> T get(final Class<T> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
public static <T, ID_TYPE> T get(final Class<T> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||||
return DataAccess.getWhere(clazz, options.getAllArray());
|
return DataAccess.getWhere(clazz, options.getAllArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> List<T> gets(final Class<T> clazz) throws Exception {
|
public static <T> List<T> gets(final Class<T> clazz) throws Exception {
|
||||||
return getsWhere(clazz);
|
return getsWhere(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> List<T> gets(final Class<T> clazz, final QueryOption... option) throws Exception {
|
public static <T> List<T> gets(final Class<T> clazz, final QueryOption... option) throws Exception {
|
||||||
return getsWhere(clazz, option);
|
return getsWhere(clazz, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <ID_TYPE> int delete(final Class<?> clazz, final ID_TYPE id) throws Exception {
|
public static <ID_TYPE> int delete(final Class<?> clazz, final ID_TYPE id) throws Exception {
|
||||||
return delete(clazz, id, null);
|
return delete(clazz, id, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Delete items with the specific Id (cf @Id) and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before).
|
/** Delete items with the specific Id (cf @Id) and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before).
|
||||||
* @param <ID_TYPE> Type of the reference @Id
|
* @param <ID_TYPE> Type of the reference @Id
|
||||||
* @param clazz Data model that might remove element
|
* @param clazz Data model that might remove element
|
||||||
@@ -1143,14 +1317,14 @@ public class DataAccess {
|
|||||||
return deleteHard(clazz, id, options);
|
return deleteHard(clazz, id, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Delete items with the specific condition and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before).
|
/** Delete items with the specific condition and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before).
|
||||||
* @param clazz Data model that might remove element.
|
* @param clazz Data model that might remove element.
|
||||||
* @param condition Condition to remove elements.
|
* @param condition Condition to remove elements.
|
||||||
* @param options (Optional) Options of the request.
|
* @param options (Optional) Options of the request.
|
||||||
* @return Number of element that is removed. */
|
* @return Number of element that is removed. */
|
||||||
public static int deleteWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
public static int deleteWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||||
|
|
||||||
final String hasDeletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
final String hasDeletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||||
if (hasDeletedFieldName != null) {
|
if (hasDeletedFieldName != null) {
|
||||||
return deleteSoftWhere(clazz, option);
|
return deleteSoftWhere(clazz, option);
|
||||||
@@ -1158,13 +1332,13 @@ public class DataAccess {
|
|||||||
return deleteHardWhere(clazz, option);
|
return deleteHardWhere(clazz, option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <ID_TYPE> int deleteHard(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
public static <ID_TYPE> int deleteHard(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||||
return deleteHardWhere(clazz, options.getAllArray());
|
return deleteHardWhere(clazz, options.getAllArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int deleteHardWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
public static int deleteHardWhere(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);
|
final Condition condition = options.get(Condition.class);
|
||||||
@@ -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,16 +1362,15 @@ public class DataAccess {
|
|||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} finally {
|
} finally {
|
||||||
entry.close();
|
entry.close();
|
||||||
entry = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <ID_TYPE> int deleteSoft(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
private static <ID_TYPE> int deleteSoft(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||||
return deleteSoftWhere(clazz, options.getAllArray());
|
return deleteSoftWhere(clazz, options.getAllArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int deleteSoftWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
public static int deleteSoftWhere(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);
|
final Condition condition = options.get(Condition.class);
|
||||||
@@ -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,20 +1399,19 @@ public class DataAccess {
|
|||||||
return ps.executeUpdate();
|
return ps.executeUpdate();
|
||||||
} finally {
|
} finally {
|
||||||
entry.close();
|
entry.close();
|
||||||
entry = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <ID_TYPE> int unsetDelete(final Class<?> clazz, final ID_TYPE id) throws Exception {
|
public static <ID_TYPE> int unsetDelete(final Class<?> clazz, final ID_TYPE id) throws Exception {
|
||||||
return unsetDeleteWhere(clazz, new Condition(getTableIdCondition(clazz, id)));
|
return unsetDeleteWhere(clazz, new Condition(getTableIdCondition(clazz, id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <ID_TYPE> int unsetDelete(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
public static <ID_TYPE> int unsetDelete(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||||
return unsetDeleteWhere(clazz, options.getAllArray());
|
return unsetDeleteWhere(clazz, options.getAllArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int unsetDeleteWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
public static int unsetDeleteWhere(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);
|
final Condition condition = options.get(Condition.class);
|
||||||
@@ -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);
|
||||||
@@ -1339,5 +1507,79 @@ public class DataAccess {
|
|||||||
entry = null;
|
entry = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
- 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, String query, List<Object> parameters, final QueryOption... option) throws Exception {
|
||||||
|
final QueryOptions options = new QueryOptions(option);
|
||||||
|
final List<LazyGetter> lazyCall = new ArrayList<>();
|
||||||
|
// TODO ... final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||||
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
|
final List<TYPE> outs = new ArrayList<>();
|
||||||
|
// real add in the BDD:
|
||||||
|
try {
|
||||||
|
final CountInOut count = new CountInOut();
|
||||||
|
LOGGER.warn("generate the query: '{}'", query.toString());
|
||||||
|
// prepare the request:
|
||||||
|
final PreparedStatement ps = entry.connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
||||||
|
final CountInOut iii = new CountInOut(1);
|
||||||
|
if (parameters != null) {
|
||||||
|
for (Object elem : parameters) {
|
||||||
|
DataAccess.addElement(ps, elem, iii);
|
||||||
|
}
|
||||||
|
iii.inc();
|
||||||
|
}
|
||||||
|
// execute the request
|
||||||
|
final ResultSet rs = ps.executeQuery();
|
||||||
|
ResultSetMetaData rsmd = rs.getMetaData();
|
||||||
|
List<RetreiveFromDB> actionToRetreive = new ArrayList<>();
|
||||||
|
for (int jjj = 0; jjj < rsmd.getColumnCount(); jjj++) {
|
||||||
|
String name = rsmd.getColumnName(jjj + 1);
|
||||||
|
// find field name ...
|
||||||
|
Field field = AnnotationTools.getFieldNamed(clazz, name);
|
||||||
|
if (field == null) {
|
||||||
|
throw new DataAccessException("Querry with unknown field: '" + name + "'");
|
||||||
|
}
|
||||||
|
// create the callback...
|
||||||
|
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 (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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -15,30 +15,30 @@ public class QueryOptions {
|
|||||||
public static final ReadAllColumn READ_ALL_COLOMN = new ReadAllColumn();
|
public static final ReadAllColumn READ_ALL_COLOMN = new ReadAllColumn();
|
||||||
public static final AccessDeletedItems ACCESS_DELETED_ITEMS = new AccessDeletedItems();
|
public static final AccessDeletedItems ACCESS_DELETED_ITEMS = new AccessDeletedItems();
|
||||||
public static final CreateDropTable CREATE_DROP_TABLE = new CreateDropTable();
|
public static final CreateDropTable CREATE_DROP_TABLE = new CreateDropTable();
|
||||||
|
|
||||||
private final List<QueryOption> options = new ArrayList<>();
|
private final List<QueryOption> options = new ArrayList<>();
|
||||||
|
|
||||||
public QueryOptions() {}
|
public QueryOptions() {}
|
||||||
|
|
||||||
public QueryOptions(final QueryOption... elems) {
|
public QueryOptions(final QueryOption... elems) {
|
||||||
if (elems == null || elems.length == 0) {
|
if (elems == null || elems.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Collections.addAll(this.options, elems);
|
Collections.addAll(this.options, elems);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(final QueryOption option) {
|
public void add(final QueryOption option) {
|
||||||
this.options.add(option);
|
this.options.add(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<QueryOption> getAll() {
|
public List<QueryOption> getAll() {
|
||||||
return this.options;
|
return this.options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryOption[] getAllArray() {
|
public QueryOption[] getAllArray() {
|
||||||
return this.options.toArray(new QueryOption[0]);
|
return this.options.toArray(new QueryOption[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T get(final Class<T> type) {
|
public <T> T get(final Class<T> type) {
|
||||||
for (final QueryOption elem : this.options) {
|
for (final QueryOption elem : this.options) {
|
||||||
@@ -48,7 +48,7 @@ public class QueryOptions {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean exist(final Class<?> type) {
|
public boolean exist(final Class<?> type) {
|
||||||
for (final QueryOption elem : this.options) {
|
for (final QueryOption elem : this.options) {
|
||||||
if (elem.getClass() == type) {
|
if (elem.getClass() == type) {
|
||||||
@@ -57,12 +57,11 @@ public class QueryOptions {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean readAllColomn(final QueryOptions options) {
|
public static boolean readAllColomn(final QueryOptions options) {
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
return options.exist(ReadAllColumn.class);
|
return options.exist(ReadAllColumn.class);
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
57
src/org/kar/archidata/serializer/CSVMessageBodyWritter.java
Normal file
57
src/org/kar/archidata/serializer/CSVMessageBodyWritter.java
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
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 writter use in jersey with :
|
||||||
|
* In your main:
|
||||||
|
* ```java
|
||||||
|
* rc.register(new CSVMessageBodyWritter());
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* and in the produce element:
|
||||||
|
* ```java
|
||||||
|
* @GET
|
||||||
|
* @Produces("text/csv")
|
||||||
|
* public List<Data> getData() {}
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
@Provider
|
||||||
|
@Produces("text/csv")
|
||||||
|
public class CSVMessageBodyWritter implements MessageBodyWriter<List<?>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
|
||||||
|
return List.class.isAssignableFrom(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSize(List<?> data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(List<?> data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
|
||||||
|
throws IOException, WebApplicationException {
|
||||||
|
if (data != null && data.size() > 0) {
|
||||||
|
CsvMapper mapper = new CsvMapper();
|
||||||
|
Object o = data.get(0);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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());
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import test.kar.archidata.model.SimpleTable;
|
|||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class TestJson {
|
public class TestJson {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestJson.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestJson.class);
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||||
@@ -39,43 +39,43 @@ public class TestJson {
|
|||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
entry.connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
LOGGER.info("Remove the test db");
|
||||||
DBEntry.closeAllForceMode();
|
DBEntry.closeAllForceMode();
|
||||||
ConfigBaseVariable.clearAllValue();
|
ConfigBaseVariable.clearAllValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testTableInsertAndRetrieve() throws Exception {
|
public void testTableInsertAndRetrieve() throws Exception {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testIO() throws Exception {
|
public void testIO() throws Exception {
|
||||||
final SerializeAsJson test = new SerializeAsJson();
|
final SerializeAsJson test = new SerializeAsJson();
|
||||||
test.data = new SimpleTable();
|
test.data = new SimpleTable();
|
||||||
test.data.data = "plopppopql";
|
test.data.data = "plopppopql";
|
||||||
|
|
||||||
final SerializeAsJson insertedData = DataAccess.insert(test);
|
final SerializeAsJson insertedData = DataAccess.insert(test);
|
||||||
|
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
Assertions.assertNotNull(insertedData.data);
|
Assertions.assertNotNull(insertedData.data);
|
||||||
Assertions.assertNotNull(insertedData.data.data);
|
Assertions.assertNotNull(insertedData.data.data);
|
||||||
Assertions.assertEquals(test.data.data, insertedData.data.data);
|
Assertions.assertEquals(test.data.data, insertedData.data.data);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final SerializeAsJson retrieve = DataAccess.get(SerializeAsJson.class, insertedData.id);
|
final SerializeAsJson retrieve = DataAccess.get(SerializeAsJson.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertTrue(retrieve.id >= 0);
|
Assertions.assertTrue(retrieve.id >= 0);
|
||||||
@@ -83,5 +83,5 @@ public class TestJson {
|
|||||||
Assertions.assertNotNull(retrieve.data.data);
|
Assertions.assertNotNull(retrieve.data.data);
|
||||||
Assertions.assertEquals(test.data.data, retrieve.data.data);
|
Assertions.assertEquals(test.data.data, retrieve.data.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import test.kar.archidata.model.SerializeListAsJson;
|
|||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class TestListJson {
|
public class TestListJson {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestListJson.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestListJson.class);
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||||
@@ -39,24 +39,24 @@ public class TestListJson {
|
|||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
entry.connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
LOGGER.info("Remove the test db");
|
||||||
DBEntry.closeAllForceMode();
|
DBEntry.closeAllForceMode();
|
||||||
ConfigBaseVariable.clearAllValue();
|
ConfigBaseVariable.clearAllValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testTableInsertAndRetrieve() throws Exception {
|
public void testTableInsertAndRetrieve() throws Exception {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testIO() throws Exception {
|
public void testIO() throws Exception {
|
||||||
@@ -67,9 +67,9 @@ public class TestListJson {
|
|||||||
test.data.add(8);
|
test.data.add(8);
|
||||||
test.data.add(6);
|
test.data.add(6);
|
||||||
test.data.add(51);
|
test.data.add(51);
|
||||||
|
|
||||||
final SerializeListAsJson insertedData = DataAccess.insert(test);
|
final SerializeListAsJson insertedData = DataAccess.insert(test);
|
||||||
|
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
@@ -80,10 +80,10 @@ public class TestListJson {
|
|||||||
Assertions.assertEquals(test.data.get(2), insertedData.data.get(2));
|
Assertions.assertEquals(test.data.get(2), insertedData.data.get(2));
|
||||||
Assertions.assertEquals(test.data.get(3), insertedData.data.get(3));
|
Assertions.assertEquals(test.data.get(3), insertedData.data.get(3));
|
||||||
Assertions.assertEquals(test.data.get(4), insertedData.data.get(4));
|
Assertions.assertEquals(test.data.get(4), insertedData.data.get(4));
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final SerializeListAsJson retrieve = DataAccess.get(SerializeListAsJson.class, insertedData.id);
|
final SerializeListAsJson retrieve = DataAccess.get(SerializeListAsJson.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertTrue(retrieve.id >= 0);
|
Assertions.assertTrue(retrieve.id >= 0);
|
||||||
@@ -95,5 +95,5 @@ public class TestListJson {
|
|||||||
Assertions.assertEquals(test.data.get(3), retrieve.data.get(3));
|
Assertions.assertEquals(test.data.get(3), retrieve.data.get(3));
|
||||||
Assertions.assertEquals(test.data.get(4), retrieve.data.get(4));
|
Assertions.assertEquals(test.data.get(4), retrieve.data.get(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import test.kar.archidata.model.TypeManyToManyRootExpand;
|
|||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class TestManyToMany {
|
public class TestManyToMany {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToMany.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToMany.class);
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||||
@@ -41,14 +41,14 @@ public class TestManyToMany {
|
|||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
entry.connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
LOGGER.info("Remove the test db");
|
||||||
DBEntry.closeAllForceMode();
|
DBEntry.closeAllForceMode();
|
||||||
ConfigBaseVariable.clearAllValue();
|
ConfigBaseVariable.clearAllValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTable() throws Exception {
|
public void testCreateTable() throws Exception {
|
||||||
@@ -57,10 +57,10 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleInsertAndRetieve() throws Exception {
|
public void testSimpleInsertAndRetieve() throws Exception {
|
||||||
@@ -71,34 +71,34 @@ public class TestManyToMany {
|
|||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
Assertions.assertNull(insertedData.remote);
|
Assertions.assertNull(insertedData.remote);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypeManyToManyRoot retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
final TypeManyToManyRoot retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.otherData);
|
Assertions.assertNotNull(retrieve.otherData);
|
||||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||||
Assertions.assertNull(retrieve.remote);
|
Assertions.assertNull(retrieve.remote);
|
||||||
|
|
||||||
DataAccess.delete(TypeManyToManyRoot.class, insertedData.id);
|
DataAccess.delete(TypeManyToManyRoot.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(3)
|
@Order(3)
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleInsertAndRetieveSubValues() throws Exception {
|
public void testSimpleInsertAndRetieveSubValues() throws Exception {
|
||||||
|
|
||||||
TypeManyToManyRemote remote = new TypeManyToManyRemote();
|
TypeManyToManyRemote remote = new TypeManyToManyRemote();
|
||||||
remote.data = "remote1";
|
remote.data = "remote1";
|
||||||
final TypeManyToManyRemote insertedRemote1 = DataAccess.insert(remote);
|
final TypeManyToManyRemote insertedRemote1 = DataAccess.insert(remote);
|
||||||
Assertions.assertEquals(insertedRemote1.data, remote.data);
|
Assertions.assertEquals(insertedRemote1.data, remote.data);
|
||||||
|
|
||||||
remote = new TypeManyToManyRemote();
|
remote = new TypeManyToManyRemote();
|
||||||
remote.data = "remote2";
|
remote.data = "remote2";
|
||||||
final TypeManyToManyRemote insertedRemote2 = DataAccess.insert(remote);
|
final TypeManyToManyRemote insertedRemote2 = DataAccess.insert(remote);
|
||||||
Assertions.assertEquals(insertedRemote2.data, remote.data);
|
Assertions.assertEquals(insertedRemote2.data, remote.data);
|
||||||
|
|
||||||
final TypeManyToManyRoot test = new TypeManyToManyRoot();
|
final TypeManyToManyRoot test = new TypeManyToManyRoot();
|
||||||
test.otherData = "kjhlkjlkj";
|
test.otherData = "kjhlkjlkj";
|
||||||
final TypeManyToManyRoot insertedData = DataAccess.insert(test);
|
final TypeManyToManyRoot insertedData = DataAccess.insert(test);
|
||||||
@@ -106,23 +106,23 @@ public class TestManyToMany {
|
|||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
Assertions.assertNull(insertedData.remote);
|
Assertions.assertNull(insertedData.remote);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
TypeManyToManyRoot retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
TypeManyToManyRoot retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.otherData);
|
Assertions.assertNotNull(retrieve.otherData);
|
||||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||||
Assertions.assertNull(retrieve.remote);
|
Assertions.assertNull(retrieve.remote);
|
||||||
|
|
||||||
// Add remote elements
|
// Add remote elements
|
||||||
AddOnManyToMany.addLink(TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote1.id);
|
AddOnManyToMany.addLink(TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote1.id);
|
||||||
AddOnManyToMany.addLink(TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote2.id);
|
AddOnManyToMany.addLink(TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote2.id);
|
||||||
|
|
||||||
retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
@@ -132,9 +132,9 @@ public class TestManyToMany {
|
|||||||
Assertions.assertEquals(retrieve.remote.size(), 2);
|
Assertions.assertEquals(retrieve.remote.size(), 2);
|
||||||
Assertions.assertEquals(retrieve.remote.get(0), insertedRemote1.id);
|
Assertions.assertEquals(retrieve.remote.get(0), insertedRemote1.id);
|
||||||
Assertions.assertEquals(retrieve.remote.get(1), insertedRemote2.id);
|
Assertions.assertEquals(retrieve.remote.get(1), insertedRemote2.id);
|
||||||
|
|
||||||
final TypeManyToManyRootExpand retrieveExpand = DataAccess.get(TypeManyToManyRootExpand.class, insertedData.id);
|
final TypeManyToManyRootExpand retrieveExpand = DataAccess.get(TypeManyToManyRootExpand.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieveExpand);
|
Assertions.assertNotNull(retrieveExpand);
|
||||||
Assertions.assertNotNull(retrieveExpand.id);
|
Assertions.assertNotNull(retrieveExpand.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieveExpand.id);
|
Assertions.assertEquals(insertedData.id, retrieveExpand.id);
|
||||||
@@ -144,13 +144,13 @@ public class TestManyToMany {
|
|||||||
Assertions.assertEquals(retrieveExpand.remote.size(), 2);
|
Assertions.assertEquals(retrieveExpand.remote.size(), 2);
|
||||||
Assertions.assertEquals(retrieveExpand.remote.get(0).id, insertedRemote1.id);
|
Assertions.assertEquals(retrieveExpand.remote.get(0).id, insertedRemote1.id);
|
||||||
Assertions.assertEquals(retrieveExpand.remote.get(1).id, insertedRemote2.id);
|
Assertions.assertEquals(retrieveExpand.remote.get(1).id, insertedRemote2.id);
|
||||||
|
|
||||||
// Remove an element
|
// Remove an element
|
||||||
int count = AddOnManyToMany.removeLink(TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote1.id);
|
int count = AddOnManyToMany.removeLink(TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote1.id);
|
||||||
Assertions.assertEquals(1, count);
|
Assertions.assertEquals(1, count);
|
||||||
|
|
||||||
retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
@@ -159,23 +159,23 @@ public class TestManyToMany {
|
|||||||
Assertions.assertNotNull(retrieve.remote);
|
Assertions.assertNotNull(retrieve.remote);
|
||||||
Assertions.assertEquals(retrieve.remote.size(), 1);
|
Assertions.assertEquals(retrieve.remote.size(), 1);
|
||||||
Assertions.assertEquals(retrieve.remote.get(0), insertedRemote2.id);
|
Assertions.assertEquals(retrieve.remote.get(0), insertedRemote2.id);
|
||||||
|
|
||||||
// Remove the second element
|
// Remove the second element
|
||||||
count = AddOnManyToMany.removeLink(TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote2.id);
|
count = AddOnManyToMany.removeLink(TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote2.id);
|
||||||
Assertions.assertEquals(1, count);
|
Assertions.assertEquals(1, count);
|
||||||
|
|
||||||
retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.otherData);
|
Assertions.assertNotNull(retrieve.otherData);
|
||||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||||
Assertions.assertNull(retrieve.remote);
|
Assertions.assertNull(retrieve.remote);
|
||||||
|
|
||||||
DataAccess.delete(TypeManyToManyRoot.class, insertedData.id);
|
DataAccess.delete(TypeManyToManyRoot.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* API TODO: - Replace list (permet de les ordonnées) - remove all links - delete en cascade .... (compliqué...) */
|
/* API TODO: - Replace list (permet de les ordonnées) - remove all links - delete en cascade .... (compliqué...) */
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ import test.kar.archidata.model.TypeManyToOneRootExpand;
|
|||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class TestManyToOne {
|
public class TestManyToOne {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToOne.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToOne.class);
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||||
@@ -40,14 +40,14 @@ public class TestManyToOne {
|
|||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
entry.connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
LOGGER.info("Remove the test db");
|
||||||
DBEntry.closeAllForceMode();
|
DBEntry.closeAllForceMode();
|
||||||
ConfigBaseVariable.clearAllValue();
|
ConfigBaseVariable.clearAllValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTable() throws Exception {
|
public void testCreateTable() throws Exception {
|
||||||
@@ -56,10 +56,10 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testAddAlements() throws Exception {
|
public void testAddAlements() throws Exception {
|
||||||
@@ -67,12 +67,12 @@ public class TestManyToOne {
|
|||||||
remote.data = "remote1";
|
remote.data = "remote1";
|
||||||
final TypeManyToOneRemote insertedRemote1 = DataAccess.insert(remote);
|
final TypeManyToOneRemote insertedRemote1 = DataAccess.insert(remote);
|
||||||
Assertions.assertEquals(insertedRemote1.data, remote.data);
|
Assertions.assertEquals(insertedRemote1.data, remote.data);
|
||||||
|
|
||||||
remote = new TypeManyToOneRemote();
|
remote = new TypeManyToOneRemote();
|
||||||
remote.data = "remote2";
|
remote.data = "remote2";
|
||||||
final TypeManyToOneRemote insertedRemote2 = DataAccess.insert(remote);
|
final TypeManyToOneRemote insertedRemote2 = DataAccess.insert(remote);
|
||||||
Assertions.assertEquals(insertedRemote2.data, remote.data);
|
Assertions.assertEquals(insertedRemote2.data, remote.data);
|
||||||
|
|
||||||
final TypeManyToOneRoot test = new TypeManyToOneRoot();
|
final TypeManyToOneRoot test = new TypeManyToOneRoot();
|
||||||
test.otherData = "kjhlkjlkj";
|
test.otherData = "kjhlkjlkj";
|
||||||
test.remoteId = insertedRemote2.id;
|
test.remoteId = insertedRemote2.id;
|
||||||
@@ -82,14 +82,14 @@ public class TestManyToOne {
|
|||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
Assertions.assertEquals(test.otherData, insertedData.otherData);
|
Assertions.assertEquals(test.otherData, insertedData.otherData);
|
||||||
Assertions.assertEquals(insertedRemote2.id, insertedData.remoteId);
|
Assertions.assertEquals(insertedRemote2.id, insertedData.remoteId);
|
||||||
|
|
||||||
TypeManyToOneRoot retrieve = DataAccess.get(TypeManyToOneRoot.class, insertedData.id);
|
TypeManyToOneRoot retrieve = DataAccess.get(TypeManyToOneRoot.class, insertedData.id);
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||||
Assertions.assertEquals(insertedRemote2.id, retrieve.remoteId);
|
Assertions.assertEquals(insertedRemote2.id, retrieve.remoteId);
|
||||||
|
|
||||||
TypeManyToOneRootExpand retrieve2 = DataAccess.get(TypeManyToOneRootExpand.class, insertedData.id);
|
TypeManyToOneRootExpand retrieve2 = DataAccess.get(TypeManyToOneRootExpand.class, insertedData.id);
|
||||||
Assertions.assertNotNull(retrieve2);
|
Assertions.assertNotNull(retrieve2);
|
||||||
Assertions.assertNotNull(retrieve2.id);
|
Assertions.assertNotNull(retrieve2.id);
|
||||||
@@ -98,20 +98,20 @@ public class TestManyToOne {
|
|||||||
Assertions.assertNotNull(retrieve2.remote);
|
Assertions.assertNotNull(retrieve2.remote);
|
||||||
Assertions.assertEquals(insertedRemote2.id, retrieve2.remote.id);
|
Assertions.assertEquals(insertedRemote2.id, retrieve2.remote.id);
|
||||||
Assertions.assertEquals(insertedRemote2.data, retrieve2.remote.data);
|
Assertions.assertEquals(insertedRemote2.data, retrieve2.remote.data);
|
||||||
|
|
||||||
// remove values:
|
// remove values:
|
||||||
final int count = DataAccess.delete(TypeManyToOneRemote.class, remote.id);
|
final int count = DataAccess.delete(TypeManyToOneRemote.class, remote.id);
|
||||||
Assertions.assertEquals(1, count);
|
Assertions.assertEquals(1, count);
|
||||||
|
|
||||||
// check fail:
|
// check fail:
|
||||||
|
|
||||||
retrieve = DataAccess.get(TypeManyToOneRoot.class, insertedData.id);
|
retrieve = DataAccess.get(TypeManyToOneRoot.class, insertedData.id);
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||||
Assertions.assertEquals(insertedRemote2.id, retrieve.remoteId);
|
Assertions.assertEquals(insertedRemote2.id, retrieve.remoteId);
|
||||||
|
|
||||||
retrieve2 = DataAccess.get(TypeManyToOneRootExpand.class, insertedData.id);
|
retrieve2 = DataAccess.get(TypeManyToOneRootExpand.class, insertedData.id);
|
||||||
Assertions.assertNotNull(retrieve2);
|
Assertions.assertNotNull(retrieve2);
|
||||||
Assertions.assertNotNull(retrieve2.id);
|
Assertions.assertNotNull(retrieve2.id);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import test.kar.archidata.model.TypesTable;
|
|||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class TestOneToMany {
|
public class TestOneToMany {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestOneToMany.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestOneToMany.class);
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||||
@@ -37,27 +37,27 @@ public class TestOneToMany {
|
|||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
entry.connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
LOGGER.info("Remove the test db");
|
||||||
DBEntry.closeAllForceMode();
|
DBEntry.closeAllForceMode();
|
||||||
ConfigBaseVariable.clearAllValue();
|
ConfigBaseVariable.clearAllValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTable() throws Exception {
|
public void testCreateTable() throws Exception {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testPlop() throws Exception {
|
public void testPlop() throws Exception {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -33,7 +33,7 @@ public class TestSimpleTable {
|
|||||||
private static final String DATA_INJECTED_2 = "dsqfsdfqsdfsqdf";
|
private static final String DATA_INJECTED_2 = "dsqfsdfqsdfsqdf";
|
||||||
private static Long idOfTheObject = null;
|
private static Long idOfTheObject = null;
|
||||||
private static Timestamp startAction = null;
|
private static Timestamp startAction = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||||
@@ -45,19 +45,19 @@ public class TestSimpleTable {
|
|||||||
// Clear the static test:
|
// Clear the static test:
|
||||||
idOfTheObject = null;
|
idOfTheObject = null;
|
||||||
startAction = null;
|
startAction = null;
|
||||||
|
|
||||||
// Connect the dataBase...
|
// Connect the dataBase...
|
||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
entry.connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
LOGGER.info("Remove the test db");
|
||||||
DBEntry.closeAllForceMode();
|
DBEntry.closeAllForceMode();
|
||||||
ConfigBaseVariable.clearAllValue();
|
ConfigBaseVariable.clearAllValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testTableInsertAndRetrieve() throws Exception {
|
public void testTableInsertAndRetrieve() throws Exception {
|
||||||
@@ -65,19 +65,19 @@ 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;
|
||||||
final SimpleTable insertedData = DataAccess.insert(test);
|
final SimpleTable insertedData = DataAccess.insert(test);
|
||||||
|
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, insertedData.id);
|
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
@@ -86,13 +86,13 @@ public class TestSimpleTable {
|
|||||||
Assertions.assertNull(retrieve.updatedAt);
|
Assertions.assertNull(retrieve.updatedAt);
|
||||||
TestSimpleTable.idOfTheObject = retrieve.id;
|
TestSimpleTable.idOfTheObject = retrieve.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testReadAllValuesUnreadable() throws Exception {
|
public void testReadAllValuesUnreadable() throws Exception {
|
||||||
// check the full values
|
// check the full values
|
||||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, QueryOptions.READ_ALL_COLOMN);
|
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, QueryOptions.READ_ALL_COLOMN);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(TestSimpleTable.idOfTheObject, retrieve.id);
|
Assertions.assertEquals(TestSimpleTable.idOfTheObject, retrieve.id);
|
||||||
@@ -105,7 +105,7 @@ public class TestSimpleTable {
|
|||||||
// Assertions.assertTrue(retrieve.updatedAt.after(this.startAction));
|
// Assertions.assertTrue(retrieve.updatedAt.after(this.startAction));
|
||||||
Assertions.assertEquals(retrieve.createdAt, retrieve.updatedAt);
|
Assertions.assertEquals(retrieve.createdAt, retrieve.updatedAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(3)
|
@Order(3)
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateData() throws Exception {
|
public void testUpdateData() throws Exception {
|
||||||
@@ -124,7 +124,7 @@ public class TestSimpleTable {
|
|||||||
LOGGER.info("created @ {} updated @ {}", retrieve.createdAt, retrieve.updatedAt);
|
LOGGER.info("created @ {} updated @ {}", retrieve.createdAt, retrieve.updatedAt);
|
||||||
Assertions.assertTrue(retrieve.updatedAt.after(retrieve.createdAt));
|
Assertions.assertTrue(retrieve.updatedAt.after(retrieve.createdAt));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(4)
|
@Order(4)
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteTheObject() throws Exception {
|
public void testDeleteTheObject() throws Exception {
|
||||||
@@ -133,23 +133,23 @@ public class TestSimpleTable {
|
|||||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject);
|
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject);
|
||||||
Assertions.assertNull(retrieve);
|
Assertions.assertNull(retrieve);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(5)
|
@Order(5)
|
||||||
@Test
|
@Test
|
||||||
public void testReadDeletedObject() throws Exception {
|
public void testReadDeletedObject() throws Exception {
|
||||||
|
|
||||||
// check if we set get deleted element
|
// check if we set get deleted element
|
||||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS);
|
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS);
|
||||||
Assertions.assertNull(retrieve);
|
Assertions.assertNull(retrieve);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(6)
|
@Order(6)
|
||||||
@Test
|
@Test
|
||||||
public void testReadAllValuesUnreadableOfDeletedObject() throws Exception {
|
public void testReadAllValuesUnreadableOfDeletedObject() throws Exception {
|
||||||
// check if we set get deleted element with all data
|
// check if we set get deleted element with all data
|
||||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS, QueryOptions.READ_ALL_COLOMN);
|
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS, QueryOptions.READ_ALL_COLOMN);
|
||||||
Assertions.assertNull(retrieve);
|
Assertions.assertNull(retrieve);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class TestSimpleTableSoftDelete {
|
|||||||
private static final String DATA_INJECTED_2 = "qsdfqsdfqsdfsqdf";
|
private static final String DATA_INJECTED_2 = "qsdfqsdfqsdfsqdf";
|
||||||
private static Long idOfTheObject = null;
|
private static Long idOfTheObject = null;
|
||||||
private static Timestamp startAction = null;
|
private static Timestamp startAction = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||||
@@ -45,19 +45,19 @@ public class TestSimpleTableSoftDelete {
|
|||||||
// Clear the static test:
|
// Clear the static test:
|
||||||
idOfTheObject = null;
|
idOfTheObject = null;
|
||||||
startAction = null;
|
startAction = null;
|
||||||
|
|
||||||
// Connect the dataBase...
|
// Connect the dataBase...
|
||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
entry.connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
LOGGER.info("Remove the test db");
|
||||||
DBEntry.closeAllForceMode();
|
DBEntry.closeAllForceMode();
|
||||||
ConfigBaseVariable.clearAllValue();
|
ConfigBaseVariable.clearAllValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testTableInsertAndRetrieve() throws Exception {
|
public void testTableInsertAndRetrieve() throws Exception {
|
||||||
@@ -65,19 +65,19 @@ 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;
|
||||||
final SimpleTableSoftDelete insertedData = DataAccess.insert(test);
|
final SimpleTableSoftDelete insertedData = DataAccess.insert(test);
|
||||||
|
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, insertedData.id);
|
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
@@ -87,13 +87,13 @@ public class TestSimpleTableSoftDelete {
|
|||||||
Assertions.assertNull(retrieve.deleted);
|
Assertions.assertNull(retrieve.deleted);
|
||||||
TestSimpleTableSoftDelete.idOfTheObject = retrieve.id;
|
TestSimpleTableSoftDelete.idOfTheObject = retrieve.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testReadAllValuesUnreadable() throws Exception {
|
public void testReadAllValuesUnreadable() throws Exception {
|
||||||
// check the full values
|
// check the full values
|
||||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.READ_ALL_COLOMN);
|
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.READ_ALL_COLOMN);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(TestSimpleTableSoftDelete.idOfTheObject, retrieve.id);
|
Assertions.assertEquals(TestSimpleTableSoftDelete.idOfTheObject, retrieve.id);
|
||||||
@@ -108,12 +108,12 @@ public class TestSimpleTableSoftDelete {
|
|||||||
Assertions.assertNotNull(retrieve.deleted);
|
Assertions.assertNotNull(retrieve.deleted);
|
||||||
Assertions.assertEquals(false, retrieve.deleted);
|
Assertions.assertEquals(false, retrieve.deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(3)
|
@Order(3)
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateData() throws Exception {
|
public void testUpdateData() throws Exception {
|
||||||
Thread.sleep(Duration.ofMillis(15));
|
Thread.sleep(Duration.ofMillis(15));
|
||||||
|
|
||||||
// Delete the entry:
|
// Delete the entry:
|
||||||
final SimpleTableSoftDelete test = new SimpleTableSoftDelete();
|
final SimpleTableSoftDelete test = new SimpleTableSoftDelete();
|
||||||
test.data = TestSimpleTableSoftDelete.DATA_INJECTED_2;
|
test.data = TestSimpleTableSoftDelete.DATA_INJECTED_2;
|
||||||
@@ -130,7 +130,7 @@ public class TestSimpleTableSoftDelete {
|
|||||||
Assertions.assertNotNull(retrieve.deleted);
|
Assertions.assertNotNull(retrieve.deleted);
|
||||||
Assertions.assertEquals(false, retrieve.deleted);
|
Assertions.assertEquals(false, retrieve.deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(4)
|
@Order(4)
|
||||||
@Test
|
@Test
|
||||||
public void testSoftDeleteTheObject() throws Exception {
|
public void testSoftDeleteTheObject() throws Exception {
|
||||||
@@ -144,11 +144,11 @@ public class TestSimpleTableSoftDelete {
|
|||||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject);
|
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject);
|
||||||
Assertions.assertNull(retrieve);
|
Assertions.assertNull(retrieve);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(5)
|
@Order(5)
|
||||||
@Test
|
@Test
|
||||||
public void testReadDeletedObject() throws Exception {
|
public void testReadDeletedObject() throws Exception {
|
||||||
|
|
||||||
// check if we set get deleted element
|
// check if we set get deleted element
|
||||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS);
|
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS);
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
@@ -158,9 +158,9 @@ public class TestSimpleTableSoftDelete {
|
|||||||
Assertions.assertNull(retrieve.createdAt);
|
Assertions.assertNull(retrieve.createdAt);
|
||||||
Assertions.assertNull(retrieve.updatedAt);
|
Assertions.assertNull(retrieve.updatedAt);
|
||||||
Assertions.assertNull(retrieve.deleted);
|
Assertions.assertNull(retrieve.deleted);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(6)
|
@Order(6)
|
||||||
@Test
|
@Test
|
||||||
public void testReadAllValuesUnreadableOfDeletedObject() throws Exception {
|
public void testReadAllValuesUnreadableOfDeletedObject() throws Exception {
|
||||||
@@ -176,6 +176,6 @@ public class TestSimpleTableSoftDelete {
|
|||||||
Assertions.assertTrue(retrieve.updatedAt.after(retrieve.createdAt));
|
Assertions.assertTrue(retrieve.updatedAt.after(retrieve.createdAt));
|
||||||
Assertions.assertNotNull(retrieve.deleted);
|
Assertions.assertNotNull(retrieve.deleted);
|
||||||
Assertions.assertEquals(true, retrieve.deleted);
|
Assertions.assertEquals(true, retrieve.deleted);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import test.kar.archidata.model.TypesEnum1;
|
|||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class TestTypeEnum1 {
|
public class TestTypeEnum1 {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum1.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum1.class);
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||||
@@ -39,44 +39,44 @@ public class TestTypeEnum1 {
|
|||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
entry.connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
LOGGER.info("Remove the test db");
|
||||||
DBEntry.closeAllForceMode();
|
DBEntry.closeAllForceMode();
|
||||||
ConfigBaseVariable.clearAllValue();
|
ConfigBaseVariable.clearAllValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTable() throws Exception {
|
public void testCreateTable() throws Exception {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testEnum() throws Exception {
|
public void testEnum() throws Exception {
|
||||||
|
|
||||||
final TypesEnum1 test = new TypesEnum1();
|
final TypesEnum1 test = new TypesEnum1();
|
||||||
test.data = Enum1ForTest.ENUM_VALUE_3;
|
test.data = Enum1ForTest.ENUM_VALUE_3;
|
||||||
final TypesEnum1 insertedData = DataAccess.insert(test);
|
final TypesEnum1 insertedData = DataAccess.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesEnum1 retrieve = DataAccess.get(TypesEnum1.class, insertedData.id);
|
final TypesEnum1 retrieve = DataAccess.get(TypesEnum1.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.data);
|
Assertions.assertNotNull(retrieve.data);
|
||||||
Assertions.assertEquals(insertedData.data, retrieve.data);
|
Assertions.assertEquals(insertedData.data, retrieve.data);
|
||||||
|
|
||||||
DataAccess.delete(TypesEnum1.class, insertedData.id);
|
DataAccess.delete(TypesEnum1.class, insertedData.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ import test.kar.archidata.model.TypesEnum2;
|
|||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class TestTypeEnum2 {
|
public class TestTypeEnum2 {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum2.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum2.class);
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||||
@@ -39,35 +39,35 @@ public class TestTypeEnum2 {
|
|||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
entry.connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
LOGGER.info("Remove the test db");
|
||||||
DBEntry.closeAllForceMode();
|
DBEntry.closeAllForceMode();
|
||||||
ConfigBaseVariable.clearAllValue();
|
ConfigBaseVariable.clearAllValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTable() throws Exception {
|
public void testCreateTable() throws Exception {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testEnum() throws Exception {
|
public void testEnum() throws Exception {
|
||||||
|
|
||||||
final TypesEnum2 test = new TypesEnum2();
|
final TypesEnum2 test = new TypesEnum2();
|
||||||
test.data = Enum2ForTest.ENUM_VALUE_4;
|
test.data = Enum2ForTest.ENUM_VALUE_4;
|
||||||
final TypesEnum2 insertedData = DataAccess.insert(test);
|
final TypesEnum2 insertedData = DataAccess.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
TypesEnum2 retrieve = DataAccess.get(TypesEnum2.class, insertedData.id);
|
TypesEnum2 retrieve = DataAccess.get(TypesEnum2.class, insertedData.id);
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
@@ -75,47 +75,47 @@ public class TestTypeEnum2 {
|
|||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.data);
|
Assertions.assertNotNull(retrieve.data);
|
||||||
Assertions.assertEquals(insertedData.data, retrieve.data);
|
Assertions.assertEquals(insertedData.data, retrieve.data);
|
||||||
|
|
||||||
// Update data to null
|
// Update data to null
|
||||||
retrieve.data = null;
|
retrieve.data = null;
|
||||||
int ret = DataAccess.update(retrieve, retrieve.id);
|
int ret = DataAccess.update(retrieve, retrieve.id);
|
||||||
Assertions.assertEquals(1, ret);
|
Assertions.assertEquals(1, ret);
|
||||||
|
|
||||||
// get new data
|
// get new data
|
||||||
retrieve = DataAccess.get(TypesEnum2.class, insertedData.id);
|
retrieve = DataAccess.get(TypesEnum2.class, insertedData.id);
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNull(retrieve.data);
|
Assertions.assertNull(retrieve.data);
|
||||||
|
|
||||||
// Remove the data
|
// Remove the data
|
||||||
ret = DataAccess.delete(TypesEnum2.class, insertedData.id);
|
ret = DataAccess.delete(TypesEnum2.class, insertedData.id);
|
||||||
Assertions.assertEquals(1, ret);
|
Assertions.assertEquals(1, ret);
|
||||||
|
|
||||||
// Get the removed data:
|
// Get the removed data:
|
||||||
retrieve = DataAccess.get(TypesEnum2.class, insertedData.id);
|
retrieve = DataAccess.get(TypesEnum2.class, insertedData.id);
|
||||||
Assertions.assertNull(retrieve);
|
Assertions.assertNull(retrieve);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(3)
|
@Order(3)
|
||||||
@Test
|
@Test
|
||||||
public void testNull() throws Exception {
|
public void testNull() throws Exception {
|
||||||
|
|
||||||
final TypesEnum2 test = new TypesEnum2();
|
final TypesEnum2 test = new TypesEnum2();
|
||||||
test.data = null;
|
test.data = null;
|
||||||
final TypesEnum2 insertedData = DataAccess.insert(test);
|
final TypesEnum2 insertedData = DataAccess.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesEnum2 retrieve = DataAccess.get(TypesEnum2.class, insertedData.id);
|
final TypesEnum2 retrieve = DataAccess.get(TypesEnum2.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNull(retrieve.data);
|
Assertions.assertNull(retrieve.data);
|
||||||
|
|
||||||
DataAccess.delete(TypesEnum2.class, insertedData.id);
|
DataAccess.delete(TypesEnum2.class, insertedData.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ import test.kar.archidata.model.TypesTable;
|
|||||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||||
public class TestTypes {
|
public class TestTypes {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypes.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypes.class);
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||||
@@ -43,212 +43,212 @@ public class TestTypes {
|
|||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
entry.connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
LOGGER.info("Remove the test db");
|
||||||
DBEntry.closeAllForceMode();
|
DBEntry.closeAllForceMode();
|
||||||
ConfigBaseVariable.clearAllValue();
|
ConfigBaseVariable.clearAllValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTable() throws Exception {
|
public void testCreateTable() throws Exception {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testInteger() throws Exception {
|
public void testInteger() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.intData = 95;
|
test.intData = 95;
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = DataAccess.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.intData);
|
Assertions.assertNotNull(retrieve.intData);
|
||||||
Assertions.assertEquals(insertedData.intData, retrieve.intData);
|
Assertions.assertEquals(insertedData.intData, retrieve.intData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(3)
|
@Order(3)
|
||||||
@Test
|
@Test
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.longData = 541684354354L;
|
test.longData = 541684354354L;
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = DataAccess.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.longData);
|
Assertions.assertNotNull(retrieve.longData);
|
||||||
Assertions.assertEquals(insertedData.longData, retrieve.longData);
|
Assertions.assertEquals(insertedData.longData, retrieve.longData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(4)
|
@Order(4)
|
||||||
@Test
|
@Test
|
||||||
public void testfloat() throws Exception {
|
public void testfloat() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.floatData = 153154.0f;
|
test.floatData = 153154.0f;
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = DataAccess.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.floatData);
|
Assertions.assertNotNull(retrieve.floatData);
|
||||||
Assertions.assertEquals(insertedData.floatData, retrieve.floatData);
|
Assertions.assertEquals(insertedData.floatData, retrieve.floatData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(5)
|
@Order(5)
|
||||||
@Test
|
@Test
|
||||||
public void testDouble() throws Exception {
|
public void testDouble() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.doubleData = 153152654654.0;
|
test.doubleData = 153152654654.0;
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = DataAccess.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.doubleData);
|
Assertions.assertNotNull(retrieve.doubleData);
|
||||||
Assertions.assertEquals(insertedData.doubleData, retrieve.doubleData);
|
Assertions.assertEquals(insertedData.doubleData, retrieve.doubleData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(6)
|
@Order(6)
|
||||||
@Test
|
@Test
|
||||||
public void testText() throws Exception {
|
public void testText() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.textData = "lkjlkjlkjmlkqjsdùkljqsùmckljvùwxmckvmwlkdnfqmsjdvnmclkwsjdn;vbcm <wkdjncvm<wk:dnxcm<lwkdnc mqs<wdn:cx,<nm wlx!k:cn<;wmlx:!c;,<wmlx!:c;n<wm ldx:;c,<nwmlx:c,;<wmlx!:c;,< w";
|
test.textData = "lkjlkjlkjmlkqjsdùkljqsùmckljvùwxmckvmwlkdnfqmsjdvnmclkwsjdn;vbcm <wkdjncvm<wk:dnxcm<lwkdnc mqs<wdn:cx,<nm wlx!k:cn<;wmlx:!c;,<wmlx!:c;n<wm ldx:;c,<nwmlx:c,;<wmlx!:c;,< w";
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = DataAccess.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.textData);
|
Assertions.assertNotNull(retrieve.textData);
|
||||||
Assertions.assertEquals(insertedData.textData, retrieve.textData);
|
Assertions.assertEquals(insertedData.textData, retrieve.textData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(7)
|
@Order(7)
|
||||||
@Test
|
@Test
|
||||||
public void testVarChar() throws Exception {
|
public void testVarChar() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.varcharData = "123456789123456789";
|
test.varcharData = "123456789123456789";
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = DataAccess.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.varcharData);
|
Assertions.assertNotNull(retrieve.varcharData);
|
||||||
Assertions.assertEquals(insertedData.varcharData, retrieve.varcharData);
|
Assertions.assertEquals(insertedData.varcharData, retrieve.varcharData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(8)
|
@Order(8)
|
||||||
@Test
|
@Test
|
||||||
public void testBooleanTrue() throws Exception {
|
public void testBooleanTrue() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.booleanData = true;
|
test.booleanData = true;
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = DataAccess.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.booleanData);
|
Assertions.assertNotNull(retrieve.booleanData);
|
||||||
Assertions.assertEquals(insertedData.booleanData, retrieve.booleanData);
|
Assertions.assertEquals(insertedData.booleanData, retrieve.booleanData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(9)
|
@Order(9)
|
||||||
@Test
|
@Test
|
||||||
public void testBooleanFalse() throws Exception {
|
public void testBooleanFalse() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.booleanData = false;
|
test.booleanData = false;
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = DataAccess.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
Assertions.assertNotNull(retrieve.booleanData);
|
Assertions.assertNotNull(retrieve.booleanData);
|
||||||
Assertions.assertEquals(insertedData.booleanData, retrieve.booleanData);
|
Assertions.assertEquals(insertedData.booleanData, retrieve.booleanData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(10)
|
@Order(10)
|
||||||
@Test
|
@Test
|
||||||
public void testTimeStamp() throws Exception {
|
public void testTimeStamp() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.timeStampData = Timestamp.from(Instant.now());
|
test.timeStampData = Timestamp.from(Instant.now());
|
||||||
LOGGER.debug("Timestamp = {}", test.timeStampData);
|
LOGGER.debug("Timestamp = {}", test.timeStampData);
|
||||||
@@ -256,10 +256,10 @@ public class TestTypes {
|
|||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
@@ -268,14 +268,14 @@ public class TestTypes {
|
|||||||
// Can not compare the exact timestamp due to aproximation and model of storing data :
|
// Can not compare the exact timestamp due to aproximation and model of storing data :
|
||||||
// Assertions.assertEquals(insertedData.timeStampData, retrieve.timeStampData);
|
// Assertions.assertEquals(insertedData.timeStampData, retrieve.timeStampData);
|
||||||
Assertions.assertEquals(insertedData.timeStampData.toInstant().toEpochMilli(), retrieve.timeStampData.toInstant().toEpochMilli());
|
Assertions.assertEquals(insertedData.timeStampData.toInstant().toEpochMilli(), retrieve.timeStampData.toInstant().toEpochMilli());
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(11)
|
@Order(11)
|
||||||
@Test
|
@Test
|
||||||
public void testDate() throws Exception {
|
public void testDate() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.dateFullData = Date.from(Instant.now());
|
test.dateFullData = Date.from(Instant.now());
|
||||||
LOGGER.debug("Date = {}", test.dateFullData);
|
LOGGER.debug("Date = {}", test.dateFullData);
|
||||||
@@ -283,24 +283,24 @@ public class TestTypes {
|
|||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
LOGGER.debug("Retreive Date = {}", retrieve.dateFullData);
|
LOGGER.debug("Retreive Date = {}", retrieve.dateFullData);
|
||||||
Assertions.assertNotNull(retrieve.dateFullData);
|
Assertions.assertNotNull(retrieve.dateFullData);
|
||||||
Assertions.assertEquals(insertedData.dateFullData, retrieve.dateFullData);
|
Assertions.assertEquals(insertedData.dateFullData, retrieve.dateFullData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(12)
|
@Order(12)
|
||||||
@Test
|
@Test
|
||||||
public void testLocalDate() throws Exception {
|
public void testLocalDate() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.dateData = LocalDate.now();
|
test.dateData = LocalDate.now();
|
||||||
LOGGER.debug("LocalDate = {}", test.dateData);
|
LOGGER.debug("LocalDate = {}", test.dateData);
|
||||||
@@ -308,24 +308,24 @@ public class TestTypes {
|
|||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
LOGGER.debug("Retreive LocalDate = {}", retrieve.dateData);
|
LOGGER.debug("Retreive LocalDate = {}", retrieve.dateData);
|
||||||
Assertions.assertNotNull(retrieve.dateData);
|
Assertions.assertNotNull(retrieve.dateData);
|
||||||
Assertions.assertEquals(insertedData.dateData, retrieve.dateData);
|
Assertions.assertEquals(insertedData.dateData, retrieve.dateData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(13)
|
@Order(13)
|
||||||
@Test
|
@Test
|
||||||
public void testLocalTime() throws Exception {
|
public void testLocalTime() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.timeData = LocalTime.now();
|
test.timeData = LocalTime.now();
|
||||||
LOGGER.debug("LocalTime = {}", test.timeData);
|
LOGGER.debug("LocalTime = {}", test.timeData);
|
||||||
@@ -333,10 +333,10 @@ public class TestTypes {
|
|||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
@@ -345,14 +345,14 @@ public class TestTypes {
|
|||||||
Assertions.assertEquals(insertedData.timeData.getHour(), retrieve.timeData.getHour());
|
Assertions.assertEquals(insertedData.timeData.getHour(), retrieve.timeData.getHour());
|
||||||
Assertions.assertEquals(insertedData.timeData.getMinute(), retrieve.timeData.getMinute());
|
Assertions.assertEquals(insertedData.timeData.getMinute(), retrieve.timeData.getMinute());
|
||||||
Assertions.assertEquals(insertedData.timeData.getSecond(), retrieve.timeData.getSecond());
|
Assertions.assertEquals(insertedData.timeData.getSecond(), retrieve.timeData.getSecond());
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(14)
|
@Order(14)
|
||||||
@Test
|
@Test
|
||||||
public void testTextUpdateDirect() throws Exception {
|
public void testTextUpdateDirect() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.textData = "test 1";
|
test.textData = "test 1";
|
||||||
test.booleanData = null;
|
test.booleanData = null;
|
||||||
@@ -361,10 +361,10 @@ public class TestTypes {
|
|||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
@@ -373,17 +373,17 @@ public class TestTypes {
|
|||||||
Assertions.assertNull(retrieve.booleanData);
|
Assertions.assertNull(retrieve.booleanData);
|
||||||
Assertions.assertNotNull(retrieve.varcharData);
|
Assertions.assertNotNull(retrieve.varcharData);
|
||||||
Assertions.assertEquals(insertedData.varcharData, retrieve.varcharData);
|
Assertions.assertEquals(insertedData.varcharData, retrieve.varcharData);
|
||||||
|
|
||||||
// Update the text value:
|
// Update the text value:
|
||||||
retrieve.textData = "test 2";
|
retrieve.textData = "test 2";
|
||||||
retrieve.booleanData = true;
|
retrieve.booleanData = true;
|
||||||
retrieve.varcharData = null;
|
retrieve.varcharData = null;
|
||||||
final int nbUpdate = DataAccess.update(retrieve, insertedData.id);
|
final int nbUpdate = DataAccess.update(retrieve, insertedData.id);
|
||||||
Assertions.assertEquals(1, nbUpdate);
|
Assertions.assertEquals(1, nbUpdate);
|
||||||
|
|
||||||
// Get new data
|
// Get new data
|
||||||
final TypesTable retrieve2 = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve2 = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve2);
|
Assertions.assertNotNull(retrieve2);
|
||||||
Assertions.assertNotNull(retrieve2.id);
|
Assertions.assertNotNull(retrieve2.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve2.id);
|
Assertions.assertEquals(insertedData.id, retrieve2.id);
|
||||||
@@ -392,17 +392,17 @@ public class TestTypes {
|
|||||||
Assertions.assertNotNull(retrieve2.booleanData);
|
Assertions.assertNotNull(retrieve2.booleanData);
|
||||||
Assertions.assertEquals(retrieve.booleanData, retrieve2.booleanData);
|
Assertions.assertEquals(retrieve.booleanData, retrieve2.booleanData);
|
||||||
Assertions.assertNull(retrieve2.varcharData);
|
Assertions.assertNull(retrieve2.varcharData);
|
||||||
|
|
||||||
// test filter values:
|
// test filter values:
|
||||||
retrieve.textData = "test 3";
|
retrieve.textData = "test 3";
|
||||||
retrieve.booleanData = false;
|
retrieve.booleanData = false;
|
||||||
retrieve.varcharData = "test3";
|
retrieve.varcharData = "test3";
|
||||||
final int nbUpdate2 = DataAccess.update(retrieve, insertedData.id, List.of("textData"));
|
final int nbUpdate2 = DataAccess.update(retrieve, insertedData.id, List.of("textData"));
|
||||||
Assertions.assertEquals(1, nbUpdate2);
|
Assertions.assertEquals(1, nbUpdate2);
|
||||||
|
|
||||||
// Get new data
|
// Get new data
|
||||||
final TypesTable retrieve3 = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve3 = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve3);
|
Assertions.assertNotNull(retrieve3);
|
||||||
Assertions.assertNotNull(retrieve3.id);
|
Assertions.assertNotNull(retrieve3.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve3.id);
|
Assertions.assertEquals(insertedData.id, retrieve3.id);
|
||||||
@@ -412,14 +412,14 @@ public class TestTypes {
|
|||||||
// note: retreive2
|
// note: retreive2
|
||||||
Assertions.assertEquals(retrieve2.booleanData, retrieve3.booleanData);
|
Assertions.assertEquals(retrieve2.booleanData, retrieve3.booleanData);
|
||||||
Assertions.assertNull(retrieve3.varcharData);
|
Assertions.assertNull(retrieve3.varcharData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(15)
|
@Order(15)
|
||||||
@Test
|
@Test
|
||||||
public void testTextUpdateJson() throws Exception {
|
public void testTextUpdateJson() throws Exception {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.textData = "test 1";
|
test.textData = "test 1";
|
||||||
test.booleanData = null;
|
test.booleanData = null;
|
||||||
@@ -428,10 +428,10 @@ public class TestTypes {
|
|||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
Assertions.assertTrue(insertedData.id >= 0);
|
Assertions.assertTrue(insertedData.id >= 0);
|
||||||
|
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||||
@@ -440,7 +440,7 @@ public class TestTypes {
|
|||||||
Assertions.assertNull(retrieve.booleanData);
|
Assertions.assertNull(retrieve.booleanData);
|
||||||
Assertions.assertNotNull(retrieve.varcharData);
|
Assertions.assertNotNull(retrieve.varcharData);
|
||||||
Assertions.assertEquals(insertedData.varcharData, retrieve.varcharData);
|
Assertions.assertEquals(insertedData.varcharData, retrieve.varcharData);
|
||||||
|
|
||||||
// Update the text value:
|
// Update the text value:
|
||||||
final String jsonData = """
|
final String jsonData = """
|
||||||
{
|
{
|
||||||
@@ -451,10 +451,10 @@ public class TestTypes {
|
|||||||
""";
|
""";
|
||||||
final int nbUpdate = DataAccess.updateWithJson(TypesTable.class, insertedData.id, jsonData, null);
|
final int nbUpdate = DataAccess.updateWithJson(TypesTable.class, insertedData.id, jsonData, null);
|
||||||
Assertions.assertEquals(1, nbUpdate);
|
Assertions.assertEquals(1, nbUpdate);
|
||||||
|
|
||||||
// Get new data
|
// Get new data
|
||||||
final TypesTable retrieve2 = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve2 = DataAccess.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve2);
|
Assertions.assertNotNull(retrieve2);
|
||||||
Assertions.assertNotNull(retrieve2.id);
|
Assertions.assertNotNull(retrieve2.id);
|
||||||
Assertions.assertEquals(insertedData.id, retrieve2.id);
|
Assertions.assertEquals(insertedData.id, retrieve2.id);
|
||||||
@@ -463,8 +463,8 @@ public class TestTypes {
|
|||||||
Assertions.assertNotNull(retrieve2.booleanData);
|
Assertions.assertNotNull(retrieve2.booleanData);
|
||||||
Assertions.assertEquals(true, retrieve2.booleanData);
|
Assertions.assertEquals(true, retrieve2.booleanData);
|
||||||
Assertions.assertNull(retrieve2.varcharData);
|
Assertions.assertNull(retrieve2.varcharData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
DataAccess.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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.2
|
||||||
|
|||||||
Reference in New Issue
Block a user