use of org.openlca.core.database.IDatabase in project olca-app by GreenDelta.
the class EcoSpold2ImportWizard method createImport.
private EcoSpold2Import createImport() {
File[] files = filePage.getFiles();
IDatabase db = Database.get();
if (files == null || files.length == 0 || db == null)
return null;
ImportConfig conf = new ImportConfig(db);
if (App.runsInDevMode()) {
conf.checkFormulas = true;
conf.skipNullExchanges = true;
conf.withParameterFormulas = false;
conf.withParameters = false;
}
if (filePage.flowMap != null) {
conf.setFlowMap(filePage.flowMap);
}
EcoSpold2Import pi = new EcoSpold2Import(conf);
pi.setFiles(files);
return pi;
}
use of org.openlca.core.database.IDatabase in project olca-app by GreenDelta.
the class RcpActionBarAdvisor method runSpold2Import.
private void runSpold2Import(ModelType type) {
IDatabase db = Database.get();
if (db == null) {
MsgBox.error("No database opened", "You need to open a database for the import");
return;
}
File file = FileChooser.open("*.zip");
if (file == null)
return;
File[] files = new File[] { file };
Runnable imp = null;
if (type == ModelType.IMPACT_METHOD) {
imp = new MethodImport(files, db);
} else if (type == ModelType.PROCESS) {
ImportConfig conf = new ImportConfig(db);
conf.checkFormulas = true;
conf.skipNullExchanges = true;
conf.withParameterFormulas = false;
conf.withParameters = false;
EcoSpold2Import imp_ = new EcoSpold2Import(conf);
imp_.setFiles(files);
imp = imp_;
}
if (imp == null)
return;
try {
Database.getWorkspaceIdUpdater().beginTransaction();
App.runWithProgress("Run import", imp);
} catch (Exception e) {
Logger log = LoggerFactory.getLogger(getClass());
log.error("EcoSpold 2 import failed", e);
} finally {
Database.getWorkspaceIdUpdater().endTransaction();
Navigator.refresh();
Cache.evictAll();
}
}
use of org.openlca.core.database.IDatabase in project olca-app by GreenDelta.
the class MySQLDatabaseExport method run.
@Override
public void run() {
try {
IDatabase sourceDb = config.connect(DataDir.databases());
var targetDb = createTemporaryDb();
DatabaseImport io = new DatabaseImport(sourceDb, targetDb);
io.run();
sourceDb.close();
targetDb.close();
ZipUtil.pack(targetDb.getDatabaseDirectory(), zolcaFile);
FileUtils.deleteDirectory(targetDb.getDatabaseDirectory());
success = true;
} catch (Exception e) {
success = false;
ErrorReporter.on("failed export MySQL database as zolca-File", e);
}
}
use of org.openlca.core.database.IDatabase in project olca-app by GreenDelta.
the class DeleteModelAction method delete.
@SuppressWarnings("unchecked")
private <T extends RootEntity> void delete(Descriptor d) {
try {
log.trace("delete model {}", d);
IDatabase database = Database.get();
Class<T> clazz = (Class<T>) d.type.getModelClass();
BaseDao<T> dao = Daos.base(database, clazz);
T instance = dao.getForId(d.id);
dao.delete(instance);
Cache.evict(d);
DatabaseDir.deleteDir(d);
log.trace("element deleted");
} catch (Exception e) {
ErrorReporter.on("failed to delete " + d, e);
}
}
use of org.openlca.core.database.IDatabase in project olca-app by GreenDelta.
the class XNexusIndexExportAction method run.
@Override
public void run() {
IDatabase db = Database.get();
if (db == null) {
log.trace("no database activated");
return;
}
String defaultName = db.getName() + "_nexus_index.json";
File file = FileChooser.forSavingFile(M.Export, defaultName);
if (file == null)
return;
App.run("Export Nexus index", new Runner(file, db));
}
Aggregations