Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
1b4e6ca239 | |||
be8a5c713a | |||
c3f03bc1e8 | |||
c7eadc607d | |||
5f89ff7944 | |||
20d2d004cb |
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>kangaroo-and-rabbit</groupId>
|
<groupId>kangaroo-and-rabbit</groupId>
|
||||||
<artifactId>archidata</artifactId>
|
<artifactId>archidata</artifactId>
|
||||||
<version>0.23.4</version>
|
<version>0.24.0</version>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
<maven.compiler.version>3.1</maven.compiler.version>
|
<maven.compiler.version>3.1</maven.compiler.version>
|
||||||
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
import org.kar.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
import org.kar.archidata.annotation.AnnotationTools.FieldName;
|
import org.kar.archidata.annotation.AnnotationTools.FieldName;
|
||||||
import org.kar.archidata.dataAccess.CountInOut;
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
@ -72,7 +73,7 @@ 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 || objectClass == UUID.class) {
|
if (objectClass == Long.class || objectClass == UUID.class || objectClass == ObjectId.class) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final ManyToMany decorators = field.getDeclaredAnnotation(ManyToMany.class);
|
final ManyToMany decorators = field.getDeclaredAnnotation(ManyToMany.class);
|
||||||
@ -135,7 +136,11 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
querySelect.append("'");
|
querySelect.append("'");
|
||||||
if (objectClass == Long.class) {
|
if (objectClass == Long.class) {
|
||||||
querySelect.append(SEPARATOR_LONG);
|
querySelect.append(SEPARATOR_LONG);
|
||||||
} else if (objectClass == UUID.class) {} else {
|
} else if (objectClass == UUID.class) {
|
||||||
|
// ???
|
||||||
|
} else if (objectClass == ObjectId.class) {
|
||||||
|
// ???
|
||||||
|
} else {
|
||||||
final Class<?> foreignKeyType = AnnotationTools.getPrimaryKeyField(objectClass).getType();
|
final Class<?> foreignKeyType = AnnotationTools.getPrimaryKeyField(objectClass).getType();
|
||||||
if (foreignKeyType == Long.class) {
|
if (foreignKeyType == Long.class) {
|
||||||
querySelect.append(SEPARATOR_LONG);
|
querySelect.append(SEPARATOR_LONG);
|
||||||
@ -193,7 +198,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||||
.getActualTypeArguments()[0];
|
.getActualTypeArguments()[0];
|
||||||
// TODO: manage better the eager and lazy !!
|
// TODO: manage better the eager and lazy !!
|
||||||
if (objectClass == Long.class || objectClass == UUID.class) {
|
if (objectClass == Long.class || objectClass == UUID.class || objectClass == ObjectId.class) {
|
||||||
generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options);
|
generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options);
|
||||||
}
|
}
|
||||||
final ManyToMany decorators = field.getDeclaredAnnotation(ManyToMany.class);
|
final ManyToMany decorators = field.getDeclaredAnnotation(ManyToMany.class);
|
||||||
@ -234,6 +239,11 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
field.set(data, idList);
|
field.set(data, idList);
|
||||||
count.inc();
|
count.inc();
|
||||||
return;
|
return;
|
||||||
|
} else if (objectClass == ObjectId.class) {
|
||||||
|
final List<ObjectId> idList = ioDb.getListOfRawOIDs(rs, count.value);
|
||||||
|
field.set(data, idList);
|
||||||
|
count.inc();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
final ManyToMany decorators = field.getDeclaredAnnotation(ManyToMany.class);
|
final ManyToMany decorators = field.getDeclaredAnnotation(ManyToMany.class);
|
||||||
if (decorators == null) {
|
if (decorators == null) {
|
||||||
@ -285,6 +295,27 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
};
|
};
|
||||||
lazyCall.add(lambda);
|
lazyCall.add(lambda);
|
||||||
}
|
}
|
||||||
|
} else if (foreignKeyType == ObjectId.class) {
|
||||||
|
final List<ObjectId> idList = ioDb.getListOfRawOIDs(rs, count.value);
|
||||||
|
// field.set(data, idList);
|
||||||
|
count.inc();
|
||||||
|
if (idList != null && idList.size() > 0) {
|
||||||
|
final FieldName idField = AnnotationTools.getFieldName(AnnotationTools.getIdField(objectClass),
|
||||||
|
options);
|
||||||
|
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
||||||
|
final LazyGetter lambda = () -> {
|
||||||
|
final List<ObjectId> childs = new ArrayList<>(idList);
|
||||||
|
// TODO: update to have get with abstract types ....
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final Object foreignData = ioDb.getsWhere(decorators.targetEntity(),
|
||||||
|
new Condition(new QueryInList<>(idField.inTable(), childs)));
|
||||||
|
if (foreignData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
field.set(data, foreignData);
|
||||||
|
};
|
||||||
|
lazyCall.add(lambda);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,9 +340,10 @@ 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 && objectClass != UUID.class) {
|
if (objectClass != Long.class && objectClass != UUID.class && objectClass != ObjectId.class) {
|
||||||
throw new DataAccessException("Can not ManyToMany with other than List<Long> or List<UUID> Model: List<"
|
throw new DataAccessException(
|
||||||
+ objectClass.getCanonicalName() + ">");
|
"Can not ManyToMany with other than List<Long> or List<UUID> or List<ObjectId> Model: List<"
|
||||||
|
+ objectClass.getCanonicalName() + ">");
|
||||||
}
|
}
|
||||||
final FieldName columnName = AnnotationTools.getFieldName(field, options);
|
final FieldName columnName = AnnotationTools.getFieldName(field, options);
|
||||||
final String linkTableName = generateLinkTableName(tableName, columnName.inTable());
|
final String linkTableName = generateLinkTableName(tableName, columnName.inTable());
|
||||||
@ -348,9 +380,10 @@ 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 && objectClass != UUID.class) {
|
if (objectClass != Long.class && objectClass != UUID.class && objectClass != ObjectId.class) {
|
||||||
throw new DataAccessException("Can not ManyToMany with other than List<Long> or List<UUID> Model: List<"
|
throw new DataAccessException(
|
||||||
+ objectClass.getCanonicalName() + ">");
|
"Can not ManyToMany with other than List<Long> or List<UUID> or List<ObjectId> Model: List<"
|
||||||
|
+ objectClass.getCanonicalName() + ">");
|
||||||
}
|
}
|
||||||
final FieldName columnName = AnnotationTools.getFieldName(field, options);
|
final FieldName columnName = AnnotationTools.getFieldName(field, options);
|
||||||
final String linkTableName = generateLinkTableName(tableName, columnName.inTable());
|
final String linkTableName = generateLinkTableName(tableName, columnName.inTable());
|
||||||
|
@ -7,6 +7,7 @@ import java.sql.Types;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
import org.kar.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
import org.kar.archidata.annotation.AnnotationTools.FieldName;
|
import org.kar.archidata.annotation.AnnotationTools.FieldName;
|
||||||
import org.kar.archidata.dataAccess.CountInOut;
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
@ -66,6 +67,8 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
ps.setNull(iii.value, Types.VARCHAR);
|
ps.setNull(iii.value, Types.VARCHAR);
|
||||||
} else if (field.getType() == UUID.class) {
|
} else if (field.getType() == UUID.class) {
|
||||||
ps.setNull(iii.value, Types.BINARY);
|
ps.setNull(iii.value, Types.BINARY);
|
||||||
|
} else if (field.getType() == ObjectId.class) {
|
||||||
|
ps.setNull(iii.value, Types.BINARY);
|
||||||
}
|
}
|
||||||
} else if (field.getType() == Long.class) {
|
} else if (field.getType() == Long.class) {
|
||||||
final Long dataTyped = (Long) data;
|
final Long dataTyped = (Long) data;
|
||||||
@ -84,6 +87,11 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
LOGGER.info("Generate UUTD for DB: {}", dataTyped);
|
LOGGER.info("Generate UUTD for DB: {}", dataTyped);
|
||||||
final byte[] dataByte = UuidUtils.asBytes(dataTyped);
|
final byte[] dataByte = UuidUtils.asBytes(dataTyped);
|
||||||
ps.setBytes(iii.value, dataByte);
|
ps.setBytes(iii.value, dataByte);
|
||||||
|
} else if (field.getType() == ObjectId.class) {
|
||||||
|
final ObjectId dataTyped = (ObjectId) data;
|
||||||
|
LOGGER.info("Generate ObjectId for DB: {}", dataTyped);
|
||||||
|
final byte[] dataByte = dataTyped.toByteArray();
|
||||||
|
ps.setBytes(iii.value, dataByte);
|
||||||
} else {
|
} else {
|
||||||
final Field idField = AnnotationTools.getFieldOfId(field.getType());
|
final Field idField = AnnotationTools.getFieldOfId(field.getType());
|
||||||
final Object uid = idField.get(data);
|
final Object uid = idField.get(data);
|
||||||
@ -101,7 +109,8 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
@Override
|
@Override
|
||||||
public boolean canInsert(final Field field) {
|
public boolean canInsert(final Field field) {
|
||||||
if (field.getType() == Long.class || field.getType() == Integer.class || field.getType() == Short.class
|
if (field.getType() == Long.class || field.getType() == Integer.class || field.getType() == Short.class
|
||||||
|| field.getType() == String.class || field.getType() == UUID.class) {
|
|| field.getType() == String.class || field.getType() == UUID.class
|
||||||
|
|| field.getType() == ObjectId.class) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
||||||
@ -120,7 +129,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
public boolean canRetrieve(final Field field) {
|
public boolean canRetrieve(final Field field) {
|
||||||
final Class<?> classType = field.getType();
|
final Class<?> classType = field.getType();
|
||||||
if (classType == Long.class || classType == Integer.class || classType == Short.class
|
if (classType == Long.class || classType == Integer.class || classType == Short.class
|
||||||
|| classType == String.class || classType == UUID.class) {
|
|| classType == String.class || classType == UUID.class || classType == ObjectId.class) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
||||||
@ -141,7 +150,8 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
@NotNull final CountInOut count,
|
@NotNull final CountInOut count,
|
||||||
final QueryOptions options) throws Exception {
|
final QueryOptions options) throws Exception {
|
||||||
if (field.getType() == Long.class || field.getType() == Integer.class || field.getType() == Short.class
|
if (field.getType() == Long.class || field.getType() == Integer.class || field.getType() == Short.class
|
||||||
|| field.getType() == String.class || field.getType() == UUID.class) {
|
|| field.getType() == String.class || field.getType() == UUID.class
|
||||||
|
|| field.getType() == ObjectId.class) {
|
||||||
querySelect.append(" ");
|
querySelect.append(" ");
|
||||||
querySelect.append(tableName);
|
querySelect.append(tableName);
|
||||||
querySelect.append(".");
|
querySelect.append(".");
|
||||||
@ -230,6 +240,15 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (field.getType() == ObjectId.class) {
|
||||||
|
final byte[] tmp = rs.getBytes(count.value);
|
||||||
|
count.inc();
|
||||||
|
if (!rs.wasNull()) {
|
||||||
|
final ObjectId foreignKey = new ObjectId(tmp);
|
||||||
|
field.set(data, foreignKey);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
final Class<?> objectClass = field.getType();
|
final Class<?> objectClass = field.getType();
|
||||||
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
||||||
if (decorators == null) {
|
if (decorators == null) {
|
||||||
@ -279,6 +298,22 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
};
|
};
|
||||||
lazyCall.add(lambda);
|
lazyCall.add(lambda);
|
||||||
}
|
}
|
||||||
|
} else if (remotePrimaryKeyType == ObjectId.class) {
|
||||||
|
// here we have the field, the data and the the remote value ==> can create callback that generate the update of the value ...
|
||||||
|
final ObjectId foreignKey = ioDb.getListOfRawOID(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 = ioDb.get(decorators.targetEntity(), foreignKey);
|
||||||
|
if (foreignData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
field.set(data, foreignData);
|
||||||
|
};
|
||||||
|
lazyCall.add(lambda);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,7 +333,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
|||||||
final QueryOptions options) throws Exception {
|
final QueryOptions options) throws Exception {
|
||||||
final Class<?> classType = field.getType();
|
final Class<?> classType = field.getType();
|
||||||
if (classType == Long.class || classType == Integer.class || classType == Short.class
|
if (classType == Long.class || classType == Integer.class || classType == Short.class
|
||||||
|| classType == String.class || classType == UUID.class) {
|
|| classType == String.class || classType == UUID.class || classType == ObjectId.class) {
|
||||||
DataFactory.createTablesSpecificType(tableName, primaryField, field, mainTableBuilder, preActionList,
|
DataFactory.createTablesSpecificType(tableName, primaryField, field, mainTableBuilder, preActionList,
|
||||||
postActionList, createIfNotExist, createDrop, fieldId, classType, options);
|
postActionList, createIfNotExist, createDrop, fieldId, classType, options);
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
import org.kar.archidata.annotation.AnnotationTools;
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
import org.kar.archidata.annotation.AnnotationTools.FieldName;
|
import org.kar.archidata.annotation.AnnotationTools.FieldName;
|
||||||
import org.kar.archidata.dataAccess.CountInOut;
|
import org.kar.archidata.dataAccess.CountInOut;
|
||||||
@ -110,7 +111,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||||
.getActualTypeArguments()[0];
|
.getActualTypeArguments()[0];
|
||||||
if (objectClass == Long.class || objectClass == UUID.class) {
|
if (objectClass == Long.class || objectClass == UUID.class || objectClass == ObjectId.class) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final OneToMany decorators = field.getDeclaredAnnotation(OneToMany.class);
|
final OneToMany decorators = field.getDeclaredAnnotation(OneToMany.class);
|
||||||
@ -201,7 +202,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: manage better the eager and lazy !!
|
// TODO: manage better the eager and lazy !!
|
||||||
if (objectClass == Long.class || objectClass == UUID.class) {
|
if (objectClass == Long.class || objectClass == UUID.class || objectClass == ObjectId.class) {
|
||||||
generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options,
|
generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options,
|
||||||
decorators.targetEntity(), decorators.mappedBy());
|
decorators.targetEntity(), decorators.mappedBy());
|
||||||
return;
|
return;
|
||||||
@ -250,22 +251,35 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
|||||||
field.set(data, idList);
|
field.set(data, idList);
|
||||||
count.inc();
|
count.inc();
|
||||||
return;
|
return;
|
||||||
|
} else if (objectClass == ObjectId.class) {
|
||||||
|
final List<ObjectId> idList = ioDb.getListOfRawOIDs(rs, count.value);
|
||||||
|
field.set(data, idList);
|
||||||
|
count.inc();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (objectClass == decorators.targetEntity()) {
|
if (objectClass == decorators.targetEntity()) {
|
||||||
|
|
||||||
Long parentIdTmp = null;
|
Long parentIdTmp = null;
|
||||||
UUID parendUuidTmp = null;
|
UUID parendUuidTmp = null;
|
||||||
|
ObjectId parendOidTmp = null;
|
||||||
try {
|
try {
|
||||||
final String modelData = rs.getString(count.value);
|
final String modelData = rs.getString(count.value);
|
||||||
parentIdTmp = Long.valueOf(modelData);
|
parentIdTmp = Long.valueOf(modelData);
|
||||||
count.inc();
|
count.inc();
|
||||||
} catch (final NumberFormatException ex) {
|
} catch (final NumberFormatException ex) {
|
||||||
final List<UUID> idList = ioDb.getListOfRawUUIDs(rs, count.value);
|
try {
|
||||||
parendUuidTmp = idList.get(0);
|
final List<UUID> idList = ioDb.getListOfRawUUIDs(rs, count.value);
|
||||||
count.inc();
|
parendUuidTmp = idList.get(0);
|
||||||
|
count.inc();
|
||||||
|
} catch (final NumberFormatException ex2) {
|
||||||
|
// TODO : How to manage ObjectId ==> I am not sure it works well...
|
||||||
|
final List<ObjectId> idList = ioDb.getListOfRawOIDs(rs, count.value);
|
||||||
|
parendOidTmp = idList.get(0);
|
||||||
|
count.inc();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final Long parentId = parentIdTmp;
|
final Long parentId = parentIdTmp;
|
||||||
final UUID parendUuid = parendUuidTmp;
|
final UUID parendUuid = parendUuidTmp;
|
||||||
|
final ObjectId parendOid = parendOidTmp;
|
||||||
final String mappingKey = decorators.mappedBy();
|
final String mappingKey = decorators.mappedBy();
|
||||||
// We get the parent ID ... ==> need to request the list of elements
|
// We get the parent ID ... ==> need to request the list of elements
|
||||||
if (objectClass == Long.class) {
|
if (objectClass == Long.class) {
|
||||||
@ -276,6 +290,10 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
|||||||
LOGGER.error("Need to retreive all primary key of all elements");
|
LOGGER.error("Need to retreive all primary key of all elements");
|
||||||
//field.set(data, idList);
|
//field.set(data, idList);
|
||||||
return;
|
return;
|
||||||
|
} else if (objectClass == ObjectId.class) {
|
||||||
|
LOGGER.error("Need to retreive all primary key of all elements");
|
||||||
|
//field.set(data, idList);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (objectClass == decorators.targetEntity()) {
|
if (objectClass == decorators.targetEntity()) {
|
||||||
if (decorators.fetch() == FetchType.EAGER) {
|
if (decorators.fetch() == FetchType.EAGER) {
|
||||||
@ -303,6 +321,17 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
|||||||
field.set(data, foreignData);
|
field.set(data, foreignData);
|
||||||
};
|
};
|
||||||
lazyCall.add(lambda);
|
lazyCall.add(lambda);
|
||||||
|
} else if (parendOid != null) {
|
||||||
|
final LazyGetter lambda = () -> {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final Object foreignData = ioDb.getsWhere(decorators.targetEntity(),
|
||||||
|
new Condition(new QueryCondition(mappingKey, "=", parendOid)));
|
||||||
|
if (foreignData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
field.set(data, foreignData);
|
||||||
|
};
|
||||||
|
lazyCall.add(lambda);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ 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.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;
|
||||||
|
|
||||||
@ -130,35 +131,40 @@ public class MigrationEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createTableIfAbleOrWaitAdmin(final DbConfig configInput) throws MigrationException {
|
private void createTableIfAbleOrWaitAdmin(final DbConfig configInput) throws MigrationException {
|
||||||
final DbConfig config = configInput.clone();
|
if (ConfigBaseVariable.getDBAbleToCreate()) {
|
||||||
config.setDbName(null);
|
final DbConfig config = configInput.clone();
|
||||||
final String dbName = configInput.getDbName();
|
config.setDbName(null);
|
||||||
LOGGER.info("Verify existance of '{}'", dbName);
|
final String dbName = configInput.getDbName();
|
||||||
try (final DBAccess da = DBAccess.createInterface(config)) {
|
LOGGER.info("Verify existance of '{}'", dbName);
|
||||||
boolean exist = da.isDBExist(dbName);
|
try (final DBAccess da = DBAccess.createInterface(config)) {
|
||||||
if (!exist) {
|
boolean exist = da.isDBExist(dbName);
|
||||||
LOGGER.warn("DB: '{}' DOES NOT EXIST ==> create one", dbName);
|
if (!exist) {
|
||||||
// create the local DB:
|
LOGGER.warn("DB: '{}' DOES NOT EXIST ==> create one", dbName);
|
||||||
da.createDB(dbName);
|
// create the local DB:
|
||||||
}
|
da.createDB(dbName);
|
||||||
exist = da.isDBExist(dbName);
|
|
||||||
while (!exist) {
|
|
||||||
LOGGER.error("DB: '{}' DOES NOT EXIST after trying to create one ", dbName);
|
|
||||||
LOGGER.error("Waiting administrator create a new one, we check after 30 seconds...");
|
|
||||||
try {
|
|
||||||
Thread.sleep(30000);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
exist = da.isDBExist(dbName);
|
exist = da.isDBExist(dbName);
|
||||||
|
while (!exist) {
|
||||||
|
LOGGER.error("DB: '{}' DOES NOT EXIST after trying to create one ", dbName);
|
||||||
|
LOGGER.error("Waiting administrator create a new one, we check after 30 seconds...");
|
||||||
|
try {
|
||||||
|
Thread.sleep(30000);
|
||||||
|
} catch (final InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
exist = da.isDBExist(dbName);
|
||||||
|
}
|
||||||
|
} catch (final InternalServerErrorException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new MigrationException("TODO ...");
|
||||||
|
} catch (final IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new MigrationException("TODO ...");
|
||||||
}
|
}
|
||||||
} catch (final InternalServerErrorException e) {
|
} else {
|
||||||
e.printStackTrace();
|
final String dbName = configInput.getDbName();
|
||||||
throw new MigrationException("TODO ...");
|
LOGGER.warn("DB: '{}' is not check if it EXIST", dbName);
|
||||||
} catch (final IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new MigrationException("TODO ...");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package org.kar.archidata.tools;
|
|||||||
public class ConfigBaseVariable {
|
public class ConfigBaseVariable {
|
||||||
static public String tmpDataFolder;
|
static public String tmpDataFolder;
|
||||||
static public String dataFolder;
|
static public String dataFolder;
|
||||||
|
static public String dbAbleToCreate;
|
||||||
static public String dbType;
|
static public String dbType;
|
||||||
static public String dbHost;
|
static public String dbHost;
|
||||||
static public String dbPort;
|
static public String dbPort;
|
||||||
@ -23,6 +24,7 @@ public class ConfigBaseVariable {
|
|||||||
public static void clearAllValue() {
|
public static void clearAllValue() {
|
||||||
tmpDataFolder = System.getenv("DATA_TMP_FOLDER");
|
tmpDataFolder = System.getenv("DATA_TMP_FOLDER");
|
||||||
dataFolder = System.getenv("DATA_FOLDER");
|
dataFolder = System.getenv("DATA_FOLDER");
|
||||||
|
dbAbleToCreate = System.getenv("DB_ABLE_TO_CREATE");
|
||||||
dbType = System.getenv("DB_TYPE");
|
dbType = System.getenv("DB_TYPE");
|
||||||
dbHost = System.getenv("DB_HOST");
|
dbHost = System.getenv("DB_HOST");
|
||||||
dbPort = System.getenv("DB_PORT");
|
dbPort = System.getenv("DB_PORT");
|
||||||
@ -58,6 +60,13 @@ public class ConfigBaseVariable {
|
|||||||
return dataFolder;
|
return dataFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean getDBAbleToCreate() {
|
||||||
|
if (dbAbleToCreate == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return Boolean.getBoolean(dbAbleToCreate);
|
||||||
|
}
|
||||||
|
|
||||||
public static String getDBType() {
|
public static String getDBType() {
|
||||||
if (dbType == null) {
|
if (dbType == null) {
|
||||||
return "mysql";
|
return "mysql";
|
||||||
|
@ -1 +1 @@
|
|||||||
0.23.4
|
0.24.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user