Compare commits

...

8 Commits

26 changed files with 614 additions and 133 deletions

View File

@ -250,6 +250,14 @@ public class DataAccess {
return out;
}
public static UUID getListOfRawUUID(final ResultSet rs, final int iii) throws SQLException, DataAccessException {
final byte[] elem = rs.getBytes(iii);
if (rs.wasNull()) {
return null;
}
return UuidUtils.asUuid(elem);
}
protected static <T> void setValuedb(
final Class<?> type,
final T data,

View File

@ -172,6 +172,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
}
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
.getActualTypeArguments()[0];
// TODO: manage better the eager and lazy !!
if (objectClass == Long.class || objectClass == UUID.class) {
generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options);
}

View File

@ -238,7 +238,11 @@ public class AddOnManyToOne implements DataAccessAddOn {
if (dataNew != null && countNotNull.value != 0) {
field.set(data, dataNew);
}
} else {
return;
}
final Field remotePrimaryKeyField = AnnotationTools.getFieldOfId(objectClass);
final Class<?> remotePrimaryKeyType = remotePrimaryKeyField.getType();
if (remotePrimaryKeyType == Long.class) {
// here we have the field, the data and the the remote value ==> can create callback that generate the update of the value ...
final Long foreignKey = rs.getLong(count.value);
count.inc();
@ -254,6 +258,22 @@ public class AddOnManyToOne implements DataAccessAddOn {
};
lazyCall.add(lambda);
}
} 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 ...
final UUID foreignKey = DataAccess.getListOfRawUUID(rs, count.value);
count.inc();
if (foreignKey != null) {
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
final LazyGetter lambda = () -> {
// TODO: update to have get with abstract types ....
final Object foreignData = DataAccess.get(decorators.targetEntity(), foreignKey);
if (foreignData == null) {
return;
}
field.set(data, foreignData);
};
lazyCall.add(lambda);
}
}
}
}

View File

@ -5,7 +5,6 @@ import java.lang.reflect.ParameterizedType;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@ -21,6 +20,7 @@ import org.kar.archidata.dataAccess.QueryCondition;
import org.kar.archidata.dataAccess.QueryOptions;
import org.kar.archidata.dataAccess.options.Condition;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -85,15 +85,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
@Override
public void insertData(final PreparedStatement ps, final Field field, final Object rootObject, final CountInOut iii)
throws SQLException, IllegalArgumentException, IllegalAccessException {
final Object data = field.get(rootObject);
iii.inc();
if (data == null) {
ps.setNull(iii.value, Types.BIGINT);
} else {
@SuppressWarnings("unchecked")
final String dataTmp = getStringOfIds((List<Long>) data);
ps.setString(iii.value, dataTmp);
}
throw new IllegalAccessException("Can not generate an inset of @OneToMany");
}
@Override
@ -103,6 +95,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
@Override
public boolean isInsertAsync(final Field field) throws Exception {
// TODO: can be implemented later...
return false;
}
@ -126,6 +119,64 @@ public class AddOnOneToMany implements DataAccessAddOn {
return false;
}
public void generateConcatQuery(
@NotNull final String tableName,
@NotNull final String primaryKey,
@NotNull final Field field,
@NotNull final StringBuilder querySelect,
@NotNull final StringBuilder query,
@NotNull final String name,
@NotNull final CountInOut count,
final QueryOptions options,
final Class<?> targetEntity,
final String mappedBy) throws Exception {
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
.getActualTypeArguments()[0];
final String remoteTableName = AnnotationTools.getTableName(targetEntity);
final String remoteTablePrimaryKeyName = AnnotationTools
.getFieldName(AnnotationTools.getPrimaryKeyField(targetEntity));
final String tmpRemoteVariable = "tmp_" + Integer.toString(count.value);
final String remoteDeletedFieldName = AnnotationTools.getDeletedFieldName(targetEntity);
querySelect.append(" (SELECT GROUP_CONCAT(");
querySelect.append(tmpRemoteVariable);
querySelect.append(".");
querySelect.append(remoteTablePrimaryKeyName);
querySelect.append(" ");
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
querySelect.append(", ");
} else {
querySelect.append("SEPARATOR ");
}
querySelect.append("'");
if (objectClass == Long.class) {
querySelect.append(SEPARATOR_LONG);
}
querySelect.append("') FROM ");
querySelect.append(remoteTableName);
querySelect.append(" ");
querySelect.append(tmpRemoteVariable);
querySelect.append(" WHERE ");
if (remoteDeletedFieldName != null) {
querySelect.append(tmpRemoteVariable);
querySelect.append(".");
querySelect.append(remoteDeletedFieldName);
querySelect.append(" = false");
querySelect.append(" AND ");
}
querySelect.append(tableName);
querySelect.append(".");
querySelect.append(primaryKey);
querySelect.append(" = ");
querySelect.append(tmpRemoteVariable);
querySelect.append(".");
querySelect.append(mappedBy);
querySelect.append(" ");
querySelect.append(") AS ");
querySelect.append(name);
querySelect.append(" ");
}
@Override
public void generateQuery(
@NotNull final String tableName,
@ -135,17 +186,35 @@ public class AddOnOneToMany implements DataAccessAddOn {
@NotNull final StringBuilder query,
@NotNull final String name,
@NotNull final CountInOut count,
final QueryOptions options) {
final QueryOptions options) throws Exception {
if (field.getType() != List.class) {
return;
}
// Force a copy of the primaryKey to permit the async retrieve of the data
querySelect.append(" ");
querySelect.append(tableName);
querySelect.append(".");
querySelect.append(primaryKey);
querySelect.append(" AS tmp_");
querySelect.append(Integer.toString(count.value));
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
.getActualTypeArguments()[0];
final OneToMany decorators = field.getDeclaredAnnotation(OneToMany.class);
if (decorators == null) {
return;
}
// TODO: manage better the eager and lazy !!
if (objectClass == Long.class || objectClass == UUID.class) {
generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options,
decorators.targetEntity(), decorators.mappedBy());
return;
}
if (objectClass == decorators.targetEntity()) {
if (decorators.fetch() == FetchType.EAGER) {
throw new DataAccessException("EAGER is not supported for list of element...");
} else {
// Force a copy of the primaryKey to permit the async retrieve of the data
querySelect.append(" ");
querySelect.append(tableName);
querySelect.append(".");
querySelect.append(primaryKey);
querySelect.append(" AS tmp_");
querySelect.append(Integer.toString(count.value));
}
}
}
@Override
@ -160,64 +229,76 @@ public class AddOnOneToMany implements DataAccessAddOn {
LOGGER.error("Can not OneToMany with other than List Model: {}", field.getType().getCanonicalName());
return;
}
Long parentIdTmp = null;
UUID parendUuidTmp = null;
try {
final String modelData = rs.getString(count.value);
parentIdTmp = Long.valueOf(modelData);
count.inc();
} catch (final NumberFormatException ex) {
final List<UUID> idList = DataAccess.getListOfRawUUIDs(rs, count.value);
parendUuidTmp = idList.get(0);
count.inc();
}
final Long parentId = parentIdTmp;
final UUID parendUuid = parendUuidTmp;
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
.getActualTypeArguments()[0];
final OneToMany decorators = field.getDeclaredAnnotation(OneToMany.class);
if (decorators == null) {
return;
}
final String mappingKey = decorators.mappedBy();
// We get the parent ID ... ==> need to request the list of elements
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
.getActualTypeArguments()[0];
if (objectClass == Long.class) {
LOGGER.error("Need to retreive all primary key of all elements");
//field.set(data, idList);
final List<Long> idList = DataAccess.getListOfIds(rs, count.value, SEPARATOR_LONG);
field.set(data, idList);
count.inc();
return;
} else if (objectClass == UUID.class) {
LOGGER.error("Need to retreive all primary key of all elements");
//field.set(data, idList);
final List<UUID> idList = DataAccess.getListOfRawUUIDs(rs, count.value);
field.set(data, idList);
count.inc();
return;
}
if (objectClass == decorators.targetEntity()) {
if (decorators.fetch() == FetchType.EAGER) {
throw new DataAccessException("EAGER is not supported for list of element...");
} else if (parentId != null) {
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
final LazyGetter lambda = () -> {
@SuppressWarnings("unchecked")
final Object foreignData = DataAccess.getsWhere(decorators.targetEntity(),
new Condition(new QueryCondition(mappingKey, "=", parentId)));
if (foreignData == null) {
return;
}
field.set(data, foreignData);
};
lazyCall.add(lambda);
} else if (parendUuid != null) {
final LazyGetter lambda = () -> {
@SuppressWarnings("unchecked")
final Object foreignData = DataAccess.getsWhere(decorators.targetEntity(),
new Condition(new QueryCondition(mappingKey, "=", parendUuid)));
if (foreignData == null) {
return;
}
field.set(data, foreignData);
};
lazyCall.add(lambda);
Long parentIdTmp = null;
UUID parendUuidTmp = null;
try {
final String modelData = rs.getString(count.value);
parentIdTmp = Long.valueOf(modelData);
count.inc();
} catch (final NumberFormatException ex) {
final List<UUID> idList = DataAccess.getListOfRawUUIDs(rs, count.value);
parendUuidTmp = idList.get(0);
count.inc();
}
final Long parentId = parentIdTmp;
final UUID parendUuid = parendUuidTmp;
final String mappingKey = decorators.mappedBy();
// We get the parent ID ... ==> need to request the list of elements
if (objectClass == Long.class) {
LOGGER.error("Need to retreive all primary key of all elements");
//field.set(data, idList);
return;
} else if (objectClass == UUID.class) {
LOGGER.error("Need to retreive all primary key of all elements");
//field.set(data, idList);
return;
}
if (objectClass == decorators.targetEntity()) {
if (decorators.fetch() == FetchType.EAGER) {
throw new DataAccessException("EAGER is not supported for list of element...");
} else if (parentId != null) {
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
final LazyGetter lambda = () -> {
@SuppressWarnings("unchecked")
final Object foreignData = DataAccess.getsWhere(decorators.targetEntity(),
new Condition(new QueryCondition(mappingKey, "=", parentId)));
if (foreignData == null) {
return;
}
field.set(data, foreignData);
};
lazyCall.add(lambda);
} else if (parendUuid != null) {
final LazyGetter lambda = () -> {
@SuppressWarnings("unchecked")
final Object foreignData = DataAccess.getsWhere(decorators.targetEntity(),
new Condition(new QueryCondition(mappingKey, "=", parendUuid)));
if (foreignData == null) {
return;
}
field.set(data, foreignData);
};
lazyCall.add(lambda);
}
}
}
}

View File

@ -20,12 +20,21 @@ import java.util.UUID;
import org.glassfish.jersey.media.multipart.ContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.kar.archidata.catcher.RestErrorResponse;
import org.kar.archidata.externalRestApi.TsClassElement.DefinedPosition;
import org.kar.archidata.externalRestApi.model.ApiGroupModel;
import org.kar.archidata.externalRestApi.model.ClassModel;
import org.kar.archidata.externalRestApi.typescript.TsApiGeneration;
import org.kar.archidata.externalRestApi.typescript.TsClassElement;
import org.kar.archidata.externalRestApi.typescript.TsClassElement.DefinedPosition;
import org.kar.archidata.externalRestApi.typescript.TsClassElementGroup;
public class TsGenerateApi {
/**
* Generate a full API tree for Typescript in a specific folder.
* This generate a folder containing a full API with "model" filder and "api" folder.
* The generation depend of Zod and can be strict compile.
* @param api Data model to generate the api
* @param pathPackage Path to store the api.
*/
public static void generateApi(final AnalyzeApi api, final String pathPackage) throws Exception {
final List<TsClassElement> localModel = generateApiModel(api);
final TsClassElementGroup tsGroup = new TsClassElementGroup(localModel);

View File

@ -1,4 +1,4 @@
package org.kar.archidata.externalRestApi;
package org.kar.archidata.externalRestApi.typescript;
import java.io.File;
import java.io.FileWriter;
@ -12,7 +12,6 @@ import java.util.Set;
import java.util.TreeSet;
import org.kar.archidata.dataAccess.DataExport;
import org.kar.archidata.externalRestApi.TsClassElement.DefinedPosition;
import org.kar.archidata.externalRestApi.model.ApiGroupModel;
import org.kar.archidata.externalRestApi.model.ApiModel;
import org.kar.archidata.externalRestApi.model.ClassEnumModel;
@ -21,6 +20,7 @@ import org.kar.archidata.externalRestApi.model.ClassMapModel;
import org.kar.archidata.externalRestApi.model.ClassModel;
import org.kar.archidata.externalRestApi.model.ClassObjectModel;
import org.kar.archidata.externalRestApi.model.RestTypeRequest;
import org.kar.archidata.externalRestApi.typescript.TsClassElement.DefinedPosition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,4 +1,4 @@
package org.kar.archidata.externalRestApi;
package org.kar.archidata.externalRestApi.typescript;
import java.io.File;
import java.io.FileWriter;

View File

@ -1,4 +1,4 @@
package org.kar.archidata.externalRestApi;
package org.kar.archidata.externalRestApi.typescript;
import java.util.List;

View File

@ -3,12 +3,12 @@
# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
org.slf4j.simpleLogger.defaultLogLevel=debug
org.slf4j.simpleLogger.defaultLogLevel=INFO
# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, the default logging detail level is used.
#org.slf4j.simpleLogger.log.xxxxx=
org.slf4j.simpleLogger.log.org.kar.archidata=TRACE
# Set to true if you want the current date and time to be included in output messages.
# Default is false, and will output the number of milliseconds elapsed since startup.

View File

@ -22,6 +22,9 @@ import org.slf4j.LoggerFactory;
import test.kar.archidata.model.TypeManyToOneRemote;
import test.kar.archidata.model.TypeManyToOneRoot;
import test.kar.archidata.model.TypeManyToOneRootExpand;
import test.kar.archidata.model.TypeManyToOneUUIDRemote;
import test.kar.archidata.model.TypeManyToOneUUIDRoot;
import test.kar.archidata.model.TypeManyToOneUUIDRootExpand;
@ExtendWith(StepwiseExtension.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@ -52,8 +55,9 @@ public class TestManyToOne {
@Test
public void testCreateTable() throws Exception {
final List<String> sqlCommand = DataFactory.createTable(TypeManyToOneRemote.class);
final List<String> sqlCommand2 = DataFactory.createTable(TypeManyToOneRoot.class);
sqlCommand.addAll(sqlCommand2);
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneRoot.class));
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneUUIDRoot.class));
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneUUIDRemote.class));
for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuery(elem);
@ -62,7 +66,7 @@ public class TestManyToOne {
@Order(2)
@Test
public void testAddAlements() throws Exception {
public void testRemoteLong() throws Exception {
TypeManyToOneRemote remote = new TypeManyToOneRemote();
remote.data = "remote1";
final TypeManyToOneRemote insertedRemote1 = DataAccess.insert(remote);
@ -119,4 +123,63 @@ public class TestManyToOne {
Assertions.assertEquals(insertedData.otherData, retrieve2.otherData);
Assertions.assertNull(retrieve2.remote);
}
@Order(3)
@Test
public void testRemoteUUID() throws Exception {
TypeManyToOneUUIDRemote remote = new TypeManyToOneUUIDRemote();
remote.data = "remote1";
final TypeManyToOneUUIDRemote insertedRemote1 = DataAccess.insert(remote);
Assertions.assertEquals(insertedRemote1.data, remote.data);
remote = new TypeManyToOneUUIDRemote();
remote.data = "remote2";
final TypeManyToOneUUIDRemote insertedRemote2 = DataAccess.insert(remote);
Assertions.assertEquals(insertedRemote2.data, remote.data);
final TypeManyToOneUUIDRoot test = new TypeManyToOneUUIDRoot();
test.otherData = "kjhlkjlkj";
test.remoteUuid = insertedRemote2.uuid;
final TypeManyToOneUUIDRoot insertedData = DataAccess.insert(test);
Assertions.assertNotNull(insertedData);
Assertions.assertNotNull(insertedData.uuid);
Assertions.assertEquals(test.otherData, insertedData.otherData);
Assertions.assertEquals(insertedRemote2.uuid, insertedData.remoteUuid);
TypeManyToOneUUIDRoot retrieve = DataAccess.get(TypeManyToOneUUIDRoot.class, insertedData.uuid);
Assertions.assertNotNull(retrieve);
Assertions.assertNotNull(retrieve.uuid);
Assertions.assertEquals(insertedData.uuid, retrieve.uuid);
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
Assertions.assertEquals(insertedRemote2.uuid, retrieve.remoteUuid);
TypeManyToOneUUIDRootExpand retrieve2 = DataAccess.get(TypeManyToOneUUIDRootExpand.class, insertedData.uuid);
Assertions.assertNotNull(retrieve2);
Assertions.assertNotNull(retrieve2.uuid);
Assertions.assertEquals(insertedData.uuid, retrieve2.uuid);
Assertions.assertEquals(insertedData.otherData, retrieve2.otherData);
Assertions.assertNotNull(retrieve2.remote);
Assertions.assertEquals(insertedRemote2.uuid, retrieve2.remote.uuid);
Assertions.assertEquals(insertedRemote2.data, retrieve2.remote.data);
// remove values:
final int count = DataAccess.delete(TypeManyToOneUUIDRemote.class, remote.uuid);
Assertions.assertEquals(1, count);
// check fail:
retrieve = DataAccess.get(TypeManyToOneUUIDRoot.class, insertedData.uuid);
Assertions.assertNotNull(retrieve);
Assertions.assertNotNull(retrieve.uuid);
Assertions.assertEquals(insertedData.uuid, retrieve.uuid);
Assertions.assertEquals(insertedData.otherData, retrieve.otherData);
Assertions.assertEquals(insertedRemote2.uuid, retrieve.remoteUuid);
retrieve2 = DataAccess.get(TypeManyToOneUUIDRootExpand.class, insertedData.uuid);
Assertions.assertNotNull(retrieve2);
Assertions.assertNotNull(retrieve2.uuid);
Assertions.assertEquals(insertedData.uuid, retrieve2.uuid);
Assertions.assertEquals(insertedData.otherData, retrieve2.otherData);
Assertions.assertNull(retrieve2.remote);
}
}

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.util.List;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
@ -18,7 +19,12 @@ import org.kar.archidata.tools.ConfigBaseVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import test.kar.archidata.model.TypesTable;
import test.kar.archidata.model.TypeOneToManyRemote;
import test.kar.archidata.model.TypeOneToManyRoot;
import test.kar.archidata.model.TypeOneToManyRootExpand;
import test.kar.archidata.model.TypeOneToManyUUIDRemote;
import test.kar.archidata.model.TypeOneToManyUUIDRoot;
import test.kar.archidata.model.TypeOneToManyUUIDRootExpand;
@ExtendWith(StepwiseExtension.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@ -48,7 +54,10 @@ public class TestOneToMany {
@Order(1)
@Test
public void testCreateTable() throws Exception {
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
final List<String> sqlCommand = DataFactory.createTable(TypeOneToManyRemote.class);
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyRoot.class));
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyUUIDRemote.class));
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyUUIDRoot.class));
for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuery(elem);
@ -57,7 +66,161 @@ public class TestOneToMany {
@Order(2)
@Test
public void testPlop() throws Exception {
public void testParentLong() throws Exception {
// create parent:
final TypeOneToManyRoot root = new TypeOneToManyRoot();
root.otherData = "plouf";
final TypeOneToManyRoot insertedRoot = DataAccess.insert(root);
Assertions.assertEquals(insertedRoot.otherData, root.otherData);
Assertions.assertNull(insertedRoot.remoteIds);
final TypeOneToManyRoot root2 = new TypeOneToManyRoot();
root2.otherData = "plouf 2";
final TypeOneToManyRoot insertedRoot2 = DataAccess.insert(root2);
Assertions.assertEquals(insertedRoot2.otherData, root2.otherData);
Assertions.assertNull(insertedRoot2.remoteIds);
// Create Some Remotes
final TypeOneToManyRemote remote10 = new TypeOneToManyRemote();
remote10.data = "remote10";
remote10.rootId = insertedRoot.id;
final TypeOneToManyRemote insertedRemote10 = DataAccess.insert(remote10);
Assertions.assertEquals(insertedRemote10.data, remote10.data);
Assertions.assertEquals(insertedRemote10.rootId, remote10.rootId);
final TypeOneToManyRemote remote11 = new TypeOneToManyRemote();
remote11.data = "remote11";
remote11.rootId = insertedRoot.id;
final TypeOneToManyRemote insertedRemote11 = DataAccess.insert(remote11);
Assertions.assertEquals(insertedRemote11.data, remote11.data);
Assertions.assertEquals(insertedRemote11.rootId, remote11.rootId);
final TypeOneToManyRemote remote20 = new TypeOneToManyRemote();
remote20.data = "remote20";
remote20.rootId = insertedRoot2.id;
final TypeOneToManyRemote insertedRemote20 = DataAccess.insert(remote20);
Assertions.assertEquals(insertedRemote20.data, remote20.data);
Assertions.assertEquals(insertedRemote20.rootId, remote20.rootId);
// Check remote are inserted
final TypeOneToManyRoot retreiveRoot1 = DataAccess.get(TypeOneToManyRoot.class, insertedRoot.id);
Assertions.assertEquals(retreiveRoot1.otherData, insertedRoot.otherData);
Assertions.assertNotNull(retreiveRoot1.remoteIds);
Assertions.assertEquals(2, retreiveRoot1.remoteIds.size());
Assertions.assertEquals(insertedRemote10.id, retreiveRoot1.remoteIds.get(0));
Assertions.assertEquals(insertedRemote11.id, retreiveRoot1.remoteIds.get(1));
final TypeOneToManyRoot retreiveRoot2 = DataAccess.get(TypeOneToManyRoot.class, insertedRoot2.id);
Assertions.assertEquals(retreiveRoot2.otherData, insertedRoot2.otherData);
Assertions.assertNotNull(retreiveRoot2.remoteIds);
Assertions.assertEquals(1, retreiveRoot2.remoteIds.size());
Assertions.assertEquals(insertedRemote20.id, retreiveRoot2.remoteIds.get(0));
// Check remote are inserted and expandable
final TypeOneToManyRootExpand retreiveRootExpand1 = DataAccess.get(TypeOneToManyRootExpand.class,
insertedRoot.id);
Assertions.assertEquals(retreiveRootExpand1.otherData, insertedRoot.otherData);
Assertions.assertNotNull(retreiveRootExpand1.remotes);
Assertions.assertEquals(2, retreiveRootExpand1.remotes.size());
Assertions.assertEquals(insertedRemote10.id, retreiveRootExpand1.remotes.get(0).id);
Assertions.assertEquals(insertedRemote10.rootId, retreiveRootExpand1.remotes.get(0).rootId);
Assertions.assertEquals(insertedRemote10.data, retreiveRootExpand1.remotes.get(0).data);
Assertions.assertEquals(insertedRemote11.id, retreiveRootExpand1.remotes.get(1).id);
Assertions.assertEquals(insertedRemote11.rootId, retreiveRootExpand1.remotes.get(1).rootId);
Assertions.assertEquals(insertedRemote11.data, retreiveRootExpand1.remotes.get(1).data);
final TypeOneToManyRootExpand retreiveRootExpand2 = DataAccess.get(TypeOneToManyRootExpand.class,
insertedRoot2.id);
Assertions.assertEquals(retreiveRootExpand2.otherData, insertedRoot2.otherData);
Assertions.assertNotNull(retreiveRootExpand2.remotes);
Assertions.assertEquals(1, retreiveRootExpand2.remotes.size());
Assertions.assertEquals(insertedRemote20.id, retreiveRootExpand2.remotes.get(0).id);
Assertions.assertEquals(insertedRemote20.rootId, retreiveRootExpand2.remotes.get(0).rootId);
Assertions.assertEquals(insertedRemote20.data, retreiveRootExpand2.remotes.get(0).data);
}
@Order(2)
@Test
public void testParentUUID() throws Exception {
// create parent:
final TypeOneToManyUUIDRoot root = new TypeOneToManyUUIDRoot();
root.otherData = "plouf";
final TypeOneToManyUUIDRoot insertedRoot = DataAccess.insert(root);
Assertions.assertEquals(insertedRoot.otherData, root.otherData);
Assertions.assertNull(insertedRoot.remoteIds);
final TypeOneToManyUUIDRoot root2 = new TypeOneToManyUUIDRoot();
root2.otherData = "plouf 2";
final TypeOneToManyUUIDRoot insertedRoot2 = DataAccess.insert(root2);
Assertions.assertEquals(insertedRoot2.otherData, root2.otherData);
Assertions.assertNull(insertedRoot2.remoteIds);
// Create Some Remotes
final TypeOneToManyUUIDRemote remote10 = new TypeOneToManyUUIDRemote();
remote10.data = "remote10";
remote10.rootUuid = insertedRoot.uuid;
final TypeOneToManyUUIDRemote insertedRemote10 = DataAccess.insert(remote10);
Assertions.assertEquals(insertedRemote10.data, remote10.data);
Assertions.assertEquals(insertedRemote10.rootUuid, remote10.rootUuid);
final TypeOneToManyUUIDRemote remote11 = new TypeOneToManyUUIDRemote();
remote11.data = "remote11";
remote11.rootUuid = insertedRoot.uuid;
final TypeOneToManyUUIDRemote insertedRemote11 = DataAccess.insert(remote11);
Assertions.assertEquals(insertedRemote11.data, remote11.data);
Assertions.assertEquals(insertedRemote11.rootUuid, remote11.rootUuid);
final TypeOneToManyUUIDRemote remote20 = new TypeOneToManyUUIDRemote();
remote20.data = "remote20";
remote20.rootUuid = insertedRoot2.uuid;
final TypeOneToManyUUIDRemote insertedRemote20 = DataAccess.insert(remote20);
Assertions.assertEquals(insertedRemote20.data, remote20.data);
Assertions.assertEquals(insertedRemote20.rootUuid, remote20.rootUuid);
// Check remote are inserted
final TypeOneToManyUUIDRoot retreiveRoot1 = DataAccess.get(TypeOneToManyUUIDRoot.class, insertedRoot.uuid);
Assertions.assertEquals(retreiveRoot1.otherData, insertedRoot.otherData);
Assertions.assertNotNull(retreiveRoot1.remoteIds);
Assertions.assertEquals(2, retreiveRoot1.remoteIds.size());
Assertions.assertEquals(insertedRemote10.uuid, retreiveRoot1.remoteIds.get(0));
Assertions.assertEquals(insertedRemote11.uuid, retreiveRoot1.remoteIds.get(1));
final TypeOneToManyUUIDRoot retreiveRoot2 = DataAccess.get(TypeOneToManyUUIDRoot.class, insertedRoot2.uuid);
Assertions.assertEquals(retreiveRoot2.otherData, insertedRoot2.otherData);
Assertions.assertNotNull(retreiveRoot2.remoteIds);
Assertions.assertEquals(1, retreiveRoot2.remoteIds.size());
Assertions.assertEquals(insertedRemote20.uuid, retreiveRoot2.remoteIds.get(0));
// Check remote are inserted and expandable
final TypeOneToManyUUIDRootExpand retreiveRootExpand1 = DataAccess.get(TypeOneToManyUUIDRootExpand.class,
insertedRoot.uuid);
Assertions.assertEquals(retreiveRootExpand1.otherData, insertedRoot.otherData);
Assertions.assertNotNull(retreiveRootExpand1.remotes);
Assertions.assertEquals(2, retreiveRootExpand1.remotes.size());
Assertions.assertEquals(insertedRemote10.uuid, retreiveRootExpand1.remotes.get(0).uuid);
Assertions.assertEquals(insertedRemote10.rootUuid, retreiveRootExpand1.remotes.get(0).rootUuid);
Assertions.assertEquals(insertedRemote10.data, retreiveRootExpand1.remotes.get(0).data);
Assertions.assertEquals(insertedRemote11.uuid, retreiveRootExpand1.remotes.get(1).uuid);
Assertions.assertEquals(insertedRemote11.rootUuid, retreiveRootExpand1.remotes.get(1).rootUuid);
Assertions.assertEquals(insertedRemote11.data, retreiveRootExpand1.remotes.get(1).data);
final TypeOneToManyUUIDRootExpand retreiveRootExpand2 = DataAccess.get(TypeOneToManyUUIDRootExpand.class,
insertedRoot2.uuid);
Assertions.assertEquals(retreiveRootExpand2.otherData, insertedRoot2.otherData);
Assertions.assertNotNull(retreiveRootExpand2.remotes);
Assertions.assertEquals(1, retreiveRootExpand2.remotes.size());
Assertions.assertEquals(insertedRemote20.uuid, retreiveRootExpand2.remotes.get(0).uuid);
Assertions.assertEquals(insertedRemote20.rootUuid, retreiveRootExpand2.remotes.get(0).rootUuid);
Assertions.assertEquals(insertedRemote20.data, retreiveRootExpand2.remotes.get(0).data);
}
}

View File

@ -1,15 +1,8 @@
package test.kar.archidata.model;
import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import org.kar.archidata.model.GenericData;
public class TypeManyToManyRemote {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, unique = true)
public Long id = null;
public class TypeManyToManyRemote extends GenericData {
public String data;
}

View File

@ -2,18 +2,12 @@ package test.kar.archidata.model;
import java.util.List;
import jakarta.persistence.Column;
import org.kar.archidata.model.GenericData;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
public class TypeManyToManyRoot {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, unique = true)
public Long id = null;
public class TypeManyToManyRoot extends GenericData {
public String otherData;

View File

@ -2,20 +2,14 @@ package test.kar.archidata.model;
import java.util.List;
import jakarta.persistence.Column;
import org.kar.archidata.model.GenericData;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
@Table(name = "TypeManyToManyRoot")
public class TypeManyToManyRootExpand {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, unique = true)
public Long id = null;
public class TypeManyToManyRootExpand extends GenericData {
public String otherData;

View File

@ -1,16 +1,14 @@
package test.kar.archidata.model;
import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import org.kar.archidata.model.GenericData;
public class TypeManyToOneRemote {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, unique = true)
public Long id = null;
public class TypeManyToOneRemote extends GenericData {
public String data;
@Override
public String toString() {
return "TypeManyToOneRemote [data=" + this.data + ", id=" + this.id + "]";
}
}

View File

@ -1,20 +1,22 @@
package test.kar.archidata.model;
import org.kar.archidata.model.GenericData;
import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
public class TypeManyToOneRoot {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, unique = true)
public Long id = null;
public class TypeManyToOneRoot extends GenericData {
public String otherData;
@ManyToOne(targetEntity = TypeManyToOneRemote.class)
@Column(nullable = false)
public Long remoteId;
@Override
public String toString() {
return "TypeManyToOneRoot [otherData=" + this.otherData + ", remoteId=" + this.remoteId + ", id=" + this.id
+ "]";
}
}

View File

@ -1,23 +1,25 @@
package test.kar.archidata.model;
import org.kar.archidata.model.GenericData;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
@Table(name = "TypeManyToOneRoot")
public class TypeManyToOneRootExpand {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, unique = true)
public Long id = null;
public class TypeManyToOneRootExpand extends GenericData {
public String otherData;
@ManyToOne(fetch = FetchType.LAZY, targetEntity = TypeManyToOneRemote.class)
@Column(name = "remoteId", nullable = false)
public TypeManyToOneRemote remote;
@Override
public String toString() {
return "TypeManyToOneRootExpand [otherData=" + this.otherData + ", remote=" + this.remote + ", id=" + this.id
+ "]";
}
}

View File

@ -0,0 +1,9 @@
package test.kar.archidata.model;
import org.kar.archidata.model.UUIDGenericData;
public class TypeManyToOneUUIDRemote extends UUIDGenericData {
public String data;
}

View File

@ -0,0 +1,17 @@
package test.kar.archidata.model;
import java.util.UUID;
import org.kar.archidata.model.UUIDGenericData;
import jakarta.persistence.Column;
import jakarta.persistence.ManyToOne;
public class TypeManyToOneUUIDRoot extends UUIDGenericData {
public String otherData;
@ManyToOne(targetEntity = TypeManyToOneUUIDRemote.class)
@Column(nullable = false)
public UUID remoteUuid;
}

View File

@ -0,0 +1,18 @@
package test.kar.archidata.model;
import org.kar.archidata.model.UUIDGenericData;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
@Table(name = "TypeManyToOneUUIDRoot")
public class TypeManyToOneUUIDRootExpand extends UUIDGenericData {
public String otherData;
@ManyToOne(fetch = FetchType.LAZY, targetEntity = TypeManyToOneUUIDRemote.class)
@Column(name = "remoteUuid", nullable = false)
public TypeManyToOneUUIDRemote remote;
}

View File

@ -0,0 +1,15 @@
package test.kar.archidata.model;
import org.kar.archidata.model.GenericData;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
public class TypeOneToManyRemote extends GenericData {
@ManyToOne(fetch = FetchType.LAZY, targetEntity = TypeOneToManyRoot.class)
public Long rootId;
public String data;
}

View File

@ -0,0 +1,15 @@
package test.kar.archidata.model;
import java.util.List;
import org.kar.archidata.model.GenericData;
import jakarta.persistence.OneToMany;
public class TypeOneToManyRoot extends GenericData {
public String otherData;
@OneToMany(targetEntity = TypeOneToManyRemote.class, mappedBy = "rootId")
public List<Long> remoteIds;
}

View File

@ -0,0 +1,25 @@
package test.kar.archidata.model;
import java.util.List;
import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
@Table(name = "TypeOneToManyRoot")
public class TypeOneToManyRootExpand {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false, unique = true)
public Long id = null;
public String otherData;
@OneToMany(targetEntity = TypeOneToManyRemote.class, mappedBy = "rootId")
@Column(nullable = false)
public List<TypeOneToManyRemote> remotes;
}

View File

@ -0,0 +1,17 @@
package test.kar.archidata.model;
import java.util.UUID;
import org.kar.archidata.model.UUIDGenericData;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
public class TypeOneToManyUUIDRemote extends UUIDGenericData {
@ManyToOne(fetch = FetchType.LAZY, targetEntity = TypeOneToManyUUIDRoot.class)
public UUID rootUuid;
public String data;
}

View File

@ -0,0 +1,18 @@
package test.kar.archidata.model;
import java.util.List;
import java.util.UUID;
import org.kar.archidata.model.UUIDGenericData;
import jakarta.persistence.Column;
import jakarta.persistence.OneToMany;
public class TypeOneToManyUUIDRoot extends UUIDGenericData {
public String otherData;
@OneToMany(targetEntity = TypeOneToManyUUIDRemote.class, mappedBy = "rootUuid")
@Column(nullable = false)
public List<UUID> remoteIds;
}

View File

@ -0,0 +1,19 @@
package test.kar.archidata.model;
import java.util.List;
import org.kar.archidata.model.UUIDGenericData;
import jakarta.persistence.Column;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
@Table(name = "TypeOneToManyUUIDRoot")
public class TypeOneToManyUUIDRootExpand extends UUIDGenericData {
public String otherData;
@OneToMany(targetEntity = TypeOneToManyUUIDRemote.class, mappedBy = "rootUuid")
@Column(nullable = false)
public List<TypeOneToManyUUIDRemote> remotes;
}