Compare commits
2 Commits
6b0c392ff3
...
c682cc7803
Author | SHA1 | Date | |
---|---|---|---|
c682cc7803 | |||
c144cd378e |
50
pom.xml
50
pom.xml
@ -188,33 +188,29 @@
|
|||||||
<version>4.8.6</version>
|
<version>4.8.6</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Morphia -->
|
<!-- Morphia -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.morphia.morphia</groupId>
|
<groupId>dev.morphia.morphia</groupId>
|
||||||
<artifactId>morphia-core</artifactId>
|
<artifactId>morphia-core</artifactId>
|
||||||
<version>2.3.0</version>
|
<version>2.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- MongoDB Java Driver -->
|
||||||
<!-- MongoDB Java Driver -->
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.mongodb</groupId>
|
||||||
<groupId>org.mongodb</groupId>
|
<artifactId>mongodb-driver-sync</artifactId>
|
||||||
<artifactId>mongodb-driver-sync</artifactId>
|
<version>4.3.0</version>
|
||||||
<version>4.3.0</version>
|
</dependency>
|
||||||
</dependency>
|
<!-- Bean Validation (JSR 303 / 380) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.validator</groupId>
|
||||||
<!-- Bean Validation (JSR 303 / 380) -->
|
<artifactId>hibernate-validator</artifactId>
|
||||||
<dependency>
|
<version>7.0.0.Final</version>
|
||||||
<groupId>org.hibernate.validator</groupId>
|
</dependency>
|
||||||
<artifactId>hibernate-validator</artifactId>
|
<dependency>
|
||||||
<version>7.0.0.Final</version>
|
<groupId>javax.validation</groupId>
|
||||||
</dependency>
|
<artifactId>validation-api</artifactId>
|
||||||
|
<version>2.0.1.Final</version>
|
||||||
<dependency>
|
</dependency>
|
||||||
<groupId>javax.validation</groupId>
|
|
||||||
<artifactId>validation-api</artifactId>
|
|
||||||
<version>2.0.1.Final</version>
|
|
||||||
</dependency>
|
|
||||||
<!--
|
<!--
|
||||||
************************************************************
|
************************************************************
|
||||||
** TEST dependency **
|
** TEST dependency **
|
||||||
|
@ -1,15 +1,28 @@
|
|||||||
package org.kar.archidata;
|
package org.kar.archidata;
|
||||||
|
|
||||||
import org.kar.archidata.db.DBConfig;
|
import org.kar.archidata.db.DBConfig;
|
||||||
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
|
|
||||||
public class GlobalConfiguration {
|
public class GlobalConfiguration {
|
||||||
public static final DBConfig dbConfig;
|
private static final DBConfig dbConfig;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
dbConfig = new DBConfig(ConfigBaseVariable.getDBType(), ConfigBaseVariable.getDBHost(),
|
DBConfig dbConfigTmp = null;
|
||||||
Integer.parseInt(ConfigBaseVariable.getDBPort()), ConfigBaseVariable.getDBLogin(),
|
try {
|
||||||
ConfigBaseVariable.getDBPassword(), ConfigBaseVariable.getDBName(),
|
dbConfigTmp = new DBConfig(ConfigBaseVariable.getDBType(), ConfigBaseVariable.getDBHost(),
|
||||||
ConfigBaseVariable.getDBKeepConnected());
|
Integer.parseInt(ConfigBaseVariable.getDBPort()), ConfigBaseVariable.getDBLogin(),
|
||||||
|
ConfigBaseVariable.getDBPassword(), ConfigBaseVariable.getDBName(),
|
||||||
|
ConfigBaseVariable.getDBKeepConnected());
|
||||||
|
} catch (NumberFormatException | DataAccessException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.println("Fail to configure db access ... in static GlobalConfiguration");
|
||||||
|
}
|
||||||
|
dbConfig = dbConfigTmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DBConfig getDbconfig() {
|
||||||
|
return dbConfig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
package org.kar.archidata;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
|
||||||
import org.kar.archidata.dataAccess.QueryOptions;
|
|
||||||
import org.kar.archidata.dataAccess.options.DBInterfaceOption;
|
|
||||||
import org.kar.archidata.dataAccess.options.QueryOption;
|
|
||||||
import org.kar.archidata.db.DBEntry;
|
|
||||||
import org.kar.archidata.model.User;
|
|
||||||
|
|
||||||
public class UserDB {
|
|
||||||
|
|
||||||
public UserDB() {}
|
|
||||||
|
|
||||||
public static User getUsers(final long userId, QueryOption... option) throws Exception {
|
|
||||||
return DataAccess.get(User.class, userId, option);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static User getUserOrCreate(final long userId, final String userLogin, QueryOption... option)
|
|
||||||
throws Exception {
|
|
||||||
final User user = getUsers(userId);
|
|
||||||
if (user != null) {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
createUsersInfoFromOAuth(userId, userLogin, option);
|
|
||||||
return getUsers(userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void createUsersInfoFromOAuth(final long userId, final String login, QueryOption... option)
|
|
||||||
throws IOException {
|
|
||||||
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')";
|
|
||||||
try {
|
|
||||||
final PreparedStatement ps = entry.connection.prepareStatement(query);
|
|
||||||
ps.setLong(1, userId);
|
|
||||||
ps.setString(2, login);
|
|
||||||
ps.executeUpdate();
|
|
||||||
} catch (final SQLException throwables) {
|
|
||||||
throwables.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
entry.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,6 +11,7 @@ import org.kar.archidata.exception.DataAccessException;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import dev.morphia.annotations.Entity;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.annotation.Nullable;
|
import jakarta.annotation.Nullable;
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
@ -31,6 +32,7 @@ import jakarta.ws.rs.DefaultValue;
|
|||||||
public class AnnotationTools {
|
public class AnnotationTools {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(AnnotationTools.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(AnnotationTools.class);
|
||||||
|
|
||||||
|
// For SQL declaration table Name
|
||||||
public static String getTableName(final Class<?> clazz, final QueryOptions options) throws DataAccessException {
|
public static String getTableName(final Class<?> clazz, final QueryOptions options) throws DataAccessException {
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
final List<OverrideTableName> data = options.get(OverrideTableName.class);
|
final List<OverrideTableName> data = options.get(OverrideTableName.class);
|
||||||
@ -41,16 +43,13 @@ public class AnnotationTools {
|
|||||||
return AnnotationTools.getTableName(clazz);
|
return AnnotationTools.getTableName(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTableName(final Class<?> element) throws DataAccessException {
|
// For SQL declaration table Name
|
||||||
|
public static String getTableName(final Class<?> element) {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Table.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Table.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
// when no annotation is detected, then the table name is the class name
|
// when no annotation is detected, then the table name is the class name
|
||||||
return element.getSimpleName();
|
return element.getSimpleName();
|
||||||
}
|
}
|
||||||
if (annotation.length > 1) {
|
|
||||||
throw new DataAccessException(
|
|
||||||
"Must not have more than 1 element @Table on " + element.getClass().getCanonicalName());
|
|
||||||
}
|
|
||||||
final String tmp = ((Table) annotation[0]).name();
|
final String tmp = ((Table) annotation[0]).name();
|
||||||
if (tmp == null) {
|
if (tmp == null) {
|
||||||
return element.getSimpleName();
|
return element.getSimpleName();
|
||||||
@ -58,6 +57,31 @@ public class AnnotationTools {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getCollectionName(final Class<?> clazz, final QueryOptions options) {
|
||||||
|
if (options != null) {
|
||||||
|
// TODO: maybe change OverrideTableName with OverrideCollectionName
|
||||||
|
final List<OverrideTableName> data = options.get(OverrideTableName.class);
|
||||||
|
if (data.size() == 1) {
|
||||||
|
return data.get(0).getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return AnnotationTools.getCollectionName(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For No-SQL Table/Collection Name
|
||||||
|
public static String getCollectionName(final Class<?> clazz) {
|
||||||
|
final Annotation[] annotation = clazz.getDeclaredAnnotationsByType(Entity.class);
|
||||||
|
if (annotation.length == 0) {
|
||||||
|
// when no annotation is detected, then the table name is the class name
|
||||||
|
return clazz.getSimpleName();
|
||||||
|
}
|
||||||
|
final String tmp = ((Entity) annotation[0]).value();
|
||||||
|
if (tmp == null) {
|
||||||
|
return clazz.getSimpleName();
|
||||||
|
}
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean getSchemaReadOnly(final Field element) throws DataAccessException {
|
public static boolean getSchemaReadOnly(final Field element) throws DataAccessException {
|
||||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Schema.class);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Schema.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
|
@ -56,7 +56,7 @@ import jakarta.ws.rs.core.StreamingOutput;
|
|||||||
// https://stackoverflow.com/questions/35367113/jersey-webservice-scalable-approach-to-download-file-and-reply-to-client
|
// https://stackoverflow.com/questions/35367113/jersey-webservice-scalable-approach-to-download-file-and-reply-to-client
|
||||||
// https://gist.github.com/aitoroses/4f7a2b197b732a6a691d
|
// https://gist.github.com/aitoroses/4f7a2b197b732a6a691d
|
||||||
|
|
||||||
@Path("/data")
|
// TODO: must be inherited and set the default dataAccess interface @Path("/data")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public class DataResource {
|
public class DataResource {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DataResource.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DataResource.class);
|
||||||
@ -64,6 +64,7 @@ public class DataResource {
|
|||||||
private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks
|
private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks
|
||||||
/** Upload some datas */
|
/** Upload some datas */
|
||||||
private static long tmpFolderId = 1;
|
private static long tmpFolderId = 1;
|
||||||
|
protected final DataAccess da = DataAccess.createInterface();
|
||||||
|
|
||||||
private static void createFolder(final String path) throws IOException {
|
private static void createFolder(final String path) throws IOException {
|
||||||
if (!Files.exists(java.nio.file.Path.of(path))) {
|
if (!Files.exists(java.nio.file.Path.of(path))) {
|
||||||
@ -118,10 +119,10 @@ public class DataResource {
|
|||||||
return getFileData(uuid) + ".json";
|
return getFileData(uuid) + ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data getWithSha512(final String sha512) {
|
public Data getWithSha512(final String sha512) {
|
||||||
LOGGER.info("find sha512 = {}", sha512);
|
LOGGER.info("find sha512 = {}", sha512);
|
||||||
try {
|
try {
|
||||||
return DataAccess.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512)));
|
return this.da.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512)));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -129,10 +130,10 @@ public class DataResource {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data getWithId(final long id) {
|
public Data getWithId(final long id) {
|
||||||
LOGGER.info("find id = {}", id);
|
LOGGER.info("find id = {}", id);
|
||||||
try {
|
try {
|
||||||
return DataAccess.get(Data.class, id);
|
return this.da.get(Data.class, id);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -140,7 +141,7 @@ public class DataResource {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data createNewData(final long tmpUID, final String originalFileName, final String sha512)
|
public Data createNewData(final long tmpUID, final String originalFileName, final String sha512)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
// determine mime type:
|
// determine mime type:
|
||||||
Data injectedData = new Data();
|
Data injectedData = new Data();
|
||||||
@ -161,7 +162,7 @@ public class DataResource {
|
|||||||
injectedData.size = Files.size(Paths.get(tmpPath));
|
injectedData.size = Files.size(Paths.get(tmpPath));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
injectedData = DataAccess.insert(injectedData);
|
injectedData = this.da.insert(injectedData);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
@ -254,7 +255,7 @@ public class DataResource {
|
|||||||
|
|
||||||
public Data getSmall(final UUID id) {
|
public Data getSmall(final UUID id) {
|
||||||
try {
|
try {
|
||||||
return DataAccess.get(Data.class, id);
|
return this.da.get(Data.class, id);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -500,8 +501,8 @@ public class DataResource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void undelete(final Long id) throws Exception {
|
public void undelete(final Long id) throws Exception {
|
||||||
DataAccess.unsetDelete(Data.class, id);
|
this.da.unsetDelete(Data.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -29,7 +29,7 @@ public interface DataAccessAddOn {
|
|||||||
* @param iii The index of injection
|
* @param iii The index of injection
|
||||||
* @return the new index of injection in case of multiple value management
|
* @return the new index of injection in case of multiple value management
|
||||||
* @throws SQLException */
|
* @throws SQLException */
|
||||||
void insertData(PreparedStatement ps, final Field field, Object data, CountInOut iii)
|
void insertData(final DataAccessSQL ioDb, PreparedStatement ps, final Field field, Object data, CountInOut iii)
|
||||||
throws Exception, SQLException, IllegalArgumentException, IllegalAccessException;
|
throws Exception, SQLException, IllegalArgumentException, IllegalAccessException;
|
||||||
|
|
||||||
/** Element can insert in the single request
|
/** Element can insert in the single request
|
||||||
@ -58,6 +58,7 @@ public interface DataAccessAddOn {
|
|||||||
|
|
||||||
// Return the number of colomn read
|
// Return the number of colomn read
|
||||||
void fillFromQuery(
|
void fillFromQuery(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
ResultSet rs,
|
ResultSet rs,
|
||||||
Field field,
|
Field field,
|
||||||
Object data,
|
Object data,
|
||||||
@ -100,6 +101,7 @@ public interface DataAccessAddOn {
|
|||||||
* @param data Data that might be inserted.
|
* @param data Data that might be inserted.
|
||||||
* @param actions Asynchronous action to do after main request. */
|
* @param actions Asynchronous action to do after main request. */
|
||||||
default void asyncInsert(
|
default void asyncInsert(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
final String tableName,
|
final String tableName,
|
||||||
final Object localId,
|
final Object localId,
|
||||||
final Field field,
|
final Field field,
|
||||||
@ -122,6 +124,7 @@ public interface DataAccessAddOn {
|
|||||||
* @param data Data that might be inserted.
|
* @param data Data that might be inserted.
|
||||||
* @param actions Asynchronous action to do after main request. */
|
* @param actions Asynchronous action to do after main request. */
|
||||||
default void asyncUpdate(
|
default void asyncUpdate(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
final String tableName,
|
final String tableName,
|
||||||
final Object localId,
|
final Object localId,
|
||||||
final Field field,
|
final Field field,
|
||||||
@ -130,11 +133,11 @@ public interface DataAccessAddOn {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default void drop(final String tableName, final Field field) throws Exception {
|
default void drop(final DataAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default void cleanAll(final String tableName, final Field field) throws Exception {
|
default void cleanAll(final DataAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1370
src/org/kar/archidata/dataAccess/DataAccessMorphia.java
Normal file
1370
src/org/kar/archidata/dataAccess/DataAccessMorphia.java
Normal file
File diff suppressed because it is too large
Load Diff
1619
src/org/kar/archidata/dataAccess/DataAccessSQL.java
Normal file
1619
src/org/kar/archidata/dataAccess/DataAccessSQL.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -19,12 +19,10 @@ import java.util.UUID;
|
|||||||
import org.kar.archidata.dataAccess.exportTools.TableQuery;
|
import org.kar.archidata.dataAccess.exportTools.TableQuery;
|
||||||
import org.kar.archidata.dataAccess.exportTools.TableQueryTypes;
|
import org.kar.archidata.dataAccess.exportTools.TableQueryTypes;
|
||||||
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.GroupBy;
|
import org.kar.archidata.dataAccess.options.GroupBy;
|
||||||
import org.kar.archidata.dataAccess.options.Limit;
|
import org.kar.archidata.dataAccess.options.Limit;
|
||||||
import org.kar.archidata.dataAccess.options.OrderBy;
|
import org.kar.archidata.dataAccess.options.OrderBy;
|
||||||
import org.kar.archidata.dataAccess.options.QueryOption;
|
import org.kar.archidata.dataAccess.options.QueryOption;
|
||||||
import org.kar.archidata.db.DBEntry;
|
|
||||||
import org.kar.archidata.exception.DataAccessException;
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
import org.kar.archidata.tools.DateTools;
|
import org.kar.archidata.tools.DateTools;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -246,24 +244,24 @@ public class DataExport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static TableQuery queryTable(
|
public static TableQuery queryTable(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
final List<TableQueryTypes> headers,
|
final List<TableQueryTypes> headers,
|
||||||
final String query,
|
final String query,
|
||||||
final List<Object> parameters,
|
final List<Object> parameters,
|
||||||
final QueryOption... option) throws Exception {
|
final QueryOption... option) throws Exception {
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
return queryTable(headers, query, parameters, options);
|
return queryTable(ioDb, headers, query, parameters, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TableQuery queryTable(
|
public static TableQuery queryTable(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
final List<TableQueryTypes> headers,
|
final List<TableQueryTypes> headers,
|
||||||
final String queryBase,
|
final String queryBase,
|
||||||
final List<Object> parameters,
|
final List<Object> parameters,
|
||||||
final QueryOptions options) throws Exception {
|
final QueryOptions options) throws Exception {
|
||||||
final List<LazyGetter> lazyCall = new ArrayList<>();
|
final List<LazyGetter> lazyCall = new ArrayList<>();
|
||||||
// TODO ... final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
|
||||||
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
|
||||||
|
|
||||||
final Condition condition = DataAccess.conditionFusionOrEmpty(options, false);
|
final Condition condition = ioDb.conditionFusionOrEmpty(options, false);
|
||||||
final StringBuilder query = new StringBuilder(queryBase);
|
final StringBuilder query = new StringBuilder(queryBase);
|
||||||
final TableQuery out = new TableQuery(headers);
|
final TableQuery out = new TableQuery(headers);
|
||||||
// real add in the BDD:
|
// real add in the BDD:
|
||||||
@ -286,18 +284,18 @@ public class DataExport {
|
|||||||
}
|
}
|
||||||
LOGGER.warn("generate the query: '{}'", query.toString());
|
LOGGER.warn("generate the query: '{}'", query.toString());
|
||||||
// prepare the request:
|
// prepare the request:
|
||||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(),
|
final PreparedStatement ps = ioDb.getConnection().prepareStatement(query.toString(),
|
||||||
Statement.RETURN_GENERATED_KEYS);
|
Statement.RETURN_GENERATED_KEYS);
|
||||||
final CountInOut iii = new CountInOut(1);
|
final CountInOut iii = new CountInOut(1);
|
||||||
if (parameters != null) {
|
if (parameters != null) {
|
||||||
for (final Object elem : parameters) {
|
for (final Object elem : parameters) {
|
||||||
DataAccess.addElement(ps, elem, iii);
|
ioDb.addElement(ps, elem, iii);
|
||||||
}
|
}
|
||||||
iii.inc();
|
iii.inc();
|
||||||
}
|
}
|
||||||
condition.injectQuery(ps, iii);
|
condition.injectQuery(ioDb, ps, iii);
|
||||||
if (limits.size() == 1) {
|
if (limits.size() == 1) {
|
||||||
limits.get(0).injectQuery(ps, iii);
|
limits.get(0).injectQuery(ioDb, ps, iii);
|
||||||
}
|
}
|
||||||
// execute the request
|
// execute the request
|
||||||
final ResultSet rs = ps.executeQuery();
|
final ResultSet rs = ps.executeQuery();
|
||||||
@ -332,8 +330,6 @@ public class DataExport {
|
|||||||
throw ex;
|
throw ex;
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
} finally {
|
|
||||||
entry.close();
|
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -383,8 +383,8 @@ public class DataFactory {
|
|||||||
}
|
}
|
||||||
alreadyAdded.add(dataName);
|
alreadyAdded.add(dataName);
|
||||||
LOGGER.trace(" + '{}'", elem.getName());
|
LOGGER.trace(" + '{}'", elem.getName());
|
||||||
if (DataAccess.isAddOnField(elem)) {
|
if (DataAccessSQL.isAddOnField(elem)) {
|
||||||
final DataAccessAddOn addOn = DataAccess.findAddOnforField(elem);
|
final DataAccessAddOn addOn = DataAccessSQL.findAddOnforField(elem);
|
||||||
LOGGER.trace("Create type for: {} ==> {} (ADD-ON)", AnnotationTools.getFieldName(elem),
|
LOGGER.trace("Create type for: {} ==> {} (ADD-ON)", AnnotationTools.getFieldName(elem),
|
||||||
elem.getType());
|
elem.getType());
|
||||||
if (addOn != null) {
|
if (addOn != null) {
|
||||||
@ -439,4 +439,4 @@ public class DataFactory {
|
|||||||
return preActionList;
|
return preActionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.conversions.Bson;
|
||||||
|
|
||||||
|
import com.mongodb.client.model.Filters;
|
||||||
|
|
||||||
public class QueryAnd implements QueryItem {
|
public class QueryAnd implements QueryItem {
|
||||||
protected final List<QueryItem> childs;
|
protected final List<QueryItem> childs;
|
||||||
|
|
||||||
@ -41,14 +45,23 @@ public class QueryAnd implements QueryItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
|
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||||
|
throws Exception {
|
||||||
for (final QueryItem elem : this.childs) {
|
for (final QueryItem elem : this.childs) {
|
||||||
elem.injectQuery(ps, iii);
|
elem.injectQuery(ioDb, ps, iii);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
return this.childs.size();
|
return this.childs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateFilter(final List<Bson> filters) {
|
||||||
|
final List<Bson> filtersLocal = new ArrayList<>();
|
||||||
|
for (final QueryItem elem : this.childs) {
|
||||||
|
elem.generateFilter(filtersLocal);
|
||||||
|
}
|
||||||
|
filters.add(Filters.and(filtersLocal.toArray(new Bson[0])));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
package org.kar.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.conversions.Bson;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.mongodb.client.model.Filters;
|
||||||
|
|
||||||
public class QueryCondition implements QueryItem {
|
public class QueryCondition implements QueryItem {
|
||||||
|
static final Logger LOGGER = LoggerFactory.getLogger(DataAccess.class);
|
||||||
private final String key;
|
private final String key;
|
||||||
private final String comparator;
|
private final String comparator;
|
||||||
private final Object value;
|
private final Object value;
|
||||||
@ -32,8 +40,29 @@ public class QueryCondition implements QueryItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
|
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||||
DataAccess.addElement(ps, this.value, iii);
|
throws Exception {
|
||||||
|
ioDb.addElement(ps, this.value, iii);
|
||||||
iii.inc();
|
iii.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateFilter(final List<Bson> filters) {
|
||||||
|
if ("=".equals(this.comparator)) {
|
||||||
|
filters.add(Filters.eq(this.key, this.value));
|
||||||
|
} else if ("!=".equals(this.comparator)) {
|
||||||
|
filters.add(Filters.ne(this.key, this.value));
|
||||||
|
} else if (">".equals(this.comparator)) {
|
||||||
|
filters.add(Filters.gt(this.key, this.value));
|
||||||
|
} else if (">=".equals(this.comparator)) {
|
||||||
|
filters.add(Filters.gte(this.key, this.value));
|
||||||
|
} else if ("<".equals(this.comparator)) {
|
||||||
|
filters.add(Filters.lt(this.key, this.value));
|
||||||
|
} else if ("<=".equals(this.comparator)) {
|
||||||
|
filters.add(Filters.lte(this.key, this.value));
|
||||||
|
} else {
|
||||||
|
LOGGER.error("Not manage comparison: '{}'", this.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,10 @@ package org.kar.archidata.dataAccess;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.conversions.Bson;
|
||||||
|
|
||||||
|
import com.mongodb.client.model.Filters;
|
||||||
|
|
||||||
public class QueryInList<T> implements QueryItem {
|
public class QueryInList<T> implements QueryItem {
|
||||||
protected final String key;
|
protected final String key;
|
||||||
protected final String comparator;
|
protected final String comparator;
|
||||||
@ -44,10 +48,16 @@ public class QueryInList<T> implements QueryItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
|
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||||
|
throws Exception {
|
||||||
for (final Object elem : this.value) {
|
for (final Object elem : this.value) {
|
||||||
DataAccess.addElement(ps, elem, iii);
|
ioDb.addElement(ps, elem, iii);
|
||||||
iii.inc();
|
iii.inc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateFilter(final List<Bson> filters) {
|
||||||
|
filters.add(Filters.in(this.key, this.value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
package org.kar.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.conversions.Bson;
|
||||||
|
|
||||||
public interface QueryItem {
|
public interface QueryItem {
|
||||||
|
// For SQL mode query construction
|
||||||
void generateQuery(StringBuilder query, String tableName);
|
void generateQuery(StringBuilder query, String tableName);
|
||||||
|
|
||||||
void injectQuery(PreparedStatement ps, CountInOut iii) throws Exception;
|
// For SQL mode query injection
|
||||||
|
void injectQuery(DataAccessSQL ioDb, PreparedStatement ps, CountInOut iii) throws Exception;
|
||||||
|
|
||||||
|
// For No-SQL mode filter creation
|
||||||
|
void generateFilter(List<Bson> filters);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package org.kar.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.conversions.Bson;
|
||||||
|
|
||||||
|
import com.mongodb.client.model.Filters;
|
||||||
|
|
||||||
public class QueryNotNull implements QueryItem {
|
public class QueryNotNull implements QueryItem {
|
||||||
private final String key;
|
private final String key;
|
||||||
@ -20,5 +25,11 @@ public class QueryNotNull implements QueryItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {}
|
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||||
|
throws Exception {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateFilter(final List<Bson> filters) {
|
||||||
|
filters.add(Filters.exists(this.key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package org.kar.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.conversions.Bson;
|
||||||
|
|
||||||
|
import com.mongodb.client.model.Filters;
|
||||||
|
|
||||||
public class QueryNull implements QueryItem {
|
public class QueryNull implements QueryItem {
|
||||||
private final String key;
|
private final String key;
|
||||||
@ -20,5 +25,12 @@ public class QueryNull implements QueryItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {}
|
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||||
|
throws Exception {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateFilter(final List<Bson> filters) {
|
||||||
|
// Not sure of the result ... maybe check it ...
|
||||||
|
filters.add(Filters.eq(this.key, null));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
package org.kar.archidata.dataAccess;
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.conversions.Bson;
|
||||||
|
|
||||||
|
import com.mongodb.client.model.Filters;
|
||||||
|
|
||||||
public class QueryOr implements QueryItem {
|
public class QueryOr implements QueryItem {
|
||||||
protected final List<QueryItem> childs;
|
protected final List<QueryItem> childs;
|
||||||
|
|
||||||
@ -34,9 +39,19 @@ public class QueryOr implements QueryItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
|
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||||
|
throws Exception {
|
||||||
for (final QueryItem elem : this.childs) {
|
for (final QueryItem elem : this.childs) {
|
||||||
elem.injectQuery(ps, iii);
|
elem.injectQuery(ioDb, ps, iii);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateFilter(final List<Bson> filters) {
|
||||||
|
final List<Bson> filtersLocal = new ArrayList<>();
|
||||||
|
for (final QueryItem elem : this.childs) {
|
||||||
|
elem.generateFilter(filtersLocal);
|
||||||
|
}
|
||||||
|
filters.add(Filters.or(filtersLocal.toArray(new Bson[0])));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,14 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
import org.kar.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
import org.kar.archidata.annotation.DataJson;
|
import org.kar.archidata.annotation.DataJson;
|
||||||
import org.kar.archidata.dataAccess.CountInOut;
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.dataAccess.DataAccessAddOn;
|
import org.kar.archidata.dataAccess.DataAccessAddOn;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessMorphia;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.kar.archidata.dataAccess.LazyGetter;
|
import org.kar.archidata.dataAccess.LazyGetter;
|
||||||
import org.kar.archidata.dataAccess.QueryOptions;
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
@ -31,6 +34,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.mongodb.client.MongoCollection;
|
||||||
|
import com.mongodb.client.model.Filters;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
@ -55,7 +60,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertData(final PreparedStatement ps, final Field field, final Object rootObject, final CountInOut iii)
|
public void insertData(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
|
final PreparedStatement ps,
|
||||||
|
final Field field,
|
||||||
|
final Object rootObject,
|
||||||
|
final CountInOut iii)
|
||||||
throws IllegalArgumentException, IllegalAccessException, SQLException, JsonProcessingException {
|
throws IllegalArgumentException, IllegalAccessException, SQLException, JsonProcessingException {
|
||||||
final Object data = field.get(rootObject);
|
final Object data = field.get(rootObject);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
@ -102,6 +112,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillFromQuery(
|
public void fillFromQuery(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
final ResultSet rs,
|
final ResultSet rs,
|
||||||
final Field field,
|
final Field field,
|
||||||
final Object data,
|
final Object data,
|
||||||
@ -172,11 +183,14 @@ public class AddOnDataJson implements DataAccessAddOn {
|
|||||||
postActionList, createIfNotExist, createDrop, fieldId, JsonValue.class);
|
postActionList, createIfNotExist, createDrop, fieldId, JsonValue.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addLink(final Class<?> clazz, final Long id, final String column, final Long remoteKey)
|
public static void addLink(
|
||||||
throws Exception {
|
final DataAccess ioDb,
|
||||||
|
final Class<?> clazz,
|
||||||
|
final Long id,
|
||||||
|
final String column,
|
||||||
|
final Long remoteKey) throws Exception {
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
final TableCoversLongLong data = DataAccess.get(TableCoversLongLong.class, id,
|
final TableCoversLongLong data = ioDb.get(TableCoversLongLong.class, id, new OverrideTableName(tableName));
|
||||||
new OverrideTableName(tableName));
|
|
||||||
if (data.covers == null) {
|
if (data.covers == null) {
|
||||||
data.covers = new ArrayList<>();
|
data.covers = new ArrayList<>();
|
||||||
}
|
}
|
||||||
@ -186,7 +200,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.covers.add(remoteKey);
|
data.covers.add(remoteKey);
|
||||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
ioDb.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -200,22 +214,31 @@ public class AddOnDataJson implements DataAccessAddOn {
|
|||||||
* @param remoteKey The UUID to add to the covers list.
|
* @param remoteKey The UUID to add to the covers list.
|
||||||
* @throws Exception If an error occurs during data retrieval or update.
|
* @throws Exception If an error occurs during data retrieval or update.
|
||||||
*/
|
*/
|
||||||
public static void addLink(final Class<?> clazz, final Long id, final String column, final UUID remoteKey)
|
public static void addLink(
|
||||||
throws Exception {
|
final DataAccess ioDb,
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
final Class<?> clazz,
|
||||||
// TODO: Get primary key name
|
final Long id,
|
||||||
final TableCoversLongUUID data = DataAccess.get(TableCoversLongUUID.class, id,
|
final String column,
|
||||||
new OverrideTableName(tableName));
|
final UUID remoteKey) throws Exception {
|
||||||
if (data.covers == null) {
|
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||||
data.covers = new ArrayList<>();
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
}
|
// TODO: Get primary key name
|
||||||
for (final UUID elem : data.covers) {
|
final TableCoversLongUUID data = ioDb.get(TableCoversLongUUID.class, id, new OverrideTableName(tableName));
|
||||||
if (elem.equals(remoteKey)) {
|
if (data.covers == null) {
|
||||||
return;
|
data.covers = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
for (final UUID elem : data.covers) {
|
||||||
|
if (elem.equals(remoteKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.covers.add(remoteKey);
|
||||||
|
ioDb.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));// TODO: ,new OverrideFieldName("covers", column));
|
||||||
|
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new DataAccessException("DataAccess Not managed");
|
||||||
}
|
}
|
||||||
data.covers.add(remoteKey);
|
|
||||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));// TODO: ,new OverrideFieldName("covers", column));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -229,113 +252,210 @@ public class AddOnDataJson implements DataAccessAddOn {
|
|||||||
* @param remoteKey The UUID to add to the covers list.
|
* @param remoteKey The UUID to add to the covers list.
|
||||||
* @throws Exception If an error occurs during data retrieval or update.
|
* @throws Exception If an error occurs during data retrieval or update.
|
||||||
*/
|
*/
|
||||||
public static void addLink(final Class<?> clazz, final UUID uuid, final String column, final UUID remoteKey)
|
public static void addLink(
|
||||||
throws Exception {
|
final DataAccess ioDb,
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
final Class<?> clazz,
|
||||||
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, uuid,
|
final UUID uuid,
|
||||||
new OverrideTableName(tableName));
|
final String column,
|
||||||
if (data.covers == null) {
|
final UUID remoteKey) throws Exception {
|
||||||
data.covers = new ArrayList<>();
|
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||||
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
|
final TableCoversUUIDUUID data = ioDb.get(TableCoversUUIDUUID.class, uuid,
|
||||||
|
new OverrideTableName(tableName));
|
||||||
|
if (data.covers == null) {
|
||||||
|
data.covers = new ArrayList<>();
|
||||||
|
}
|
||||||
|
for (final UUID elem : data.covers) {
|
||||||
|
if (elem.equals(remoteKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.covers.add(remoteKey);
|
||||||
|
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||||
|
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new DataAccessException("DataAccess Not managed");
|
||||||
}
|
}
|
||||||
for (final UUID elem : data.covers) {
|
}
|
||||||
if (elem.equals(remoteKey)) {
|
|
||||||
|
public static void addLink(
|
||||||
|
final DataAccess ioDb,
|
||||||
|
final Class<?> clazz,
|
||||||
|
final UUID uuid,
|
||||||
|
final String column,
|
||||||
|
final Long remoteKey) throws Exception {
|
||||||
|
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||||
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
|
final TableCoversUUIDLong data = ioDb.get(TableCoversUUIDLong.class, uuid,
|
||||||
|
new OverrideTableName(tableName));
|
||||||
|
if (data.covers == null) {
|
||||||
|
data.covers = new ArrayList<>();
|
||||||
|
}
|
||||||
|
for (final Long elem : data.covers) {
|
||||||
|
if (elem.equals(remoteKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.covers.add(remoteKey);
|
||||||
|
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||||
|
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new DataAccessException("DataAccess Not managed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeLink(
|
||||||
|
final DataAccess ioDb,
|
||||||
|
final Class<?> clazz,
|
||||||
|
final UUID uuid,
|
||||||
|
final String column,
|
||||||
|
final Long remoteKey) throws Exception {
|
||||||
|
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||||
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
|
final TableCoversUUIDLong data = ioDb.get(TableCoversUUIDLong.class, uuid,
|
||||||
|
new OverrideTableName(tableName));
|
||||||
|
if (data.covers == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final List<Long> newList = new ArrayList<>();
|
||||||
|
for (final Long elem : data.covers) {
|
||||||
|
if (elem.equals(remoteKey)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
newList.add(elem);
|
||||||
|
}
|
||||||
|
data.covers = newList;
|
||||||
|
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||||
|
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new DataAccessException("DataAccess Not managed");
|
||||||
}
|
}
|
||||||
data.covers.add(remoteKey);
|
|
||||||
DataAccess.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addLink(final Class<?> clazz, final UUID uuid, final String column, final Long remoteKey)
|
public static void removeLink(
|
||||||
throws Exception {
|
final DataAccess ioDb,
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
final Class<?> clazz,
|
||||||
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, uuid,
|
final UUID uuid,
|
||||||
new OverrideTableName(tableName));
|
final String column,
|
||||||
if (data.covers == null) {
|
final UUID remoteKey) throws Exception {
|
||||||
data.covers = new ArrayList<>();
|
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||||
}
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
for (final Long elem : data.covers) {
|
final TableCoversUUIDUUID data = ioDb.get(TableCoversUUIDUUID.class, uuid,
|
||||||
if (elem.equals(remoteKey)) {
|
new OverrideTableName(tableName));
|
||||||
|
if (data.covers == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final List<UUID> newList = new ArrayList<>();
|
||||||
|
for (final UUID elem : data.covers) {
|
||||||
|
if (elem.equals(remoteKey)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
newList.add(elem);
|
||||||
|
}
|
||||||
|
data.covers = newList;
|
||||||
|
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||||
|
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new DataAccessException("DataAccess Not managed");
|
||||||
}
|
}
|
||||||
data.covers.add(remoteKey);
|
|
||||||
DataAccess.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeLink(final Class<?> clazz, final UUID uuid, final String column, final Long remoteKey)
|
public static void removeLink(
|
||||||
throws Exception {
|
final DataAccess ioDb,
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
final Class<?> clazz,
|
||||||
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, uuid,
|
final Long id,
|
||||||
new OverrideTableName(tableName));
|
final String column,
|
||||||
if (data.covers == null) {
|
final Long remoteKey) throws Exception {
|
||||||
return;
|
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||||
}
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
final List<Long> newList = new ArrayList<>();
|
final TableCoversLongLong data = ioDb.get(TableCoversLongLong.class, id, new OverrideTableName(tableName));
|
||||||
for (final Long elem : data.covers) {
|
if (data.covers == null) {
|
||||||
if (elem.equals(remoteKey)) {
|
return;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
newList.add(elem);
|
final List<Long> newList = new ArrayList<>();
|
||||||
|
for (final Long elem : data.covers) {
|
||||||
|
if (elem.equals(remoteKey)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
newList.add(elem);
|
||||||
|
}
|
||||||
|
data.covers = newList;
|
||||||
|
ioDb.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||||
|
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new DataAccessException("DataAccess Not managed");
|
||||||
}
|
}
|
||||||
data.covers = newList;
|
|
||||||
DataAccess.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeLink(final Class<?> clazz, final UUID uuid, final String column, final UUID remoteKey)
|
public static void removeLink(
|
||||||
throws Exception {
|
final DataAccess ioDb,
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
final Class<?> clazz,
|
||||||
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, uuid,
|
final Long id,
|
||||||
new OverrideTableName(tableName));
|
final String column,
|
||||||
if (data.covers == null) {
|
final UUID remoteKey) throws Exception {
|
||||||
return;
|
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||||
}
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
final List<UUID> newList = new ArrayList<>();
|
final TableCoversLongUUID data = ioDb.get(TableCoversLongUUID.class, id, new OverrideTableName(tableName));
|
||||||
for (final UUID elem : data.covers) {
|
if (data.covers == null) {
|
||||||
if (elem.equals(remoteKey)) {
|
return;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
newList.add(elem);
|
final List<UUID> newList = new ArrayList<>();
|
||||||
}
|
for (final UUID elem : data.covers) {
|
||||||
data.covers = newList;
|
if (elem.equals(remoteKey)) {
|
||||||
DataAccess.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
continue;
|
||||||
}
|
}
|
||||||
|
newList.add(elem);
|
||||||
|
}
|
||||||
|
data.covers = newList;
|
||||||
|
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||||
|
final String collectionName = AnnotationTools.getCollectionName(clazz);
|
||||||
|
final Field primaryfield = AnnotationTools.getPrimaryKeyField(clazz);
|
||||||
|
final String primaryFieldName = AnnotationTools.getFieldName(primaryfield);
|
||||||
|
|
||||||
public static void removeLink(final Class<?> clazz, final Long id, final String column, final Long remoteKey)
|
final MongoCollection<Document> collection = dam.getInterface().getDatastore().getDatabase()
|
||||||
throws Exception {
|
.getCollection(collectionName);
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
// retrieve previous value:
|
||||||
final TableCoversLongLong data = DataAccess.get(TableCoversLongLong.class, id,
|
final Document ret = collection.find(Filters.eq(primaryFieldName, id)).first();
|
||||||
new OverrideTableName(tableName));
|
if (ret == null) {
|
||||||
if (data.covers == null) {
|
throw new DataAccessException("Element does not exist ...");
|
||||||
return;
|
|
||||||
}
|
|
||||||
final List<Long> newList = new ArrayList<>();
|
|
||||||
for (final Long elem : data.covers) {
|
|
||||||
if (elem.equals(remoteKey)) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
newList.add(elem);
|
final List<UUID> newList = new ArrayList<>();
|
||||||
}
|
final List listValues = ret.get(remoteKey, newList.getClass());
|
||||||
data.covers = newList;
|
/*
|
||||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
final Document actions = new Document();
|
||||||
}
|
|
||||||
|
|
||||||
public static void removeLink(final Class<?> clazz, final Long id, final String column, final UUID remoteKey)
|
// update value:
|
||||||
throws Exception {
|
final Document actions = new Document();
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
if (!docSet.isEmpty()) {
|
||||||
final TableCoversLongUUID data = DataAccess.get(TableCoversLongUUID.class, id,
|
actions.append("$set", docSet);
|
||||||
new OverrideTableName(tableName));
|
|
||||||
if (data.covers == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final List<UUID> newList = new ArrayList<>();
|
|
||||||
for (final UUID elem : data.covers) {
|
|
||||||
if (elem.equals(remoteKey)) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
newList.add(elem);
|
if (!docUnSet.isEmpty()) {
|
||||||
|
actions.append("$unset", docUnSet);
|
||||||
|
}
|
||||||
|
LOGGER.info("update some values: {}", actions.toJson());
|
||||||
|
final UpdateResult ret = collection.updateMany(filters, actions);
|
||||||
|
return ret.getModifiedCount();
|
||||||
|
|
||||||
|
final TableCoversLongUUID data = ioDb.getDocument(tableName, id);
|
||||||
|
if (data.covers == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final List<UUID> newList = new ArrayList<>();
|
||||||
|
for (final UUID elem : data.covers) {
|
||||||
|
if (elem.equals(remoteKey)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
newList.add(elem);
|
||||||
|
}
|
||||||
|
data.covers = newList;
|
||||||
|
*/
|
||||||
|
} else {
|
||||||
|
throw new DataAccessException("DataAccess Not managed");
|
||||||
}
|
}
|
||||||
data.covers = newList;
|
|
||||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ import org.kar.archidata.annotation.AnnotationTools;
|
|||||||
import org.kar.archidata.dataAccess.CountInOut;
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.dataAccess.DataAccessAddOn;
|
import org.kar.archidata.dataAccess.DataAccessAddOn;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessMorphia;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.kar.archidata.dataAccess.LazyGetter;
|
import org.kar.archidata.dataAccess.LazyGetter;
|
||||||
import org.kar.archidata.dataAccess.QueryAnd;
|
import org.kar.archidata.dataAccess.QueryAnd;
|
||||||
@ -56,8 +58,12 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertData(final PreparedStatement ps, final Field field, final Object rootObject, final CountInOut iii)
|
public void insertData(
|
||||||
throws SQLException, IllegalArgumentException, IllegalAccessException {
|
final DataAccessSQL ioDb,
|
||||||
|
final PreparedStatement ps,
|
||||||
|
final Field field,
|
||||||
|
final Object rootObject,
|
||||||
|
final CountInOut iii) throws SQLException, IllegalArgumentException, IllegalAccessException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,6 +215,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillFromQuery(
|
public void fillFromQuery(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
final ResultSet rs,
|
final ResultSet rs,
|
||||||
final Field field,
|
final Field field,
|
||||||
final Object data,
|
final Object data,
|
||||||
@ -222,12 +229,12 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||||
.getActualTypeArguments()[0];
|
.getActualTypeArguments()[0];
|
||||||
if (objectClass == Long.class) {
|
if (objectClass == Long.class) {
|
||||||
final List<Long> idList = DataAccess.getListOfIds(rs, count.value, SEPARATOR_LONG);
|
final List<Long> idList = ioDb.getListOfIds(rs, count.value, SEPARATOR_LONG);
|
||||||
field.set(data, idList);
|
field.set(data, idList);
|
||||||
count.inc();
|
count.inc();
|
||||||
return;
|
return;
|
||||||
} else if (objectClass == UUID.class) {
|
} else if (objectClass == UUID.class) {
|
||||||
final List<UUID> idList = DataAccess.getListOfRawUUIDs(rs, count.value);
|
final List<UUID> idList = ioDb.getListOfRawUUIDs(rs, count.value);
|
||||||
field.set(data, idList);
|
field.set(data, idList);
|
||||||
count.inc();
|
count.inc();
|
||||||
return;
|
return;
|
||||||
@ -241,7 +248,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
if (decorators.fetch() == FetchType.EAGER) {
|
if (decorators.fetch() == FetchType.EAGER) {
|
||||||
throw new DataAccessException("EAGER is not supported for list of element...");
|
throw new DataAccessException("EAGER is not supported for list of element...");
|
||||||
} else if (foreignKeyType == Long.class) {
|
} else if (foreignKeyType == Long.class) {
|
||||||
final List<Long> idList = DataAccess.getListOfIds(rs, count.value, SEPARATOR_LONG);
|
final List<Long> idList = ioDb.getListOfIds(rs, count.value, SEPARATOR_LONG);
|
||||||
// field.set(data, idList);
|
// field.set(data, idList);
|
||||||
count.inc();
|
count.inc();
|
||||||
if (idList != null && idList.size() > 0) {
|
if (idList != null && idList.size() > 0) {
|
||||||
@ -251,7 +258,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
final List<Long> childs = new ArrayList<>(idList);
|
final List<Long> childs = new ArrayList<>(idList);
|
||||||
// TODO: update to have get with abstract types ....
|
// TODO: update to have get with abstract types ....
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Object foreignData = DataAccess.getsWhere(decorators.targetEntity(),
|
final Object foreignData = ioDb.getsWhere(decorators.targetEntity(),
|
||||||
new Condition(new QueryInList<>(idField, childs)));
|
new Condition(new QueryInList<>(idField, childs)));
|
||||||
if (foreignData == null) {
|
if (foreignData == null) {
|
||||||
return;
|
return;
|
||||||
@ -261,7 +268,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
lazyCall.add(lambda);
|
lazyCall.add(lambda);
|
||||||
}
|
}
|
||||||
} else if (foreignKeyType == UUID.class) {
|
} else if (foreignKeyType == UUID.class) {
|
||||||
final List<UUID> idList = DataAccess.getListOfRawUUIDs(rs, count.value);
|
final List<UUID> idList = ioDb.getListOfRawUUIDs(rs, count.value);
|
||||||
// field.set(data, idList);
|
// field.set(data, idList);
|
||||||
count.inc();
|
count.inc();
|
||||||
if (idList != null && idList.size() > 0) {
|
if (idList != null && idList.size() > 0) {
|
||||||
@ -271,7 +278,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
final List<UUID> childs = new ArrayList<>(idList);
|
final List<UUID> childs = new ArrayList<>(idList);
|
||||||
// TODO: update to have get with abstract types ....
|
// TODO: update to have get with abstract types ....
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Object foreignData = DataAccess.getsWhere(decorators.targetEntity(),
|
final Object foreignData = ioDb.getsWhere(decorators.targetEntity(),
|
||||||
new Condition(new QueryInList<>(idField, childs)));
|
new Condition(new QueryInList<>(idField, childs)));
|
||||||
if (foreignData == null) {
|
if (foreignData == null) {
|
||||||
return;
|
return;
|
||||||
@ -291,6 +298,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void asyncUpdate(
|
public void asyncUpdate(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
final String tableName,
|
final String tableName,
|
||||||
final Object localKey,
|
final Object localKey,
|
||||||
final Field field,
|
final Field field,
|
||||||
@ -312,30 +320,30 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
if (localKey instanceof final Long localKeyLong) {
|
if (localKey instanceof final Long localKeyLong) {
|
||||||
if (objectClass == Long.class) {
|
if (objectClass == Long.class) {
|
||||||
actions.add(() -> {
|
actions.add(() -> {
|
||||||
DataAccess.deleteWhere(LinkTableLongLong.class, new OverrideTableName(linkTableName),
|
ioDb.deleteWhere(LinkTableLongLong.class, new OverrideTableName(linkTableName),
|
||||||
new Condition(new QueryCondition("object1Id", "=", localKeyLong)));
|
new Condition(new QueryCondition("object1Id", "=", localKeyLong)));
|
||||||
});
|
});
|
||||||
asyncInsert(tableName, localKey, field, data, actions);
|
asyncInsert(ioDb, tableName, localKey, field, data, actions);
|
||||||
} else {
|
} else {
|
||||||
actions.add(() -> {
|
actions.add(() -> {
|
||||||
DataAccess.deleteWhere(LinkTableLongUUID.class, new OverrideTableName(linkTableName),
|
ioDb.deleteWhere(LinkTableLongUUID.class, new OverrideTableName(linkTableName),
|
||||||
new Condition(new QueryCondition("object1Id", "=", localKeyLong)));
|
new Condition(new QueryCondition("object1Id", "=", localKeyLong)));
|
||||||
});
|
});
|
||||||
asyncInsert(tableName, localKey, field, data, actions);
|
asyncInsert(ioDb, tableName, localKey, field, data, actions);
|
||||||
}
|
}
|
||||||
} else if (localKey instanceof final UUID localKeyUUID) {
|
} else if (localKey instanceof final UUID localKeyUUID) {
|
||||||
if (objectClass == Long.class) {
|
if (objectClass == Long.class) {
|
||||||
actions.add(() -> {
|
actions.add(() -> {
|
||||||
DataAccess.deleteWhere(LinkTableUUIDLong.class, new OverrideTableName(linkTableName),
|
ioDb.deleteWhere(LinkTableUUIDLong.class, new OverrideTableName(linkTableName),
|
||||||
new Condition(new QueryCondition("object1Id", "=", localKeyUUID)));
|
new Condition(new QueryCondition("object1Id", "=", localKeyUUID)));
|
||||||
});
|
});
|
||||||
asyncInsert(tableName, localKey, field, data, actions);
|
asyncInsert(ioDb, tableName, localKey, field, data, actions);
|
||||||
} else {
|
} else {
|
||||||
actions.add(() -> {
|
actions.add(() -> {
|
||||||
DataAccess.deleteWhere(LinkTableUUIDUUID.class, new OverrideTableName(linkTableName),
|
ioDb.deleteWhere(LinkTableUUIDUUID.class, new OverrideTableName(linkTableName),
|
||||||
new Condition(new QueryCondition("object1Id", "=", localKeyUUID)));
|
new Condition(new QueryCondition("object1Id", "=", localKeyUUID)));
|
||||||
});
|
});
|
||||||
asyncInsert(tableName, localKey, field, data, actions);
|
asyncInsert(ioDb, tableName, localKey, field, data, actions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -347,6 +355,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void asyncInsert(
|
public void asyncInsert(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
final String tableName,
|
final String tableName,
|
||||||
final Object localKey,
|
final Object localKey,
|
||||||
final Field field,
|
final Field field,
|
||||||
@ -389,7 +398,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
actions.add(() -> {
|
actions.add(() -> {
|
||||||
DataAccess.insertMultiple(insertElements, new OverrideTableName(linkTableName));
|
ioDb.insertMultiple(insertElements, new OverrideTableName(linkTableName));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// ========================================================
|
// ========================================================
|
||||||
@ -412,7 +421,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
actions.add(() -> {
|
actions.add(() -> {
|
||||||
DataAccess.insertMultiple(insertElements, new OverrideTableName(linkTableName));
|
ioDb.insertMultiple(insertElements, new OverrideTableName(linkTableName));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (localKey instanceof final UUID localKeyUUID) {
|
} else if (localKey instanceof final UUID localKeyUUID) {
|
||||||
@ -437,7 +446,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
actions.add(() -> {
|
actions.add(() -> {
|
||||||
DataAccess.insertMultiple(insertElements, new OverrideTableName(linkTableName));
|
ioDb.insertMultiple(insertElements, new OverrideTableName(linkTableName));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// ========================================================
|
// ========================================================
|
||||||
@ -460,7 +469,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
actions.add(() -> {
|
actions.add(() -> {
|
||||||
DataAccess.insertMultiple(insertElements, new OverrideTableName(linkTableName));
|
ioDb.insertMultiple(insertElements, new OverrideTableName(linkTableName));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -471,7 +480,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drop(final String tableName, final Field field) throws Exception {
|
public void drop(final DataAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||||
final String columnName = AnnotationTools.getFieldName(field);
|
final String columnName = AnnotationTools.getFieldName(field);
|
||||||
final String linkTableName = generateLinkTableName(tableName, columnName);
|
final String linkTableName = generateLinkTableName(tableName, columnName);
|
||||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||||
@ -480,11 +489,11 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
throw new DataAccessException("Can not ManyToMany with other than List<Long> or List<UUID> Model: List<"
|
throw new DataAccessException("Can not ManyToMany with other than List<Long> or List<UUID> Model: List<"
|
||||||
+ objectClass.getCanonicalName() + ">");
|
+ objectClass.getCanonicalName() + ">");
|
||||||
}
|
}
|
||||||
DataAccess.drop(LinkTableLongLong.class, new OverrideTableName(linkTableName));
|
ioDb.drop(LinkTableLongLong.class, new OverrideTableName(linkTableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cleanAll(final String tableName, final Field field) throws Exception {
|
public void cleanAll(final DataAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||||
final String columnName = AnnotationTools.getFieldName(field);
|
final String columnName = AnnotationTools.getFieldName(field);
|
||||||
final String linkTableName = generateLinkTableName(tableName, columnName);
|
final String linkTableName = generateLinkTableName(tableName, columnName);
|
||||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||||
@ -493,27 +502,47 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
throw new DataAccessException("Can not ManyToMany with other than List<Long> or List<UUID> Model: List<"
|
throw new DataAccessException("Can not ManyToMany with other than List<Long> or List<UUID> Model: List<"
|
||||||
+ objectClass.getCanonicalName() + ">");
|
+ objectClass.getCanonicalName() + ">");
|
||||||
}
|
}
|
||||||
DataAccess.cleanAll(LinkTableLongLong.class, new OverrideTableName(linkTableName));
|
ioDb.cleanAll(LinkTableLongLong.class, new OverrideTableName(linkTableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addLink(final Class<?> clazz, final long localKey, final String column, final long remoteKey)
|
public static void addLink(
|
||||||
throws Exception {
|
final DataAccess ioDb,
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
final Class<?> clazz,
|
||||||
final String linkTableName = generateLinkTableName(tableName, column);
|
final long localKey,
|
||||||
/* final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; if (objectClass != Long.class && objectClass != UUID.class) { throw new
|
final String column,
|
||||||
* DataAccessException("Can not ManyToMany with other than List<Long> or List<UUID> Model: List<" + objectClass.getCanonicalName() + ">"); } */
|
final long remoteKey) throws Exception {
|
||||||
final LinkTableLongLong insertElement = new LinkTableLongLong(localKey, remoteKey);
|
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||||
DataAccess.insert(insertElement, new OverrideTableName(linkTableName));
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
|
final String linkTableName = generateLinkTableName(tableName, column);
|
||||||
|
/* final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; if (objectClass != Long.class && objectClass != UUID.class) { throw new
|
||||||
|
* DataAccessException("Can not ManyToMany with other than List<Long> or List<UUID> Model: List<" + objectClass.getCanonicalName() + ">"); } */
|
||||||
|
final LinkTableLongLong insertElement = new LinkTableLongLong(localKey, remoteKey);
|
||||||
|
daSQL.insert(insertElement, new OverrideTableName(linkTableName));
|
||||||
|
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new DataAccessException("DataAccess Not managed");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int removeLink(final Class<?> clazz, final long localKey, final String column, final long remoteKey)
|
public static long removeLink(
|
||||||
throws Exception {
|
final DataAccess ioDb,
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
final Class<?> clazz,
|
||||||
final String linkTableName = generateLinkTableName(tableName, column);
|
final long localKey,
|
||||||
return DataAccess.deleteWhere(LinkTableLongLong.class, new OverrideTableName(linkTableName),
|
final String column,
|
||||||
new Condition(new QueryAnd(new QueryCondition("object1Id", "=", localKey),
|
final long remoteKey) throws Exception {
|
||||||
new QueryCondition("object2Id", "=", remoteKey))));
|
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||||
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
|
final String linkTableName = generateLinkTableName(tableName, column);
|
||||||
|
return daSQL.deleteWhere(LinkTableLongLong.class, new OverrideTableName(linkTableName),
|
||||||
|
new Condition(new QueryAnd(new QueryCondition("object1Id", "=", localKey),
|
||||||
|
new QueryCondition("object2Id", "=", remoteKey))));
|
||||||
|
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||||
|
return 0L;
|
||||||
|
} else {
|
||||||
|
throw new DataAccessException("DataAccess Not managed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,8 +9,8 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.kar.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
import org.kar.archidata.dataAccess.CountInOut;
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
|
||||||
import org.kar.archidata.dataAccess.DataAccessAddOn;
|
import org.kar.archidata.dataAccess.DataAccessAddOn;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.kar.archidata.dataAccess.LazyGetter;
|
import org.kar.archidata.dataAccess.LazyGetter;
|
||||||
import org.kar.archidata.dataAccess.QueryOptions;
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
@ -48,8 +48,12 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertData(final PreparedStatement ps, final Field field, final Object rootObject, final CountInOut iii)
|
public void insertData(
|
||||||
throws Exception {
|
final DataAccessSQL ioDb,
|
||||||
|
final PreparedStatement ps,
|
||||||
|
final Field field,
|
||||||
|
final Object rootObject,
|
||||||
|
final CountInOut iii) throws Exception {
|
||||||
final Object data = field.get(rootObject);
|
final Object data = field.get(rootObject);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
if (field.getType() == Long.class) {
|
if (field.getType() == Long.class) {
|
||||||
@ -149,7 +153,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
if (field.getType() == decorators.targetEntity()) {
|
if (field.getType() == decorators.targetEntity()) {
|
||||||
if (decorators.fetch() == FetchType.EAGER) {
|
if (decorators.fetch() == FetchType.EAGER) {
|
||||||
// TODO: rework this to have a lazy mode ...
|
// TODO: rework this to have a lazy mode ...
|
||||||
DataAccess.generateSelectField(querySelect, query, field.getType(), options, count);
|
DataAccessSQL.generateSelectField(querySelect, query, field.getType(), options, count);
|
||||||
final Class<?> subType = field.getType();
|
final Class<?> subType = field.getType();
|
||||||
final String subTableName = AnnotationTools.getTableName(subType);
|
final String subTableName = AnnotationTools.getTableName(subType);
|
||||||
final Field idField = AnnotationTools.getFieldOfId(subType);
|
final Field idField = AnnotationTools.getFieldOfId(subType);
|
||||||
@ -178,6 +182,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillFromQuery(
|
public void fillFromQuery(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
final ResultSet rs,
|
final ResultSet rs,
|
||||||
final Field field,
|
final Field field,
|
||||||
final Object data,
|
final Object data,
|
||||||
@ -233,8 +238,8 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
if (objectClass == decorators.targetEntity()) {
|
if (objectClass == decorators.targetEntity()) {
|
||||||
if (decorators.fetch() == FetchType.EAGER) {
|
if (decorators.fetch() == FetchType.EAGER) {
|
||||||
final CountInOut countNotNull = new CountInOut(0);
|
final CountInOut countNotNull = new CountInOut(0);
|
||||||
final Object dataNew = DataAccess.createObjectFromSQLRequest(rs, objectClass, count, countNotNull,
|
final Object dataNew = ioDb.createObjectFromSQLRequest(rs, objectClass, count, countNotNull, options,
|
||||||
options, lazyCall);
|
lazyCall);
|
||||||
if (dataNew != null && countNotNull.value != 0) {
|
if (dataNew != null && countNotNull.value != 0) {
|
||||||
field.set(data, dataNew);
|
field.set(data, dataNew);
|
||||||
}
|
}
|
||||||
@ -250,7 +255,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
||||||
final LazyGetter lambda = () -> {
|
final LazyGetter lambda = () -> {
|
||||||
// TODO: update to have get with abstract types ....
|
// TODO: update to have get with abstract types ....
|
||||||
final Object foreignData = DataAccess.get(decorators.targetEntity(), foreignKey);
|
final Object foreignData = ioDb.get(decorators.targetEntity(), foreignKey);
|
||||||
if (foreignData == null) {
|
if (foreignData == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -260,13 +265,13 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
} else if (remotePrimaryKeyType == UUID.class) {
|
} else if (remotePrimaryKeyType == UUID.class) {
|
||||||
// here we have the field, the data and the the remote value ==> can create callback that generate the update of the value ...
|
// here we have the field, the data and the the remote value ==> can create callback that generate the update of the value ...
|
||||||
final UUID foreignKey = DataAccess.getListOfRawUUID(rs, count.value);
|
final UUID foreignKey = ioDb.getListOfRawUUID(rs, count.value);
|
||||||
count.inc();
|
count.inc();
|
||||||
if (foreignKey != null) {
|
if (foreignKey != null) {
|
||||||
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
||||||
final LazyGetter lambda = () -> {
|
final LazyGetter lambda = () -> {
|
||||||
// TODO: update to have get with abstract types ....
|
// TODO: update to have get with abstract types ....
|
||||||
final Object foreignData = DataAccess.get(decorators.targetEntity(), foreignKey);
|
final Object foreignData = ioDb.get(decorators.targetEntity(), foreignKey);
|
||||||
if (foreignData == null) {
|
if (foreignData == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import org.kar.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
import org.kar.archidata.dataAccess.CountInOut;
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
|
||||||
import org.kar.archidata.dataAccess.DataAccessAddOn;
|
import org.kar.archidata.dataAccess.DataAccessAddOn;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.kar.archidata.dataAccess.LazyGetter;
|
import org.kar.archidata.dataAccess.LazyGetter;
|
||||||
import org.kar.archidata.dataAccess.QueryCondition;
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
@ -83,8 +83,12 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insertData(final PreparedStatement ps, final Field field, final Object rootObject, final CountInOut iii)
|
public void insertData(
|
||||||
throws SQLException, IllegalArgumentException, IllegalAccessException {
|
final DataAccessSQL ioDb,
|
||||||
|
final PreparedStatement ps,
|
||||||
|
final Field field,
|
||||||
|
final Object rootObject,
|
||||||
|
final CountInOut iii) throws SQLException, IllegalArgumentException, IllegalAccessException {
|
||||||
throw new IllegalAccessException("Can not generate an inset of @OneToMany");
|
throw new IllegalAccessException("Can not generate an inset of @OneToMany");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +223,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillFromQuery(
|
public void fillFromQuery(
|
||||||
|
final DataAccessSQL ioDb,
|
||||||
final ResultSet rs,
|
final ResultSet rs,
|
||||||
final Field field,
|
final Field field,
|
||||||
final Object data,
|
final Object data,
|
||||||
@ -236,12 +241,12 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (objectClass == Long.class) {
|
if (objectClass == Long.class) {
|
||||||
final List<Long> idList = DataAccess.getListOfIds(rs, count.value, SEPARATOR_LONG);
|
final List<Long> idList = ioDb.getListOfIds(rs, count.value, SEPARATOR_LONG);
|
||||||
field.set(data, idList);
|
field.set(data, idList);
|
||||||
count.inc();
|
count.inc();
|
||||||
return;
|
return;
|
||||||
} else if (objectClass == UUID.class) {
|
} else if (objectClass == UUID.class) {
|
||||||
final List<UUID> idList = DataAccess.getListOfRawUUIDs(rs, count.value);
|
final List<UUID> idList = ioDb.getListOfRawUUIDs(rs, count.value);
|
||||||
field.set(data, idList);
|
field.set(data, idList);
|
||||||
count.inc();
|
count.inc();
|
||||||
return;
|
return;
|
||||||
@ -255,7 +260,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
|||||||
parentIdTmp = Long.valueOf(modelData);
|
parentIdTmp = Long.valueOf(modelData);
|
||||||
count.inc();
|
count.inc();
|
||||||
} catch (final NumberFormatException ex) {
|
} catch (final NumberFormatException ex) {
|
||||||
final List<UUID> idList = DataAccess.getListOfRawUUIDs(rs, count.value);
|
final List<UUID> idList = ioDb.getListOfRawUUIDs(rs, count.value);
|
||||||
parendUuidTmp = idList.get(0);
|
parendUuidTmp = idList.get(0);
|
||||||
count.inc();
|
count.inc();
|
||||||
}
|
}
|
||||||
@ -279,7 +284,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
|||||||
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
||||||
final LazyGetter lambda = () -> {
|
final LazyGetter lambda = () -> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Object foreignData = DataAccess.getsWhere(decorators.targetEntity(),
|
final Object foreignData = ioDb.getsWhere(decorators.targetEntity(),
|
||||||
new Condition(new QueryCondition(mappingKey, "=", parentId)));
|
new Condition(new QueryCondition(mappingKey, "=", parentId)));
|
||||||
if (foreignData == null) {
|
if (foreignData == null) {
|
||||||
return;
|
return;
|
||||||
@ -290,7 +295,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
|||||||
} else if (parendUuid != null) {
|
} else if (parendUuid != null) {
|
||||||
final LazyGetter lambda = () -> {
|
final LazyGetter lambda = () -> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Object foreignData = DataAccess.getsWhere(decorators.targetEntity(),
|
final Object foreignData = ioDb.getsWhere(decorators.targetEntity(),
|
||||||
new Condition(new QueryCondition(mappingKey, "=", parendUuid)));
|
new Condition(new QueryCondition(mappingKey, "=", parendUuid)));
|
||||||
if (foreignData == null) {
|
if (foreignData == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -3,6 +3,7 @@ package org.kar.archidata.dataAccess.options;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.dataAccess.QueryOptions;
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
|
|
||||||
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
||||||
@ -12,11 +13,16 @@ public interface CheckFunctionInterface {
|
|||||||
* @param data The object that might be injected.
|
* @param data The object that might be injected.
|
||||||
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
||||||
* @throws Exception Exception is generate if the data are incorrect. */
|
* @throws Exception Exception is generate if the data are incorrect. */
|
||||||
void check(final String baseName, Object data, List<String> filterValue, final QueryOptions options)
|
void check(
|
||||||
throws Exception;
|
final DataAccess ioDb,
|
||||||
|
final String baseName,
|
||||||
|
Object data,
|
||||||
|
List<String> filterValue,
|
||||||
|
final QueryOptions options) throws Exception;
|
||||||
|
|
||||||
default void checkAll(final String baseName, final Object data, final QueryOptions options) throws Exception {
|
default void checkAll(final DataAccess ioDb, final String baseName, final Object data, final QueryOptions options)
|
||||||
check(baseName, data, AnnotationTools.getAllFieldsNames(data.getClass()), options);
|
throws Exception {
|
||||||
|
check(ioDb, baseName, data, AnnotationTools.getAllFieldsNames(data.getClass()), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,14 @@ package org.kar.archidata.dataAccess.options;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.dataAccess.QueryOptions;
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
|
|
||||||
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
||||||
public class CheckFunctionVoid implements CheckFunctionInterface {
|
public class CheckFunctionVoid implements CheckFunctionInterface {
|
||||||
@Override
|
@Override
|
||||||
public void check(
|
public void check(
|
||||||
|
final DataAccess ioDb,
|
||||||
final String baseName,
|
final String baseName,
|
||||||
final Object data,
|
final Object data,
|
||||||
final List<String> filterValue,
|
final List<String> filterValue,
|
||||||
|
@ -38,7 +38,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
* @param data The object that might be injected.
|
* @param data The object that might be injected.
|
||||||
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
||||||
* @throws Exception Exception is generate if the data are incorrect. */
|
* @throws Exception Exception is generate if the data are incorrect. */
|
||||||
void check(final String baseName, final K data, final QueryOptions options) throws Exception;
|
void check(DataAccess ioDb, final String baseName, final K data, final QueryOptions options) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String, List<CheckInterface<T>>> checking = null;
|
protected Map<String, List<CheckInterface<T>>> checking = null;
|
||||||
@ -67,128 +67,182 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
for (final Field field : this.clazz.getFields()) {
|
for (final Field field : this.clazz.getFields()) {
|
||||||
final String fieldName = field.getName(); // AnnotationTools.getFieldName(field);
|
final String fieldName = field.getName(); // AnnotationTools.getFieldName(field);
|
||||||
if (AnnotationTools.isPrimaryKey(field)) {
|
if (AnnotationTools.isPrimaryKey(field)) {
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
throw new InputException(baseName + fieldName,
|
(
|
||||||
"This is a '@Id' (primaryKey) ==> can not be change");
|
final DataAccess ioDb,
|
||||||
});
|
final String baseName,
|
||||||
|
final T data,
|
||||||
|
final QueryOptions options) -> {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"This is a '@Id' (primaryKey) ==> can not be change");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (AnnotationTools.getConstraintsNotNull(field)) {
|
if (AnnotationTools.getConstraintsNotNull(field)) {
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
if (field.get(data) == null) {
|
(
|
||||||
throw new InputException(baseName + fieldName, "Can not be null");
|
final DataAccess ioDb,
|
||||||
}
|
final String baseName,
|
||||||
});
|
final T data,
|
||||||
|
final QueryOptions options) -> {
|
||||||
|
if (field.get(data) == null) {
|
||||||
|
throw new InputException(baseName + fieldName, "Can not be null");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (AnnotationTools.isCreatedAtField(field) || AnnotationTools.isUpdateAtField(field)) {
|
if (AnnotationTools.isCreatedAtField(field) || AnnotationTools.isUpdateAtField(field)) {
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
throw new InputException(baseName + fieldName, "It is forbidden to change this field");
|
(
|
||||||
});
|
final DataAccess ioDb,
|
||||||
|
final String baseName,
|
||||||
|
final T data,
|
||||||
|
final QueryOptions options) -> {
|
||||||
|
throw new InputException(baseName + fieldName, "It is forbidden to change this field");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
final Class<?> type = field.getType();
|
final Class<?> type = field.getType();
|
||||||
if (type == Long.class || type == long.class) {
|
if (type == Long.class || type == long.class) {
|
||||||
final Long maxValue = AnnotationTools.getConstraintsMax(field);
|
final Long maxValue = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValue != null) {
|
if (maxValue != null) {
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final Long elemTyped = (Long) elem;
|
final QueryOptions options) -> {
|
||||||
if (elemTyped > maxValue) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName, "Value too height max: " + maxValue);
|
if (elem == null) {
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
|
final Long elemTyped = (Long) elem;
|
||||||
|
if (elemTyped > maxValue) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
final Long minValue = AnnotationTools.getConstraintsMin(field);
|
final Long minValue = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValue != null) {
|
if (minValue != null) {
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final Long elemTyped = (Long) elem;
|
final QueryOptions options) -> {
|
||||||
if (elemTyped < minValue) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName, "Value too Low min: " + minValue);
|
if (elem == null) {
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
|
final Long elemTyped = (Long) elem;
|
||||||
|
if (elemTyped < minValue) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
final QueryOptions options) -> {
|
||||||
final Condition conditionCheck = condCheckers.isEmpty() ? null
|
final Object elem = field.get(data);
|
||||||
: condCheckers.get(0).toCondition();
|
if (elem == null) {
|
||||||
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem,
|
return;
|
||||||
conditionCheck);
|
}
|
||||||
if (count == 0) {
|
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||||
throw new InputException(baseName + fieldName,
|
final Condition conditionCheck = condCheckers.isEmpty() ? null
|
||||||
"Foreign element does not exist in the DB:" + elem);
|
: condCheckers.get(0).toCondition();
|
||||||
}
|
final long count = ioDb.count(annotationManyToOne.targetEntity(), elem,
|
||||||
});
|
conditionCheck);
|
||||||
|
if (count == 0) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Foreign element does not exist in the DB:" + elem);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (type == Integer.class || type == int.class) {
|
} else if (type == Integer.class || type == int.class) {
|
||||||
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValueRoot != null) {
|
if (maxValueRoot != null) {
|
||||||
final int maxValue = maxValueRoot.intValue();
|
final int maxValue = maxValueRoot.intValue();
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final Integer elemTyped = (Integer) elem;
|
final QueryOptions options) -> {
|
||||||
if (elemTyped > maxValue) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName, "Value too height max: " + maxValue);
|
if (elem == null) {
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
|
final Integer elemTyped = (Integer) elem;
|
||||||
|
if (elemTyped > maxValue) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValueRoot != null) {
|
if (minValueRoot != null) {
|
||||||
final int minValue = minValueRoot.intValue();
|
final int minValue = minValueRoot.intValue();
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final Integer elemTyped = (Integer) elem;
|
final QueryOptions options) -> {
|
||||||
if (elemTyped < minValue) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName, "Value too Low min: " + minValue);
|
if (elem == null) {
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
|
final Integer elemTyped = (Integer) elem;
|
||||||
|
if (elemTyped < minValue) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem);
|
final QueryOptions options) -> {
|
||||||
if (count == 0) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName,
|
if (elem == null) {
|
||||||
"Foreign element does not exist in the DB:" + elem);
|
return;
|
||||||
}
|
}
|
||||||
});
|
final long count = ioDb.count(annotationManyToOne.targetEntity(), elem);
|
||||||
|
if (count == 0) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Foreign element does not exist in the DB:" + elem);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if (type == UUID.class) {
|
} else if (type == UUID.class) {
|
||||||
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
final ManyToOne annotationManyToOne = AnnotationTools.getManyToOne(field);
|
||||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final long count = DataAccess.count(annotationManyToOne.targetEntity(), elem);
|
final QueryOptions options) -> {
|
||||||
if (count == 0) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName,
|
if (elem == null) {
|
||||||
"Foreign element does not exist in the DB:" + elem);
|
return;
|
||||||
}
|
}
|
||||||
});
|
final long count = ioDb.count(annotationManyToOne.targetEntity(), elem);
|
||||||
|
if (count == 0) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Foreign element does not exist in the DB:" + elem);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if (type == Boolean.class || type == boolean.class) {
|
} else if (type == Boolean.class || type == boolean.class) {
|
||||||
|
|
||||||
@ -196,59 +250,83 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValueRoot != null) {
|
if (maxValueRoot != null) {
|
||||||
final float maxValue = maxValueRoot.floatValue();
|
final float maxValue = maxValueRoot.floatValue();
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final Float elemTyped = (Float) elem;
|
final QueryOptions options) -> {
|
||||||
if (elemTyped > maxValue) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName, "Value too height max: " + maxValue);
|
if (elem == null) {
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
|
final Float elemTyped = (Float) elem;
|
||||||
|
if (elemTyped > maxValue) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValueRoot != null) {
|
if (minValueRoot != null) {
|
||||||
final float minValue = minValueRoot.floatValue();
|
final float minValue = minValueRoot.floatValue();
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final Float elemTyped = (Float) elem;
|
final QueryOptions options) -> {
|
||||||
if (elemTyped < minValue) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName, "Value too Low min: " + minValue);
|
if (elem == null) {
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
|
final Float elemTyped = (Float) elem;
|
||||||
|
if (elemTyped < minValue) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if (type == Double.class || type == double.class) {
|
} else if (type == Double.class || type == double.class) {
|
||||||
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
final Long maxValueRoot = AnnotationTools.getConstraintsMax(field);
|
||||||
if (maxValueRoot != null) {
|
if (maxValueRoot != null) {
|
||||||
final double maxValue = maxValueRoot.doubleValue();
|
final double maxValue = maxValueRoot.doubleValue();
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final Double elemTyped = (Double) elem;
|
final QueryOptions options) -> {
|
||||||
if (elemTyped > maxValue) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName, "Value too height max: " + maxValue);
|
if (elem == null) {
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
|
final Double elemTyped = (Double) elem;
|
||||||
|
if (elemTyped > maxValue) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too height max: " + maxValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
final Long minValueRoot = AnnotationTools.getConstraintsMin(field);
|
||||||
if (minValueRoot != null) {
|
if (minValueRoot != null) {
|
||||||
final double minValue = minValueRoot.doubleValue();
|
final double minValue = minValueRoot.doubleValue();
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final Double elemTyped = (Double) elem;
|
final QueryOptions options) -> {
|
||||||
if (elemTyped < minValue) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName, "Value too Low min: " + minValue);
|
if (elem == null) {
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
|
final Double elemTyped = (Double) elem;
|
||||||
|
if (elemTyped < minValue) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Value too Low min: " + minValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if (type == Date.class || type == Timestamp.class) {
|
} else if (type == Date.class || type == Timestamp.class) {
|
||||||
|
|
||||||
@ -259,51 +337,66 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
} else if (type == String.class) {
|
} else if (type == String.class) {
|
||||||
final int maxSizeString = AnnotationTools.getLimitSize(field);
|
final int maxSizeString = AnnotationTools.getLimitSize(field);
|
||||||
if (maxSizeString > 0) {
|
if (maxSizeString > 0) {
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final String elemTyped = (String) elem;
|
final QueryOptions options) -> {
|
||||||
if (elemTyped.length() > maxSizeString) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName,
|
if (elem == null) {
|
||||||
"Too long size must be <= " + maxSizeString);
|
return;
|
||||||
}
|
}
|
||||||
});
|
final String elemTyped = (String) elem;
|
||||||
|
if (elemTyped.length() > maxSizeString) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Too long size must be <= " + maxSizeString);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
final Size limitSize = AnnotationTools.getConstraintsSize(field);
|
final Size limitSize = AnnotationTools.getConstraintsSize(field);
|
||||||
if (limitSize != null) {
|
if (limitSize != null) {
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final String elemTyped = (String) elem;
|
final QueryOptions options) -> {
|
||||||
if (elemTyped.length() > limitSize.max()) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName,
|
if (elem == null) {
|
||||||
"Too long size (constraints) must be <= " + limitSize.max());
|
return;
|
||||||
}
|
}
|
||||||
if (elemTyped.length() < limitSize.min()) {
|
final String elemTyped = (String) elem;
|
||||||
throw new InputException(baseName + fieldName,
|
if (elemTyped.length() > limitSize.max()) {
|
||||||
"Too small size (constraints) must be >= " + limitSize.min());
|
throw new InputException(baseName + fieldName,
|
||||||
}
|
"Too long size (constraints) must be <= " + limitSize.max());
|
||||||
});
|
}
|
||||||
|
if (elemTyped.length() < limitSize.min()) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"Too small size (constraints) must be >= " + limitSize.min());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
final String patternString = AnnotationTools.getConstraintsPattern(field);
|
final String patternString = AnnotationTools.getConstraintsPattern(field);
|
||||||
if (patternString != null) {
|
if (patternString != null) {
|
||||||
final Pattern pattern = Pattern.compile(patternString);
|
final Pattern pattern = Pattern.compile(patternString);
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final Object elem = field.get(data);
|
(
|
||||||
if (elem == null) {
|
final DataAccess ioDb,
|
||||||
return;
|
final String baseName,
|
||||||
}
|
final T data,
|
||||||
final String elemTyped = (String) elem;
|
final QueryOptions options) -> {
|
||||||
if (!pattern.matcher(elemTyped).find()) {
|
final Object elem = field.get(data);
|
||||||
throw new InputException(baseName + fieldName,
|
if (elem == null) {
|
||||||
"does not match the required pattern (constraints) must be '" + patternString
|
return;
|
||||||
+ "'");
|
}
|
||||||
}
|
final String elemTyped = (String) elem;
|
||||||
});
|
if (!pattern.matcher(elemTyped).find()) {
|
||||||
|
throw new InputException(baseName + fieldName,
|
||||||
|
"does not match the required pattern (constraints) must be '"
|
||||||
|
+ patternString + "'");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if (type == JsonValue.class) {
|
} else if (type == JsonValue.class) {
|
||||||
final DataJson jsonAnnotation = AnnotationTools.getDataJson(field);
|
final DataJson jsonAnnotation = AnnotationTools.getDataJson(field);
|
||||||
@ -311,9 +404,14 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
// Here if we have an error it crash at start and no new instance after creation...
|
// Here if we have an error it crash at start and no new instance after creation...
|
||||||
final CheckFunctionInterface instance = jsonAnnotation.checker().getDeclaredConstructor()
|
final CheckFunctionInterface instance = jsonAnnotation.checker().getDeclaredConstructor()
|
||||||
.newInstance();
|
.newInstance();
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
instance.checkAll(baseName + fieldName + ".", field.get(data), options);
|
(
|
||||||
});
|
final DataAccess ioDb,
|
||||||
|
final String baseName,
|
||||||
|
final T data,
|
||||||
|
final QueryOptions options) -> {
|
||||||
|
instance.checkAll(ioDb, baseName + fieldName + ".", field.get(data), options);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if (type.isEnum()) {
|
} else if (type.isEnum()) {
|
||||||
// nothing to do.
|
// nothing to do.
|
||||||
@ -321,21 +419,26 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
// keep this is last ==> take more time...
|
// keep this is last ==> take more time...
|
||||||
if (AnnotationTools.isUnique(field)) {
|
if (AnnotationTools.isUnique(field)) {
|
||||||
// Create the request ...
|
// Create the request ...
|
||||||
add(fieldName, (final String baseName, final T data, final QueryOptions options) -> {
|
add(fieldName,
|
||||||
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
(
|
||||||
Object other = null;
|
final DataAccess ioDb,
|
||||||
if (condCheckers.isEmpty()) {
|
final String baseName,
|
||||||
other = DataAccess.getWhere(this.clazz,
|
final T data,
|
||||||
new Condition(new QueryCondition(fieldName, "==", field.get(data))));
|
final QueryOptions options) -> {
|
||||||
} else {
|
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
|
||||||
other = DataAccess.getWhere(this.clazz,
|
Object other = null;
|
||||||
new Condition(new QueryCondition(fieldName, "==", field.get(data))),
|
if (condCheckers.isEmpty()) {
|
||||||
condCheckers.get(0).toCondition());
|
other = ioDb.getWhere(this.clazz,
|
||||||
}
|
new Condition(new QueryCondition(fieldName, "==", field.get(data))));
|
||||||
if (other != null) {
|
} else {
|
||||||
throw new InputException(baseName + fieldName, "Name already exist in the DB");
|
other = ioDb.getWhere(this.clazz,
|
||||||
}
|
new Condition(new QueryCondition(fieldName, "==", field.get(data))),
|
||||||
});
|
condCheckers.get(0).toCondition());
|
||||||
|
}
|
||||||
|
if (other != null) {
|
||||||
|
throw new InputException(baseName + fieldName, "Name already exist in the DB");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -345,8 +448,18 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void check(final DataAccess ioDb, final String baseName, final Object data) throws Exception {
|
||||||
|
check(ioDb, baseName, data, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void check(final DataAccess ioDb, final String baseName, final Object data, final List<String> filterValue)
|
||||||
|
throws Exception {
|
||||||
|
check(ioDb, baseName, data, filterValue, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void check(
|
public void check(
|
||||||
|
final DataAccess ioDb,
|
||||||
final String baseName,
|
final String baseName,
|
||||||
final Object data,
|
final Object data,
|
||||||
final List<String> filterValue,
|
final List<String> filterValue,
|
||||||
@ -365,7 +478,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (final CheckInterface<T> action : actions) {
|
for (final CheckInterface<T> action : actions) {
|
||||||
action.check(baseName, dataCasted, options);
|
action.check(ioDb, baseName, dataCasted, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkTyped(dataCasted, filterValue, options);
|
checkTyped(dataCasted, filterValue, options);
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
package org.kar.archidata.dataAccess.options;
|
package org.kar.archidata.dataAccess.options;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.conversions.Bson;
|
||||||
import org.kar.archidata.dataAccess.CountInOut;
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.QueryItem;
|
import org.kar.archidata.dataAccess.QueryItem;
|
||||||
import org.kar.archidata.dataAccess.QueryOptions;
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
|
|
||||||
|
import com.mongodb.client.model.Filters;
|
||||||
|
|
||||||
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
||||||
public class Condition extends QueryOption {
|
public class Condition extends QueryOption {
|
||||||
public final QueryItem condition;
|
public final QueryItem condition;
|
||||||
@ -24,9 +30,10 @@ public class Condition extends QueryOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
|
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||||
|
throws Exception {
|
||||||
if (this.condition != null) {
|
if (this.condition != null) {
|
||||||
this.condition.injectQuery(ps, iii);
|
this.condition.injectQuery(ioDb, ps, iii);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,4 +69,26 @@ public class Condition extends QueryOption {
|
|||||||
}
|
}
|
||||||
query.append("\n");
|
query.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Bson getFilter(final String collectionName, final QueryOptions options, final String deletedFieldName) {
|
||||||
|
boolean exclude_deleted = true;
|
||||||
|
if (options != null) {
|
||||||
|
exclude_deleted = !options.exist(AccessDeletedItems.class);
|
||||||
|
}
|
||||||
|
final List<Bson> filter = new ArrayList<>();
|
||||||
|
if (exclude_deleted && deletedFieldName != null) {
|
||||||
|
filter.add(Filters.ne(deletedFieldName, false));
|
||||||
|
}
|
||||||
|
// Check if we have a condition to generate
|
||||||
|
if (this.condition != null) {
|
||||||
|
this.condition.generateFilter(filter);
|
||||||
|
}
|
||||||
|
if (filter.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (filter.size() == 1) {
|
||||||
|
return filter.get(0);
|
||||||
|
}
|
||||||
|
return Filters.and(filter.toArray(new Bson[0]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,8 @@
|
|||||||
package org.kar.archidata.dataAccess.options;
|
package org.kar.archidata.dataAccess.options;
|
||||||
|
|
||||||
import java.io.IOException;
|
@Deprecated
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.kar.archidata.GlobalConfiguration;
|
|
||||||
import org.kar.archidata.dataAccess.QueryOptions;
|
|
||||||
import org.kar.archidata.db.DBConfig;
|
|
||||||
import org.kar.archidata.db.DBEntry;
|
|
||||||
|
|
||||||
public class DBInterfaceOption extends QueryOption {
|
public class DBInterfaceOption extends QueryOption {
|
||||||
|
/*
|
||||||
private DBEntry entry = null;
|
private DBEntry entry = null;
|
||||||
private final DBConfig config;
|
private final DBConfig config;
|
||||||
private final boolean root;
|
private final boolean root;
|
||||||
@ -47,5 +41,6 @@ public class DBInterfaceOption extends QueryOption {
|
|||||||
return dbOption.get(0).getEntry(options);
|
return dbOption.get(0).getEntry(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package org.kar.archidata.dataAccess.options;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
|
||||||
import org.kar.archidata.dataAccess.CountInOut;
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
|
|
||||||
public class Limit extends QueryOption {
|
public class Limit extends QueryOption {
|
||||||
protected final long limit;
|
protected final long limit;
|
||||||
@ -16,8 +16,13 @@ public class Limit extends QueryOption {
|
|||||||
query.append(" LIMIT ? \n");
|
query.append(" LIMIT ? \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
|
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||||
DataAccess.addElement(ps, this.limit, iii);
|
throws Exception {
|
||||||
|
ioDb.addElement(ps, this.limit, iii);
|
||||||
iii.inc();
|
iii.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getValue() {
|
||||||
|
return this.limit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ package org.kar.archidata.dataAccess.options;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
import org.kar.archidata.dataAccess.CountInOut;
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
|
import org.kar.archidata.dataAccess.options.OrderItem.Order;
|
||||||
|
|
||||||
public class OrderBy extends QueryOption {
|
public class OrderBy extends QueryOption {
|
||||||
protected final List<OrderItem> childs;
|
protected final List<OrderItem> childs;
|
||||||
@ -40,4 +42,10 @@ public class OrderBy extends QueryOption {
|
|||||||
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
|
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
|
||||||
// nothing to add.
|
// nothing to add.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void generateSort(final Document data) {
|
||||||
|
for (final OrderItem elem : this.childs) {
|
||||||
|
data.append(elem.value, elem.order == Order.ASC ? 1 : -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.kar.archidata.db;
|
package org.kar.archidata.db;
|
||||||
|
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -15,10 +16,13 @@ public class DBConfig {
|
|||||||
private final boolean keepConnected;
|
private final boolean keepConnected;
|
||||||
|
|
||||||
public DBConfig(final String type, final String hostname, final Integer port, final String login,
|
public DBConfig(final String type, final String hostname, final Integer port, final String login,
|
||||||
final String password, final String dbName, final boolean keepConnected) {
|
final String password, final String dbName, final boolean keepConnected) throws DataAccessException {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
this.type = "mysql";
|
this.type = "mysql";
|
||||||
} else {
|
} else {
|
||||||
|
if (!"mysql".equals(type) && !"sqlite".equals(type) && !"mongo".equals(type)) {
|
||||||
|
throw new DataAccessException("unexpected DB type: '" + type + "'");
|
||||||
|
}
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
if (hostname == null) {
|
if (hostname == null) {
|
||||||
@ -27,7 +31,11 @@ public class DBConfig {
|
|||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
}
|
}
|
||||||
if (port == null) {
|
if (port == null) {
|
||||||
this.port = 3306;
|
if ("mysql".equals(this.type)) {
|
||||||
|
this.port = 3306;
|
||||||
|
} else {
|
||||||
|
this.port = 27017;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
@ -35,6 +43,7 @@ public class DBConfig {
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
this.dbName = dbName;
|
this.dbName = dbName;
|
||||||
this.keepConnected = keepConnected;
|
this.keepConnected = keepConnected;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -48,6 +57,10 @@ public class DBConfig {
|
|||||||
return this.hostname;
|
return this.hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return this.port;
|
return this.port;
|
||||||
}
|
}
|
||||||
@ -82,11 +95,17 @@ public class DBConfig {
|
|||||||
}
|
}
|
||||||
return "jdbc:sqlite:" + this.hostname + ".db";
|
return "jdbc:sqlite:" + this.hostname + ".db";
|
||||||
}
|
}
|
||||||
if (isRoot) {
|
if ("mongo".equals(this.type)) {
|
||||||
return "jdbc:" + this.type + "://" + this.hostname + ":" + this.port
|
return "mongodb://" + getLogin() + ":" + getPassword() + "@" + this.hostname + ":" + this.port;
|
||||||
+ "/?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC";
|
|
||||||
}
|
}
|
||||||
return "jdbc:" + this.type + "://" + this.hostname + ":" + this.port + "/" + this.dbName
|
if ("mysql".equals(this.type)) {
|
||||||
+ "?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC";
|
if (isRoot) {
|
||||||
|
return "jdbc:" + this.type + "://" + this.hostname + ":" + this.port
|
||||||
|
+ "/?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC";
|
||||||
|
}
|
||||||
|
return "jdbc:" + this.type + "://" + this.hostname + ":" + this.port + "/" + this.dbName
|
||||||
|
+ "?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC";
|
||||||
|
}
|
||||||
|
return "dead_code";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,6 @@ package org.kar.archidata.db;
|
|||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -13,11 +10,11 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
public class DBEntry implements Closeable {
|
public class DBEntry implements Closeable {
|
||||||
final static Logger LOGGER = LoggerFactory.getLogger(DBEntry.class);
|
final static Logger LOGGER = LoggerFactory.getLogger(DBEntry.class);
|
||||||
public DBConfig config;
|
private final DBConfig config;
|
||||||
public Connection connection;
|
private DbInterface ioDb;
|
||||||
private static List<DBEntry> stored = new ArrayList<>();
|
private static List<DBEntry> stored = new ArrayList<>();
|
||||||
|
|
||||||
private DBEntry(final DBConfig config, final boolean root) throws IOException {
|
private DBEntry(final DBConfig config, final boolean root, final Class<?>... classes) throws IOException {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
if (root) {
|
if (root) {
|
||||||
connectRoot();
|
connectRoot();
|
||||||
@ -49,24 +46,28 @@ public class DBEntry implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void connectRoot() throws IOException {
|
public void connectRoot() throws IOException {
|
||||||
try {
|
// TODO: maybe better check for root connection ...
|
||||||
this.connection = DriverManager.getConnection(this.config.getUrl(true), this.config.getLogin(),
|
if ("mysql".equals(this.config.getType())) {
|
||||||
this.config.getPassword());
|
this.ioDb = new DbInterfaceSQL(this.config);
|
||||||
} catch (final SQLException ex) {
|
} else if ("sqlite".equals(this.config.getType())) {
|
||||||
throw new IOException("Connection db fail: " + ex.getMessage() + " On URL: " + this.config.getUrl(true));
|
this.ioDb = new DbInterfaceSQL(this.config);
|
||||||
|
} else if ("mongo".equals(this.config.getType())) {
|
||||||
|
this.ioDb = new DbInterfaceMorphia(this.config);
|
||||||
|
} else {
|
||||||
|
throw new IOException("DB type: '" + this.config.getType() + "'is not managed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect() throws IOException {
|
public void connect() throws IOException {
|
||||||
try {
|
if ("mysql".equals(this.config.getType())) {
|
||||||
this.connection = DriverManager.getConnection(this.config.getUrl(), this.config.getLogin(),
|
this.ioDb = new DbInterfaceSQL(this.config);
|
||||||
this.config.getPassword());
|
} else if ("sqlite".equals(this.config.getType())) {
|
||||||
} catch (final SQLException ex) {
|
this.ioDb = new DbInterfaceSQL(this.config);
|
||||||
LOGGER.error("Connection db fail: " + ex.getMessage() + " On URL: " + this.config.getUrl(true));
|
} else if ("mongo".equals(this.config.getType())) {
|
||||||
throw new IOException("Connection db fail: " + ex.getMessage() + " On URL: " + this.config.getUrl(true));
|
this.ioDb = new DbInterfaceMorphia(this.config);
|
||||||
|
} else {
|
||||||
|
throw new IOException("DB type: '" + this.config.getType() + "'is not managed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -78,12 +79,11 @@ public class DBEntry implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void closeForce() throws IOException {
|
public void closeForce() throws IOException {
|
||||||
try {
|
this.ioDb.close();
|
||||||
// connection.commit();
|
}
|
||||||
this.connection.close();
|
|
||||||
} catch (final SQLException ex) {
|
public DbInterface getDbInterface() {
|
||||||
throw new IOException("Dis-connection db fail: " + ex.getMessage());
|
return this.ioDb;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void closeAllForceMode() throws IOException {
|
public static void closeAllForceMode() throws IOException {
|
||||||
|
16
src/org/kar/archidata/db/DbInterface.java
Normal file
16
src/org/kar/archidata/db/DbInterface.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package org.kar.archidata.db;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class DbInterface implements Closeable {
|
||||||
|
private final static Logger LOGGER = LoggerFactory.getLogger(DbInterface.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
LOGGER.error("Check db interface close implementation !!! " + this.getClass().getCanonicalName());
|
||||||
|
}
|
||||||
|
}
|
72
src/org/kar/archidata/db/DbInterfaceMorphia.java
Normal file
72
src/org/kar/archidata/db/DbInterfaceMorphia.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package org.kar.archidata.db;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.bson.UuidRepresentation;
|
||||||
|
import org.bson.codecs.configuration.CodecRegistries;
|
||||||
|
import org.bson.codecs.configuration.CodecRegistry;
|
||||||
|
import org.bson.codecs.pojo.PojoCodecProvider;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.mongodb.ConnectionString;
|
||||||
|
import com.mongodb.MongoClientSettings;
|
||||||
|
import com.mongodb.client.MongoClient;
|
||||||
|
import com.mongodb.client.MongoClients;
|
||||||
|
|
||||||
|
import dev.morphia.Datastore;
|
||||||
|
import dev.morphia.Morphia;
|
||||||
|
|
||||||
|
public class DbInterfaceMorphia extends DbInterface implements Closeable {
|
||||||
|
private final static Logger LOGGER = LoggerFactory.getLogger(DbInterfaceMorphia.class);
|
||||||
|
private final MongoClient mongoClient;
|
||||||
|
private final Datastore datastore;
|
||||||
|
|
||||||
|
public DbInterfaceMorphia(final DBConfig config, final Class<?>... classes) throws IOException {
|
||||||
|
this(config.getUrl(), config.getDbName(), classes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbInterfaceMorphia(final String dbUrl, final String dbName, final Class<?>... classes) {
|
||||||
|
// Connect to MongoDB (simple form):
|
||||||
|
// final MongoClient mongoClient = MongoClients.create(dbUrl);
|
||||||
|
LOGGER.info("Connect on the DB: {}", dbUrl);
|
||||||
|
// Connect to MongoDB (complex form):
|
||||||
|
final ConnectionString connectionString = new ConnectionString(dbUrl);
|
||||||
|
// Créer un CodecRegistry pour UUID
|
||||||
|
//final CodecRegistry uuidCodecRegistry = CodecRegistries.fromCodecs(new UUIDCodec());
|
||||||
|
// Créer un CodecRegistry pour POJOs
|
||||||
|
final CodecRegistry pojoCodecRegistry = CodecRegistries
|
||||||
|
.fromProviders(PojoCodecProvider.builder().automatic(true).build());
|
||||||
|
// Ajouter le CodecRegistry par défaut, le codec UUID et celui pour POJOs
|
||||||
|
//final CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
|
||||||
|
// MongoClientSettings.getDefaultCodecRegistry(), /*uuidCodecRegistry, */ pojoCodecRegistry);
|
||||||
|
|
||||||
|
final CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
|
||||||
|
MongoClientSettings.getDefaultCodecRegistry(),
|
||||||
|
CodecRegistries.fromCodecs(new org.bson.codecs.UuidCodec(UuidRepresentation.STANDARD)),
|
||||||
|
pojoCodecRegistry);
|
||||||
|
// Configurer MongoClientSettings
|
||||||
|
final MongoClientSettings clientSettings = MongoClientSettings.builder() //
|
||||||
|
.applyConnectionString(connectionString)//
|
||||||
|
.codecRegistry(codecRegistry) //
|
||||||
|
.uuidRepresentation(UuidRepresentation.STANDARD)//
|
||||||
|
.build();
|
||||||
|
this.mongoClient = MongoClients.create(clientSettings);
|
||||||
|
this.datastore = Morphia.createDatastore(this.mongoClient, "karusic");
|
||||||
|
// Map entities
|
||||||
|
this.datastore.getMapper().map(classes);
|
||||||
|
// Ensure indexes
|
||||||
|
this.datastore.ensureIndexes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Datastore getDatastore() {
|
||||||
|
return this.datastore;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
this.mongoClient.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
43
src/org/kar/archidata/db/DbInterfaceSQL.java
Normal file
43
src/org/kar/archidata/db/DbInterfaceSQL.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package org.kar.archidata.db;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class DbInterfaceSQL extends DbInterface implements Closeable {
|
||||||
|
final static Logger LOGGER = LoggerFactory.getLogger(DbInterfaceSQL.class);
|
||||||
|
|
||||||
|
private Connection connection = null;
|
||||||
|
|
||||||
|
public DbInterfaceSQL(final DBConfig config) throws IOException {
|
||||||
|
this(config.getUrl(), config.getLogin(), config.getPassword());
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbInterfaceSQL(final String dbUrl, final String login, final String password) throws IOException {
|
||||||
|
try {
|
||||||
|
this.connection = DriverManager.getConnection(dbUrl, login, password);
|
||||||
|
} catch (final SQLException ex) {
|
||||||
|
LOGGER.error("Connection db fail: " + ex.getMessage() + " On URL: " + dbUrl);
|
||||||
|
throw new IOException("Connection db fail: " + ex.getMessage() + " On URL: " + dbUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection getConnection() {
|
||||||
|
return this.connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
try {
|
||||||
|
this.connection.close();
|
||||||
|
this.connection = null;
|
||||||
|
} catch (final SQLException ex) {
|
||||||
|
throw new IOException("Dis-connection db fail: " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package org.kar.archidata.migration;
|
package org.kar.archidata.migration;
|
||||||
|
|
||||||
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
|
||||||
public interface AsyncCall {
|
public interface AsyncCall {
|
||||||
void doRequest() throws Exception;
|
void doRequest(DataAccess da) throws Exception;
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.kar.archidata.dataAccess.QueryOptions;
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
import org.kar.archidata.db.DBConfig;
|
import org.kar.archidata.db.DBConfig;
|
||||||
import org.kar.archidata.db.DBEntry;
|
|
||||||
import org.kar.archidata.migration.model.Migration;
|
import org.kar.archidata.migration.model.Migration;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -24,17 +24,20 @@ public class MigrationEngine {
|
|||||||
// initialization of the migration if the DB is not present...
|
// initialization of the migration if the DB is not present...
|
||||||
private MigrationInterface init;
|
private MigrationInterface init;
|
||||||
|
|
||||||
|
protected final DataAccess da;
|
||||||
|
|
||||||
/** Migration engine constructor (empty). */
|
/** Migration engine constructor (empty). */
|
||||||
public MigrationEngine() {
|
public MigrationEngine(final DataAccess da) {
|
||||||
this(new ArrayList<>(), null);
|
this(da, new ArrayList<>(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Migration engine constructor (specific mode).
|
/** Migration engine constructor (specific mode).
|
||||||
* @param datas All the migration ordered.
|
* @param datas All the migration ordered.
|
||||||
* @param init Initialization migration model. */
|
* @param init Initialization migration model. */
|
||||||
public MigrationEngine(final List<MigrationInterface> datas, final MigrationInterface init) {
|
public MigrationEngine(final DataAccess da, final List<MigrationInterface> datas, final MigrationInterface init) {
|
||||||
this.datas = datas;
|
this.datas = datas;
|
||||||
this.init = init;
|
this.init = init;
|
||||||
|
this.da = da;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a Migration in the list
|
/** Add a Migration in the list
|
||||||
@ -53,16 +56,16 @@ public class MigrationEngine {
|
|||||||
* @return Model represent the last migration. If null then no migration has been done.
|
* @return Model represent the last migration. If null then no migration has been done.
|
||||||
* @throws MigrationException */
|
* @throws MigrationException */
|
||||||
public Migration getCurrentVersion() throws MigrationException {
|
public Migration getCurrentVersion() throws MigrationException {
|
||||||
if (!DataAccess.isTableExist("KAR_migration")) {
|
if (!this.da.isTableExist("KAR_migration")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
List<Migration> data = null;
|
List<Migration> data = null;
|
||||||
try {
|
try {
|
||||||
data = DataAccess.gets(Migration.class, QueryOptions.READ_ALL_COLOMN);
|
data = this.da.gets(Migration.class, QueryOptions.READ_ALL_COLOMN);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// Previous version does not have the same timeCode...
|
// Previous version does not have the same timeCode...
|
||||||
data = DataAccess.gets(Migration.class);
|
data = this.da.gets(Migration.class);
|
||||||
}
|
}
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
LOGGER.error("Can not collect the migration table in the DB:{}");
|
LOGGER.error("Can not collect the migration table in the DB:{}");
|
||||||
@ -135,13 +138,13 @@ public class MigrationEngine {
|
|||||||
|
|
||||||
// STEP 1: Check the DB exist:
|
// STEP 1: Check the DB exist:
|
||||||
LOGGER.info("Verify existance of '{}'", config.getDbName());
|
LOGGER.info("Verify existance of '{}'", config.getDbName());
|
||||||
boolean exist = DataAccess.isDBExist(config.getDbName());
|
boolean exist = this.da.isDBExist(config.getDbName());
|
||||||
if (!exist) {
|
if (!exist) {
|
||||||
LOGGER.warn("DB: '{}' DOES NOT EXIST ==> create one", config.getDbName());
|
LOGGER.warn("DB: '{}' DOES NOT EXIST ==> create one", config.getDbName());
|
||||||
// create the local DB:
|
// create the local DB:
|
||||||
DataAccess.createDB(config.getDbName());
|
this.da.createDB(config.getDbName());
|
||||||
}
|
}
|
||||||
exist = DataAccess.isDBExist(config.getDbName());
|
exist = this.da.isDBExist(config.getDbName());
|
||||||
while (!exist) {
|
while (!exist) {
|
||||||
LOGGER.error("DB: '{}' DOES NOT EXIST after trying to create one ", config.getDbName());
|
LOGGER.error("DB: '{}' DOES NOT EXIST after trying to create one ", config.getDbName());
|
||||||
LOGGER.error("Waiting administrator create a new one, we check after 30 seconds...");
|
LOGGER.error("Waiting administrator create a new one, we check after 30 seconds...");
|
||||||
@ -151,31 +154,32 @@ public class MigrationEngine {
|
|||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
exist = DataAccess.isDBExist(config.getDbName());
|
exist = this.da.isDBExist(config.getDbName());
|
||||||
}
|
}
|
||||||
LOGGER.info("DB '{}' exist.", config.getDbName());
|
LOGGER.info("DB '{}' exist.", config.getDbName());
|
||||||
// STEP 2: Check migration table exist:
|
// STEP 2: Check migration table exist:
|
||||||
LOGGER.info("Verify existance of migration table '{}'", "KAR_migration");
|
LOGGER.info("Verify existance of migration table '{}'", "KAR_migration");
|
||||||
// TODO: set the class in parameters instead of string...
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
exist = DataAccess.isTableExist("KAR_migration");
|
exist = this.da.isTableExist("KAR_migration");
|
||||||
if (!exist) {
|
if (!exist) {
|
||||||
LOGGER.info("'{}' Does not exist create a new one...", "KAR_migration");
|
LOGGER.info("'{}' Does not exist create a new one...", "KAR_migration");
|
||||||
// create the table:
|
// create the table:
|
||||||
List<String> sqlQuery;
|
List<String> sqlQuery;
|
||||||
try {
|
try {
|
||||||
sqlQuery = DataFactory.createTable(Migration.class);
|
sqlQuery = DataFactory.createTable(Migration.class);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
throw new MigrationException(
|
throw new MigrationException(
|
||||||
"Fail to create the local DB SQL model for migaration ==> wait administrator interventions");
|
"Fail to create the local DB SQL model for migaration ==> wait administrator interventions");
|
||||||
}
|
}
|
||||||
LOGGER.info("Create Table with : {}", sqlQuery.get(0));
|
LOGGER.info("Create Table with : {}", sqlQuery.get(0));
|
||||||
try {
|
try {
|
||||||
DataAccess.executeQuery(sqlQuery.get(0));
|
daSQL.executeQuery(sqlQuery.get(0));
|
||||||
} catch (SQLException | IOException ex) {
|
} catch (SQLException | IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
throw new MigrationException(
|
throw new MigrationException(
|
||||||
"Fail to create the local DB model for migaration ==> wait administrator interventions");
|
"Fail to create the local DB model for migaration ==> wait administrator interventions");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Migration currentVersion = getCurrentVersion();
|
final Migration currentVersion = getCurrentVersion();
|
||||||
@ -217,18 +221,10 @@ public class MigrationEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DBEntry entry;
|
final int id = 0;
|
||||||
try {
|
final int count = toApply.size();
|
||||||
entry = DBEntry.createInterface(config);
|
for (final MigrationInterface elem : toApply) {
|
||||||
final int id = 0;
|
migrateSingle(elem, id, count);
|
||||||
final int count = toApply.size();
|
|
||||||
for (final MigrationInterface elem : toApply) {
|
|
||||||
migrateSingle(entry, elem, id, count);
|
|
||||||
}
|
|
||||||
} catch (final IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new MigrationException("An error occured in the migration (can not access to the DB): '"
|
|
||||||
+ currentVersion.name + "' defect @" + currentVersion.stepId + "/" + currentVersion.count);
|
|
||||||
}
|
}
|
||||||
if (needPlaceholder) {
|
if (needPlaceholder) {
|
||||||
if (this.datas.size() == 0) {
|
if (this.datas.size() == 0) {
|
||||||
@ -244,7 +240,7 @@ public class MigrationEngine {
|
|||||||
migrationResult.count = 0;
|
migrationResult.count = 0;
|
||||||
migrationResult.log = "Place-holder for first initialization";
|
migrationResult.log = "Place-holder for first initialization";
|
||||||
try {
|
try {
|
||||||
migrationResult = DataAccess.insert(migrationResult);
|
migrationResult = this.da.insert(migrationResult);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -254,8 +250,7 @@ public class MigrationEngine {
|
|||||||
LOGGER.info("Execute migration ... [ END ]");
|
LOGGER.info("Execute migration ... [ END ]");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void migrateSingle(final DBEntry entry, final MigrationInterface elem, final int id, final int count)
|
public void migrateSingle(final MigrationInterface elem, final int id, final int count) throws MigrationException {
|
||||||
throws MigrationException {
|
|
||||||
LOGGER.info("---------------------------------------------------------");
|
LOGGER.info("---------------------------------------------------------");
|
||||||
LOGGER.info("-- Migrate: [{}/{}] {} [BEGIN]", id, count, elem.getName());
|
LOGGER.info("-- Migrate: [{}/{}] {} [BEGIN]", id, count, elem.getName());
|
||||||
LOGGER.info("---------------------------------------------------------");
|
LOGGER.info("---------------------------------------------------------");
|
||||||
@ -274,7 +269,7 @@ public class MigrationEngine {
|
|||||||
}
|
}
|
||||||
migrationResult.log = log.toString();
|
migrationResult.log = log.toString();
|
||||||
try {
|
try {
|
||||||
migrationResult = DataAccess.insert(migrationResult);
|
migrationResult = this.da.insert(migrationResult);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new MigrationException(
|
throw new MigrationException(
|
||||||
@ -282,7 +277,7 @@ public class MigrationEngine {
|
|||||||
}
|
}
|
||||||
boolean ret = true;
|
boolean ret = true;
|
||||||
try {
|
try {
|
||||||
ret = elem.applyMigration(entry, log, migrationResult);
|
ret = elem.applyMigration(this.da, log, migrationResult);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
log.append("\nFail in the migration apply ");
|
log.append("\nFail in the migration apply ");
|
||||||
log.append(e.getLocalizedMessage());
|
log.append(e.getLocalizedMessage());
|
||||||
@ -293,7 +288,7 @@ public class MigrationEngine {
|
|||||||
if (ret) {
|
if (ret) {
|
||||||
migrationResult.terminated = true;
|
migrationResult.terminated = true;
|
||||||
try {
|
try {
|
||||||
DataAccess.update(migrationResult, migrationResult.id, List.of("terminated"));
|
this.da.update(migrationResult, migrationResult.id, List.of("terminated"));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new MigrationException(
|
throw new MigrationException(
|
||||||
@ -303,7 +298,7 @@ public class MigrationEngine {
|
|||||||
try {
|
try {
|
||||||
log.append("Fail in the migration engine...");
|
log.append("Fail in the migration engine...");
|
||||||
migrationResult.log = log.toString();
|
migrationResult.log = log.toString();
|
||||||
DataAccess.update(migrationResult, migrationResult.id, List.of("log"));
|
this.da.update(migrationResult, migrationResult.id, List.of("log"));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new MigrationException("Fail to update migration Log in the migration table: "
|
throw new MigrationException("Fail to update migration Log in the migration table: "
|
||||||
@ -316,7 +311,7 @@ public class MigrationEngine {
|
|||||||
LOGGER.info("Migrate: [{}/{}] {} [ END ]", id, count, elem.getName());
|
LOGGER.info("Migrate: [{}/{}] {} [ END ]", id, count, elem.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void revertTo(final DBEntry entry, final String migrationName) throws MigrationException {
|
public void revertTo(final String migrationName) throws MigrationException {
|
||||||
final Migration currentVersion = getCurrentVersion();
|
final Migration currentVersion = getCurrentVersion();
|
||||||
final List<MigrationInterface> toApply = new ArrayList<>();
|
final List<MigrationInterface> toApply = new ArrayList<>();
|
||||||
boolean find = false;
|
boolean find = false;
|
||||||
@ -335,11 +330,11 @@ public class MigrationEngine {
|
|||||||
final int id = 0;
|
final int id = 0;
|
||||||
final int count = toApply.size();
|
final int count = toApply.size();
|
||||||
for (final MigrationInterface elem : toApply) {
|
for (final MigrationInterface elem : toApply) {
|
||||||
revertSingle(entry, elem, id, count);
|
revertSingle(elem, id, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void revertSingle(final DBEntry entry, final MigrationInterface elem, final int id, final int count) {
|
public void revertSingle(final MigrationInterface elem, final int id, final int count) {
|
||||||
LOGGER.info("Revert migration: {} [BEGIN]", elem.getName());
|
LOGGER.info("Revert migration: {} [BEGIN]", elem.getName());
|
||||||
|
|
||||||
LOGGER.info("Revert migration: {} [ END ]", elem.getName());
|
LOGGER.info("Revert migration: {} [ END ]", elem.getName());
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package org.kar.archidata.migration;
|
package org.kar.archidata.migration;
|
||||||
|
|
||||||
import org.kar.archidata.db.DBEntry;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.migration.model.Migration;
|
import org.kar.archidata.migration.model.Migration;
|
||||||
|
|
||||||
public interface MigrationInterface {
|
public interface MigrationInterface {
|
||||||
@ -13,13 +13,13 @@ public interface MigrationInterface {
|
|||||||
* @param log Stored data in the BDD for the migration progression.
|
* @param log Stored data in the BDD for the migration progression.
|
||||||
* @param migration Migration post data on each step...
|
* @param migration Migration post data on each step...
|
||||||
* @return true if migration is finished. */
|
* @return true if migration is finished. */
|
||||||
boolean applyMigration(DBEntry entry, StringBuilder log, Migration model) throws Exception;
|
boolean applyMigration(DataAccess entry, StringBuilder log, Migration model) throws Exception;
|
||||||
|
|
||||||
/** Remove a migration the system to the previous version.
|
/** Remove a migration the system to the previous version.
|
||||||
* @param entry DB interface for the migration.
|
* @param entry DB interface for the migration.
|
||||||
* @param log Stored data in the BDD for the migration progression.
|
* @param log Stored data in the BDD for the migration progression.
|
||||||
* @return true if migration is finished. */
|
* @return true if migration is finished. */
|
||||||
boolean revertMigration(DBEntry entry, StringBuilder log) throws Exception;
|
boolean revertMigration(DataAccess entry, StringBuilder log) throws Exception;
|
||||||
|
|
||||||
/** Get the number of step in the migration process.
|
/** Get the number of step in the migration process.
|
||||||
* @return count of SQL access. */
|
* @return count of SQL access. */
|
||||||
|
@ -6,8 +6,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.kar.archidata.db.DBEntry;
|
|
||||||
import org.kar.archidata.migration.model.Migration;
|
import org.kar.archidata.migration.model.Migration;
|
||||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -70,7 +70,7 @@ public class MigrationSqlStep implements MigrationInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applyMigration(final DBEntry entry, final StringBuilder log, final Migration model)
|
public boolean applyMigration(final DataAccess da, final StringBuilder log, final Migration model)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
if (!this.isGenerated) {
|
if (!this.isGenerated) {
|
||||||
this.isGenerated = true;
|
this.isGenerated = true;
|
||||||
@ -106,9 +106,11 @@ public class MigrationSqlStep implements MigrationInterface {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (action.action() != null) {
|
if (action.action() != null) {
|
||||||
DataAccess.executeQuery(action.action());
|
if (da instanceof final DataAccessSQL ioDBSQL) {
|
||||||
|
ioDBSQL.executeQuery(action.action());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
action.async().doRequest();
|
action.async().doRequest(da);
|
||||||
}
|
}
|
||||||
} catch (SQLException | IOException ex) {
|
} catch (SQLException | IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@ -117,7 +119,7 @@ public class MigrationSqlStep implements MigrationInterface {
|
|||||||
model.stepId = iii + 1;
|
model.stepId = iii + 1;
|
||||||
model.log = log.toString();
|
model.log = log.toString();
|
||||||
try {
|
try {
|
||||||
DataAccess.update(model, model.id, List.of("stepId", "log"));
|
da.update(model, model.id, List.of("stepId", "log"));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -128,7 +130,7 @@ public class MigrationSqlStep implements MigrationInterface {
|
|||||||
model.stepId = iii + 1;
|
model.stepId = iii + 1;
|
||||||
model.log = log.toString();
|
model.log = log.toString();
|
||||||
try {
|
try {
|
||||||
DataAccess.update(model, model.id, List.of("stepId", "log"));
|
da.update(model, model.id, List.of("stepId", "log"));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -143,7 +145,7 @@ public class MigrationSqlStep implements MigrationInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean revertMigration(final DBEntry entry, final StringBuilder log) throws Exception {
|
public boolean revertMigration(final DataAccess da, final StringBuilder log) throws Exception {
|
||||||
generateRevertStep();
|
generateRevertStep();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import jakarta.ws.rs.DefaultValue;
|
|||||||
|
|
||||||
public class UUIDGenericData extends GenericTiming {
|
public class UUIDGenericData extends GenericTiming {
|
||||||
@Id
|
@Id
|
||||||
|
|
||||||
@DefaultValue("(UUID_TO_BIN(UUID(), TRUE))")
|
@DefaultValue("(UUID_TO_BIN(UUID(), TRUE))")
|
||||||
@Column(nullable = false, unique = true)
|
@Column(nullable = false, unique = true)
|
||||||
@Schema(description = "Unique UUID of the object", required = false, readOnly = true, example = "e6b33c1c-d24d-11ee-b616-02420a030102")
|
@Schema(description = "Unique UUID of the object", required = false, readOnly = true, example = "e6b33c1c-d24d-11ee-b616-02420a030102")
|
||||||
|
@ -72,6 +72,9 @@ public class ConfigBaseVariable {
|
|||||||
|
|
||||||
public static String getDBPort() {
|
public static String getDBPort() {
|
||||||
if (dbPort == null) {
|
if (dbPort == null) {
|
||||||
|
if (getDBType().equals("mongo")) {
|
||||||
|
return "27017";
|
||||||
|
}
|
||||||
return "3306";
|
return "3306";
|
||||||
}
|
}
|
||||||
return dbPort;
|
return dbPort;
|
||||||
|
@ -77,9 +77,9 @@ public class DataTools {
|
|||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data getWithSha512(final String sha512) {
|
public static Data getWithSha512(final DataAccess ioDb, final String sha512) {
|
||||||
try {
|
try {
|
||||||
return DataAccess.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512)),
|
return ioDb.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512)),
|
||||||
new ReadAllColumn());
|
new ReadAllColumn());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
@ -88,9 +88,9 @@ public class DataTools {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data getWithId(final long id) {
|
public static Data getWithId(final DataAccess ioDb, final long id) {
|
||||||
try {
|
try {
|
||||||
return DataAccess.getWhere(Data.class, new Condition(new QueryAnd(
|
return ioDb.getWhere(Data.class, new Condition(new QueryAnd(
|
||||||
List.of(new QueryCondition("deleted", "=", false), new QueryCondition("id", "=", id)))));
|
List.of(new QueryCondition("deleted", "=", false), new QueryCondition("id", "=", id)))));
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
@ -100,6 +100,7 @@ public class DataTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Data createNewData(
|
public static Data createNewData(
|
||||||
|
final DataAccess ioDb,
|
||||||
final long tmpUID,
|
final long tmpUID,
|
||||||
final String originalFileName,
|
final String originalFileName,
|
||||||
final String sha512,
|
final String sha512,
|
||||||
@ -113,7 +114,7 @@ public class DataTools {
|
|||||||
out.sha512 = sha512;
|
out.sha512 = sha512;
|
||||||
out.mimeType = mimeType;
|
out.mimeType = mimeType;
|
||||||
out.size = fileSize;
|
out.size = fileSize;
|
||||||
out = DataAccess.insert(out);
|
out = ioDb.insert(out);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -130,8 +131,11 @@ public class DataTools {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Data createNewData(final long tmpUID, final String originalFileName, final String sha512)
|
public static Data createNewData(
|
||||||
throws IOException, SQLException {
|
final DataAccess ioDb,
|
||||||
|
final long tmpUID,
|
||||||
|
final String originalFileName,
|
||||||
|
final String sha512) throws IOException, SQLException {
|
||||||
// determine mime type:
|
// determine mime type:
|
||||||
String mimeType = "";
|
String mimeType = "";
|
||||||
final String extension = originalFileName.substring(originalFileName.lastIndexOf('.') + 1);
|
final String extension = originalFileName.substring(originalFileName.lastIndexOf('.') + 1);
|
||||||
@ -144,12 +148,12 @@ public class DataTools {
|
|||||||
case "webm" -> "video/webm";
|
case "webm" -> "video/webm";
|
||||||
default -> throw new IOException("Can not find the mime type of data input: '" + extension + "'");
|
default -> throw new IOException("Can not find the mime type of data input: '" + extension + "'");
|
||||||
};
|
};
|
||||||
return createNewData(tmpUID, originalFileName, sha512, mimeType);
|
return createNewData(ioDb, tmpUID, originalFileName, sha512, mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void undelete(final UUID id) {
|
public static void undelete(final DataAccess ioDb, final UUID id) {
|
||||||
try {
|
try {
|
||||||
DataAccess.unsetDelete(Data.class, id);
|
ioDb.unsetDelete(Data.class, id);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -272,13 +276,14 @@ public class DataTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <CLASS_TYPE, ID_TYPE> void uploadCoverFromUri(
|
public static <CLASS_TYPE, ID_TYPE> void uploadCoverFromUri(
|
||||||
|
final DataAccess ioDb,
|
||||||
final Class<CLASS_TYPE> clazz,
|
final Class<CLASS_TYPE> clazz,
|
||||||
final ID_TYPE id,
|
final ID_TYPE id,
|
||||||
final String url) throws Exception {
|
final String url) throws Exception {
|
||||||
|
|
||||||
LOGGER.info(" - id: {}", id);
|
LOGGER.info(" - id: {}", id);
|
||||||
LOGGER.info(" - url: {} ", url);
|
LOGGER.info(" - url: {} ", url);
|
||||||
final CLASS_TYPE media = DataAccess.get(clazz, id);
|
final CLASS_TYPE media = ioDb.get(clazz, id);
|
||||||
if (media == null) {
|
if (media == null) {
|
||||||
throw new InputException(clazz.getCanonicalName(),
|
throw new InputException(clazz.getCanonicalName(),
|
||||||
"[" + id.toString() + "] Id does not exist or removed...");
|
"[" + id.toString() + "] Id does not exist or removed...");
|
||||||
@ -310,7 +315,7 @@ public class DataTools {
|
|||||||
|
|
||||||
final long tmpUID = getTmpDataId();
|
final long tmpUID = getTmpDataId();
|
||||||
final String sha512 = saveTemporaryFile(dataResponse, tmpUID);
|
final String sha512 = saveTemporaryFile(dataResponse, tmpUID);
|
||||||
Data data = getWithSha512(sha512);
|
Data data = getWithSha512(ioDb, sha512);
|
||||||
final String mimeType = getMimeType(dataResponse);
|
final String mimeType = getMimeType(dataResponse);
|
||||||
if (!Arrays.asList(SUPPORTED_IMAGE_MIME_TYPE).contains(mimeType)) {
|
if (!Arrays.asList(SUPPORTED_IMAGE_MIME_TYPE).contains(mimeType)) {
|
||||||
throw new FailException(Response.Status.NOT_ACCEPTABLE,
|
throw new FailException(Response.Status.NOT_ACCEPTABLE,
|
||||||
@ -321,7 +326,7 @@ public class DataTools {
|
|||||||
if (data == null) {
|
if (data == null) {
|
||||||
LOGGER.info("Need to add the data in the BDD ... ");
|
LOGGER.info("Need to add the data in the BDD ... ");
|
||||||
try {
|
try {
|
||||||
data = createNewData(tmpUID, url, sha512, mimeType);
|
data = createNewData(ioDb, tmpUID, url, sha512, mimeType);
|
||||||
} catch (final IOException ex) {
|
} catch (final IOException ex) {
|
||||||
removeTemporaryFile(tmpUID);
|
removeTemporaryFile(tmpUID);
|
||||||
throw new FailException(Response.Status.NOT_MODIFIED,
|
throw new FailException(Response.Status.NOT_MODIFIED,
|
||||||
@ -333,7 +338,7 @@ public class DataTools {
|
|||||||
}
|
}
|
||||||
} else if (data.deleted) {
|
} else if (data.deleted) {
|
||||||
LOGGER.error("Data already exist but deleted");
|
LOGGER.error("Data already exist but deleted");
|
||||||
undelete(data.uuid);
|
undelete(ioDb, data.uuid);
|
||||||
data.deleted = false;
|
data.deleted = false;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("Data already exist ... all good");
|
LOGGER.error("Data already exist ... all good");
|
||||||
@ -341,15 +346,16 @@ public class DataTools {
|
|||||||
// Fist step: retrieve all the Id of each parents:...
|
// Fist step: retrieve all the Id of each parents:...
|
||||||
LOGGER.info("Find typeNode");
|
LOGGER.info("Find typeNode");
|
||||||
if (id instanceof final Long idLong) {
|
if (id instanceof final Long idLong) {
|
||||||
AddOnDataJson.addLink(clazz, idLong, "covers", data.uuid);
|
AddOnDataJson.addLink(ioDb, clazz, idLong, "covers", data.uuid);
|
||||||
} else if (id instanceof final UUID idUUID) {
|
} else if (id instanceof final UUID idUUID) {
|
||||||
AddOnDataJson.addLink(clazz, idUUID, "covers", data.uuid);
|
AddOnDataJson.addLink(ioDb, clazz, idUUID, "covers", data.uuid);
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Fail to add Cover can not detect type...");
|
throw new IOException("Fail to add Cover can not detect type...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <CLASS_TYPE, ID_TYPE> void uploadCover(
|
public static <CLASS_TYPE, ID_TYPE> void uploadCover(
|
||||||
|
final DataAccess ioDb,
|
||||||
final Class<CLASS_TYPE> clazz,
|
final Class<CLASS_TYPE> clazz,
|
||||||
final ID_TYPE id,
|
final ID_TYPE id,
|
||||||
final InputStream fileInputStream,
|
final InputStream fileInputStream,
|
||||||
@ -360,7 +366,7 @@ public class DataTools {
|
|||||||
LOGGER.info(" - file_name: {} ", fileMetaData.getFileName());
|
LOGGER.info(" - file_name: {} ", fileMetaData.getFileName());
|
||||||
LOGGER.info(" - fileInputStream: {}", fileInputStream);
|
LOGGER.info(" - fileInputStream: {}", fileInputStream);
|
||||||
LOGGER.info(" - fileMetaData: {}", fileMetaData);
|
LOGGER.info(" - fileMetaData: {}", fileMetaData);
|
||||||
final CLASS_TYPE media = DataAccess.get(clazz, id);
|
final CLASS_TYPE media = ioDb.get(clazz, id);
|
||||||
if (media == null) {
|
if (media == null) {
|
||||||
throw new InputException(clazz.getCanonicalName(),
|
throw new InputException(clazz.getCanonicalName(),
|
||||||
"[" + id.toString() + "] Id does not exist or removed...");
|
"[" + id.toString() + "] Id does not exist or removed...");
|
||||||
@ -368,11 +374,11 @@ public class DataTools {
|
|||||||
|
|
||||||
final long tmpUID = getTmpDataId();
|
final long tmpUID = getTmpDataId();
|
||||||
final String sha512 = saveTemporaryFile(fileInputStream, tmpUID);
|
final String sha512 = saveTemporaryFile(fileInputStream, tmpUID);
|
||||||
Data data = getWithSha512(sha512);
|
Data data = getWithSha512(ioDb, sha512);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
LOGGER.info("Need to add the data in the BDD ... ");
|
LOGGER.info("Need to add the data in the BDD ... ");
|
||||||
try {
|
try {
|
||||||
data = createNewData(tmpUID, fileMetaData.getFileName(), sha512);
|
data = createNewData(ioDb, tmpUID, fileMetaData.getFileName(), sha512);
|
||||||
} catch (final IOException ex) {
|
} catch (final IOException ex) {
|
||||||
removeTemporaryFile(tmpUID);
|
removeTemporaryFile(tmpUID);
|
||||||
throw new FailException(Response.Status.NOT_MODIFIED,
|
throw new FailException(Response.Status.NOT_MODIFIED,
|
||||||
@ -384,7 +390,7 @@ public class DataTools {
|
|||||||
}
|
}
|
||||||
} else if (data.deleted) {
|
} else if (data.deleted) {
|
||||||
LOGGER.error("Data already exist but deleted");
|
LOGGER.error("Data already exist but deleted");
|
||||||
undelete(data.uuid);
|
undelete(ioDb, data.uuid);
|
||||||
data.deleted = false;
|
data.deleted = false;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("Data already exist ... all good");
|
LOGGER.error("Data already exist ... all good");
|
||||||
@ -392,9 +398,9 @@ public class DataTools {
|
|||||||
// Fist step: retrieve all the Id of each parents:...
|
// Fist step: retrieve all the Id of each parents:...
|
||||||
LOGGER.info("Find typeNode");
|
LOGGER.info("Find typeNode");
|
||||||
if (id instanceof final Long idLong) {
|
if (id instanceof final Long idLong) {
|
||||||
AddOnDataJson.addLink(clazz, idLong, "covers", data.uuid);
|
AddOnDataJson.addLink(ioDb, clazz, idLong, "covers", data.uuid);
|
||||||
} else if (id instanceof final UUID idUUID) {
|
} else if (id instanceof final UUID idUUID) {
|
||||||
AddOnDataJson.addLink(clazz, idUUID, "covers", data.uuid);
|
AddOnDataJson.addLink(ioDb, clazz, idUUID, "covers", data.uuid);
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Fail to add Cover can not detect type...");
|
throw new IOException("Fail to add Cover can not detect type...");
|
||||||
}
|
}
|
||||||
|
@ -12,22 +12,38 @@ public class ConfigureDb {
|
|||||||
final static private Logger LOGGER = LoggerFactory.getLogger(ConfigureDb.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(ConfigureDb.class);
|
||||||
|
|
||||||
public static void configure() throws IOException {
|
public static void configure() throws IOException {
|
||||||
if (true) {
|
String modeTest = System.getenv("TEST_E2E_MODE");
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
if (modeTest == null || modeTest.isEmpty() || "false".equalsIgnoreCase(modeTest)) {
|
||||||
ConfigBaseVariable.dbType = "sqlite";
|
modeTest = "SQLITE-MEMORY";
|
||||||
ConfigBaseVariable.dbHost = "memory";
|
} else if ("true".equalsIgnoreCase(modeTest)) {
|
||||||
// for test we need to connect all time the DB
|
modeTest = "MY-SQL";
|
||||||
ConfigBaseVariable.dbKeepConnected = "true";
|
}
|
||||||
}
|
// override the local test:
|
||||||
} else {
|
modeTest = "MONGO";
|
||||||
// Enable this if you want to access to a local MySQL base to test with an adminer
|
if ("SQLITE-MEMORY".equalsIgnoreCase(modeTest)) {
|
||||||
|
ConfigBaseVariable.dbType = "sqlite";
|
||||||
|
ConfigBaseVariable.dbHost = "memory";
|
||||||
|
// for test we need to connect all time the DB
|
||||||
|
ConfigBaseVariable.dbKeepConnected = "true";
|
||||||
|
} else if ("SQLITE".equalsIgnoreCase(modeTest)) {
|
||||||
|
ConfigBaseVariable.dbType = "sqlite";
|
||||||
|
ConfigBaseVariable.dbKeepConnected = "true";
|
||||||
|
} else if ("MY-SQL".equalsIgnoreCase(modeTest)) {
|
||||||
|
ConfigBaseVariable.dbType = "mysql";
|
||||||
|
ConfigBaseVariable.bdDatabase = "test_db";
|
||||||
|
ConfigBaseVariable.dbPort = "3906";
|
||||||
|
ConfigBaseVariable.dbUser = "root";
|
||||||
|
} else if ("MONGO".equalsIgnoreCase(modeTest)) {
|
||||||
|
ConfigBaseVariable.dbType = "mongo";
|
||||||
|
ConfigBaseVariable.bdDatabase = "test_mongo_db";
|
||||||
|
} else {
|
||||||
|
// User local modification ...
|
||||||
ConfigBaseVariable.bdDatabase = "test_db";
|
ConfigBaseVariable.bdDatabase = "test_db";
|
||||||
ConfigBaseVariable.dbPort = "3906";
|
ConfigBaseVariable.dbPort = "3906";
|
||||||
ConfigBaseVariable.dbUser = "root";
|
ConfigBaseVariable.dbUser = "root";
|
||||||
//ConfigBaseVariable.dbPassword = "password";
|
|
||||||
}
|
}
|
||||||
// Connect the dataBase...
|
// Connect the dataBase...
|
||||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.getDbconfig());
|
||||||
entry.connect();
|
entry.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -24,6 +25,8 @@ import test.kar.archidata.model.SimpleTable;
|
|||||||
public class TestJson {
|
public class TestJson {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestJson.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestJson.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
ConfigureDb.configure();
|
ConfigureDb.configure();
|
||||||
@ -34,13 +37,19 @@ public class TestJson {
|
|||||||
ConfigureDb.clear();
|
ConfigureDb.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestJson() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@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) {
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
for (final String elem : sqlCommand) {
|
||||||
DataAccess.executeSimpleQuery(elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
daSQL.executeSimpleQuery(elem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +60,7 @@ public class TestJson {
|
|||||||
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 = this.da.insert(test);
|
||||||
|
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
@ -61,7 +70,7 @@ public class TestJson {
|
|||||||
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 = this.da.get(SerializeAsJson.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
|
@ -13,6 +13,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -24,6 +25,8 @@ import test.kar.archidata.model.SerializeListAsJson;
|
|||||||
public class TestListJson {
|
public class TestListJson {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestListJson.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestListJson.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
ConfigureDb.configure();
|
ConfigureDb.configure();
|
||||||
@ -34,13 +37,19 @@ public class TestListJson {
|
|||||||
ConfigureDb.clear();
|
ConfigureDb.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestListJson() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@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) {
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
for (final String elem : sqlCommand) {
|
||||||
DataAccess.executeSimpleQuery(elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
daSQL.executeSimpleQuery(elem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +64,7 @@ public class TestListJson {
|
|||||||
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 = this.da.insert(test);
|
||||||
|
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.id);
|
Assertions.assertNotNull(insertedData.id);
|
||||||
@ -69,7 +78,7 @@ public class TestListJson {
|
|||||||
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 = this.da.get(SerializeListAsJson.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
|
@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -26,6 +27,8 @@ import test.kar.archidata.model.TypeManyToManyRootExpand;
|
|||||||
public class TestManyToMany {
|
public class TestManyToMany {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToMany.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToMany.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
ConfigureDb.configure();
|
ConfigureDb.configure();
|
||||||
@ -36,15 +39,21 @@ public class TestManyToMany {
|
|||||||
ConfigureDb.clear();
|
ConfigureDb.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestManyToMany() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTable() throws Exception {
|
public void testCreateTable() throws Exception {
|
||||||
final List<String> sqlCommand2 = DataFactory.createTable(TypeManyToManyRoot.class);
|
final List<String> sqlCommand2 = DataFactory.createTable(TypeManyToManyRoot.class);
|
||||||
final List<String> sqlCommand = DataFactory.createTable(TypeManyToManyRemote.class);
|
final List<String> sqlCommand = DataFactory.createTable(TypeManyToManyRemote.class);
|
||||||
sqlCommand.addAll(sqlCommand2);
|
sqlCommand.addAll(sqlCommand2);
|
||||||
for (final String elem : sqlCommand) {
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
for (final String elem : sqlCommand) {
|
||||||
DataAccess.executeSimpleQuery(elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
daSQL.executeSimpleQuery(elem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,14 +62,14 @@ public class TestManyToMany {
|
|||||||
public void testSimpleInsertAndRetieve() throws Exception {
|
public void testSimpleInsertAndRetieve() throws Exception {
|
||||||
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 = this.da.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.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 = this.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -69,7 +78,7 @@ public class TestManyToMany {
|
|||||||
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);
|
this.da.delete(TypeManyToManyRoot.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(3)
|
@Order(3)
|
||||||
@ -78,24 +87,24 @@ public class TestManyToMany {
|
|||||||
|
|
||||||
TypeManyToManyRemote remote = new TypeManyToManyRemote();
|
TypeManyToManyRemote remote = new TypeManyToManyRemote();
|
||||||
remote.data = "remote1";
|
remote.data = "remote1";
|
||||||
final TypeManyToManyRemote insertedRemote1 = DataAccess.insert(remote);
|
final TypeManyToManyRemote insertedRemote1 = this.da.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 = this.da.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 = this.da.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.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 = this.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -105,10 +114,10 @@ public class TestManyToMany {
|
|||||||
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(this.da, TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote1.id);
|
||||||
AddOnManyToMany.addLink(TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote2.id);
|
AddOnManyToMany.addLink(this.da, TypeManyToManyRoot.class, retrieve.id, "remote", insertedRemote2.id);
|
||||||
|
|
||||||
retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
retrieve = this.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -120,7 +129,7 @@ public class TestManyToMany {
|
|||||||
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 = this.da.get(TypeManyToManyRootExpand.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieveExpand);
|
Assertions.assertNotNull(retrieveExpand);
|
||||||
Assertions.assertNotNull(retrieveExpand.id);
|
Assertions.assertNotNull(retrieveExpand.id);
|
||||||
@ -133,10 +142,11 @@ public class TestManyToMany {
|
|||||||
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);
|
long count = AddOnManyToMany.removeLink(this.da, TypeManyToManyRoot.class, retrieve.id, "remote",
|
||||||
|
insertedRemote1.id);
|
||||||
Assertions.assertEquals(1, count);
|
Assertions.assertEquals(1, count);
|
||||||
|
|
||||||
retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
retrieve = this.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -148,10 +158,11 @@ public class TestManyToMany {
|
|||||||
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(this.da, TypeManyToManyRoot.class, retrieve.id, "remote",
|
||||||
|
insertedRemote2.id);
|
||||||
Assertions.assertEquals(1, count);
|
Assertions.assertEquals(1, count);
|
||||||
|
|
||||||
retrieve = DataAccess.get(TypeManyToManyRoot.class, insertedData.id);
|
retrieve = this.da.get(TypeManyToManyRoot.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -160,9 +171,9 @@ public class TestManyToMany {
|
|||||||
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);
|
this.da.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é...) */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -28,6 +29,8 @@ import test.kar.archidata.model.TypeManyToOneUUIDRootExpand;
|
|||||||
public class TestManyToOne {
|
public class TestManyToOne {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToOne.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToOne.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
ConfigureDb.configure();
|
ConfigureDb.configure();
|
||||||
@ -38,6 +41,10 @@ public class TestManyToOne {
|
|||||||
ConfigureDb.clear();
|
ConfigureDb.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestManyToOne() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTable() throws Exception {
|
public void testCreateTable() throws Exception {
|
||||||
@ -45,9 +52,11 @@ public class TestManyToOne {
|
|||||||
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneRoot.class));
|
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneRoot.class));
|
||||||
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneUUIDRoot.class));
|
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneUUIDRoot.class));
|
||||||
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneUUIDRemote.class));
|
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneUUIDRemote.class));
|
||||||
for (final String elem : sqlCommand) {
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
for (final String elem : sqlCommand) {
|
||||||
DataAccess.executeSimpleQuery(elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
daSQL.executeSimpleQuery(elem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,32 +65,32 @@ public class TestManyToOne {
|
|||||||
public void testRemoteLong() throws Exception {
|
public void testRemoteLong() throws Exception {
|
||||||
TypeManyToOneRemote remote = new TypeManyToOneRemote();
|
TypeManyToOneRemote remote = new TypeManyToOneRemote();
|
||||||
remote.data = "remote1";
|
remote.data = "remote1";
|
||||||
final TypeManyToOneRemote insertedRemote1 = DataAccess.insert(remote);
|
final TypeManyToOneRemote insertedRemote1 = this.da.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 = this.da.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;
|
||||||
final TypeManyToOneRoot insertedData = DataAccess.insert(test);
|
final TypeManyToOneRoot insertedData = this.da.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.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 = this.da.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 = this.da.get(TypeManyToOneRootExpand.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);
|
||||||
@ -91,19 +100,19 @@ public class TestManyToOne {
|
|||||||
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 long count = this.da.delete(TypeManyToOneRemote.class, remote.id);
|
||||||
Assertions.assertEquals(1, count);
|
Assertions.assertEquals(1L, count);
|
||||||
|
|
||||||
// check fail:
|
// check fail:
|
||||||
|
|
||||||
retrieve = DataAccess.get(TypeManyToOneRoot.class, insertedData.id);
|
retrieve = this.da.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 = this.da.get(TypeManyToOneRootExpand.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);
|
||||||
@ -116,31 +125,31 @@ public class TestManyToOne {
|
|||||||
public void testRemoteUUID() throws Exception {
|
public void testRemoteUUID() throws Exception {
|
||||||
TypeManyToOneUUIDRemote remote = new TypeManyToOneUUIDRemote();
|
TypeManyToOneUUIDRemote remote = new TypeManyToOneUUIDRemote();
|
||||||
remote.data = "remote1";
|
remote.data = "remote1";
|
||||||
final TypeManyToOneUUIDRemote insertedRemote1 = DataAccess.insert(remote);
|
final TypeManyToOneUUIDRemote insertedRemote1 = this.da.insert(remote);
|
||||||
Assertions.assertEquals(insertedRemote1.data, remote.data);
|
Assertions.assertEquals(insertedRemote1.data, remote.data);
|
||||||
|
|
||||||
remote = new TypeManyToOneUUIDRemote();
|
remote = new TypeManyToOneUUIDRemote();
|
||||||
remote.data = "remote2";
|
remote.data = "remote2";
|
||||||
final TypeManyToOneUUIDRemote insertedRemote2 = DataAccess.insert(remote);
|
final TypeManyToOneUUIDRemote insertedRemote2 = this.da.insert(remote);
|
||||||
Assertions.assertEquals(insertedRemote2.data, remote.data);
|
Assertions.assertEquals(insertedRemote2.data, remote.data);
|
||||||
|
|
||||||
final TypeManyToOneUUIDRoot test = new TypeManyToOneUUIDRoot();
|
final TypeManyToOneUUIDRoot test = new TypeManyToOneUUIDRoot();
|
||||||
test.otherData = "kjhlkjlkj";
|
test.otherData = "kjhlkjlkj";
|
||||||
test.remoteUuid = insertedRemote2.uuid;
|
test.remoteUuid = insertedRemote2.uuid;
|
||||||
final TypeManyToOneUUIDRoot insertedData = DataAccess.insert(test);
|
final TypeManyToOneUUIDRoot insertedData = this.da.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertNotNull(insertedData.uuid);
|
Assertions.assertNotNull(insertedData.uuid);
|
||||||
Assertions.assertEquals(test.otherData, insertedData.otherData);
|
Assertions.assertEquals(test.otherData, insertedData.otherData);
|
||||||
Assertions.assertEquals(insertedRemote2.uuid, insertedData.remoteUuid);
|
Assertions.assertEquals(insertedRemote2.uuid, insertedData.remoteUuid);
|
||||||
|
|
||||||
TypeManyToOneUUIDRoot retrieve = DataAccess.get(TypeManyToOneUUIDRoot.class, insertedData.uuid);
|
TypeManyToOneUUIDRoot retrieve = this.da.get(TypeManyToOneUUIDRoot.class, insertedData.uuid);
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.uuid);
|
Assertions.assertNotNull(retrieve.uuid);
|
||||||
Assertions.assertEquals(insertedData.uuid, retrieve.uuid);
|
Assertions.assertEquals(insertedData.uuid, retrieve.uuid);
|
||||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||||
Assertions.assertEquals(insertedRemote2.uuid, retrieve.remoteUuid);
|
Assertions.assertEquals(insertedRemote2.uuid, retrieve.remoteUuid);
|
||||||
|
|
||||||
TypeManyToOneUUIDRootExpand retrieve2 = DataAccess.get(TypeManyToOneUUIDRootExpand.class, insertedData.uuid);
|
TypeManyToOneUUIDRootExpand retrieve2 = this.da.get(TypeManyToOneUUIDRootExpand.class, insertedData.uuid);
|
||||||
Assertions.assertNotNull(retrieve2);
|
Assertions.assertNotNull(retrieve2);
|
||||||
Assertions.assertNotNull(retrieve2.uuid);
|
Assertions.assertNotNull(retrieve2.uuid);
|
||||||
Assertions.assertEquals(insertedData.uuid, retrieve2.uuid);
|
Assertions.assertEquals(insertedData.uuid, retrieve2.uuid);
|
||||||
@ -150,23 +159,23 @@ public class TestManyToOne {
|
|||||||
Assertions.assertEquals(insertedRemote2.data, retrieve2.remote.data);
|
Assertions.assertEquals(insertedRemote2.data, retrieve2.remote.data);
|
||||||
|
|
||||||
// remove values:
|
// remove values:
|
||||||
final int count = DataAccess.delete(TypeManyToOneUUIDRemote.class, remote.uuid);
|
final long count = this.da.delete(TypeManyToOneUUIDRemote.class, remote.uuid);
|
||||||
Assertions.assertEquals(1, count);
|
Assertions.assertEquals(1, count);
|
||||||
|
|
||||||
// check fail:
|
// check fail:
|
||||||
|
|
||||||
retrieve = DataAccess.get(TypeManyToOneUUIDRoot.class, insertedData.uuid);
|
retrieve = this.da.get(TypeManyToOneUUIDRoot.class, insertedData.uuid);
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.uuid);
|
Assertions.assertNotNull(retrieve.uuid);
|
||||||
Assertions.assertEquals(insertedData.uuid, retrieve.uuid);
|
Assertions.assertEquals(insertedData.uuid, retrieve.uuid);
|
||||||
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
|
||||||
Assertions.assertEquals(insertedRemote2.uuid, retrieve.remoteUuid);
|
Assertions.assertEquals(insertedRemote2.uuid, retrieve.remoteUuid);
|
||||||
|
|
||||||
retrieve2 = DataAccess.get(TypeManyToOneUUIDRootExpand.class, insertedData.uuid);
|
retrieve2 = this.da.get(TypeManyToOneUUIDRootExpand.class, insertedData.uuid);
|
||||||
Assertions.assertNotNull(retrieve2);
|
Assertions.assertNotNull(retrieve2);
|
||||||
Assertions.assertNotNull(retrieve2.uuid);
|
Assertions.assertNotNull(retrieve2.uuid);
|
||||||
Assertions.assertEquals(insertedData.uuid, retrieve2.uuid);
|
Assertions.assertEquals(insertedData.uuid, retrieve2.uuid);
|
||||||
Assertions.assertEquals(insertedData.otherData, retrieve2.otherData);
|
Assertions.assertEquals(insertedData.otherData, retrieve2.otherData);
|
||||||
Assertions.assertNull(retrieve2.remote);
|
Assertions.assertNull(retrieve2.remote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -28,6 +29,8 @@ import test.kar.archidata.model.TypeOneToManyUUIDRootExpand;
|
|||||||
public class TestOneToMany {
|
public class TestOneToMany {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestOneToMany.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestOneToMany.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
ConfigureDb.configure();
|
ConfigureDb.configure();
|
||||||
@ -38,6 +41,10 @@ public class TestOneToMany {
|
|||||||
ConfigureDb.clear();
|
ConfigureDb.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestOneToMany() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTable() throws Exception {
|
public void testCreateTable() throws Exception {
|
||||||
@ -45,9 +52,11 @@ public class TestOneToMany {
|
|||||||
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyRoot.class));
|
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyRoot.class));
|
||||||
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyUUIDRemote.class));
|
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyUUIDRemote.class));
|
||||||
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyUUIDRoot.class));
|
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyUUIDRoot.class));
|
||||||
for (final String elem : sqlCommand) {
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
for (final String elem : sqlCommand) {
|
||||||
DataAccess.executeSimpleQuery(elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
daSQL.executeSimpleQuery(elem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,13 +67,13 @@ public class TestOneToMany {
|
|||||||
|
|
||||||
final TypeOneToManyRoot root = new TypeOneToManyRoot();
|
final TypeOneToManyRoot root = new TypeOneToManyRoot();
|
||||||
root.otherData = "plouf";
|
root.otherData = "plouf";
|
||||||
final TypeOneToManyRoot insertedRoot = DataAccess.insert(root);
|
final TypeOneToManyRoot insertedRoot = this.da.insert(root);
|
||||||
Assertions.assertEquals(insertedRoot.otherData, root.otherData);
|
Assertions.assertEquals(insertedRoot.otherData, root.otherData);
|
||||||
Assertions.assertNull(insertedRoot.remoteIds);
|
Assertions.assertNull(insertedRoot.remoteIds);
|
||||||
|
|
||||||
final TypeOneToManyRoot root2 = new TypeOneToManyRoot();
|
final TypeOneToManyRoot root2 = new TypeOneToManyRoot();
|
||||||
root2.otherData = "plouf 2";
|
root2.otherData = "plouf 2";
|
||||||
final TypeOneToManyRoot insertedRoot2 = DataAccess.insert(root2);
|
final TypeOneToManyRoot insertedRoot2 = this.da.insert(root2);
|
||||||
Assertions.assertEquals(insertedRoot2.otherData, root2.otherData);
|
Assertions.assertEquals(insertedRoot2.otherData, root2.otherData);
|
||||||
Assertions.assertNull(insertedRoot2.remoteIds);
|
Assertions.assertNull(insertedRoot2.remoteIds);
|
||||||
|
|
||||||
@ -73,34 +82,34 @@ public class TestOneToMany {
|
|||||||
final TypeOneToManyRemote remote10 = new TypeOneToManyRemote();
|
final TypeOneToManyRemote remote10 = new TypeOneToManyRemote();
|
||||||
remote10.data = "remote10";
|
remote10.data = "remote10";
|
||||||
remote10.rootId = insertedRoot.id;
|
remote10.rootId = insertedRoot.id;
|
||||||
final TypeOneToManyRemote insertedRemote10 = DataAccess.insert(remote10);
|
final TypeOneToManyRemote insertedRemote10 = this.da.insert(remote10);
|
||||||
Assertions.assertEquals(insertedRemote10.data, remote10.data);
|
Assertions.assertEquals(insertedRemote10.data, remote10.data);
|
||||||
Assertions.assertEquals(insertedRemote10.rootId, remote10.rootId);
|
Assertions.assertEquals(insertedRemote10.rootId, remote10.rootId);
|
||||||
|
|
||||||
final TypeOneToManyRemote remote11 = new TypeOneToManyRemote();
|
final TypeOneToManyRemote remote11 = new TypeOneToManyRemote();
|
||||||
remote11.data = "remote11";
|
remote11.data = "remote11";
|
||||||
remote11.rootId = insertedRoot.id;
|
remote11.rootId = insertedRoot.id;
|
||||||
final TypeOneToManyRemote insertedRemote11 = DataAccess.insert(remote11);
|
final TypeOneToManyRemote insertedRemote11 = this.da.insert(remote11);
|
||||||
Assertions.assertEquals(insertedRemote11.data, remote11.data);
|
Assertions.assertEquals(insertedRemote11.data, remote11.data);
|
||||||
Assertions.assertEquals(insertedRemote11.rootId, remote11.rootId);
|
Assertions.assertEquals(insertedRemote11.rootId, remote11.rootId);
|
||||||
|
|
||||||
final TypeOneToManyRemote remote20 = new TypeOneToManyRemote();
|
final TypeOneToManyRemote remote20 = new TypeOneToManyRemote();
|
||||||
remote20.data = "remote20";
|
remote20.data = "remote20";
|
||||||
remote20.rootId = insertedRoot2.id;
|
remote20.rootId = insertedRoot2.id;
|
||||||
final TypeOneToManyRemote insertedRemote20 = DataAccess.insert(remote20);
|
final TypeOneToManyRemote insertedRemote20 = this.da.insert(remote20);
|
||||||
Assertions.assertEquals(insertedRemote20.data, remote20.data);
|
Assertions.assertEquals(insertedRemote20.data, remote20.data);
|
||||||
Assertions.assertEquals(insertedRemote20.rootId, remote20.rootId);
|
Assertions.assertEquals(insertedRemote20.rootId, remote20.rootId);
|
||||||
|
|
||||||
// Check remote are inserted
|
// Check remote are inserted
|
||||||
|
|
||||||
final TypeOneToManyRoot retreiveRoot1 = DataAccess.get(TypeOneToManyRoot.class, insertedRoot.id);
|
final TypeOneToManyRoot retreiveRoot1 = this.da.get(TypeOneToManyRoot.class, insertedRoot.id);
|
||||||
Assertions.assertEquals(retreiveRoot1.otherData, insertedRoot.otherData);
|
Assertions.assertEquals(retreiveRoot1.otherData, insertedRoot.otherData);
|
||||||
Assertions.assertNotNull(retreiveRoot1.remoteIds);
|
Assertions.assertNotNull(retreiveRoot1.remoteIds);
|
||||||
Assertions.assertEquals(2, retreiveRoot1.remoteIds.size());
|
Assertions.assertEquals(2, retreiveRoot1.remoteIds.size());
|
||||||
Assertions.assertEquals(insertedRemote10.id, retreiveRoot1.remoteIds.get(0));
|
Assertions.assertEquals(insertedRemote10.id, retreiveRoot1.remoteIds.get(0));
|
||||||
Assertions.assertEquals(insertedRemote11.id, retreiveRoot1.remoteIds.get(1));
|
Assertions.assertEquals(insertedRemote11.id, retreiveRoot1.remoteIds.get(1));
|
||||||
|
|
||||||
final TypeOneToManyRoot retreiveRoot2 = DataAccess.get(TypeOneToManyRoot.class, insertedRoot2.id);
|
final TypeOneToManyRoot retreiveRoot2 = this.da.get(TypeOneToManyRoot.class, insertedRoot2.id);
|
||||||
Assertions.assertEquals(retreiveRoot2.otherData, insertedRoot2.otherData);
|
Assertions.assertEquals(retreiveRoot2.otherData, insertedRoot2.otherData);
|
||||||
Assertions.assertNotNull(retreiveRoot2.remoteIds);
|
Assertions.assertNotNull(retreiveRoot2.remoteIds);
|
||||||
Assertions.assertEquals(1, retreiveRoot2.remoteIds.size());
|
Assertions.assertEquals(1, retreiveRoot2.remoteIds.size());
|
||||||
@ -108,8 +117,7 @@ public class TestOneToMany {
|
|||||||
|
|
||||||
// Check remote are inserted and expandable
|
// Check remote are inserted and expandable
|
||||||
|
|
||||||
final TypeOneToManyRootExpand retreiveRootExpand1 = DataAccess.get(TypeOneToManyRootExpand.class,
|
final TypeOneToManyRootExpand retreiveRootExpand1 = this.da.get(TypeOneToManyRootExpand.class, insertedRoot.id);
|
||||||
insertedRoot.id);
|
|
||||||
Assertions.assertEquals(retreiveRootExpand1.otherData, insertedRoot.otherData);
|
Assertions.assertEquals(retreiveRootExpand1.otherData, insertedRoot.otherData);
|
||||||
Assertions.assertNotNull(retreiveRootExpand1.remotes);
|
Assertions.assertNotNull(retreiveRootExpand1.remotes);
|
||||||
Assertions.assertEquals(2, retreiveRootExpand1.remotes.size());
|
Assertions.assertEquals(2, retreiveRootExpand1.remotes.size());
|
||||||
@ -120,7 +128,7 @@ public class TestOneToMany {
|
|||||||
Assertions.assertEquals(insertedRemote11.rootId, retreiveRootExpand1.remotes.get(1).rootId);
|
Assertions.assertEquals(insertedRemote11.rootId, retreiveRootExpand1.remotes.get(1).rootId);
|
||||||
Assertions.assertEquals(insertedRemote11.data, retreiveRootExpand1.remotes.get(1).data);
|
Assertions.assertEquals(insertedRemote11.data, retreiveRootExpand1.remotes.get(1).data);
|
||||||
|
|
||||||
final TypeOneToManyRootExpand retreiveRootExpand2 = DataAccess.get(TypeOneToManyRootExpand.class,
|
final TypeOneToManyRootExpand retreiveRootExpand2 = this.da.get(TypeOneToManyRootExpand.class,
|
||||||
insertedRoot2.id);
|
insertedRoot2.id);
|
||||||
Assertions.assertEquals(retreiveRootExpand2.otherData, insertedRoot2.otherData);
|
Assertions.assertEquals(retreiveRootExpand2.otherData, insertedRoot2.otherData);
|
||||||
Assertions.assertNotNull(retreiveRootExpand2.remotes);
|
Assertions.assertNotNull(retreiveRootExpand2.remotes);
|
||||||
@ -138,13 +146,13 @@ public class TestOneToMany {
|
|||||||
|
|
||||||
final TypeOneToManyUUIDRoot root = new TypeOneToManyUUIDRoot();
|
final TypeOneToManyUUIDRoot root = new TypeOneToManyUUIDRoot();
|
||||||
root.otherData = "plouf";
|
root.otherData = "plouf";
|
||||||
final TypeOneToManyUUIDRoot insertedRoot = DataAccess.insert(root);
|
final TypeOneToManyUUIDRoot insertedRoot = this.da.insert(root);
|
||||||
Assertions.assertEquals(insertedRoot.otherData, root.otherData);
|
Assertions.assertEquals(insertedRoot.otherData, root.otherData);
|
||||||
Assertions.assertNull(insertedRoot.remoteIds);
|
Assertions.assertNull(insertedRoot.remoteIds);
|
||||||
|
|
||||||
final TypeOneToManyUUIDRoot root2 = new TypeOneToManyUUIDRoot();
|
final TypeOneToManyUUIDRoot root2 = new TypeOneToManyUUIDRoot();
|
||||||
root2.otherData = "plouf 2";
|
root2.otherData = "plouf 2";
|
||||||
final TypeOneToManyUUIDRoot insertedRoot2 = DataAccess.insert(root2);
|
final TypeOneToManyUUIDRoot insertedRoot2 = this.da.insert(root2);
|
||||||
Assertions.assertEquals(insertedRoot2.otherData, root2.otherData);
|
Assertions.assertEquals(insertedRoot2.otherData, root2.otherData);
|
||||||
Assertions.assertNull(insertedRoot2.remoteIds);
|
Assertions.assertNull(insertedRoot2.remoteIds);
|
||||||
|
|
||||||
@ -153,34 +161,34 @@ public class TestOneToMany {
|
|||||||
final TypeOneToManyUUIDRemote remote10 = new TypeOneToManyUUIDRemote();
|
final TypeOneToManyUUIDRemote remote10 = new TypeOneToManyUUIDRemote();
|
||||||
remote10.data = "remote10";
|
remote10.data = "remote10";
|
||||||
remote10.rootUuid = insertedRoot.uuid;
|
remote10.rootUuid = insertedRoot.uuid;
|
||||||
final TypeOneToManyUUIDRemote insertedRemote10 = DataAccess.insert(remote10);
|
final TypeOneToManyUUIDRemote insertedRemote10 = this.da.insert(remote10);
|
||||||
Assertions.assertEquals(insertedRemote10.data, remote10.data);
|
Assertions.assertEquals(insertedRemote10.data, remote10.data);
|
||||||
Assertions.assertEquals(insertedRemote10.rootUuid, remote10.rootUuid);
|
Assertions.assertEquals(insertedRemote10.rootUuid, remote10.rootUuid);
|
||||||
|
|
||||||
final TypeOneToManyUUIDRemote remote11 = new TypeOneToManyUUIDRemote();
|
final TypeOneToManyUUIDRemote remote11 = new TypeOneToManyUUIDRemote();
|
||||||
remote11.data = "remote11";
|
remote11.data = "remote11";
|
||||||
remote11.rootUuid = insertedRoot.uuid;
|
remote11.rootUuid = insertedRoot.uuid;
|
||||||
final TypeOneToManyUUIDRemote insertedRemote11 = DataAccess.insert(remote11);
|
final TypeOneToManyUUIDRemote insertedRemote11 = this.da.insert(remote11);
|
||||||
Assertions.assertEquals(insertedRemote11.data, remote11.data);
|
Assertions.assertEquals(insertedRemote11.data, remote11.data);
|
||||||
Assertions.assertEquals(insertedRemote11.rootUuid, remote11.rootUuid);
|
Assertions.assertEquals(insertedRemote11.rootUuid, remote11.rootUuid);
|
||||||
|
|
||||||
final TypeOneToManyUUIDRemote remote20 = new TypeOneToManyUUIDRemote();
|
final TypeOneToManyUUIDRemote remote20 = new TypeOneToManyUUIDRemote();
|
||||||
remote20.data = "remote20";
|
remote20.data = "remote20";
|
||||||
remote20.rootUuid = insertedRoot2.uuid;
|
remote20.rootUuid = insertedRoot2.uuid;
|
||||||
final TypeOneToManyUUIDRemote insertedRemote20 = DataAccess.insert(remote20);
|
final TypeOneToManyUUIDRemote insertedRemote20 = this.da.insert(remote20);
|
||||||
Assertions.assertEquals(insertedRemote20.data, remote20.data);
|
Assertions.assertEquals(insertedRemote20.data, remote20.data);
|
||||||
Assertions.assertEquals(insertedRemote20.rootUuid, remote20.rootUuid);
|
Assertions.assertEquals(insertedRemote20.rootUuid, remote20.rootUuid);
|
||||||
|
|
||||||
// Check remote are inserted
|
// Check remote are inserted
|
||||||
|
|
||||||
final TypeOneToManyUUIDRoot retreiveRoot1 = DataAccess.get(TypeOneToManyUUIDRoot.class, insertedRoot.uuid);
|
final TypeOneToManyUUIDRoot retreiveRoot1 = this.da.get(TypeOneToManyUUIDRoot.class, insertedRoot.uuid);
|
||||||
Assertions.assertEquals(retreiveRoot1.otherData, insertedRoot.otherData);
|
Assertions.assertEquals(retreiveRoot1.otherData, insertedRoot.otherData);
|
||||||
Assertions.assertNotNull(retreiveRoot1.remoteIds);
|
Assertions.assertNotNull(retreiveRoot1.remoteIds);
|
||||||
Assertions.assertEquals(2, retreiveRoot1.remoteIds.size());
|
Assertions.assertEquals(2, retreiveRoot1.remoteIds.size());
|
||||||
Assertions.assertEquals(insertedRemote10.uuid, retreiveRoot1.remoteIds.get(0));
|
Assertions.assertEquals(insertedRemote10.uuid, retreiveRoot1.remoteIds.get(0));
|
||||||
Assertions.assertEquals(insertedRemote11.uuid, retreiveRoot1.remoteIds.get(1));
|
Assertions.assertEquals(insertedRemote11.uuid, retreiveRoot1.remoteIds.get(1));
|
||||||
|
|
||||||
final TypeOneToManyUUIDRoot retreiveRoot2 = DataAccess.get(TypeOneToManyUUIDRoot.class, insertedRoot2.uuid);
|
final TypeOneToManyUUIDRoot retreiveRoot2 = this.da.get(TypeOneToManyUUIDRoot.class, insertedRoot2.uuid);
|
||||||
Assertions.assertEquals(retreiveRoot2.otherData, insertedRoot2.otherData);
|
Assertions.assertEquals(retreiveRoot2.otherData, insertedRoot2.otherData);
|
||||||
Assertions.assertNotNull(retreiveRoot2.remoteIds);
|
Assertions.assertNotNull(retreiveRoot2.remoteIds);
|
||||||
Assertions.assertEquals(1, retreiveRoot2.remoteIds.size());
|
Assertions.assertEquals(1, retreiveRoot2.remoteIds.size());
|
||||||
@ -188,7 +196,7 @@ public class TestOneToMany {
|
|||||||
|
|
||||||
// Check remote are inserted and expandable
|
// Check remote are inserted and expandable
|
||||||
|
|
||||||
final TypeOneToManyUUIDRootExpand retreiveRootExpand1 = DataAccess.get(TypeOneToManyUUIDRootExpand.class,
|
final TypeOneToManyUUIDRootExpand retreiveRootExpand1 = this.da.get(TypeOneToManyUUIDRootExpand.class,
|
||||||
insertedRoot.uuid);
|
insertedRoot.uuid);
|
||||||
Assertions.assertEquals(retreiveRootExpand1.otherData, insertedRoot.otherData);
|
Assertions.assertEquals(retreiveRootExpand1.otherData, insertedRoot.otherData);
|
||||||
Assertions.assertNotNull(retreiveRootExpand1.remotes);
|
Assertions.assertNotNull(retreiveRootExpand1.remotes);
|
||||||
@ -200,7 +208,7 @@ public class TestOneToMany {
|
|||||||
Assertions.assertEquals(insertedRemote11.rootUuid, retreiveRootExpand1.remotes.get(1).rootUuid);
|
Assertions.assertEquals(insertedRemote11.rootUuid, retreiveRootExpand1.remotes.get(1).rootUuid);
|
||||||
Assertions.assertEquals(insertedRemote11.data, retreiveRootExpand1.remotes.get(1).data);
|
Assertions.assertEquals(insertedRemote11.data, retreiveRootExpand1.remotes.get(1).data);
|
||||||
|
|
||||||
final TypeOneToManyUUIDRootExpand retreiveRootExpand2 = DataAccess.get(TypeOneToManyUUIDRootExpand.class,
|
final TypeOneToManyUUIDRootExpand retreiveRootExpand2 = this.da.get(TypeOneToManyUUIDRootExpand.class,
|
||||||
insertedRoot2.uuid);
|
insertedRoot2.uuid);
|
||||||
Assertions.assertEquals(retreiveRootExpand2.otherData, insertedRoot2.otherData);
|
Assertions.assertEquals(retreiveRootExpand2.otherData, insertedRoot2.otherData);
|
||||||
Assertions.assertNotNull(retreiveRootExpand2.remotes);
|
Assertions.assertNotNull(retreiveRootExpand2.remotes);
|
||||||
@ -210,4 +218,4 @@ public class TestOneToMany {
|
|||||||
Assertions.assertEquals(insertedRemote20.data, retreiveRootExpand2.remotes.get(0).data);
|
Assertions.assertEquals(insertedRemote20.data, retreiveRootExpand2.remotes.get(0).data);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -23,6 +24,8 @@ import test.kar.archidata.model.TypesTable;
|
|||||||
public class TestRawQuery {
|
public class TestRawQuery {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypes.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypes.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
ConfigureDb.configure();
|
ConfigureDb.configure();
|
||||||
@ -33,75 +36,88 @@ public class TestRawQuery {
|
|||||||
ConfigureDb.clear();
|
ConfigureDb.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestRawQuery() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
|
LOGGER.error("lkjddlkj");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@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) {
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
for (final String elem : sqlCommand) {
|
||||||
DataAccess.executeSimpleQuery(elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
daSQL.executeSimpleQuery(elem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testGet() throws Exception {
|
public void testGet() throws Exception {
|
||||||
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
|
|
||||||
final TypesTable test = new TypesTable();
|
final TypesTable test = new TypesTable();
|
||||||
test.intData = 95;
|
test.intData = 95;
|
||||||
test.floatData = 1.0F;
|
test.floatData = 1.0F;
|
||||||
DataAccess.insert(test);
|
this.da.insert(test);
|
||||||
test.intData = 96;
|
test.intData = 96;
|
||||||
test.floatData = 2.0F;
|
test.floatData = 2.0F;
|
||||||
DataAccess.insert(test);
|
this.da.insert(test);
|
||||||
test.intData = 97;
|
test.intData = 97;
|
||||||
test.floatData = 3.0F;
|
test.floatData = 3.0F;
|
||||||
DataAccess.insert(test);
|
this.da.insert(test);
|
||||||
test.intData = 98;
|
test.intData = 98;
|
||||||
test.floatData = 4.0F;
|
test.floatData = 4.0F;
|
||||||
DataAccess.insert(test);
|
this.da.insert(test);
|
||||||
test.intData = 99;
|
test.intData = 99;
|
||||||
test.floatData = 5.0F;
|
test.floatData = 5.0F;
|
||||||
DataAccess.insert(test);
|
this.da.insert(test);
|
||||||
test.intData = 99;
|
test.intData = 99;
|
||||||
test.floatData = 6.0F;
|
test.floatData = 6.0F;
|
||||||
DataAccess.insert(test);
|
this.da.insert(test);
|
||||||
test.intData = 99;
|
test.intData = 99;
|
||||||
test.floatData = 7.0F;
|
test.floatData = 7.0F;
|
||||||
DataAccess.insert(test);
|
this.da.insert(test);
|
||||||
{
|
{
|
||||||
final String query = """
|
final String query = """
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM TypesTable
|
FROM TypesTable
|
||||||
WHERE `intData` = ?
|
WHERE `intData` = ?
|
||||||
ORDER BY id DESC
|
ORDER BY id DESC
|
||||||
""";
|
""";
|
||||||
final List<Object> parameters = List.of(Integer.valueOf(99));
|
final List<Object> parameters = List.of(Integer.valueOf(99));
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final List<TypesTable> retrieve = DataAccess.query(TypesTable.class, query, parameters);
|
final List<TypesTable> retrieve = daSQL.query(TypesTable.class, query, parameters);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertEquals(3, retrieve.size());
|
Assertions.assertEquals(3, retrieve.size());
|
||||||
Assertions.assertEquals(99, retrieve.get(0).intData);
|
Assertions.assertEquals(99, retrieve.get(0).intData);
|
||||||
Assertions.assertEquals(7.0F, retrieve.get(0).floatData);
|
Assertions.assertEquals(7.0F, retrieve.get(0).floatData);
|
||||||
Assertions.assertEquals(6.0F, retrieve.get(1).floatData);
|
Assertions.assertEquals(6.0F, retrieve.get(1).floatData);
|
||||||
Assertions.assertEquals(5.0F, retrieve.get(2).floatData);
|
Assertions.assertEquals(5.0F, retrieve.get(2).floatData);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
||||||
final String query = """
|
final String query = """
|
||||||
SELECT DISTINCT intData
|
SELECT DISTINCT intData
|
||||||
FROM TypesTable
|
FROM TypesTable
|
||||||
WHERE `intData` = ?
|
WHERE `intData` = ?
|
||||||
ORDER BY id DESC
|
ORDER BY id DESC
|
||||||
""";
|
""";
|
||||||
final List<Object> parameters = List.of(Integer.valueOf(99));
|
final List<Object> parameters = List.of(Integer.valueOf(99));
|
||||||
// Try to retrieve all the data:
|
// Try to retrieve all the data:
|
||||||
final List<TypesTable> retrieve = DataAccess.query(TypesTable.class, query, parameters);
|
final List<TypesTable> retrieve = daSQL.query(TypesTable.class, query, parameters);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertEquals(1, retrieve.size());
|
Assertions.assertEquals(1, retrieve.size());
|
||||||
Assertions.assertEquals(99, retrieve.get(0).intData);
|
Assertions.assertEquals(99, retrieve.get(0).intData);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("Not a SQL DB ...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.kar.archidata.dataAccess.QueryOptions;
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -31,6 +32,8 @@ public class TestSimpleTable {
|
|||||||
private static Long idOfTheObject = null;
|
private static Long idOfTheObject = null;
|
||||||
private static Timestamp startAction = null;
|
private static Timestamp startAction = null;
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
// Clear the static test:
|
// Clear the static test:
|
||||||
@ -44,25 +47,31 @@ public class TestSimpleTable {
|
|||||||
ConfigureDb.clear();
|
ConfigureDb.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestSimpleTable() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testTableInsertAndRetrieve() throws Exception {
|
public void testTableInsertAndRetrieve() throws Exception {
|
||||||
TestSimpleTable.startAction = Timestamp.from(Instant.now());
|
TestSimpleTable.startAction = Timestamp.from(Instant.now());
|
||||||
final List<String> sqlCommand = DataFactory.createTable(SimpleTable.class);
|
final List<String> sqlCommand = DataFactory.createTable(SimpleTable.class);
|
||||||
for (final String elem : sqlCommand) {
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
for (final String elem : sqlCommand) {
|
||||||
DataAccess.executeSimpleQuery(elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
daSQL.executeSimpleQuery(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 = this.da.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 = this.da.get(SimpleTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -77,7 +86,7 @@ public class TestSimpleTable {
|
|||||||
@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,
|
final SimpleTable retrieve = this.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||||
QueryOptions.READ_ALL_COLOMN);
|
QueryOptions.READ_ALL_COLOMN);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
@ -100,8 +109,8 @@ public class TestSimpleTable {
|
|||||||
// Delete the entry:
|
// Delete the entry:
|
||||||
final SimpleTable test = new SimpleTable();
|
final SimpleTable test = new SimpleTable();
|
||||||
test.data = TestSimpleTable.DATA_INJECTED_2;
|
test.data = TestSimpleTable.DATA_INJECTED_2;
|
||||||
DataAccess.update(test, TestSimpleTable.idOfTheObject, List.of("data"));
|
this.da.update(test, TestSimpleTable.idOfTheObject, List.of("data"));
|
||||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
final SimpleTable retrieve = this.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||||
QueryOptions.READ_ALL_COLOMN);
|
QueryOptions.READ_ALL_COLOMN);
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -117,8 +126,8 @@ public class TestSimpleTable {
|
|||||||
@Test
|
@Test
|
||||||
public void testDeleteTheObject() throws Exception {
|
public void testDeleteTheObject() throws Exception {
|
||||||
// Delete the entry:
|
// Delete the entry:
|
||||||
DataAccess.delete(SimpleTable.class, TestSimpleTable.idOfTheObject);
|
this.da.delete(SimpleTable.class, TestSimpleTable.idOfTheObject);
|
||||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject);
|
final SimpleTable retrieve = this.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject);
|
||||||
Assertions.assertNull(retrieve);
|
Assertions.assertNull(retrieve);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +136,7 @@ public class TestSimpleTable {
|
|||||||
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,
|
final SimpleTable retrieve = this.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||||
QueryOptions.ACCESS_DELETED_ITEMS);
|
QueryOptions.ACCESS_DELETED_ITEMS);
|
||||||
Assertions.assertNull(retrieve);
|
Assertions.assertNull(retrieve);
|
||||||
|
|
||||||
@ -137,7 +146,7 @@ public class TestSimpleTable {
|
|||||||
@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,
|
final SimpleTable retrieve = this.da.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||||
QueryOptions.ACCESS_DELETED_ITEMS, QueryOptions.READ_ALL_COLOMN);
|
QueryOptions.ACCESS_DELETED_ITEMS, QueryOptions.READ_ALL_COLOMN);
|
||||||
Assertions.assertNull(retrieve);
|
Assertions.assertNull(retrieve);
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.kar.archidata.dataAccess.QueryOptions;
|
import org.kar.archidata.dataAccess.QueryOptions;
|
||||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||||
@ -32,6 +33,8 @@ public class TestSimpleTableSoftDelete {
|
|||||||
private static Long idOfTheObject = null;
|
private static Long idOfTheObject = null;
|
||||||
private static Timestamp startAction = null;
|
private static Timestamp startAction = null;
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
// Clear the static test:
|
// Clear the static test:
|
||||||
@ -46,25 +49,31 @@ public class TestSimpleTableSoftDelete {
|
|||||||
ConfigureDb.clear();
|
ConfigureDb.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestSimpleTableSoftDelete() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testTableInsertAndRetrieve() throws Exception {
|
public void testTableInsertAndRetrieve() throws Exception {
|
||||||
TestSimpleTableSoftDelete.startAction = Timestamp.from(Instant.now());
|
TestSimpleTableSoftDelete.startAction = Timestamp.from(Instant.now());
|
||||||
final List<String> sqlCommand = DataFactory.createTable(SimpleTableSoftDelete.class);
|
final List<String> sqlCommand = DataFactory.createTable(SimpleTableSoftDelete.class);
|
||||||
for (final String elem : sqlCommand) {
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
for (final String elem : sqlCommand) {
|
||||||
DataAccess.executeSimpleQuery(elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
daSQL.executeSimpleQuery(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 = this.da.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 = this.da.get(SimpleTableSoftDelete.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -80,7 +89,7 @@ public class TestSimpleTableSoftDelete {
|
|||||||
@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,
|
final SimpleTableSoftDelete retrieve = this.da.get(SimpleTableSoftDelete.class,
|
||||||
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.READ_ALL_COLOMN);
|
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.READ_ALL_COLOMN);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
@ -107,8 +116,8 @@ public class TestSimpleTableSoftDelete {
|
|||||||
// 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;
|
||||||
DataAccess.update(test, TestSimpleTableSoftDelete.idOfTheObject, List.of("data"));
|
this.da.update(test, TestSimpleTableSoftDelete.idOfTheObject, List.of("data"));
|
||||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class,
|
final SimpleTableSoftDelete retrieve = this.da.get(SimpleTableSoftDelete.class,
|
||||||
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS,
|
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS,
|
||||||
QueryOptions.READ_ALL_COLOMN);
|
QueryOptions.READ_ALL_COLOMN);
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
@ -132,8 +141,8 @@ public class TestSimpleTableSoftDelete {
|
|||||||
Thread.sleep(Duration.ofMillis(15));
|
Thread.sleep(Duration.ofMillis(15));
|
||||||
}
|
}
|
||||||
// Delete the entry:
|
// Delete the entry:
|
||||||
DataAccess.delete(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject);
|
this.da.delete(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject);
|
||||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class,
|
final SimpleTableSoftDelete retrieve = this.da.get(SimpleTableSoftDelete.class,
|
||||||
TestSimpleTableSoftDelete.idOfTheObject);
|
TestSimpleTableSoftDelete.idOfTheObject);
|
||||||
Assertions.assertNull(retrieve);
|
Assertions.assertNull(retrieve);
|
||||||
}
|
}
|
||||||
@ -143,7 +152,7 @@ public class TestSimpleTableSoftDelete {
|
|||||||
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,
|
final SimpleTableSoftDelete retrieve = this.da.get(SimpleTableSoftDelete.class,
|
||||||
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS);
|
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS);
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -159,7 +168,7 @@ public class TestSimpleTableSoftDelete {
|
|||||||
@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 SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class,
|
final SimpleTableSoftDelete retrieve = this.da.get(SimpleTableSoftDelete.class,
|
||||||
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS,
|
TestSimpleTableSoftDelete.idOfTheObject, QueryOptions.ACCESS_DELETED_ITEMS,
|
||||||
QueryOptions.READ_ALL_COLOMN);
|
QueryOptions.READ_ALL_COLOMN);
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
|
@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -24,6 +25,8 @@ import test.kar.archidata.model.TypesEnum1;
|
|||||||
public class TestTypeEnum1 {
|
public class TestTypeEnum1 {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum1.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum1.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
ConfigureDb.configure();
|
ConfigureDb.configure();
|
||||||
@ -34,13 +37,19 @@ public class TestTypeEnum1 {
|
|||||||
ConfigureDb.clear();
|
ConfigureDb.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestTypeEnum1() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@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) {
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
for (final String elem : sqlCommand) {
|
||||||
DataAccess.executeSimpleQuery(elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
daSQL.executeSimpleQuery(elem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,13 +59,13 @@ public class TestTypeEnum1 {
|
|||||||
|
|
||||||
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 = this.da.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 = this.da.get(TypesEnum1.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -64,6 +73,6 @@ public class TestTypeEnum1 {
|
|||||||
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);
|
this.da.delete(TypesEnum1.class, insertedData.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -24,6 +25,8 @@ import test.kar.archidata.model.TypesEnum2;
|
|||||||
public class TestTypeEnum2 {
|
public class TestTypeEnum2 {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum2.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum2.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
ConfigureDb.configure();
|
ConfigureDb.configure();
|
||||||
@ -34,13 +37,19 @@ public class TestTypeEnum2 {
|
|||||||
ConfigureDb.clear();
|
ConfigureDb.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestTypeEnum2() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@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) {
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
for (final String elem : sqlCommand) {
|
||||||
DataAccess.executeSimpleQuery(elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
daSQL.executeSimpleQuery(elem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,13 +59,13 @@ public class TestTypeEnum2 {
|
|||||||
|
|
||||||
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 = this.da.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 = this.da.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);
|
||||||
@ -65,22 +74,22 @@ public class TestTypeEnum2 {
|
|||||||
|
|
||||||
// Update data to null
|
// Update data to null
|
||||||
retrieve.data = null;
|
retrieve.data = null;
|
||||||
int ret = DataAccess.update(retrieve, retrieve.id);
|
long ret = this.da.update(retrieve, retrieve.id);
|
||||||
Assertions.assertEquals(1, ret);
|
Assertions.assertEquals(1L, ret);
|
||||||
|
|
||||||
// get new data
|
// get new data
|
||||||
retrieve = DataAccess.get(TypesEnum2.class, insertedData.id);
|
retrieve = this.da.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 = this.da.delete(TypesEnum2.class, insertedData.id);
|
||||||
Assertions.assertEquals(1, ret);
|
Assertions.assertEquals(1L, ret);
|
||||||
|
|
||||||
// Get the removed data:
|
// Get the removed data:
|
||||||
retrieve = DataAccess.get(TypesEnum2.class, insertedData.id);
|
retrieve = this.da.get(TypesEnum2.class, insertedData.id);
|
||||||
Assertions.assertNull(retrieve);
|
Assertions.assertNull(retrieve);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,19 +99,19 @@ public class TestTypeEnum2 {
|
|||||||
|
|
||||||
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 = this.da.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 = this.da.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);
|
this.da.delete(TypesEnum2.class, insertedData.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
|
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||||
import org.kar.archidata.dataAccess.DataFactory;
|
import org.kar.archidata.dataAccess.DataFactory;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -28,6 +29,8 @@ import test.kar.archidata.model.TypesTable;
|
|||||||
public class TestTypes {
|
public class TestTypes {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypes.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypes.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
ConfigureDb.configure();
|
ConfigureDb.configure();
|
||||||
@ -38,13 +41,19 @@ public class TestTypes {
|
|||||||
ConfigureDb.clear();
|
ConfigureDb.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TestTypes() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@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) {
|
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||||
LOGGER.debug("request: '{}'", elem);
|
for (final String elem : sqlCommand) {
|
||||||
DataAccess.executeSimpleQuery(elem);
|
LOGGER.debug("request: '{}'", elem);
|
||||||
|
daSQL.executeSimpleQuery(elem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,13 +63,13 @@ public class TestTypes {
|
|||||||
|
|
||||||
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 = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -68,7 +77,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(3)
|
@Order(3)
|
||||||
@ -77,13 +86,13 @@ public class TestTypes {
|
|||||||
|
|
||||||
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 = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -91,7 +100,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(4)
|
@Order(4)
|
||||||
@ -100,13 +109,13 @@ public class TestTypes {
|
|||||||
|
|
||||||
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 = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -114,7 +123,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(5)
|
@Order(5)
|
||||||
@ -123,13 +132,13 @@ public class TestTypes {
|
|||||||
|
|
||||||
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 = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -137,7 +146,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(6)
|
@Order(6)
|
||||||
@ -146,13 +155,13 @@ public class TestTypes {
|
|||||||
|
|
||||||
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 = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -160,7 +169,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(7)
|
@Order(7)
|
||||||
@ -169,13 +178,13 @@ public class TestTypes {
|
|||||||
|
|
||||||
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 = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -183,7 +192,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(8)
|
@Order(8)
|
||||||
@ -192,13 +201,13 @@ public class TestTypes {
|
|||||||
|
|
||||||
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 = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -206,7 +215,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(9)
|
@Order(9)
|
||||||
@ -215,13 +224,13 @@ public class TestTypes {
|
|||||||
|
|
||||||
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 = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -229,7 +238,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(10)
|
@Order(10)
|
||||||
@ -239,13 +248,13 @@ public class TestTypes {
|
|||||||
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);
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -257,7 +266,7 @@ public class TestTypes {
|
|||||||
Assertions.assertEquals(insertedData.timeStampData.toInstant().toEpochMilli(),
|
Assertions.assertEquals(insertedData.timeStampData.toInstant().toEpochMilli(),
|
||||||
retrieve.timeStampData.toInstant().toEpochMilli());
|
retrieve.timeStampData.toInstant().toEpochMilli());
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(11)
|
@Order(11)
|
||||||
@ -267,13 +276,13 @@ public class TestTypes {
|
|||||||
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);
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -282,7 +291,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(12)
|
@Order(12)
|
||||||
@ -292,13 +301,13 @@ public class TestTypes {
|
|||||||
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);
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -307,7 +316,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(13)
|
@Order(13)
|
||||||
@ -317,13 +326,13 @@ public class TestTypes {
|
|||||||
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);
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -334,7 +343,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(14)
|
@Order(14)
|
||||||
@ -345,13 +354,13 @@ public class TestTypes {
|
|||||||
test.textData = "test 1";
|
test.textData = "test 1";
|
||||||
test.booleanData = null;
|
test.booleanData = null;
|
||||||
test.varcharData = "plop";
|
test.varcharData = "plop";
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -366,11 +375,11 @@ public class TestTypes {
|
|||||||
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 long nbUpdate = this.da.update(retrieve, insertedData.id);
|
||||||
Assertions.assertEquals(1, nbUpdate);
|
Assertions.assertEquals(1L, nbUpdate);
|
||||||
|
|
||||||
// Get new data
|
// Get new data
|
||||||
final TypesTable retrieve2 = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve2 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve2);
|
Assertions.assertNotNull(retrieve2);
|
||||||
Assertions.assertNotNull(retrieve2.id);
|
Assertions.assertNotNull(retrieve2.id);
|
||||||
@ -385,11 +394,11 @@ public class TestTypes {
|
|||||||
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 long nbUpdate2 = this.da.update(retrieve, insertedData.id, List.of("textData"));
|
||||||
Assertions.assertEquals(1, nbUpdate2);
|
Assertions.assertEquals(1L, nbUpdate2);
|
||||||
|
|
||||||
// Get new data
|
// Get new data
|
||||||
final TypesTable retrieve3 = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve3 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve3);
|
Assertions.assertNotNull(retrieve3);
|
||||||
Assertions.assertNotNull(retrieve3.id);
|
Assertions.assertNotNull(retrieve3.id);
|
||||||
@ -401,7 +410,7 @@ public class TestTypes {
|
|||||||
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);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(15)
|
@Order(15)
|
||||||
@ -412,13 +421,13 @@ public class TestTypes {
|
|||||||
test.textData = "test 1";
|
test.textData = "test 1";
|
||||||
test.booleanData = null;
|
test.booleanData = null;
|
||||||
test.varcharData = "plop";
|
test.varcharData = "plop";
|
||||||
final TypesTable insertedData = DataAccess.insert(test);
|
final TypesTable insertedData = this.da.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 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve);
|
Assertions.assertNotNull(retrieve);
|
||||||
Assertions.assertNotNull(retrieve.id);
|
Assertions.assertNotNull(retrieve.id);
|
||||||
@ -437,11 +446,11 @@ public class TestTypes {
|
|||||||
"varcharData": null
|
"varcharData": null
|
||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
final int nbUpdate = DataAccess.updateWithJson(TypesTable.class, insertedData.id, jsonData);
|
final long nbUpdate = this.da.updateWithJson(TypesTable.class, insertedData.id, jsonData);
|
||||||
Assertions.assertEquals(1, nbUpdate);
|
Assertions.assertEquals(1L, nbUpdate);
|
||||||
|
|
||||||
// Get new data
|
// Get new data
|
||||||
final TypesTable retrieve2 = DataAccess.get(TypesTable.class, insertedData.id);
|
final TypesTable retrieve2 = this.da.get(TypesTable.class, insertedData.id);
|
||||||
|
|
||||||
Assertions.assertNotNull(retrieve2);
|
Assertions.assertNotNull(retrieve2);
|
||||||
Assertions.assertNotNull(retrieve2.id);
|
Assertions.assertNotNull(retrieve2.id);
|
||||||
@ -452,7 +461,7 @@ public class TestTypes {
|
|||||||
Assertions.assertEquals(true, retrieve2.booleanData);
|
Assertions.assertEquals(true, retrieve2.booleanData);
|
||||||
Assertions.assertNull(retrieve2.varcharData);
|
Assertions.assertNull(retrieve2.varcharData);
|
||||||
|
|
||||||
DataAccess.delete(TypesTable.class, insertedData.id);
|
this.da.delete(TypesTable.class, insertedData.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,12 @@ import org.junit.jupiter.api.TestMethodOrder;
|
|||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.GlobalConfiguration;
|
import org.kar.archidata.GlobalConfiguration;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.db.DBEntry;
|
|
||||||
import org.kar.archidata.migration.MigrationEngine;
|
import org.kar.archidata.migration.MigrationEngine;
|
||||||
import org.kar.archidata.migration.MigrationException;
|
import org.kar.archidata.migration.MigrationException;
|
||||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import test.kar.archidata.ConfigureDb;
|
||||||
import test.kar.archidata.StepwiseExtension;
|
import test.kar.archidata.StepwiseExtension;
|
||||||
import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
||||||
|
|
||||||
@ -27,37 +26,33 @@ import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
|||||||
public class TestMigrationFail {
|
public class TestMigrationFail {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFirstInit.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFirstInit.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
|
public TestMigrationFail() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
ConfigureDb.configure();
|
||||||
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
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
ConfigureDb.clear();
|
||||||
DBEntry.closeAllForceMode();
|
|
||||||
ConfigBaseVariable.clearAllValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testInitializeTable() throws Exception {
|
public void testInitializeTable() throws Exception {
|
||||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||||
// add initialization:
|
// add initialization:
|
||||||
migrationEngine.setInit(new InitializationFirst());
|
migrationEngine.setInit(new InitializationFirst());
|
||||||
migrationEngine.migrateErrorThrow(GlobalConfiguration.dbConfig);
|
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
|
||||||
|
|
||||||
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
|
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
|
||||||
test.testData = 95.0;
|
test.testData = 95.0;
|
||||||
final TypesMigrationInitialisationFirst insertedData = DataAccess.insert(test);
|
final TypesMigrationInitialisationFirst insertedData = this.da.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertEquals(95.0, insertedData.testData);
|
Assertions.assertEquals(95.0, insertedData.testData);
|
||||||
}
|
}
|
||||||
@ -65,14 +60,14 @@ public class TestMigrationFail {
|
|||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateTwoMigration() throws Exception {
|
public void testUpdateTwoMigration() throws Exception {
|
||||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||||
// add initialization:
|
// add initialization:
|
||||||
migrationEngine.setInit(new InitializationCurrent());
|
migrationEngine.setInit(new InitializationCurrent());
|
||||||
migrationEngine.add(new Migration1());
|
migrationEngine.add(new Migration1());
|
||||||
migrationEngine.add(new MigrationFail());
|
migrationEngine.add(new MigrationFail());
|
||||||
Assertions.assertThrows(MigrationException.class, () -> {
|
Assertions.assertThrows(MigrationException.class, () -> {
|
||||||
migrationEngine.migrateErrorThrow(GlobalConfiguration.dbConfig);
|
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,11 @@ import org.junit.jupiter.api.TestMethodOrder;
|
|||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.GlobalConfiguration;
|
import org.kar.archidata.GlobalConfiguration;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.db.DBEntry;
|
|
||||||
import org.kar.archidata.migration.MigrationEngine;
|
import org.kar.archidata.migration.MigrationEngine;
|
||||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import test.kar.archidata.ConfigureDb;
|
||||||
import test.kar.archidata.StepwiseExtension;
|
import test.kar.archidata.StepwiseExtension;
|
||||||
import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
|
import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
|
||||||
import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
||||||
@ -27,37 +26,33 @@ import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
|||||||
public class TestMigrationFirstInit {
|
public class TestMigrationFirstInit {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFail.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFail.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
|
public TestMigrationFirstInit() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
ConfigureDb.configure();
|
||||||
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
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
ConfigureDb.clear();
|
||||||
DBEntry.closeAllForceMode();
|
|
||||||
ConfigBaseVariable.clearAllValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testInitialMigration() throws Exception {
|
public void testInitialMigration() throws Exception {
|
||||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||||
// add initialization:
|
// add initialization:
|
||||||
migrationEngine.setInit(new InitializationFirst());
|
migrationEngine.setInit(new InitializationFirst());
|
||||||
migrationEngine.migrateErrorThrow(GlobalConfiguration.dbConfig);
|
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
|
||||||
|
|
||||||
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
|
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
|
||||||
test.testData = 95.0;
|
test.testData = 95.0;
|
||||||
final TypesMigrationInitialisationFirst insertedData = DataAccess.insert(test);
|
final TypesMigrationInitialisationFirst insertedData = this.da.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertEquals(95.0, insertedData.testData);
|
Assertions.assertEquals(95.0, insertedData.testData);
|
||||||
}
|
}
|
||||||
@ -65,14 +60,14 @@ public class TestMigrationFirstInit {
|
|||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testInitialMigrationReopen() throws Exception {
|
public void testInitialMigrationReopen() throws Exception {
|
||||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||||
// add initialization:
|
// add initialization:
|
||||||
migrationEngine.setInit(new InitializationFirst());
|
migrationEngine.setInit(new InitializationFirst());
|
||||||
migrationEngine.migrateErrorThrow(GlobalConfiguration.dbConfig);
|
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
|
||||||
|
|
||||||
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
|
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
|
||||||
test.testData = 99.0;
|
test.testData = 99.0;
|
||||||
final TypesMigrationInitialisationFirst insertedData = DataAccess.insert(test);
|
final TypesMigrationInitialisationFirst insertedData = this.da.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertEquals(99.0, insertedData.testData);
|
Assertions.assertEquals(99.0, insertedData.testData);
|
||||||
}
|
}
|
||||||
@ -80,16 +75,16 @@ public class TestMigrationFirstInit {
|
|||||||
@Order(3)
|
@Order(3)
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateTwoMigration() throws Exception {
|
public void testUpdateTwoMigration() throws Exception {
|
||||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||||
// add initialization:
|
// add initialization:
|
||||||
migrationEngine.setInit(new InitializationCurrent());
|
migrationEngine.setInit(new InitializationCurrent());
|
||||||
migrationEngine.add(new Migration1());
|
migrationEngine.add(new Migration1());
|
||||||
migrationEngine.add(new Migration2());
|
migrationEngine.add(new Migration2());
|
||||||
migrationEngine.migrateErrorThrow(GlobalConfiguration.dbConfig);
|
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
|
||||||
|
|
||||||
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
||||||
test.testDataMigration2 = 125.0;
|
test.testDataMigration2 = 125.0;
|
||||||
final TypesMigrationInitialisationCurrent insertedData = DataAccess.insert(test);
|
final TypesMigrationInitialisationCurrent insertedData = this.da.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertEquals(125.0, insertedData.testDataMigration2);
|
Assertions.assertEquals(125.0, insertedData.testDataMigration2);
|
||||||
}
|
}
|
||||||
@ -97,17 +92,17 @@ public class TestMigrationFirstInit {
|
|||||||
@Order(4)
|
@Order(4)
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateTwoMigrationReopen() throws Exception {
|
public void testUpdateTwoMigrationReopen() throws Exception {
|
||||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||||
// add initialization:
|
// add initialization:
|
||||||
migrationEngine.setInit(new InitializationCurrent());
|
migrationEngine.setInit(new InitializationCurrent());
|
||||||
migrationEngine.add(new Migration1());
|
migrationEngine.add(new Migration1());
|
||||||
migrationEngine.add(new Migration2());
|
migrationEngine.add(new Migration2());
|
||||||
migrationEngine.migrateErrorThrow(GlobalConfiguration.dbConfig);
|
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
|
||||||
|
|
||||||
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
||||||
test.testDataMigration2 = 2563.0;
|
test.testDataMigration2 = 2563.0;
|
||||||
final TypesMigrationInitialisationCurrent insertedData = DataAccess.insert(test);
|
final TypesMigrationInitialisationCurrent insertedData = this.da.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertEquals(2563.0, insertedData.testDataMigration2);
|
Assertions.assertEquals(2563.0, insertedData.testDataMigration2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,12 @@ import org.junit.jupiter.api.TestMethodOrder;
|
|||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.kar.archidata.GlobalConfiguration;
|
import org.kar.archidata.GlobalConfiguration;
|
||||||
import org.kar.archidata.dataAccess.DataAccess;
|
import org.kar.archidata.dataAccess.DataAccess;
|
||||||
import org.kar.archidata.db.DBEntry;
|
|
||||||
import org.kar.archidata.migration.MigrationEngine;
|
import org.kar.archidata.migration.MigrationEngine;
|
||||||
import org.kar.archidata.migration.model.Migration;
|
import org.kar.archidata.migration.model.Migration;
|
||||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import test.kar.archidata.ConfigureDb;
|
||||||
import test.kar.archidata.StepwiseExtension;
|
import test.kar.archidata.StepwiseExtension;
|
||||||
import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
|
import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
|
||||||
|
|
||||||
@ -28,44 +27,40 @@ import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
|
|||||||
public class TestMigrationFirstInitWithMigration {
|
public class TestMigrationFirstInitWithMigration {
|
||||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFirstInitWithMigration.class);
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFirstInitWithMigration.class);
|
||||||
|
|
||||||
|
private DataAccess da = null;
|
||||||
|
|
||||||
|
public TestMigrationFirstInitWithMigration() {
|
||||||
|
this.da = DataAccess.createInterface();
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void configureWebServer() throws Exception {
|
public static void configureWebServer() throws Exception {
|
||||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
ConfigureDb.configure();
|
||||||
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
|
@AfterAll
|
||||||
public static void removeDataBase() throws IOException {
|
public static void removeDataBase() throws IOException {
|
||||||
LOGGER.info("Remove the test db");
|
ConfigureDb.clear();
|
||||||
DBEntry.closeAllForceMode();
|
|
||||||
ConfigBaseVariable.clearAllValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Order(1)
|
@Order(1)
|
||||||
@Test
|
@Test
|
||||||
public void testInitialMigration() throws Exception {
|
public void testInitialMigration() throws Exception {
|
||||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||||
// add initialization:
|
// add initialization:
|
||||||
migrationEngine.setInit(new InitializationCurrent());
|
migrationEngine.setInit(new InitializationCurrent());
|
||||||
// add migration for old version
|
// add migration for old version
|
||||||
migrationEngine.add(new Migration1());
|
migrationEngine.add(new Migration1());
|
||||||
migrationEngine.add(new Migration2());
|
migrationEngine.add(new Migration2());
|
||||||
migrationEngine.migrateErrorThrow(GlobalConfiguration.dbConfig);
|
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
|
||||||
|
|
||||||
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
||||||
test.testDataMigration2 = 95.0;
|
test.testDataMigration2 = 95.0;
|
||||||
final TypesMigrationInitialisationCurrent insertedData = DataAccess.insert(test);
|
final TypesMigrationInitialisationCurrent insertedData = this.da.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertEquals(95.0, insertedData.testDataMigration2);
|
Assertions.assertEquals(95.0, insertedData.testDataMigration2);
|
||||||
|
|
||||||
final List<Migration> elements = DataAccess.gets(Migration.class);
|
final List<Migration> elements = this.da.gets(Migration.class);
|
||||||
LOGGER.info("List of migrations:");
|
LOGGER.info("List of migrations:");
|
||||||
for (final Migration elem : elements) {
|
for (final Migration elem : elements) {
|
||||||
LOGGER.info(" - {} => {}", elem.id, elem.name);
|
LOGGER.info(" - {} => {}", elem.id, elem.name);
|
||||||
@ -75,18 +70,18 @@ public class TestMigrationFirstInitWithMigration {
|
|||||||
@Order(2)
|
@Order(2)
|
||||||
@Test
|
@Test
|
||||||
public void testInitialMigrationReopen() throws Exception {
|
public void testInitialMigrationReopen() throws Exception {
|
||||||
final MigrationEngine migrationEngine = new MigrationEngine();
|
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
|
||||||
// add initialization:
|
// add initialization:
|
||||||
migrationEngine.setInit(new InitializationCurrent());
|
migrationEngine.setInit(new InitializationCurrent());
|
||||||
// add migration for old version
|
// add migration for old version
|
||||||
migrationEngine.add(new Migration1());
|
migrationEngine.add(new Migration1());
|
||||||
migrationEngine.add(new Migration2());
|
migrationEngine.add(new Migration2());
|
||||||
migrationEngine.migrateErrorThrow(GlobalConfiguration.dbConfig);
|
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
|
||||||
|
|
||||||
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
|
||||||
test.testDataMigration2 = 99.0;
|
test.testDataMigration2 = 99.0;
|
||||||
final TypesMigrationInitialisationCurrent insertedData = DataAccess.insert(test);
|
final TypesMigrationInitialisationCurrent insertedData = this.da.insert(test);
|
||||||
Assertions.assertNotNull(insertedData);
|
Assertions.assertNotNull(insertedData);
|
||||||
Assertions.assertEquals(99.0, insertedData.testDataMigration2);
|
Assertions.assertEquals(99.0, insertedData.testDataMigration2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user