Compare commits
3 Commits
38503fac8e
...
37f1362c3c
Author | SHA1 | Date | |
---|---|---|---|
37f1362c3c | |||
e2ee68cc03 | |||
f05527ce01 |
@ -258,15 +258,11 @@ public class AnnotationTools {
|
|||||||
return false;
|
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);
|
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
|
||||||
if (annotation.length == 0) {
|
if (annotation.length == 0) {
|
||||||
return element.getName();
|
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();
|
final String name = ((Column) annotation[0]).name();
|
||||||
if (name.isBlank()) {
|
if (name.isBlank()) {
|
||||||
return element.getName();
|
return element.getName();
|
||||||
|
@ -27,7 +27,7 @@ import jakarta.persistence.GenerationType;
|
|||||||
public class DataFactory {
|
public class DataFactory {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(DataFactory.class);
|
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 (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||||
if (type == UUID.class) {
|
if (type == UUID.class) {
|
||||||
return "binary(16)";
|
return "binary(16)";
|
||||||
|
@ -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.TableCoversUUIDLong;
|
||||||
import org.kar.archidata.dataAccess.addOn.model.TableCoversUUIDUUID;
|
import org.kar.archidata.dataAccess.addOn.model.TableCoversUUIDUUID;
|
||||||
import org.kar.archidata.dataAccess.options.OverrideTableName;
|
import org.kar.archidata.dataAccess.options.OverrideTableName;
|
||||||
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSQLFieldType(final Field elem) throws Exception {
|
public String getSQLFieldType(final Field elem) throws DataAccessException {
|
||||||
final String fieldName = AnnotationTools.getFieldName(elem);
|
final String fieldName = AnnotationTools.getFieldName(elem);
|
||||||
return DataFactory.convertTypeInSQL(String.class, fieldName);
|
return DataFactory.convertTypeInSQL(String.class, fieldName);
|
||||||
}
|
}
|
||||||
|
@ -108,13 +108,18 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
@NotNull final String name,
|
@NotNull final String name,
|
||||||
@NotNull final CountInOut count,
|
@NotNull final CountInOut count,
|
||||||
final QueryOptions options) throws Exception {
|
final QueryOptions options) throws Exception {
|
||||||
|
final ManyToMany manyToMany = AnnotationTools.getManyToMany(field);
|
||||||
final String linkTableName = generateLinkTableName(tableName, name);
|
final String linkTableName = generateLinkTableName(tableName, name);
|
||||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||||
.getActualTypeArguments()[0];
|
.getActualTypeArguments()[0];
|
||||||
final String tmpVariable = "tmp_" + Integer.toString(count.value);
|
final String tmpVariable = "tmp_" + Integer.toString(count.value);
|
||||||
querySelect.append(" (SELECT GROUP_CONCAT(");
|
querySelect.append(" (SELECT GROUP_CONCAT(");
|
||||||
querySelect.append(tmpVariable);
|
querySelect.append(tmpVariable);
|
||||||
querySelect.append(".object2Id ");
|
if (manyToMany.mappedBy() == null) {
|
||||||
|
querySelect.append(".object2Id ");
|
||||||
|
} else {
|
||||||
|
querySelect.append(".object1Id ");
|
||||||
|
}
|
||||||
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
|
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||||
querySelect.append(", ");
|
querySelect.append(", ");
|
||||||
} else {
|
} else {
|
||||||
@ -143,11 +148,19 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
querySelect.append(" = ");
|
querySelect.append(" = ");
|
||||||
querySelect.append(tmpVariable);
|
querySelect.append(tmpVariable);
|
||||||
querySelect.append(".");
|
querySelect.append(".");
|
||||||
querySelect.append("object1Id ");
|
if (manyToMany.mappedBy() == null) {
|
||||||
|
querySelect.append("object1Id ");
|
||||||
|
} else {
|
||||||
|
querySelect.append("object2Id ");
|
||||||
|
}
|
||||||
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||||
querySelect.append(" GROUP BY ");
|
querySelect.append(" GROUP BY ");
|
||||||
querySelect.append(tmpVariable);
|
querySelect.append(tmpVariable);
|
||||||
querySelect.append(".object1Id");
|
if (manyToMany.mappedBy() == null) {
|
||||||
|
querySelect.append(".object1Id");
|
||||||
|
} else {
|
||||||
|
querySelect.append(".object2Id");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
querySelect.append(") AS ");
|
querySelect.append(") AS ");
|
||||||
querySelect.append(name);
|
querySelect.append(name);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.kar.archidata.dataAccess.addOn.model;
|
package org.kar.archidata.dataAccess.addOn.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ public class TableCoversLongUUID {
|
|||||||
|
|
||||||
public TableCoversLongUUID(final Long id, final List<UUID> covers) {
|
public TableCoversLongUUID(final Long id, final List<UUID> covers) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.covers = covers;
|
this.covers = new ArrayList<>(covers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.kar.archidata.dataAccess.addOn.model;
|
package org.kar.archidata.dataAccess.addOn.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ public class TableCoversUUIDLong {
|
|||||||
|
|
||||||
public TableCoversUUIDLong(final UUID uuid, final List<Long> covers) {
|
public TableCoversUUIDLong(final UUID uuid, final List<Long> covers) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.covers = covers;
|
this.covers = new ArrayList<>(covers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -3,6 +3,9 @@ package org.kar.archidata.externalRestApi.typescript;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
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.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -415,7 +418,10 @@ public class TsApiGeneration {
|
|||||||
}
|
}
|
||||||
for (final ClassModel model : writeImports) {
|
for (final ClassModel model : writeImports) {
|
||||||
final TsClassElement tsModel = tsGroup.find(model);
|
final TsClassElement tsModel = tsGroup.find(model);
|
||||||
if (tsModel.nativeType == DefinedPosition.NATIVE) {
|
if (tsModel.nativeType != DefinedPosition.NORMAL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (tsModel.models.get(0).isNoWriteSpecificMode()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
finalImportSet.add(tsModel.tsTypeName + "Write");
|
finalImportSet.add(tsModel.tsTypeName + "Write");
|
||||||
@ -433,6 +439,10 @@ public class TsApiGeneration {
|
|||||||
|
|
||||||
out.append(data.toString());
|
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 String fileName = TsClassElement.determineFileName(element.name);
|
||||||
final FileWriter myWriter = new FileWriter(
|
final FileWriter myWriter = new FileWriter(
|
||||||
pathPackage + File.separator + "api" + File.separator + fileName + ".ts");
|
pathPackage + File.separator + "api" + File.separator + fileName + ".ts");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user