|
@@ -1,176 +1,249 @@
|
|
|
package com.x.server.console.action;
|
|
package com.x.server.console.action;
|
|
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.io.InputStream;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
|
+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.Comparator;
|
|
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
import javax.persistence.EntityManager;
|
|
|
import javax.persistence.EntityManagerFactory;
|
|
import javax.persistence.EntityManagerFactory;
|
|
|
-import javax.persistence.FlushModeType;
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Root;
|
|
import javax.persistence.criteria.Root;
|
|
|
|
|
|
|
|
|
|
+import org.apache.commons.io.FilenameUtils;
|
|
|
|
|
+import org.apache.commons.lang3.BooleanUtils;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.apache.openjpa.persistence.OpenJPAPersistence;
|
|
|
|
|
+
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.JsonArray;
|
|
import com.google.gson.JsonArray;
|
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonElement;
|
|
|
import com.x.base.core.container.factory.PersistenceXmlHelper;
|
|
import com.x.base.core.container.factory.PersistenceXmlHelper;
|
|
|
import com.x.base.core.entity.JpaObject;
|
|
import com.x.base.core.entity.JpaObject;
|
|
|
|
|
+import com.x.base.core.entity.StorageObject;
|
|
|
|
|
+import com.x.base.core.entity.annotation.ContainerEntity;
|
|
|
import com.x.base.core.project.config.Config;
|
|
import com.x.base.core.project.config.Config;
|
|
|
|
|
+import com.x.base.core.project.config.StorageMapping;
|
|
|
|
|
+import com.x.base.core.project.config.StorageMappings;
|
|
|
import com.x.base.core.project.gson.XGsonBuilder;
|
|
import com.x.base.core.project.gson.XGsonBuilder;
|
|
|
import com.x.base.core.project.logger.Logger;
|
|
import com.x.base.core.project.logger.Logger;
|
|
|
import com.x.base.core.project.logger.LoggerFactory;
|
|
import com.x.base.core.project.logger.LoggerFactory;
|
|
|
-import com.x.base.core.project.tools.BaseTools;
|
|
|
|
|
import com.x.base.core.project.tools.DateTools;
|
|
import com.x.base.core.project.tools.DateTools;
|
|
|
-import com.x.base.core.project.tools.DefaultCharset;
|
|
|
|
|
import com.x.base.core.project.tools.ListTools;
|
|
import com.x.base.core.project.tools.ListTools;
|
|
|
|
|
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
|
|
-import org.apache.commons.io.FilenameUtils;
|
|
|
|
|
-import org.apache.commons.lang3.BooleanUtils;
|
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
-import org.apache.openjpa.persistence.OpenJPAPersistence;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * @author zhourui
|
|
|
|
|
- */
|
|
|
|
|
public class RestoreData {
|
|
public class RestoreData {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(RestoreData.class);
|
|
private static Logger logger = LoggerFactory.getLogger(RestoreData.class);
|
|
|
|
|
|
|
|
- private Date start = new Date();
|
|
|
|
|
-
|
|
|
|
|
- private File dir;
|
|
|
|
|
-
|
|
|
|
|
- private DumpRestoreDataCatalog catalog;
|
|
|
|
|
-
|
|
|
|
|
- private Gson pureGsonDateFormated = XGsonBuilder.instance();
|
|
|
|
|
-
|
|
|
|
|
public boolean execute(String path) throws Exception {
|
|
public boolean execute(String path) throws Exception {
|
|
|
|
|
+ Date start = new Date();
|
|
|
|
|
+ Path dir;
|
|
|
if (StringUtils.isEmpty(path)) {
|
|
if (StringUtils.isEmpty(path)) {
|
|
|
- logger.print("path is empty.");
|
|
|
|
|
|
|
+ logger.warn("path is empty.");
|
|
|
}
|
|
}
|
|
|
if (BooleanUtils.isTrue(DateTools.isCompactDateTime(path))) {
|
|
if (BooleanUtils.isTrue(DateTools.isCompactDateTime(path))) {
|
|
|
- this.dir = new File(Config.base(), "local/dump/dumpData_" + path);
|
|
|
|
|
- this.catalog = BaseTools.readConfigObject("local/dump/dumpData_" + path + "/catalog.json",
|
|
|
|
|
- DumpRestoreDataCatalog.class);
|
|
|
|
|
|
|
+ dir = Paths.get(Config.base(), "local", "dump", "dumpData_" + path);
|
|
|
} else {
|
|
} else {
|
|
|
- this.dir = new File(path);
|
|
|
|
|
- if (!(this.dir.exists() && this.dir.isDirectory())) {
|
|
|
|
|
- logger.print("dir not exist: {}.", path);
|
|
|
|
|
|
|
+ dir = Paths.get(path);
|
|
|
|
|
+ if ((!Files.exists(dir)) || (!Files.isDirectory(dir))) {
|
|
|
|
|
+ logger.warn("directory not exist: {}.", path);
|
|
|
return false;
|
|
return false;
|
|
|
- } else if (StringUtils.startsWith(dir.getAbsolutePath(), Config.base())) {
|
|
|
|
|
- logger.print("path can not in base directory.");
|
|
|
|
|
|
|
+ } else if (dir.startsWith(Paths.get(Config.base()))) {
|
|
|
|
|
+ logger.warn("path can not in base directory.");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- this.catalog = XGsonBuilder.instance().fromJson(
|
|
|
|
|
- FileUtils.readFileToString(new File(dir, "catalog.json"), DefaultCharset.charset_utf_8),
|
|
|
|
|
- DumpRestoreDataCatalog.class);
|
|
|
|
|
- return this.execute();
|
|
|
|
|
|
|
+ Thread thread = new Thread(new RunnableImpl(dir, start));
|
|
|
|
|
+ thread.start();
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
|
- public boolean execute() throws Exception {
|
|
|
|
|
- List<String> containerEntityNames = new ArrayList<>();
|
|
|
|
|
- containerEntityNames.addAll((List<String>) Config.resource(Config.RESOURCE_CONTAINERENTITYNAMES));
|
|
|
|
|
- List<String> classNames = new ArrayList<>();
|
|
|
|
|
- classNames.addAll(this.catalog.keySet());
|
|
|
|
|
- classNames = ListTools.includesExcludesWildcard(classNames, Config.dumpRestoreData().getIncludes(),
|
|
|
|
|
- Config.dumpRestoreData().getExcludes());
|
|
|
|
|
- classNames = ListTools.includesExcludesWildcard(containerEntityNames, classNames, null);
|
|
|
|
|
-
|
|
|
|
|
- logger.print("find: {} data to restore, path: {}.", classNames.size(), this.dir.getAbsolutePath());
|
|
|
|
|
- File persistence = new File(Config.dir_local_temp_classes(), DateTools.compact(this.start) + "_dump.xml");
|
|
|
|
|
- PersistenceXmlHelper.write(persistence.getAbsolutePath(), classNames);
|
|
|
|
|
- long count = 0;
|
|
|
|
|
- for (int i = 0; i < classNames.size(); i++) {
|
|
|
|
|
- Class<JpaObject> cls = (Class<JpaObject>) Class.forName(classNames.get(i));
|
|
|
|
|
|
|
+ public class RunnableImpl implements Runnable {
|
|
|
|
|
+
|
|
|
|
|
+ private Path dir;
|
|
|
|
|
+ private Date start;
|
|
|
|
|
+ private DumpRestoreDataCatalog catalog;
|
|
|
|
|
+ private Gson gson;
|
|
|
|
|
+
|
|
|
|
|
+ public RunnableImpl(Path dir, Date start) throws IOException {
|
|
|
|
|
+ this.dir = dir;
|
|
|
|
|
+ this.start = start;
|
|
|
|
|
+ this.catalog = new DumpRestoreDataCatalog();
|
|
|
|
|
+ this.gson = XGsonBuilder.instance();
|
|
|
|
|
+ Path path = dir.resolve("catalog.json");
|
|
|
|
|
+ this.catalog = XGsonBuilder.instance().fromJson(
|
|
|
|
|
+ new String(Files.readAllBytes(path), StandardCharsets.UTF_8), DumpRestoreDataCatalog.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<String> classNames = this.entities();
|
|
|
|
|
+ logger.print("find: {} data to restore, path: {}.", classNames.size(), this.dir.toString());
|
|
|
|
|
+ Path xml = Paths.get(Config.dir_local_temp_classes().getAbsolutePath(),
|
|
|
|
|
+ DateTools.compact(start) + "_restore.xml");
|
|
|
|
|
+ PersistenceXmlHelper.write(xml.toString(), classNames);
|
|
|
|
|
+ Stream<String> stream = BooleanUtils.isTrue(Config.dumpRestoreData().getParallel())
|
|
|
|
|
+ ? classNames.parallelStream()
|
|
|
|
|
+ : classNames.stream();
|
|
|
|
|
+ AtomicInteger idx = new AtomicInteger(1);
|
|
|
|
|
+ AtomicLong total = new AtomicLong(0);
|
|
|
|
|
+ stream.forEach(className -> {
|
|
|
|
|
+ String nameOfThread = Thread.currentThread().getName();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.currentThread().setName(RestoreData.class.getName() + ":" + className);
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ Class<JpaObject> cls = (Class<JpaObject>) Class.forName(className);
|
|
|
|
|
+ logger.print("restore data({}/{}): {}.", idx.getAndAdd(1), classNames.size(), cls.getName());
|
|
|
|
|
+ long size = restore(cls, xml);
|
|
|
|
|
+ total.getAndAdd(size);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error(new Exception(String.format("restore:%s error.", className), e));
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ Thread.currentThread().setName(nameOfThread);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ logger.print("restore data completed, directory: {}, count: {}, total: {}, elapsed: {} minutes.",
|
|
|
|
|
+ dir.toString(), idx.get(), total.longValue(),
|
|
|
|
|
+ (System.currentTimeMillis() - start.getTime()) / 1000 / 60);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private List<String> entities() throws Exception {
|
|
|
|
|
+ List<String> containerEntityNames = new ArrayList<>();
|
|
|
|
|
+ containerEntityNames.addAll((List<String>) Config.resource(Config.RESOURCE_CONTAINERENTITYNAMES));
|
|
|
|
|
+ List<String> classNames = new ArrayList<>();
|
|
|
|
|
+ classNames.addAll(this.catalog.keySet());
|
|
|
|
|
+ classNames = ListTools.includesExcludesWildcard(classNames, Config.dumpRestoreData().getIncludes(),
|
|
|
|
|
+ Config.dumpRestoreData().getExcludes());
|
|
|
|
|
+ return ListTools.includesExcludesWildcard(containerEntityNames, classNames, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private long restore(Class<?> cls, Path xml) throws Exception {
|
|
|
EntityManagerFactory emf = OpenJPAPersistence.createEntityManagerFactory(cls.getName(),
|
|
EntityManagerFactory emf = OpenJPAPersistence.createEntityManagerFactory(cls.getName(),
|
|
|
- persistence.getName(), PersistenceXmlHelper.properties(cls.getName(), Config.slice().getEnable()));
|
|
|
|
|
- if (emf != null) {
|
|
|
|
|
- EntityManager em = emf.createEntityManager();
|
|
|
|
|
- em.setFlushMode(FlushModeType.COMMIT);
|
|
|
|
|
- try {
|
|
|
|
|
- logger.print("restore data({}/{}): {}, count: {}.", (i + 1), classNames.size(), cls.getName(),
|
|
|
|
|
- catalog.get(cls.getName()));
|
|
|
|
|
- count = count + this.store(cls, em);
|
|
|
|
|
- } finally {
|
|
|
|
|
- em.close();
|
|
|
|
|
- emf.close();
|
|
|
|
|
|
|
+ xml.getFileName().toString(),
|
|
|
|
|
+ PersistenceXmlHelper.properties(cls.getName(), Config.slice().getEnable()));
|
|
|
|
|
+ AtomicLong count = new AtomicLong(0);
|
|
|
|
|
+ AtomicInteger batch = new AtomicInteger(1);
|
|
|
|
|
+ try {
|
|
|
|
|
+ Path directory = dir.resolve(cls.getName());
|
|
|
|
|
+ if ((!Files.exists(directory)) || (!Files.isDirectory(directory))) {
|
|
|
|
|
+ throw new ExceptionDirectoryNotExist(directory);
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- logger.warn("can not create 'EntityManagerFactory' for Entity:[" + cls.getName() + "]");
|
|
|
|
|
|
|
+ StorageMappings storageMappings = Config.storageMappings();
|
|
|
|
|
+ this.clean(cls, emf, storageMappings, cls.getAnnotation(ContainerEntity.class));
|
|
|
|
|
+ List<Path> paths = this.list(directory);
|
|
|
|
|
+ paths.stream().forEachOrdered(o -> {
|
|
|
|
|
+ logger.print("restore {}/{} part of data:{}.", batch.getAndAdd(1), paths.size(), cls.getName());
|
|
|
|
|
+ EntityManager em = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ em = emf.createEntityManager();
|
|
|
|
|
+ em.getTransaction().begin();
|
|
|
|
|
+ JsonArray raws = this.convert(o);
|
|
|
|
|
+ for (JsonElement json : raws) {
|
|
|
|
|
+ Object t = gson.fromJson(json, cls);
|
|
|
|
|
+ if (StorageObject.class.isAssignableFrom(cls)) {
|
|
|
|
|
+ Path sub = o.resolveSibling(FilenameUtils.getBaseName(o.getFileName().toString()));
|
|
|
|
|
+ this.binary(t, cls, sub, storageMappings);
|
|
|
|
|
+ }
|
|
|
|
|
+ em.persist(t);
|
|
|
|
|
+ count.getAndAdd(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ em.getTransaction().commit();
|
|
|
|
|
+ em.clear();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error(new Exception(String.format("restore error with file:%s.", o.toString()), e));
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ em.close();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ logger.print("restore data: {} completed, count: {}.", cls.getName(), count.intValue());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error(e);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ emf.close();
|
|
|
}
|
|
}
|
|
|
|
|
+ return count.longValue();
|
|
|
}
|
|
}
|
|
|
- logger.print("restore data completed, total count: {}, elapsed: {} minutes.", count,
|
|
|
|
|
- (System.currentTimeMillis() - start.getTime()) / 1000 / 60);
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- private <T> long store(Class<T> cls, EntityManager em) throws Exception {
|
|
|
|
|
- File directory = new File(this.dir, cls.getName());
|
|
|
|
|
- if ((!directory.exists()) || (!directory.isDirectory())) {
|
|
|
|
|
- throw new Exception("can not find directory: " + directory.getAbsolutePath() + ".");
|
|
|
|
|
|
|
+ private List<Path> list(Path directory) throws IOException {
|
|
|
|
|
+ List<Path> list = new ArrayList<>();
|
|
|
|
|
+ try (Stream<Path> stream = Files.list(directory)) {
|
|
|
|
|
+ stream.filter(p -> StringUtils.endsWithIgnoreCase(p.getFileName().toString(), ".json"))
|
|
|
|
|
+ .sorted((Path p1, Path p2) -> {
|
|
|
|
|
+ Integer i1 = Integer.parseInt(FilenameUtils.getBaseName(p1.getFileName().toString()));
|
|
|
|
|
+ Integer i2 = Integer.parseInt(FilenameUtils.getBaseName(p2.getFileName().toString()));
|
|
|
|
|
+ return i1.compareTo(i2);
|
|
|
|
|
+ }).forEach(list::add);
|
|
|
|
|
+ }
|
|
|
|
|
+ return list;
|
|
|
}
|
|
}
|
|
|
- long count = 0;
|
|
|
|
|
- List<File> files = new ArrayList<>(FileUtils.listFiles(directory, new String[] { "json" }, false));
|
|
|
|
|
- /** 对文件进行排序,和dump的时候的顺序保持一直 */
|
|
|
|
|
- Collections.sort(files, new Comparator<File>() {
|
|
|
|
|
- public int compare(File o1, File o2) {
|
|
|
|
|
- String n1 = FilenameUtils.getBaseName(o1.getName());
|
|
|
|
|
- String n2 = FilenameUtils.getBaseName(o2.getName());
|
|
|
|
|
- Integer i1 = Integer.parseInt(n1);
|
|
|
|
|
- Integer i2 = Integer.parseInt(n2);
|
|
|
|
|
- return i1.compareTo(i2);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ private void binary(Object o, Class<?> cls, Path sub, StorageMappings storageMappings) throws Exception {
|
|
|
|
|
+ StorageObject so = (StorageObject) o;
|
|
|
|
|
+ StorageMapping mapping = null;
|
|
|
|
|
+ if (BooleanUtils.isTrue(Config.dumpRestoreData().getRedistribute())) {
|
|
|
|
|
+ mapping = storageMappings.random((Class<StorageObject>) cls);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ mapping = storageMappings.get((Class<StorageObject>) cls, so.getStorage());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (null == mapping) {
|
|
|
|
|
+ throw new ExceptionMappingNotExist();
|
|
|
|
|
+ }
|
|
|
|
|
+ Path path = sub.resolve(Paths.get(so.path()).getFileName());
|
|
|
|
|
+ if (!Files.exists(path)) {
|
|
|
|
|
+ throw new ExceptionFileNotExist(path);
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
- /** 尽量在最后进行清空操作 */
|
|
|
|
|
- this.clean(cls, em);
|
|
|
|
|
- File file = null;
|
|
|
|
|
- for (int i = 0; i < files.size(); i++) {
|
|
|
|
|
- file = files.get(i);
|
|
|
|
|
- logger.print("restoring {}/{} part of data:{}.", (i + 1), files.size(), cls.getName());
|
|
|
|
|
- JsonArray raws = this.convert(file);
|
|
|
|
|
- em.getTransaction().begin();
|
|
|
|
|
- for (JsonElement o : raws) {
|
|
|
|
|
- T t = pureGsonDateFormated.fromJson(o, cls);
|
|
|
|
|
- em.persist(t);
|
|
|
|
|
- count++;
|
|
|
|
|
|
|
+ try (InputStream input = Files.newInputStream(path)) {
|
|
|
|
|
+ so.saveContent(mapping, input, so.getName());
|
|
|
}
|
|
}
|
|
|
- em.getTransaction().commit();
|
|
|
|
|
- em.clear();
|
|
|
|
|
}
|
|
}
|
|
|
- System.out.println("restore data: " + cls.getName() + " completed, count: " + count + ".");
|
|
|
|
|
- return count;
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- private JsonArray convert(File file) throws Exception {
|
|
|
|
|
- /* 必须先转换成 jsonElement 不能直接转成泛型T,如果直接转会有类型不匹配比如Integer变成了Double */
|
|
|
|
|
- String json = FileUtils.readFileToString(file, DefaultCharset.charset);
|
|
|
|
|
- JsonElement jsonElement = pureGsonDateFormated.fromJson(json, JsonElement.class);
|
|
|
|
|
- return jsonElement.getAsJsonArray();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private JsonArray convert(Path path) throws IOException {
|
|
|
|
|
+ // 必须先转换成 jsonElement 不能直接转成泛型T,如果直接转会有类型不匹配比如Integer变成了Double
|
|
|
|
|
+ String json = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
|
|
|
|
+ JsonElement jsonElement = gson.fromJson(json, JsonElement.class);
|
|
|
|
|
+ return jsonElement.getAsJsonArray();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- private <T> void clean(Class<T> cls, EntityManager em) throws Exception {
|
|
|
|
|
- List<T> list = null;
|
|
|
|
|
- do {
|
|
|
|
|
- if (ListTools.isNotEmpty(list)) {
|
|
|
|
|
- em.getTransaction().begin();
|
|
|
|
|
- for (T t : list) {
|
|
|
|
|
- em.remove(t);
|
|
|
|
|
|
|
+ private <T> void clean(Class<T> cls, EntityManagerFactory emf, StorageMappings storageMappings,
|
|
|
|
|
+ ContainerEntity containerEntity) throws Exception {
|
|
|
|
|
+ EntityManager em = emf.createEntityManager();
|
|
|
|
|
+ List<T> list = null;
|
|
|
|
|
+ do {
|
|
|
|
|
+ if (ListTools.isNotEmpty(list)) {
|
|
|
|
|
+ em.getTransaction().begin();
|
|
|
|
|
+ for (T t : list) {
|
|
|
|
|
+ em.remove(t);
|
|
|
|
|
+ if (StorageObject.class.isAssignableFrom(cls)) {
|
|
|
|
|
+ StorageObject so = (StorageObject) t;
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ StorageMapping mapping = storageMappings.get((Class<StorageObject>) cls, so.getStorage());
|
|
|
|
|
+ if (null != mapping) {
|
|
|
|
|
+ so.deleteContent(mapping);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ em.getTransaction().commit();
|
|
|
}
|
|
}
|
|
|
- em.getTransaction().commit();
|
|
|
|
|
- }
|
|
|
|
|
- CriteriaBuilder cb = em.getCriteriaBuilder();
|
|
|
|
|
- CriteriaQuery<T> cq = cb.createQuery(cls);
|
|
|
|
|
- Root<T> root = cq.from(cls);
|
|
|
|
|
- cq.select(root);
|
|
|
|
|
- list = em.createQuery(cq).setMaxResults(Config.dumpRestoreData().getBatchSize()).getResultList();
|
|
|
|
|
- } while (ListTools.isNotEmpty(list));
|
|
|
|
|
|
|
+ CriteriaBuilder cb = em.getCriteriaBuilder();
|
|
|
|
|
+ CriteriaQuery<T> cq = cb.createQuery(cls);
|
|
|
|
|
+ Root<T> root = cq.from(cls);
|
|
|
|
|
+ list = em.createQuery(cq.select(root)).setMaxResults(containerEntity.dumpSize()).getResultList();
|
|
|
|
|
+ } while (ListTools.isNotEmpty(list));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|