[DEV] add clean all for test mode
This commit is contained in:
parent
ba314a97ed
commit
f3ea7983df
@ -1307,4 +1307,37 @@ public class DataAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void cleanAll(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||||
|
final QueryOptions options = new QueryOptions(option);
|
||||||
|
final String tableName = AnnotationTools.getTableName(clazz, options);
|
||||||
|
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||||
|
final StringBuilder query = new StringBuilder();
|
||||||
|
query.append("DELETE FROM `");
|
||||||
|
query.append(tableName);
|
||||||
|
query.append("`");
|
||||||
|
try {
|
||||||
|
LOGGER.trace("Execute Querry: {}", query.toString());
|
||||||
|
// Remove main table
|
||||||
|
final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
|
||||||
|
ps.executeUpdate();
|
||||||
|
// search subTable:
|
||||||
|
for (final Field field : clazz.getFields()) {
|
||||||
|
// static field is only for internal global declaration ==> remove it ..
|
||||||
|
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (AnnotationTools.isGenericField(field)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final DataAccessAddOn addOn = findAddOnforField(field);
|
||||||
|
if (addOn != null && !addOn.canInsert(field)) {
|
||||||
|
addOn.cleanAll(tableName, field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
entry.close();
|
||||||
|
entry = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -102,4 +102,8 @@ public interface DataAccessAddOn {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default void cleanAll(final String tableName, final Field field) throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -258,6 +258,13 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
|||||||
DataAccess.drop(LinkTable.class, new OverrideTableName(linkTableName));
|
DataAccess.drop(LinkTable.class, new OverrideTableName(linkTableName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanAll(final String tableName, final Field field) throws Exception {
|
||||||
|
final String columnName = AnnotationTools.getFieldName(field);
|
||||||
|
final String linkTableName = generateLinkTableName(tableName, columnName);
|
||||||
|
DataAccess.cleanAll(LinkTable.class, new OverrideTableName(linkTableName));
|
||||||
|
}
|
||||||
|
|
||||||
public static void addLink(final Class<?> clazz, final long localKey, final String column, final long remoteKey) throws Exception {
|
public static void addLink(final Class<?> clazz, final long localKey, final String column, final long remoteKey) throws Exception {
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
final String linkTableName = generateLinkTableName(tableName, column);
|
final String linkTableName = generateLinkTableName(tableName, column);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user