/** * Externalizes a {@link CouchDbDatastore} to a XML element * * @param datastore * @return */ public Element toElement(final CouchDbDatastore datastore) { final Element ds = getDocument().createElement("couchdb-datastore"); ds.setAttribute("name", datastore.getName()); if (!Strings.isNullOrEmpty(datastore.getDescription())) { ds.setAttribute("description", datastore.getDescription()); } appendElement(ds, "hostname", datastore.getHostname()); appendElement(ds, "port", datastore.getPort()); appendElement(ds, "username", datastore.getUsername()); appendElement(ds, "password", encodePassword(datastore.getPassword())); appendElement(ds, "ssl", datastore.isSslEnabled()); return ds; }
protected CouchDbDatastore createDatastore() { final String name = _datastoreNameTextField.getText(); final String hostname = _hostnameTextField.getText(); final Integer port = Integer.parseInt(_portTextField.getText()); final boolean sslEnabled = _sslCheckBox.isSelected(); final String username = _usernameTextField.getText(); final String password = new String(_passwordField.getPassword()); final SimpleTableDef[] tableDefs = _tableDefinitionWidget.getTableDefs(); return new CouchDbDatastore(name, hostname, port, username, password, sslEnabled, tableDefs); }
_tableDefinitionWidget = new TableDefinitionOptionSelectionPanel(windowContext, this, null); } else { _datastoreNameTextField.setText(originalDatastore.getName()); _datastoreNameTextField.setEnabled(false); _hostnameTextField.setText(originalDatastore.getHostname()); _portTextField.setText(originalDatastore.getPort() + ""); _sslCheckBox.setSelected(originalDatastore.isSslEnabled()); _usernameTextField.setText(originalDatastore.getUsername()); _passwordField.setText(new String(originalDatastore.getPassword())); _tableDefinitionWidget = new TableDefinitionOptionSelectionPanel(windowContext, this, originalDatastore.getTableDefs());
} else if (datastore instanceof CouchDbDatastore) { final CouchDbDatastore couchDbDatastore = (CouchDbDatastore) datastore; return (couchDbDatastore.isSslEnabled() ? "https://" : "http://") + couchDbDatastore.getHostname() + ":" + couchDbDatastore.getPort(); } else if (datastore instanceof PojoDatastore) { return "In-memory collection of records.";
@Override protected void decorateIdentity(final List<Object> identifiers) { super.decorateIdentity(identifiers); identifiers.add(_hostname); identifiers.add(getPort()); identifiers.add(_username); identifiers.add(_password); identifiers.add(_sslEnabled); identifiers.add(_tableDefs); }
@Override protected UsageAwareDatastoreConnection<CouchDbDataContext> createDatastoreConnection() { final StdHttpClient.Builder httpClient = new StdHttpClient.Builder(); httpClient.host(getHostname()); if (_port != null) { httpClient.port(_port); } if (_username != null) { httpClient.username(_username); } if (_password != null) { httpClient.password(_password); } httpClient.enableSSL(_sslEnabled); httpClient.connectionTimeout(HTTP_TIMEOUT); httpClient.socketTimeout(HTTP_TIMEOUT); final CouchDbDataContext dataContext; if (_tableDefs != null && _tableDefs.length > 0) { dataContext = new CouchDbDataContext(httpClient, _tableDefs); } else { dataContext = new CouchDbDataContext(httpClient); } return new UpdateableDatastoreConnectionImpl<>(dataContext, this); }
final SimpleTableDef[] tableDefs = ((CouchDbDatastore) datastore).getTableDefs(); if (tableDefs == null) { return true;
return new CouchDbDatastore(name, hostname, port, username, password, sslEnabled, tableDefs);