Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 48c32a3744 | |||
| fc521d2287 | |||
| 15125e2d6d | |||
| 6f1dd991c5 |
11
.classpath
11
.classpath
@@ -30,5 +30,16 @@
|
|||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="target/generated-sources/annotations">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
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.6.2</version>
|
<version>0.6.3</version>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.version>3.1</maven.compiler.version>
|
<maven.compiler.version>3.1</maven.compiler.version>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ import jakarta.ws.rs.core.StreamingOutput;
|
|||||||
@Path("/data")
|
@Path("/data")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public class DataResource {
|
public class DataResource {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(MediaType.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DataResource.class);
|
||||||
private final static int CHUNK_SIZE = 1024 * 1024; // 1MB chunks
|
private final static int CHUNK_SIZE = 1024 * 1024; // 1MB chunks
|
||||||
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 */
|
||||||
|
|||||||
@@ -448,9 +448,9 @@ public class DataAccess {
|
|||||||
|
|
||||||
// TODO: this function will replace the previous one !!!
|
// TODO: this function will replace the previous one !!!
|
||||||
protected static RetreiveFromDB createSetValueFromDbCallback(final int count, final Field field) throws Exception {
|
protected static RetreiveFromDB createSetValueFromDbCallback(final int count, final Field field) throws Exception {
|
||||||
Class<?> type = field.getType();
|
final Class<?> type = field.getType();
|
||||||
if (type == Long.class) {
|
if (type == Long.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final Long tmp = rs.getLong(count);
|
final Long tmp = rs.getLong(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(obj, null);
|
field.set(obj, null);
|
||||||
@@ -460,7 +460,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == long.class) {
|
if (type == long.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final Long tmp = rs.getLong(count);
|
final Long tmp = rs.getLong(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
// field.set(data, null);
|
// field.set(data, null);
|
||||||
@@ -470,7 +470,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == Integer.class) {
|
if (type == Integer.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final Integer tmp = rs.getInt(count);
|
final Integer tmp = rs.getInt(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(obj, null);
|
field.set(obj, null);
|
||||||
@@ -480,7 +480,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == int.class) {
|
if (type == int.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final Integer tmp = rs.getInt(count);
|
final Integer tmp = rs.getInt(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
// field.set(obj, null);
|
// field.set(obj, null);
|
||||||
@@ -490,7 +490,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == Float.class) {
|
if (type == Float.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final Float tmp = rs.getFloat(count);
|
final Float tmp = rs.getFloat(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(obj, null);
|
field.set(obj, null);
|
||||||
@@ -500,7 +500,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == float.class) {
|
if (type == float.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final Float tmp = rs.getFloat(count);
|
final Float tmp = rs.getFloat(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
// field.set(obj, null);
|
// field.set(obj, null);
|
||||||
@@ -510,7 +510,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == Double.class) {
|
if (type == Double.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final Double tmp = rs.getDouble(count);
|
final Double tmp = rs.getDouble(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(obj, null);
|
field.set(obj, null);
|
||||||
@@ -520,7 +520,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == double.class) {
|
if (type == double.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final Double tmp = rs.getDouble(count);
|
final Double tmp = rs.getDouble(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
// field.set(obj, null);
|
// field.set(obj, null);
|
||||||
@@ -530,7 +530,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == Boolean.class) {
|
if (type == Boolean.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final Boolean tmp = rs.getBoolean(count);
|
final Boolean tmp = rs.getBoolean(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(obj, null);
|
field.set(obj, null);
|
||||||
@@ -540,7 +540,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == boolean.class) {
|
if (type == boolean.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final Boolean tmp = rs.getBoolean(count);
|
final Boolean tmp = rs.getBoolean(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
// field.set(obj, null);
|
// field.set(obj, null);
|
||||||
@@ -550,7 +550,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == Timestamp.class) {
|
if (type == Timestamp.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final Timestamp tmp = rs.getTimestamp(count);
|
final Timestamp tmp = rs.getTimestamp(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(obj, null);
|
field.set(obj, null);
|
||||||
@@ -560,7 +560,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == Date.class) {
|
if (type == Date.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
try {
|
try {
|
||||||
final Timestamp tmp = rs.getTimestamp(count);
|
final Timestamp tmp = rs.getTimestamp(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
@@ -582,7 +582,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == LocalDate.class) {
|
if (type == LocalDate.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final java.sql.Date tmp = rs.getDate(count);
|
final java.sql.Date tmp = rs.getDate(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(obj, null);
|
field.set(obj, null);
|
||||||
@@ -592,7 +592,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == LocalTime.class) {
|
if (type == LocalTime.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final java.sql.Time tmp = rs.getTime(count);
|
final java.sql.Time tmp = rs.getTime(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(obj, null);
|
field.set(obj, null);
|
||||||
@@ -602,7 +602,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type == String.class) {
|
if (type == String.class) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final String tmp = rs.getString(count);
|
final String tmp = rs.getString(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(obj, null);
|
field.set(obj, null);
|
||||||
@@ -612,7 +612,7 @@ public class DataAccess {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type.isEnum()) {
|
if (type.isEnum()) {
|
||||||
return (final ResultSet rs, Object obj) -> {
|
return (final ResultSet rs, final Object obj) -> {
|
||||||
final String tmp = rs.getString(count);
|
final String tmp = rs.getString(count);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(obj, null);
|
field.set(obj, null);
|
||||||
@@ -1508,42 +1508,51 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* - useful code to manage external query: List<T> query<T>(class<T> clazz, ); ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2"); */
|
||||||
- useful code to manage external query: List<T> query<T>(class<T> clazz, );
|
public static <TYPE> List<TYPE> query(final Class<TYPE> clazz, final String query, final List<Object> parameters, final QueryOption... option) throws Exception {
|
||||||
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
|
|
||||||
*/
|
|
||||||
public static <TYPE> List<TYPE> query(final Class<TYPE> clazz, String query, List<Object> parameters, final QueryOption... option) throws Exception {
|
|
||||||
final QueryOptions options = new QueryOptions(option);
|
final QueryOptions options = new QueryOptions(option);
|
||||||
|
return query(clazz, query, parameters, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <TYPE> List<TYPE> query(final Class<TYPE> clazz, final String queryBase, final List<Object> parameters, final QueryOptions options) throws Exception {
|
||||||
final List<LazyGetter> lazyCall = new ArrayList<>();
|
final List<LazyGetter> lazyCall = new ArrayList<>();
|
||||||
// TODO ... final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
// TODO ... final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||||
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||||
|
|
||||||
|
Condition condition = options.get(Condition.class);
|
||||||
|
if (condition == null) {
|
||||||
|
condition = new Condition();
|
||||||
|
}
|
||||||
|
final StringBuilder query = new StringBuilder(queryBase);
|
||||||
final List<TYPE> outs = new ArrayList<>();
|
final List<TYPE> outs = new ArrayList<>();
|
||||||
// real add in the BDD:
|
// real add in the BDD:
|
||||||
try {
|
try {
|
||||||
final CountInOut count = new CountInOut();
|
final CountInOut count = new CountInOut();
|
||||||
|
condition.whereAppendQuery(query, null, options, null);
|
||||||
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, Statement.RETURN_GENERATED_KEYS);
|
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
||||||
final CountInOut iii = new CountInOut(1);
|
final CountInOut iii = new CountInOut(1);
|
||||||
if (parameters != null) {
|
if (parameters != null) {
|
||||||
for (Object elem : parameters) {
|
for (final Object elem : parameters) {
|
||||||
DataAccess.addElement(ps, elem, iii);
|
DataAccess.addElement(ps, elem, iii);
|
||||||
}
|
}
|
||||||
iii.inc();
|
iii.inc();
|
||||||
}
|
}
|
||||||
|
condition.injectQuerry(ps, iii);
|
||||||
// execute the request
|
// execute the request
|
||||||
final ResultSet rs = ps.executeQuery();
|
final ResultSet rs = ps.executeQuery();
|
||||||
ResultSetMetaData rsmd = rs.getMetaData();
|
final ResultSetMetaData rsmd = rs.getMetaData();
|
||||||
List<RetreiveFromDB> actionToRetreive = new ArrayList<>();
|
final List<RetreiveFromDB> actionToRetreive = new ArrayList<>();
|
||||||
for (int jjj = 0; jjj < rsmd.getColumnCount(); jjj++) {
|
for (int jjj = 0; jjj < rsmd.getColumnCount(); jjj++) {
|
||||||
String name = rsmd.getColumnName(jjj + 1);
|
final String name = rsmd.getColumnName(jjj + 1);
|
||||||
// find field name ...
|
// find field name ...
|
||||||
Field field = AnnotationTools.getFieldNamed(clazz, name);
|
final Field field = AnnotationTools.getFieldNamed(clazz, name);
|
||||||
if (field == null) {
|
if (field == null) {
|
||||||
throw new DataAccessException("Querry with unknown field: '" + name + "'");
|
throw new DataAccessException("Querry with unknown field: '" + name + "'");
|
||||||
}
|
}
|
||||||
// create the callback...
|
// create the callback...
|
||||||
RetreiveFromDB element = createSetValueFromDbCallback(jjj + 1, field);
|
final RetreiveFromDB element = createSetValueFromDbCallback(jjj + 1, field);
|
||||||
actionToRetreive.add(element);
|
actionToRetreive.add(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1559,7 +1568,7 @@ public class DataAccess {
|
|||||||
if (data == null) {
|
if (data == null) {
|
||||||
// TODO...
|
// TODO...
|
||||||
} else {
|
} else {
|
||||||
for (RetreiveFromDB action : actionToRetreive) {
|
for (final RetreiveFromDB action : actionToRetreive) {
|
||||||
action.doRequest(rs, data);
|
action.doRequest(rs, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ public class QueryAnd implements QueryItem {
|
|||||||
Collections.addAll(this.childs, items);
|
Collections.addAll(this.childs, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void add(final QueryItem... items) {
|
||||||
|
Collections.addAll(this.childs, items);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||||
if (this.childs.size() >= 1) {
|
if (this.childs.size() >= 1) {
|
||||||
@@ -43,4 +47,8 @@ public class QueryAnd implements QueryItem {
|
|||||||
elem.injectQuerry(ps, iii);
|
elem.injectQuerry(ps, iii);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return this.childs.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ public class QueryCondition implements QueryItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||||
|
if (tableName != null) {
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
query.append(".");
|
query.append(".");
|
||||||
|
}
|
||||||
query.append(this.key);
|
query.append(this.key);
|
||||||
query.append(" ");
|
query.append(" ");
|
||||||
query.append(this.comparator);
|
query.append(this.comparator);
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ public class QueryInList<T> implements QueryItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||||
|
if (tableName != null) {
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
query.append(".");
|
query.append(".");
|
||||||
|
}
|
||||||
query.append(this.key);
|
query.append(this.key);
|
||||||
query.append(" ");
|
query.append(" ");
|
||||||
query.append(this.comparator);
|
query.append(this.comparator);
|
||||||
|
|||||||
24
src/org/kar/archidata/dataAccess/QueryNotNull.java
Normal file
24
src/org/kar/archidata/dataAccess/QueryNotNull.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
|
||||||
|
public class QueryNotNull implements QueryItem {
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
public QueryNotNull(final String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||||
|
if (tableName != null) {
|
||||||
|
query.append(tableName);
|
||||||
|
query.append(".");
|
||||||
|
}
|
||||||
|
query.append(this.key);
|
||||||
|
query.append(" IS NOT NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {}
|
||||||
|
}
|
||||||
24
src/org/kar/archidata/dataAccess/QueryNull.java
Normal file
24
src/org/kar/archidata/dataAccess/QueryNull.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
|
||||||
|
public class QueryNull implements QueryItem {
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
public QueryNull(final String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||||
|
if (tableName != null) {
|
||||||
|
query.append(tableName);
|
||||||
|
query.append(".");
|
||||||
|
}
|
||||||
|
query.append(this.key);
|
||||||
|
query.append(" IS NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.kar.archidata.dataAccess.addOn;
|
package org.kar.archidata.dataAccess.addOn;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
@@ -17,6 +18,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
@@ -85,6 +87,40 @@ public class AddOnDataJson implements DataAccessAddOn {
|
|||||||
count.inc();
|
count.inc();
|
||||||
if (!rs.wasNull()) {
|
if (!rs.wasNull()) {
|
||||||
final ObjectMapper objectMapper = new ObjectMapper();
|
final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
if (field.getType() == List.class) {
|
||||||
|
ParameterizedType listType = (ParameterizedType) field.getGenericType();
|
||||||
|
Class<?> listClass = (Class<?>) listType.getActualTypeArguments()[0];
|
||||||
|
if (listClass == Long.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Long>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Float.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Float>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Double.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Double>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Integer.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Integer>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == Short.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<Short>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (listClass == String.class) {
|
||||||
|
final Object dataParsed = objectMapper.readValue(jsonData, new TypeReference<List<String>>() {});// field.getType());
|
||||||
|
field.set(data, dataParsed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
final Object dataParsed = objectMapper.readValue(jsonData, field.getType());
|
final Object dataParsed = objectMapper.readValue(jsonData, field.getType());
|
||||||
field.set(data, dataParsed);
|
field.set(data, dataParsed);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert(final Field field) {
|
public boolean canInsert(final Field field) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
49
src/org/kar/archidata/serializer/CSVMessageBodyWriter.java
Normal file
49
src/org/kar/archidata/serializer/CSVMessageBodyWriter.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package org.kar.archidata.serializer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
|
||||||
|
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.Produces;
|
||||||
|
import jakarta.ws.rs.WebApplicationException;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.MultivaluedMap;
|
||||||
|
import jakarta.ws.rs.ext.MessageBodyWriter;
|
||||||
|
import jakarta.ws.rs.ext.Provider;
|
||||||
|
|
||||||
|
/** Body writer use in jersey with : In your main: ```java rc.register(new CSVMessageBodyWritter()); ```
|
||||||
|
*
|
||||||
|
* and in the produce element: ```java
|
||||||
|
* @GET
|
||||||
|
* @Produces(CSVMessageBodyWritter.CSV_TYPE) public List<Data> getData() {} ``` */
|
||||||
|
@Provider
|
||||||
|
@Produces("text/csv")
|
||||||
|
public class CSVMessageBodyWriter implements MessageBodyWriter<List<Object>> {
|
||||||
|
public static final String CSV_TYPE = "text/csv";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
|
||||||
|
return List.class.isAssignableFrom(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSize(final List<Object> data, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(final List<Object> data, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType,
|
||||||
|
final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException {
|
||||||
|
if (data != null && data.size() > 0) {
|
||||||
|
final CsvMapper mapper = new CsvMapper();
|
||||||
|
final Object o = data.get(0);
|
||||||
|
final CsvSchema schema = mapper.schemaFor(o.getClass()).withHeader();
|
||||||
|
mapper.writer(schema).writeValue(entityStream, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package org.kar.archidata.serializer;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
|
|
||||||
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
|
|
||||||
|
|
||||||
import jakarta.ws.rs.Produces;
|
|
||||||
import jakarta.ws.rs.WebApplicationException;
|
|
||||||
import jakarta.ws.rs.core.MediaType;
|
|
||||||
import jakarta.ws.rs.core.MultivaluedMap;
|
|
||||||
import jakarta.ws.rs.ext.MessageBodyWriter;
|
|
||||||
import jakarta.ws.rs.ext.Provider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Body writter use in jersey with :
|
|
||||||
* In your main:
|
|
||||||
* ```java
|
|
||||||
* rc.register(new CSVMessageBodyWritter());
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* and in the produce element:
|
|
||||||
* ```java
|
|
||||||
* @GET
|
|
||||||
* @Produces("text/csv")
|
|
||||||
* public List<Data> getData() {}
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
@Provider
|
|
||||||
@Produces("text/csv")
|
|
||||||
public class CSVMessageBodyWritter implements MessageBodyWriter<List<?>> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
|
|
||||||
return List.class.isAssignableFrom(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getSize(List<?> data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeTo(List<?> data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
|
|
||||||
throws IOException, WebApplicationException {
|
|
||||||
if (data != null && data.size() > 0) {
|
|
||||||
CsvMapper mapper = new CsvMapper();
|
|
||||||
Object o = data.get(0);
|
|
||||||
CsvSchema schema = mapper.schemaFor(o.getClass()).withHeader();
|
|
||||||
mapper.writer(schema).writeValue(entityStream, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -19,6 +19,7 @@ import org.kar.archidata.dataAccess.QueryAnd;
|
|||||||
import org.kar.archidata.dataAccess.QueryCondition;
|
import org.kar.archidata.dataAccess.QueryCondition;
|
||||||
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
||||||
import org.kar.archidata.dataAccess.options.Condition;
|
import org.kar.archidata.dataAccess.options.Condition;
|
||||||
|
import org.kar.archidata.dataAccess.options.ReadAllColumn;
|
||||||
import org.kar.archidata.model.Data;
|
import org.kar.archidata.model.Data;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -76,7 +77,7 @@ public class DataTools {
|
|||||||
|
|
||||||
public static Data getWithSha512(final String sha512) {
|
public static Data getWithSha512(final String sha512) {
|
||||||
try {
|
try {
|
||||||
return DataAccess.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512)));
|
return DataAccess.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512)), new ReadAllColumn());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.6.2
|
0.6.3
|
||||||
|
|||||||
Reference in New Issue
Block a user