Compare commits

...

3 Commits

7 changed files with 35 additions and 13 deletions

View File

@ -258,15 +258,11 @@ public class AnnotationTools {
return false;
}
public static String getFieldName(final Field element) throws DataAccessException {
public static String getFieldName(final Field element) {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
if (annotation.length == 0) {
return element.getName();
}
if (annotation.length > 1) {
throw new DataAccessException(
"Must not have more than 1 element @Column on " + element.getClass().getCanonicalName());
}
final String name = ((Column) annotation[0]).name();
if (name.isBlank()) {
return element.getName();

View File

@ -27,7 +27,7 @@ import jakarta.persistence.GenerationType;
public class DataFactory {
static final Logger LOGGER = LoggerFactory.getLogger(DataFactory.class);
public static String convertTypeInSQL(final Class<?> type, final String fieldName) throws Exception {
public static String convertTypeInSQL(final Class<?> type, final String fieldName) throws DataAccessException {
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
if (type == UUID.class) {
return "binary(16)";

View File

@ -23,6 +23,7 @@ import org.kar.archidata.dataAccess.addOn.model.TableCoversLongUUID;
import org.kar.archidata.dataAccess.addOn.model.TableCoversUUIDLong;
import org.kar.archidata.dataAccess.addOn.model.TableCoversUUIDUUID;
import org.kar.archidata.dataAccess.options.OverrideTableName;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -42,7 +43,7 @@ public class AddOnDataJson implements DataAccessAddOn {
}
@Override
public String getSQLFieldType(final Field elem) throws Exception {
public String getSQLFieldType(final Field elem) throws DataAccessException {
final String fieldName = AnnotationTools.getFieldName(elem);
return DataFactory.convertTypeInSQL(String.class, fieldName);
}

View File

@ -108,13 +108,18 @@ public class AddOnManyToMany implements DataAccessAddOn {
@NotNull final String name,
@NotNull final CountInOut count,
final QueryOptions options) throws Exception {
final ManyToMany manyToMany = AnnotationTools.getManyToMany(field);
final String linkTableName = generateLinkTableName(tableName, name);
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
.getActualTypeArguments()[0];
final String tmpVariable = "tmp_" + Integer.toString(count.value);
querySelect.append(" (SELECT GROUP_CONCAT(");
querySelect.append(tmpVariable);
if (manyToMany.mappedBy() == null) {
querySelect.append(".object2Id ");
} else {
querySelect.append(".object1Id ");
}
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
querySelect.append(", ");
} else {
@ -143,11 +148,19 @@ public class AddOnManyToMany implements DataAccessAddOn {
querySelect.append(" = ");
querySelect.append(tmpVariable);
querySelect.append(".");
if (manyToMany.mappedBy() == null) {
querySelect.append("object1Id ");
} else {
querySelect.append("object2Id ");
}
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
querySelect.append(" GROUP BY ");
querySelect.append(tmpVariable);
if (manyToMany.mappedBy() == null) {
querySelect.append(".object1Id");
} else {
querySelect.append(".object2Id");
}
}
querySelect.append(") AS ");
querySelect.append(name);

View File

@ -1,5 +1,6 @@
package org.kar.archidata.dataAccess.addOn.model;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@ -14,7 +15,7 @@ public class TableCoversLongUUID {
public TableCoversLongUUID(final Long id, final List<UUID> covers) {
this.id = id;
this.covers = covers;
this.covers = new ArrayList<>(covers);
}
@Id

View File

@ -1,5 +1,6 @@
package org.kar.archidata.dataAccess.addOn.model;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@ -14,7 +15,7 @@ public class TableCoversUUIDLong {
public TableCoversUUIDLong(final UUID uuid, final List<Long> covers) {
this.uuid = uuid;
this.covers = covers;
this.covers = new ArrayList<>(covers);
}
@Id

View File

@ -3,6 +3,9 @@ package org.kar.archidata.externalRestApi.typescript;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@ -415,7 +418,10 @@ public class TsApiGeneration {
}
for (final ClassModel model : writeImports) {
final TsClassElement tsModel = tsGroup.find(model);
if (tsModel.nativeType == DefinedPosition.NATIVE) {
if (tsModel.nativeType != DefinedPosition.NORMAL) {
continue;
}
if (tsModel.models.get(0).isNoWriteSpecificMode()) {
continue;
}
finalImportSet.add(tsModel.tsTypeName + "Write");
@ -433,6 +439,10 @@ public class TsApiGeneration {
out.append(data.toString());
final Path path = Paths.get(pathPackage + File.separator + "api");
if (Files.notExists(path)) {
Files.createDirectories(path);
}
final String fileName = TsClassElement.determineFileName(element.name);
final FileWriter myWriter = new FileWriter(
pathPackage + File.separator + "api" + File.separator + fileName + ".ts");