use of org.jkiss.utils.xml.XMLException in project dbeaver by dbeaver.
the class PostgrePlanAnalyser method explain.
public void explain(DBCSession session) throws DBCException {
JDBCSession connection = (JDBCSession) session;
boolean oldAutoCommit = false;
try {
oldAutoCommit = connection.getAutoCommit();
if (oldAutoCommit) {
connection.setAutoCommit(false);
}
try (JDBCPreparedStatement dbStat = connection.prepareStatement(getPlanQueryString())) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.next()) {
SQLXML planXML = dbResult.getSQLXML(1);
parsePlan(planXML);
}
} catch (XMLException e) {
throw new DBCException("Can't parse plan XML", e);
}
}
} catch (SQLException e) {
throw new DBCException(e, session.getDataSource());
} finally {
// Rollback changes because EXPLAIN actually executes query and it could be INSERT/UPDATE
try {
connection.rollback();
if (oldAutoCommit) {
connection.setAutoCommit(true);
}
} catch (SQLException e) {
log.error("Error closing plan analyser", e);
}
}
}
use of org.jkiss.utils.xml.XMLException in project dbeaver by dbeaver.
the class ConfigImportWizardPageSqlDeveloper method parseConnections.
private void parseConnections(File connectionsFile, ImportData importData) throws DBException {
try {
Document configDocument = XMLUtils.parseDocument(connectionsFile);
for (Element refElement : XMLUtils.getChildElementList(configDocument.getDocumentElement(), "Reference")) {
final String conName = refElement.getAttribute("name");
if (CommonUtils.isEmpty(conName)) {
continue;
}
final Map<String, String> propsMap = new LinkedHashMap<>();
final Element refAddressesElement = XMLUtils.getChildElement(refElement, "RefAddresses");
if (refAddressesElement != null) {
for (Element refAddr : XMLUtils.getChildElementList(refAddressesElement, "StringRefAddr")) {
String addrType = refAddr.getAttribute("addrType");
String addrContent = XMLUtils.getChildElementBody(refAddr, "Contents");
if (!CommonUtils.isEmpty(addrType) && !CommonUtils.isEmpty(addrContent)) {
propsMap.put(addrType, addrContent);
}
}
}
String host = propsMap.get("hostname");
String port = propsMap.get("port");
String sid = propsMap.get("sid");
String serviceName = propsMap.get("serviceName");
String user = propsMap.get("user");
String role = propsMap.get("role");
String osAuth = propsMap.get("OS_AUTHENTICATION");
String url = propsMap.get("customUrl");
if (CommonUtils.isEmpty(host) && CommonUtils.isEmpty(url)) {
continue;
}
String dbName = CommonUtils.isEmpty(sid) ? serviceName : sid;
ImportConnectionInfo connectionInfo = new ImportConnectionInfo(oraDriver, null, conName, url, host, port, dbName, user, null);
if (!CommonUtils.isEmpty(sid)) {
connectionInfo.setProviderProperty(OracleConstants.PROP_SID_SERVICE, OracleConnectionType.SID.name());
} else if (!CommonUtils.isEmpty(serviceName)) {
connectionInfo.setProviderProperty(OracleConstants.PROP_SID_SERVICE, OracleConnectionType.SERVICE.name());
}
if (CommonUtils.toBoolean(osAuth)) {
connectionInfo.setUser(OracleConstants.OS_AUTH_PROP);
}
if (!CommonUtils.isEmpty(role)) {
connectionInfo.setProviderProperty(OracleConstants.PROP_INTERNAL_LOGON, role);
}
importData.addConnection(connectionInfo);
}
} catch (XMLException e) {
throw new DBException("Configuration parse error: " + e.getMessage());
}
}
use of org.jkiss.utils.xml.XMLException in project dbeaver by dbeaver.
the class ConfigImportWizardPageDbvis method loadConnections.
@Override
protected void loadConnections(ImportData importData) throws DBException {
File homeFolder = RuntimeUtils.getUserHomeDir();
File dbvisConfigHome = new File(homeFolder, DBVIS_HOME_FOLDER);
if (!dbvisConfigHome.exists()) {
throw new DBException(ImportConfigMessages.config_import_wizard_page_dbvis_label_installation_not_found);
}
File configFolder = new File(dbvisConfigHome, DBVIS_CONFIG70_FOLDER);
if (!configFolder.exists()) {
throw new DBException("Only DBVisualizer 7.x version is supported");
}
File configFile = new File(configFolder, DBVIS_CONFIG_FILE);
if (!configFile.exists()) {
throw new DBException("DBVisualizer configuration file not found");
}
try {
Document configDocument = XMLUtils.parseDocument(configFile);
Element driversElement = XMLUtils.getChildElement(configDocument.getDocumentElement(), "Drivers");
if (driversElement != null) {
for (Element driverElement : XMLUtils.getChildElementList(driversElement, "Driver")) {
String name = XMLUtils.getChildElementBody(driverElement, "Name");
String sampleURL = XMLUtils.getChildElementBody(driverElement, "URLFormat");
String driverClass = XMLUtils.getChildElementBody(driverElement, "DefaultClass");
String lastName = XMLUtils.getChildElementBody(driverElement, "LastName");
// String lastVersion = XMLUtils.getChildElementBody(driverElement, "LastVersion");
if (!CommonUtils.isEmpty(name) && !CommonUtils.isEmpty(sampleURL) && !CommonUtils.isEmpty(driverClass)) {
ImportDriverInfo driver = new ImportDriverInfo(null, name, sampleURL, driverClass);
if (!CommonUtils.isEmpty(lastName)) {
driver.setDescription(lastName);
}
adaptSampleUrl(driver);
// Parse libraries
Element locationsElement = XMLUtils.getChildElement(driverElement, "Locations");
if (locationsElement != null) {
for (Element locationElement : XMLUtils.getChildElementList(locationsElement, "Location")) {
String path = XMLUtils.getChildElementBody(locationElement, "Path");
if (!CommonUtils.isEmpty(path)) {
driver.addLibrary(path);
}
}
}
importData.addDriver(driver);
}
}
}
Element databasesElement = XMLUtils.getChildElement(configDocument.getDocumentElement(), "Databases");
if (databasesElement != null) {
for (Element dbElement : XMLUtils.getChildElementList(databasesElement, "Database")) {
String alias = XMLUtils.getChildElementBody(dbElement, "Alias");
String url = XMLUtils.getChildElementBody(dbElement, "Url");
String driverName = XMLUtils.getChildElementBody(dbElement, "Driver");
String user = XMLUtils.getChildElementBody(dbElement, "Userid");
String password = null;
String passwordEncoded = XMLUtils.getChildElementBody(dbElement, "Password");
/*
if (!CommonUtils.isEmpty(passwordEncoded)) {
try {
password = new String(Base64.decode(passwordEncoded), ContentUtils.DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
// Ignore
}
}
*/
String hostName = null, port = null, database = null;
Element urlVarsElement = XMLUtils.getChildElement(dbElement, "UrlVariables");
if (urlVarsElement != null) {
Element driverElement = XMLUtils.getChildElement(urlVarsElement, "Driver");
if (driverElement != null) {
for (Element urlVarElement : XMLUtils.getChildElementList(driverElement, "UrlVariable")) {
final String varName = urlVarElement.getAttribute("UrlVariableName");
final String varValue = XMLUtils.getElementBody(urlVarElement);
if ("Server".equals(varName)) {
hostName = varValue;
} else if ("Port".equals(varName)) {
port = varValue;
} else if ("Database".equals(varName)) {
database = varValue;
}
}
}
}
if (!CommonUtils.isEmpty(alias) && !CommonUtils.isEmpty(driverName) && (!CommonUtils.isEmpty(url) || !CommonUtils.isEmpty(hostName))) {
ImportDriverInfo driver = importData.getDriver(driverName);
if (driver != null) {
ImportConnectionInfo connectionInfo = new ImportConnectionInfo(driver, dbElement.getAttribute("id"), alias, url, hostName, port, database, user, password);
importData.addConnection(connectionInfo);
}
}
}
}
} catch (XMLException e) {
throw new DBException("Configuration parse error: " + e.getMessage());
}
}
use of org.jkiss.utils.xml.XMLException in project dbeaver by serge-rider.
the class ConfigImportWizardPageSqlDeveloper method parseConnections.
private void parseConnections(File connectionsFile, ImportData importData) throws DBException {
try {
Document configDocument = XMLUtils.parseDocument(connectionsFile);
for (Element refElement : XMLUtils.getChildElementList(configDocument.getDocumentElement(), "Reference")) {
final String conName = refElement.getAttribute("name");
if (CommonUtils.isEmpty(conName)) {
continue;
}
final Map<String, String> propsMap = new LinkedHashMap<>();
final Element refAddressesElement = XMLUtils.getChildElement(refElement, "RefAddresses");
if (refAddressesElement != null) {
for (Element refAddr : XMLUtils.getChildElementList(refAddressesElement, "StringRefAddr")) {
String addrType = refAddr.getAttribute("addrType");
String addrContent = XMLUtils.getChildElementBody(refAddr, "Contents");
if (!CommonUtils.isEmpty(addrType) && !CommonUtils.isEmpty(addrContent)) {
propsMap.put(addrType, addrContent);
}
}
}
String host = propsMap.get("hostname");
String port = propsMap.get("port");
String sid = propsMap.get("sid");
String serviceName = propsMap.get("serviceName");
String user = propsMap.get("user");
String role = propsMap.get("role");
String osAuth = propsMap.get("OS_AUTHENTICATION");
String url = propsMap.get("customUrl");
if (CommonUtils.isEmpty(host) && CommonUtils.isEmpty(url)) {
continue;
}
String dbName = CommonUtils.isEmpty(sid) ? serviceName : sid;
ImportConnectionInfo connectionInfo = new ImportConnectionInfo(oraDriver, null, conName, url, host, port, dbName, user, null);
if (!CommonUtils.isEmpty(sid)) {
connectionInfo.setProviderProperty(OracleConstants.PROP_SID_SERVICE, OracleConnectionType.SID.name());
} else if (!CommonUtils.isEmpty(serviceName)) {
connectionInfo.setProviderProperty(OracleConstants.PROP_SID_SERVICE, OracleConnectionType.SERVICE.name());
}
if (CommonUtils.toBoolean(osAuth)) {
connectionInfo.setUser(OracleConstants.OS_AUTH_PROP);
}
if (!CommonUtils.isEmpty(role)) {
connectionInfo.setProviderProperty(OracleConstants.PROP_INTERNAL_LOGON, role);
}
importData.addConnection(connectionInfo);
}
} catch (XMLException e) {
throw new DBException("Configuration parse error: " + e.getMessage());
}
}
use of org.jkiss.utils.xml.XMLException in project dbeaver by serge-rider.
the class MavenArtifactVersion method loadPOM.
private void loadPOM(DBRProgressMonitor monitor) throws IOException {
monitor.subTask("Load POM " + this);
File localPOM = getLocalPOM();
if (!localPOM.exists()) {
cachePOM(localPOM);
}
Document pomDocument;
try (InputStream mdStream = new FileInputStream(localPOM)) {
pomDocument = XMLUtils.parseDocument(mdStream);
} catch (XMLException e) {
throw new IOException("Error parsing POM", e);
}
Element root = pomDocument.getDocumentElement();
name = CommonUtils.trim(XMLUtils.getChildElementBody(root, "name"));
url = CommonUtils.trim(XMLUtils.getChildElementBody(root, "url"));
version = CommonUtils.trim(XMLUtils.getChildElementBody(root, "version"));
packaging = CommonUtils.trim(XMLUtils.getChildElementBody(root, "packaging"));
description = CommonUtils.trim(XMLUtils.getChildElementBody(root, "description"));
if (description != null) {
description = CommonUtils.compactWhiteSpaces(description.trim());
}
repositories.addAll(parseRepositories(root));
{
// Parent
Element parentElement = XMLUtils.getChildElement(root, "parent");
if (parentElement != null) {
String parentGroupId = CommonUtils.trim(XMLUtils.getChildElementBody(parentElement, "groupId"));
String parentArtifactId = CommonUtils.trim(XMLUtils.getChildElementBody(parentElement, "artifactId"));
String parentVersion = CommonUtils.trim(XMLUtils.getChildElementBody(parentElement, "version"));
if (parentGroupId == null || parentArtifactId == null || parentVersion == null) {
log.error("Broken parent reference: " + parentGroupId + ":" + parentArtifactId + ":" + parentVersion);
} else {
MavenArtifactReference parentReference = new MavenArtifactReference(parentGroupId, parentArtifactId, null, parentVersion);
if (this.version == null) {
this.version = parentReference.getVersion();
}
parent = MavenRegistry.getInstance().findArtifact(monitor, this, parentReference);
if (parent == null) {
log.error("Artifact [" + this + "] parent [" + parentReference + "] not found");
}
}
}
}
{
// Licenses
Element licensesElement = XMLUtils.getChildElement(root, "licenses");
if (licensesElement != null) {
for (Element prop : XMLUtils.getChildElementList(licensesElement, "license")) {
licenses.add(new MavenArtifactLicense(XMLUtils.getChildElementBody(prop, "name"), XMLUtils.getChildElementBody(prop, "url")));
}
}
}
// Default profile
MavenProfile defaultProfile = new MavenProfile(DEFAULT_PROFILE_ID);
defaultProfile.active = true;
profiles.add(defaultProfile);
parseProfile(monitor, defaultProfile, root, true);
{
// Profiles
Element licensesElement = XMLUtils.getChildElement(root, "profiles");
if (licensesElement != null) {
for (Element profElement : XMLUtils.getChildElementList(licensesElement, "profile")) {
MavenProfile profile = new MavenProfile(XMLUtils.getChildElementBody(profElement, "id"));
profiles.add(profile);
parseProfile(monitor, profile, profElement, false);
}
}
}
monitor.worked(1);
}
Aggregations