use of org.exist.storage.DBBroker in project exist by eXist-db.
the class ExportGUI method exportDB.
// GEN-LAST:event_btnConfSelectActionPerformed
private void exportDB(final String exportTarget, final List<ErrorReport> errorList) {
if (!startDB()) {
return;
}
try {
final SystemExport.StatusCallback callback = new SystemExport.StatusCallback() {
public void startCollection(final String path) {
progress.setString(path);
}
public void startDocument(final String name, final int current, final int count) {
progress.setString(name);
progress.setValue(progress.getValue() + 1);
}
public void error(final String message, final Throwable exception) {
displayMessage(message);
if (exception != null) {
displayMessage(exception.toString());
}
displayMessage("---------------------------------------------------");
}
};
progress.setIndeterminate(false);
progress.setValue(0);
progress.setStringPainted(true);
progress.setMinimum(0);
progress.setMaximum(documentCount);
Object[] selected = directAccessBtn.getSelectedObjects();
final boolean directAccess = (selected != null) && (selected[0] != null);
selected = incrementalBtn.getSelectedObjects();
final boolean incremental = (selected != null) && (selected[0] != null);
selected = zipBtn.getSelectedObjects();
final boolean zip = (selected != null) && (selected[0] != null);
displayMessage("Starting export ...");
final long start = System.currentTimeMillis();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final SystemExport sysexport = new SystemExport(broker, transaction, callback, null, directAccess);
final Path file = sysexport.export(exportTarget, incremental, zip, errorList);
transaction.commit();
final long end = System.currentTimeMillis();
displayMessage("Export to " + file.toAbsolutePath().toString() + " completed successfully.");
displayMessage("Export took " + (end - start) + "ms.");
} catch (final EXistException e) {
System.err.println("ERROR: Failed to retrieve database broker: " + e.getMessage());
}
} finally {
progress.setString("");
progress.setValue(0);
currentTask.setText(" ");
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class ExportMain method process.
private static void process(final ParsedArguments arguments) {
final boolean verbose = getBool(arguments, verboseArg);
final boolean noCheck = getBool(arguments, noCheckArg);
final boolean checkDocs = getBool(arguments, checkDocsArg);
final boolean direct = getBool(arguments, directAccessArg);
boolean export = getBool(arguments, exportArg);
final boolean noExport = getBool(arguments, noExportArg);
if (noExport) {
export = false;
}
final boolean incremental = getBool(arguments, incrementalArg);
boolean zip = getBool(arguments, zipArg);
final boolean noZip = getBool(arguments, noZipArg);
if (noZip) {
zip = false;
}
final Optional<Path> dbConfig = getOpt(arguments, configArg).map(File::toPath);
final Path exportTarget = arguments.get(outputDirArg).toPath();
final BrokerPool pool = startDB(dbConfig);
if (pool == null) {
System.exit(SystemExitCodes.CATCH_ALL_GENERAL_ERROR_EXIT_CODE);
}
// return value
int retval = 0;
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
List<ErrorReport> errors = null;
if (!noCheck) {
final ConsistencyCheck checker = new ConsistencyCheck(broker, transaction, direct, checkDocs);
errors = checker.checkAll(new CheckCallback());
}
if (errors != null && !errors.isEmpty()) {
System.err.println("ERRORS FOUND.");
retval = 1;
} else {
System.out.println("No errors.");
}
if (export) {
if (!Files.exists(exportTarget)) {
Files.createDirectories(exportTarget);
} else if (!Files.isDirectory(exportTarget)) {
System.err.println("Output dir already exists and is a file: " + exportTarget.toAbsolutePath().toString());
System.exit(SystemExitCodes.INVALID_ARGUMENT_EXIT_CODE);
}
final SystemExport sysexport = new SystemExport(broker, transaction, new Callback(verbose), null, direct);
sysexport.export(exportTarget.toAbsolutePath().toString(), incremental, zip, errors);
}
transaction.commit();
} catch (final EXistException e) {
System.err.println("ERROR: Failed to retrieve database broker: " + e.getMessage());
retval = SystemExitCodes.NO_BROKER_EXIT_CODE;
} catch (final TerminatedException e) {
System.err.println("WARN: Export was terminated by db.");
retval = SystemExitCodes.TERMINATED_EARLY_EXIT_CODE;
} catch (final PermissionDeniedException pde) {
System.err.println("ERROR: Failed to retrieve database data: " + pde.getMessage());
retval = SystemExitCodes.PERMISSION_DENIED_EXIT_CODE;
} catch (final IOException ioe) {
System.err.println("ERROR: Failed to retrieve database data: " + ioe.getMessage());
retval = SystemExitCodes.IO_ERROR_EXIT_CODE;
} finally {
BrokerPool.stopAll(false);
}
System.exit(retval);
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class Launcher method checkInstalledApps.
private void checkInstalledApps() {
try {
final BrokerPool pool = BrokerPool.getInstance();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final XQuery xquery = pool.getXQueryService();
final Sequence pkgs = xquery.execute(broker, "repo:list()", null);
for (final SequenceIterator i = pkgs.iterate(); i.hasNext(); ) {
final ExistRepository.Notification notification = new ExistRepository.Notification(ExistRepository.Action.INSTALL, i.nextItem().getStringValue());
final Optional<ExistRepository> expathRepo = pool.getExpathRepo();
if (expathRepo.isPresent()) {
update(expathRepo.get(), notification);
utilityPanel.update(expathRepo.get(), notification);
}
expathRepo.orElseThrow(() -> new EXistException("EXPath repository is not available."));
}
}
} catch (final EXistException | XPathException | PermissionDeniedException e) {
System.err.println("Failed to check installed packages: " + e.getMessage());
e.printStackTrace();
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class Profiler method isLogEnabled.
public final boolean isLogEnabled() {
try {
final DBBroker broker = db.getActiveBroker();
final Boolean globalProp = (Boolean) broker.getConfiguration().getProperty(CONFIG_PROPERTY_TRACELOG);
return logEnabled || (globalProp != null && globalProp);
} catch (Throwable t) {
log.debug("Ignored exception: {}", t.getMessage());
return logEnabled;
}
}
use of org.exist.storage.DBBroker in project exist by eXist-db.
the class SecurityManagerTest method setup.
@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException {
final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
final SecurityManager securityManager = brokerPool.getSecurityManager();
// create the personal group
final Group group = new GroupAider(TEST_GROUP_NAME);
group.setMetadataValue(EXistSchemaType.DESCRIPTION, "Personal group for " + TEST_GROUP_NAME);
try (final DBBroker broker = brokerPool.get(Optional.of(securityManager.getSystemSubject()))) {
securityManager.addGroup(broker, group);
// create the account
final Account user = new UserAider(TEST_USER_NAME);
user.setPassword(TEST_USER_NAME);
user.addGroup(TEST_GROUP_NAME);
securityManager.addAccount(user);
// add the new account as a manager of their personal group
final Group personalGroup = securityManager.getGroup(TEST_GROUP_NAME);
personalGroup.addManager(securityManager.getAccount(TEST_USER_NAME));
securityManager.updateGroup(personalGroup);
}
}
Aggregations