[DEV] change model of the DB ==> faster for our usecase
This commit is contained in:
parent
cf221ec2bb
commit
e92b6c7651
@ -5,7 +5,11 @@ import java.lang.reflect.Field;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
import org.kar.karusic.annotation.SQLAutoIncrement;
|
import org.kar.karusic.annotation.SQLAutoIncrement;
|
||||||
import org.kar.karusic.annotation.SQLComment;
|
import org.kar.karusic.annotation.SQLComment;
|
||||||
@ -15,6 +19,7 @@ import org.kar.karusic.annotation.SQLNotNull;
|
|||||||
import org.kar.karusic.annotation.SQLNotRead;
|
import org.kar.karusic.annotation.SQLNotRead;
|
||||||
import org.kar.karusic.annotation.SQLPrimaryKey;
|
import org.kar.karusic.annotation.SQLPrimaryKey;
|
||||||
import org.kar.karusic.annotation.SQLTableLinkGeneric;
|
import org.kar.karusic.annotation.SQLTableLinkGeneric;
|
||||||
|
import org.kar.karusic.annotation.SQLTableLinkGeneric.ModelLink;
|
||||||
import org.kar.karusic.annotation.SQLTableName;
|
import org.kar.karusic.annotation.SQLTableName;
|
||||||
import org.kar.karusic.annotation.SQLUpdateTime;
|
import org.kar.karusic.annotation.SQLUpdateTime;
|
||||||
import org.kar.karusic.db.DBEntry;
|
import org.kar.karusic.db.DBEntry;
|
||||||
@ -143,7 +148,7 @@ public class SqlWrapper {
|
|||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
field.set(data, null);
|
field.set(data, null);
|
||||||
} else {
|
} else {
|
||||||
System.out.println(" ==> " + tmp);
|
//System.out.println(" ==> " + tmp);
|
||||||
field.set(data, tmp);
|
field.set(data, tmp);
|
||||||
}
|
}
|
||||||
} else if (type == long.class ) {
|
} else if (type == long.class ) {
|
||||||
@ -232,6 +237,13 @@ public class SqlWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static ModelLink getLinkMode(Field elem) {
|
||||||
|
SQLTableLinkGeneric[] decorators = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class);
|
||||||
|
if (decorators == null || decorators.length == 0) {
|
||||||
|
return SQLTableLinkGeneric.ModelLink.NONE;
|
||||||
|
}
|
||||||
|
return decorators[0].value();
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> T insert(T data) throws Exception {
|
public static <T> T insert(T data) throws Exception {
|
||||||
Class<?> clazz = data.getClass();
|
Class<?> clazz = data.getClass();
|
||||||
@ -254,8 +266,8 @@ public class SqlWrapper {
|
|||||||
if (primaryKey) {
|
if (primaryKey) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
ModelLink linkGeneric = getLinkMode(elem);
|
||||||
if (linkGeneric) {
|
if (linkGeneric == ModelLink.EXTERNAL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
||||||
@ -305,8 +317,8 @@ public class SqlWrapper {
|
|||||||
primaryKeyField = elem;
|
primaryKeyField = elem;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
ModelLink linkGeneric = getLinkMode(elem);
|
||||||
if (linkGeneric) {
|
if (linkGeneric == ModelLink.EXTERNAL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
||||||
@ -317,6 +329,7 @@ public class SqlWrapper {
|
|||||||
if (updateTime) {
|
if (updateTime) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (linkGeneric == ModelLink.NONE) {
|
||||||
Class<?> type = elem.getType();
|
Class<?> type = elem.getType();
|
||||||
if (!type.isPrimitive()) {
|
if (!type.isPrimitive()) {
|
||||||
Object tmp = elem.get(data);
|
Object tmp = elem.get(data);
|
||||||
@ -324,8 +337,19 @@ public class SqlWrapper {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
count++;
|
|
||||||
setValuedb(type, data, iii++, elem, ps);
|
setValuedb(type, data, iii++, elem, ps);
|
||||||
|
} else {
|
||||||
|
// transform the data in string to insert it ...
|
||||||
|
Object tmp = elem.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii++, Types.BIGINT);
|
||||||
|
} else {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
String dataTmp = getStringOfIds((List<Long>)tmp);
|
||||||
|
ps.setString(iii++, dataTmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
// execute the request
|
// execute the request
|
||||||
int affectedRows = ps.executeUpdate();
|
int affectedRows = ps.executeUpdate();
|
||||||
@ -403,8 +427,8 @@ public class SqlWrapper {
|
|||||||
primaryKeyField = elem;
|
primaryKeyField = elem;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
ModelLink linkGeneric = getLinkMode(elem);
|
||||||
if (linkGeneric) {
|
if (linkGeneric == ModelLink.EXTERNAL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
||||||
@ -450,8 +474,8 @@ public class SqlWrapper {
|
|||||||
if (primaryKey) {
|
if (primaryKey) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
ModelLink linkGeneric = getLinkMode(elem);
|
||||||
if (linkGeneric) {
|
if (linkGeneric == ModelLink.EXTERNAL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
||||||
@ -463,6 +487,7 @@ public class SqlWrapper {
|
|||||||
if (updateTime || !filterValue.contains(name)) {
|
if (updateTime || !filterValue.contains(name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (linkGeneric == ModelLink.NONE) {
|
||||||
Class<?> type = elem.getType();
|
Class<?> type = elem.getType();
|
||||||
if (!type.isPrimitive()) {
|
if (!type.isPrimitive()) {
|
||||||
Object tmp = elem.get(data);
|
Object tmp = elem.get(data);
|
||||||
@ -470,8 +495,19 @@ public class SqlWrapper {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
count++;
|
|
||||||
setValuedb(type, data, iii++, elem, ps);
|
setValuedb(type, data, iii++, elem, ps);
|
||||||
|
} else {
|
||||||
|
// transform the data in string to insert it ...
|
||||||
|
Object tmp = elem.get(data);
|
||||||
|
if (tmp == null) {
|
||||||
|
ps.setNull(iii++, Types.BIGINT);
|
||||||
|
} else {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
String dataTmp = getStringOfIds((List<Long>)tmp);
|
||||||
|
ps.setString(iii++, dataTmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
ps.setLong(iii++, id);
|
ps.setLong(iii++, id);
|
||||||
// execute the request
|
// execute the request
|
||||||
@ -505,8 +541,8 @@ public class SqlWrapper {
|
|||||||
if (primaryKey) {
|
if (primaryKey) {
|
||||||
primaryKeyField = elem;
|
primaryKeyField = elem;
|
||||||
}
|
}
|
||||||
boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
ModelLink linkGeneric = getLinkMode(elem);
|
||||||
if (linkGeneric) {
|
if (linkGeneric != ModelLink.NONE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
||||||
@ -555,8 +591,8 @@ public class SqlWrapper {
|
|||||||
Object data = clazz.getConstructors()[0].newInstance();
|
Object data = clazz.getConstructors()[0].newInstance();
|
||||||
count = 1;
|
count = 1;
|
||||||
for (Field elem : clazz.getFields()) {
|
for (Field elem : clazz.getFields()) {
|
||||||
boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
ModelLink linkGeneric = getLinkMode(elem);
|
||||||
if (linkGeneric) {
|
if (linkGeneric != ModelLink.NONE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
||||||
@ -606,8 +642,8 @@ public class SqlWrapper {
|
|||||||
if (primaryKey) {
|
if (primaryKey) {
|
||||||
primaryKeyField = elem;
|
primaryKeyField = elem;
|
||||||
}
|
}
|
||||||
boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
ModelLink linkGeneric = getLinkMode(elem);
|
||||||
if (linkGeneric) {
|
if (linkGeneric != ModelLink.NONE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
||||||
@ -628,6 +664,7 @@ public class SqlWrapper {
|
|||||||
query.append(" ");
|
query.append(" ");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
query.append(".");
|
query.append(".");
|
||||||
|
|
||||||
query.append(name);
|
query.append(name);
|
||||||
}
|
}
|
||||||
query.append(" FROM `");
|
query.append(" FROM `");
|
||||||
@ -655,8 +692,8 @@ public class SqlWrapper {
|
|||||||
Object data = clazz.getConstructors()[0].newInstance();
|
Object data = clazz.getConstructors()[0].newInstance();
|
||||||
count = 1;
|
count = 1;
|
||||||
for (Field elem : clazz.getFields()) {
|
for (Field elem : clazz.getFields()) {
|
||||||
boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
ModelLink linkGeneric = getLinkMode(elem);
|
||||||
if (linkGeneric) {
|
if (linkGeneric != ModelLink.NONE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
||||||
@ -685,9 +722,18 @@ public class SqlWrapper {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum StateLoad {
|
||||||
|
DISABLE,
|
||||||
|
NORMAL,
|
||||||
|
ARRAY
|
||||||
|
};
|
||||||
|
|
||||||
|
public static String getCurrentTimeStamp() {
|
||||||
|
return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> List<T> gets(Class<T> clazz, boolean fool) throws Exception {
|
public static <T> List<T> gets(Class<T> clazz, boolean fool) throws Exception {
|
||||||
|
System.out.println("request get " + clazz.getCanonicalName() + " start @" + getCurrentTimeStamp());
|
||||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||||
List<T> out = new ArrayList<>();
|
List<T> out = new ArrayList<>();
|
||||||
// real add in the BDD:
|
// real add in the BDD:
|
||||||
@ -701,10 +747,13 @@ public class SqlWrapper {
|
|||||||
|
|
||||||
boolean firstField = true;
|
boolean firstField = true;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
StateLoad[] autoClasify = new StateLoad[clazz.getFields().length];
|
||||||
|
int indexAutoClasify = 0;
|
||||||
for (Field elem : clazz.getFields()) {
|
for (Field elem : clazz.getFields()) {
|
||||||
|
|
||||||
boolean notRead = elem.getDeclaredAnnotationsByType(SQLNotRead.class).length != 0;
|
boolean notRead = elem.getDeclaredAnnotationsByType(SQLNotRead.class).length != 0;
|
||||||
if (!fool && notRead) {
|
if (!fool && notRead) {
|
||||||
|
autoClasify[indexAutoClasify++] = StateLoad.DISABLE;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String name = elem.getName();
|
String name = elem.getName();
|
||||||
@ -714,8 +763,9 @@ public class SqlWrapper {
|
|||||||
} else {
|
} else {
|
||||||
query.append(",");
|
query.append(",");
|
||||||
}
|
}
|
||||||
boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
ModelLink linkGeneric = getLinkMode(elem);
|
||||||
if (linkGeneric) {
|
if (linkGeneric == ModelLink.EXTERNAL) {
|
||||||
|
autoClasify[indexAutoClasify++] = StateLoad.ARRAY;
|
||||||
String localName = name;
|
String localName = name;
|
||||||
if (name.endsWith("s")) {
|
if (name.endsWith("s")) {
|
||||||
localName = name.substring(0, name.length()-1);
|
localName = name.substring(0, name.length()-1);
|
||||||
@ -754,6 +804,11 @@ public class SqlWrapper {
|
|||||||
" GROUP BY tmp.node_id) AS covers" +
|
" GROUP BY tmp.node_id) AS covers" +
|
||||||
*/
|
*/
|
||||||
} else {
|
} else {
|
||||||
|
if (linkGeneric == ModelLink.NONE) {
|
||||||
|
autoClasify[indexAutoClasify++] = StateLoad.NORMAL;
|
||||||
|
} else {
|
||||||
|
autoClasify[indexAutoClasify++] = StateLoad.ARRAY;
|
||||||
|
}
|
||||||
query.append(" ");
|
query.append(" ");
|
||||||
query.append(tableName);
|
query.append(tableName);
|
||||||
query.append(".");
|
query.append(".");
|
||||||
@ -773,32 +828,46 @@ public class SqlWrapper {
|
|||||||
query.append(".deleted = false ");
|
query.append(".deleted = false ");
|
||||||
firstField = true;
|
firstField = true;
|
||||||
System.out.println("generate the querry: '" + query.toString() + "'");
|
System.out.println("generate the querry: '" + query.toString() + "'");
|
||||||
|
System.out.println("request get " + clazz.getCanonicalName() + " prepare @" + getCurrentTimeStamp());
|
||||||
// prepare the request:
|
// prepare the request:
|
||||||
PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
||||||
|
|
||||||
|
System.out.println("request get " + clazz.getCanonicalName() + " query @" + getCurrentTimeStamp());
|
||||||
// execute the request
|
// execute the request
|
||||||
ResultSet rs = ps.executeQuery();
|
ResultSet rs = ps.executeQuery();
|
||||||
|
System.out.println("request get " + clazz.getCanonicalName() + " transform @" + getCurrentTimeStamp());
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
indexAutoClasify = 0;
|
||||||
Object data = clazz.getConstructors()[0].newInstance();
|
Object data = clazz.getConstructors()[0].newInstance();
|
||||||
count = 1;
|
count = 1;
|
||||||
for (Field elem : clazz.getFields()) {
|
for (Field elem : clazz.getFields()) {
|
||||||
|
/*
|
||||||
boolean notRead = elem.getDeclaredAnnotationsByType(SQLNotRead.class).length != 0;
|
boolean notRead = elem.getDeclaredAnnotationsByType(SQLNotRead.class).length != 0;
|
||||||
|
*/
|
||||||
|
boolean notRead = autoClasify[indexAutoClasify] == StateLoad.DISABLE;
|
||||||
if (!fool && notRead) {
|
if (!fool && notRead) {
|
||||||
|
indexAutoClasify++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String name = elem.getName();
|
//String name = elem.getName();
|
||||||
boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
//boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
||||||
|
boolean linkGeneric = autoClasify[indexAutoClasify] == StateLoad.ARRAY;
|
||||||
if (linkGeneric) {
|
if (linkGeneric) {
|
||||||
List<Long> idList = getListOfIds(rs, count);
|
List<Long> idList = getListOfIds(rs, count);
|
||||||
elem.set(data, idList);
|
elem.set(data, idList);
|
||||||
} else {
|
} else {
|
||||||
setValueFromDb(elem.getType(), data, count, elem, rs);
|
setValueFromDb(elem.getType(), data, count, elem, rs);
|
||||||
}
|
}
|
||||||
|
indexAutoClasify++;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
//System.out.println("Read: " + (T)data);
|
//System.out.println("Read: " + (T)data);
|
||||||
out.add((T)data);
|
out.add((T)data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("request get " + clazz.getCanonicalName() + " ready @" + getCurrentTimeStamp());
|
||||||
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -863,6 +932,13 @@ public class SqlWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* extract a list of "-" separated element from a SQL input data.
|
||||||
|
* @param rs Result Set of the BDD
|
||||||
|
* @param iii Id in the result set
|
||||||
|
* @return The list of Long value
|
||||||
|
* @throws SQLException if an error is generated in the sql request.
|
||||||
|
*/
|
||||||
protected static List<Long> getListOfIds(ResultSet rs, int iii) throws SQLException {
|
protected static List<Long> getListOfIds(ResultSet rs, int iii) throws SQLException {
|
||||||
String trackString = rs.getString(iii);
|
String trackString = rs.getString(iii);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
@ -876,10 +952,22 @@ public class SqlWrapper {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Convert the list if external Ids in a string '-' separated
|
||||||
|
* @param ids List of value (null are removed)
|
||||||
|
* @return '-' string separated
|
||||||
|
*/
|
||||||
|
protected static String getStringOfIds(List<Long> ids) {
|
||||||
|
List<Long> tmp = new ArrayList<>();
|
||||||
|
for (Long elem : ids) {
|
||||||
|
tmp.add(elem);
|
||||||
|
}
|
||||||
|
return tmp.stream().map(x->String.valueOf(x)).collect(Collectors.joining("-"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void delete(Class<?> clazz, long id) throws Exception {
|
public static void delete(Class<?> clazz, long id) throws Exception {
|
||||||
|
// TODO: I am not sure this is a real good idea.
|
||||||
}
|
}
|
||||||
public static void setDelete(Class<?> clazz, long id) throws Exception {
|
public static void setDelete(Class<?> clazz, long id) throws Exception {
|
||||||
String tableName = getTableName(clazz);
|
String tableName = getTableName(clazz);
|
||||||
@ -927,17 +1015,17 @@ public class SqlWrapper {
|
|||||||
//boolean sqlNotRead = elem.getDeclaredAnnotationsByType(SQLNotRead.class).length != 0;
|
//boolean sqlNotRead = elem.getDeclaredAnnotationsByType(SQLNotRead.class).length != 0;
|
||||||
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
boolean createTime = elem.getDeclaredAnnotationsByType(SQLCreateTime.class).length != 0;
|
||||||
boolean updateTime = elem.getDeclaredAnnotationsByType(SQLUpdateTime.class).length != 0;
|
boolean updateTime = elem.getDeclaredAnnotationsByType(SQLUpdateTime.class).length != 0;
|
||||||
boolean linkGeneric = elem.getDeclaredAnnotationsByType(SQLTableLinkGeneric.class).length != 0;
|
ModelLink linkGeneric = getLinkMode(elem);
|
||||||
String comment = getComment(elem);
|
String comment = getComment(elem);
|
||||||
String defaultValue = getDefault(elem);
|
String defaultValue = getDefault(elem);
|
||||||
System.out.println(" ==> elem `" + name + "` primaryKey=" + primaryKey + " linkGeneric=" + linkGeneric);
|
//System.out.println(" ==> elem `" + name + "` primaryKey=" + primaryKey + " linkGeneric=" + linkGeneric);
|
||||||
|
|
||||||
|
|
||||||
if (primaryKey) {
|
if (primaryKey) {
|
||||||
primaryKeyValue = name;
|
primaryKeyValue = name;
|
||||||
}
|
}
|
||||||
// special case with external link table:
|
// special case with external link table:
|
||||||
if (linkGeneric) {
|
if (linkGeneric == ModelLink.EXTERNAL) {
|
||||||
String localName = name;
|
String localName = name;
|
||||||
if (name.endsWith("s")) {
|
if (name.endsWith("s")) {
|
||||||
localName = name.substring(0, name.length()-1);
|
localName = name.substring(0, name.length()-1);
|
||||||
@ -975,7 +1063,12 @@ public class SqlWrapper {
|
|||||||
}
|
}
|
||||||
out.append(name);
|
out.append(name);
|
||||||
out.append("` ");
|
out.append("` ");
|
||||||
String typeValue = convertTypeInSQL(elem.getType());
|
String typeValue = null;
|
||||||
|
if (linkGeneric == ModelLink.INTERNAL) {
|
||||||
|
typeValue = convertTypeInSQL(String.class);
|
||||||
|
out.append(typeValue);
|
||||||
|
} else {
|
||||||
|
typeValue = convertTypeInSQL(elem.getType());
|
||||||
if (typeValue.equals("text")) {
|
if (typeValue.equals("text")) {
|
||||||
if (limitSize != null) {
|
if (limitSize != null) {
|
||||||
out.append("varchar(");
|
out.append("varchar(");
|
||||||
@ -987,6 +1080,7 @@ public class SqlWrapper {
|
|||||||
} else {
|
} else {
|
||||||
out.append(typeValue);
|
out.append(typeValue);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
out.append(" ");
|
out.append(" ");
|
||||||
if (notNull) {
|
if (notNull) {
|
||||||
out.append("NOT NULL ");
|
out.append("NOT NULL ");
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package org.kar.karusic;
|
package org.kar.karusic;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.ws.rs.core.UriBuilder;
|
import javax.ws.rs.core.UriBuilder;
|
||||||
@ -23,6 +25,7 @@ import org.kar.karusic.db.DBConfig;
|
|||||||
import org.kar.karusic.filter.AuthenticationFilter;
|
import org.kar.karusic.filter.AuthenticationFilter;
|
||||||
import org.kar.karusic.filter.CORSFilter;
|
import org.kar.karusic.filter.CORSFilter;
|
||||||
import org.kar.karusic.filter.OptionFilter;
|
import org.kar.karusic.filter.OptionFilter;
|
||||||
|
import org.kar.karusic.model.Track;
|
||||||
import org.kar.karusic.util.ConfigVariable;
|
import org.kar.karusic.util.ConfigVariable;
|
||||||
import org.kar.karusic.util.JWTWrapper;
|
import org.kar.karusic.util.JWTWrapper;
|
||||||
|
|
||||||
@ -46,6 +49,7 @@ public class WebLauncher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
//
|
//
|
||||||
// if (false) {
|
// if (false) {
|
||||||
// Track tmpTrack = new Track();
|
// Track tmpTrack = new Track();
|
||||||
@ -72,20 +76,20 @@ public class WebLauncher {
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// if (false) {
|
// if (false) {
|
||||||
// // generate the BDD:
|
// generate the BDD:
|
||||||
// try {
|
try {
|
||||||
// String out = "";
|
String out = "";
|
||||||
// out += SqlWrapper.createTable(User.class);
|
//out += SqlWrapper.createTable(User.class);
|
||||||
// out += SqlWrapper.createTable(Track.class);
|
out += SqlWrapper.createTable(Track.class);
|
||||||
// out += SqlWrapper.createTable(Artist.class);
|
// out += SqlWrapper.createTable(Artist.class);
|
||||||
// out += SqlWrapper.createTable(Gender.class);
|
// out += SqlWrapper.createTable(Gender.class);
|
||||||
// out += SqlWrapper.createTable(Playlist.class);
|
// out += SqlWrapper.createTable(Playlist.class);
|
||||||
// out += SqlWrapper.createTable(Album.class);
|
// out += SqlWrapper.createTable(Album.class);
|
||||||
// System.out.println(out);
|
System.out.println(out);
|
||||||
// } catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// // TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
// e.printStackTrace();
|
e.printStackTrace();
|
||||||
// }
|
}
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
// if (false) {
|
// if (false) {
|
||||||
|
@ -5,8 +5,16 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface SQLTableLinkGeneric {
|
public @interface SQLTableLinkGeneric {
|
||||||
|
public enum ModelLink {
|
||||||
|
NONE,
|
||||||
|
INTERNAL,
|
||||||
|
EXTERNAL
|
||||||
|
};
|
||||||
|
ModelLink value() default ModelLink.EXTERNAL;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.kar.karusic.api;
|
package org.kar.karusic.api;
|
||||||
|
|
||||||
|
import org.glassfish.jersey.internal.guava.Lists;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||||
import org.kar.karusic.SqlWrapper;
|
import org.kar.karusic.SqlWrapper;
|
||||||
@ -225,10 +226,17 @@ public class TrackResource {
|
|||||||
trackElem.albumId = albumElem!=null?albumElem.id:null;
|
trackElem.albumId = albumElem!=null?albumElem.id:null;
|
||||||
trackElem.genderId = genderElem!=null?genderElem.id:null;
|
trackElem.genderId = genderElem!=null?genderElem.id:null;
|
||||||
trackElem.dataId = data.id;
|
trackElem.dataId = data.id;
|
||||||
|
// Now list of artis has an internal management:
|
||||||
|
if (artistElem != null) {
|
||||||
|
trackElem.artists = List.of(artistElem.id);
|
||||||
|
}
|
||||||
trackElem = SqlWrapper.insert(trackElem);
|
trackElem = SqlWrapper.insert(trackElem);
|
||||||
|
/*
|
||||||
|
Old mode of artist insertion (removed due to the slowlest request of getting value
|
||||||
if (artistElem != null) {
|
if (artistElem != null) {
|
||||||
SqlWrapper.addLink(Track.class, trackElem.id, "artist", artistElem.id);
|
SqlWrapper.addLink(Track.class, trackElem.id, "artist", artistElem.id);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return Response.ok(trackElem).build();
|
return Response.ok(trackElem).build();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println("Catch an unexpected error ... " + ex.getMessage());
|
System.out.println("Catch an unexpected error ... " + ex.getMessage());
|
||||||
|
@ -28,7 +28,7 @@ public class Track extends NodeSmall {
|
|||||||
public Long albumId = null;
|
public Long albumId = null;
|
||||||
public Long track = null;
|
public Long track = null;
|
||||||
public Long dataId = null;
|
public Long dataId = null;
|
||||||
@SQLTableLinkGeneric
|
@SQLTableLinkGeneric(SQLTableLinkGeneric.ModelLink.INTERNAL)
|
||||||
public List<Long> artists = null;
|
public List<Long> artists = null;
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -29,10 +29,7 @@ import { GenderService, DataService, PlaylistService, ArtistService, AlbumServic
|
|||||||
import { BddService, CookiesService, HttpWrapperService, PopInService, SessionService, SSOService, StorageService, UserService } from 'common/service';
|
import { BddService, CookiesService, HttpWrapperService, PopInService, SessionService, SSOService, StorageService, UserService } from 'common/service';
|
||||||
import { ErrorViewerScene, SsoScene } from 'common/scene';
|
import { ErrorViewerScene, SsoScene } from 'common/scene';
|
||||||
import { UploadScene } from './scene/upload/upload';
|
import { UploadScene } from './scene/upload/upload';
|
||||||
import { ElementSeriesComponent } from './component/element-series/element-series';
|
import { ElementSeriesComponent, ElementTrackComponent, ElementSeasonComponent, ElementVideoComponent, ElementPlayerAudioComponent } from './component';
|
||||||
import { ElementVideoComponent } from './component/element-video/element-video';
|
|
||||||
import { ElementSeasonComponent } from './component/element-season/element-season';
|
|
||||||
import { ElementPlayerAudioComponent } from './component/element-player-audio/element-player-audio';
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@ -42,6 +39,7 @@ import { ElementPlayerAudioComponent } from './component/element-player-audio/el
|
|||||||
ElementDataImageComponent,
|
ElementDataImageComponent,
|
||||||
ElementTypeComponent,
|
ElementTypeComponent,
|
||||||
ElementSeriesComponent,
|
ElementSeriesComponent,
|
||||||
|
ElementTrackComponent,
|
||||||
ElementSeasonComponent,
|
ElementSeasonComponent,
|
||||||
ElementVideoComponent,
|
ElementVideoComponent,
|
||||||
ElementPlayerAudioComponent,
|
ElementPlayerAudioComponent,
|
||||||
|
11
front/src/app/component/element-track/element-track.html
Normal file
11
front/src/app/component/element-track/element-track.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<div class="item-list-element">
|
||||||
|
<div class="season-small">
|
||||||
|
{{prefixName}} {{numberAlbum}}
|
||||||
|
</div>
|
||||||
|
<div class="description-small" *ngIf="count > 1">
|
||||||
|
{{count}} Episodes
|
||||||
|
</div>
|
||||||
|
<div class="description-small" *ngIf="count == 1">
|
||||||
|
{{count}} Episode
|
||||||
|
</div>
|
||||||
|
</div>
|
47
front/src/app/component/element-track/element-track.less
Normal file
47
front/src/app/component/element-track/element-track.less
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
|
||||||
|
.item-list-element {
|
||||||
|
font-size: 20px;
|
||||||
|
padding: 1px;
|
||||||
|
height: 55px;
|
||||||
|
width: 80%;
|
||||||
|
margin: 5px auto 5px auto;
|
||||||
|
padding: 5px;
|
||||||
|
overflow: hidden;
|
||||||
|
line-height: normal;
|
||||||
|
border: none;
|
||||||
|
font-family: "Roboto","Helvetica","Arial",sans-serif;
|
||||||
|
font-weight: 500;
|
||||||
|
will-change: box-shadow;
|
||||||
|
outline: none;
|
||||||
|
cursor: pointer;
|
||||||
|
background: rgba(256, 256, 256, 0.3);
|
||||||
|
border-radius: 7px;
|
||||||
|
.material-icons {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
.material-icons {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: ~"translate(-12px,-12px)";
|
||||||
|
line-height: 24px;
|
||||||
|
width: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.title-small {
|
||||||
|
height: 50px;
|
||||||
|
//width: 100%;
|
||||||
|
font-size: 35px;
|
||||||
|
display:inline-block;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description-small {
|
||||||
|
height: 30px;
|
||||||
|
font-size: 16px;
|
||||||
|
overflow:hidden;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
51
front/src/app/component/element-track/element-track.ts
Normal file
51
front/src/app/component/element-track/element-track.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||||
|
* @license PROPRIETARY (see license file)
|
||||||
|
*/
|
||||||
|
import {Component, OnInit, Input } from '@angular/core';
|
||||||
|
|
||||||
|
import { AlbumService, DataService } from 'app/service';
|
||||||
|
import { NodeData } from 'common/model';
|
||||||
|
import { isNullOrUndefined } from 'common/utils';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-element-track',
|
||||||
|
templateUrl: './element-track.html',
|
||||||
|
styleUrls: [ './element-track.less' ]
|
||||||
|
})
|
||||||
|
export class ElementTrackComponent implements OnInit {
|
||||||
|
// input parameters
|
||||||
|
@Input() element:NodeData;
|
||||||
|
@Input() prefix:String;
|
||||||
|
|
||||||
|
prefixName: string = "";
|
||||||
|
numberAlbum: string;
|
||||||
|
count: number;
|
||||||
|
covers: string[];
|
||||||
|
description: string;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private albumService: AlbumService,
|
||||||
|
private dataService: DataService) {
|
||||||
|
|
||||||
|
}
|
||||||
|
ngOnInit() {
|
||||||
|
this.prefix = this.prefixName??"";
|
||||||
|
if (isNullOrUndefined(this.element)) {
|
||||||
|
this.numberAlbum = undefined;
|
||||||
|
this.covers = undefined;
|
||||||
|
this.description = undefined;
|
||||||
|
}
|
||||||
|
this.numberAlbum = this.element.name;
|
||||||
|
this.description = this.element.description;
|
||||||
|
this.covers = this.dataService.getCoverListThumbnailUrl(this.element.covers);
|
||||||
|
let self = this;
|
||||||
|
this.albumService.countTrack(this.element.id)
|
||||||
|
.then((response) => {
|
||||||
|
self.count = response;
|
||||||
|
}).catch((response) => {
|
||||||
|
self.count = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
16
front/src/app/component/index.ts
Normal file
16
front/src/app/component/index.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { ElementPlayerAudioComponent } from "./element-player-audio/element-player-audio";
|
||||||
|
import { ElementSeasonComponent } from "./element-season/element-season";
|
||||||
|
import { ElementSeriesComponent } from "./element-series/element-series";
|
||||||
|
import { ElementTrackComponent } from "./element-track/element-track";
|
||||||
|
import { ElementVideoComponent } from "./element-video/element-video";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export {
|
||||||
|
ElementSeriesComponent,
|
||||||
|
ElementVideoComponent,
|
||||||
|
ElementSeasonComponent,
|
||||||
|
ElementPlayerAudioComponent,
|
||||||
|
ElementTrackComponent,
|
||||||
|
};
|
||||||
|
|
@ -7,7 +7,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div [className]="covers ? 'description-area description-area-cover' : 'description-area description-area-no-cover'">
|
<div [className]="covers ? 'description-area description-area-cover' : 'description-area description-area-no-cover'">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
{{name}} / {{albumName}}
|
{{name}}
|
||||||
|
</div>
|
||||||
|
<div class="title">
|
||||||
|
{{albumName}}
|
||||||
</div>
|
</div>
|
||||||
<div class="description" *ngIf="albumDescription">
|
<div class="description" *ngIf="albumDescription">
|
||||||
{{albumDescription}}
|
{{albumDescription}}
|
||||||
@ -18,9 +21,11 @@
|
|||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
<div class="title" *ngIf="tracks.length > 1">Tracks:</div>
|
<div class="title" *ngIf="tracks.length > 1">Tracks:</div>
|
||||||
<div class="title" *ngIf="tracks.length == 1">Track:</div>
|
<div class="title" *ngIf="tracks.length == 1">Track:</div>
|
||||||
<div *ngFor="let data of tracks" class="item-list" (click)="onSelectTrack($event, data.id)" (auxclick)="onSelectTrack($event, data.id)">
|
<app-element-track
|
||||||
<app-element-season [element]="data"></app-element-season>
|
*ngFor="let data of tracks"
|
||||||
</div>
|
[element]="data"
|
||||||
|
(click)="onSelectTrack($event, data.id)"
|
||||||
|
(auxclick)="onSelectTrack($event, data.id)"></app-element-track>
|
||||||
</div>
|
</div>
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
</div>
|
</div>
|
@ -52,9 +52,9 @@ export class UploadScene implements OnInit {
|
|||||||
parsedFailedElement: FileFailParsedElement[] = [];
|
parsedFailedElement: FileFailParsedElement[] = [];
|
||||||
uploadFileValue: string = '';
|
uploadFileValue: string = '';
|
||||||
selectedFiles: FileList;
|
selectedFiles: FileList;
|
||||||
genderId: number = undefined;
|
genderId: number = null;
|
||||||
artistId: number = undefined;
|
artistId: number = null;
|
||||||
albumId: number = undefined;
|
albumId: number = null;
|
||||||
needSend: boolean = false;
|
needSend: boolean = false;
|
||||||
|
|
||||||
// list of all files already registered in the bdd to compare with the curent list of files.
|
// list of all files already registered in the bdd to compare with the curent list of files.
|
||||||
@ -279,9 +279,9 @@ export class UploadScene implements OnInit {
|
|||||||
this.parsedFailedElement = [];
|
this.parsedFailedElement = [];
|
||||||
this.listFileInBdd = undefined;
|
this.listFileInBdd = undefined;
|
||||||
|
|
||||||
this.genderId = undefined;
|
this.genderId = null;
|
||||||
this.artistId = undefined;
|
this.artistId = null;
|
||||||
this.albumId = undefined;
|
this.albumId = null;
|
||||||
//this.listGender = [ { value: null, label: '---' } ];
|
//this.listGender = [ { value: null, label: '---' } ];
|
||||||
this.listAlbum = [ { value: null, label: '---' } ];
|
this.listAlbum = [ { value: null, label: '---' } ];
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
id="filter5338">
|
id="filter5338">
|
||||||
<feFlood
|
<feFlood
|
||||||
flood-opacity="1"
|
flood-opacity="1"
|
||||||
flood-color="rgb(255,255,255)"
|
flood-color="rgb(0,255,0)"
|
||||||
result="flood"
|
result="flood"
|
||||||
id="feFlood5328" />
|
id="feFlood5328" />
|
||||||
<feComposite
|
<feComposite
|
||||||
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
7
front/src/common/utils/mobileDevice.ts
Normal file
7
front/src/common/utils/mobileDevice.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export function isMobileAgent() {
|
||||||
|
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user