use of org.hortonmachine.dbs.nosql.INosqlDb in project hortonmachine by TheHortonMachine.
the class SqlTemplatesAndActions method getDeleteCollectionDocumentByIdAction.
public Action getDeleteCollectionDocumentByIdAction(GuiBridgeHandler guiBridge, DatabaseViewer databaseViewer) {
if (isNosql) {
return new AbstractAction("Delete document by OID") {
@Override
public void actionPerformed(ActionEvent e) {
try {
if (databaseViewer.currentSelectedTable != null) {
String oid = GuiUtilities.showInputDialog(databaseViewer, "Insert the document OID", "");
if (oid != null && oid.trim().length() > 0) {
oid = oid.trim();
INosqlDb db = databaseViewer.currentConnectedNosqlDatabase;
INosqlCollection collection = db.getCollection(databaseViewer.currentSelectedTable.tableName);
collection.deleteByOid(oid);
}
} else {
GuiUtilities.showWarningMessage(databaseViewer, "Select a collection to delete the document from.");
}
} catch (Exception e1) {
GuiUtilities.handleError(databaseViewer, e1);
Logger.INSTANCE.e("Error", e1);
}
}
};
}
return null;
}
use of org.hortonmachine.dbs.nosql.INosqlDb in project hortonmachine by TheHortonMachine.
the class SqlTemplatesAndActions method getSwitchDatabaseAction.
public Action getSwitchDatabaseAction(GuiBridgeHandler guiBridge, DatabaseViewer databaseViewer) {
if (isNosql) {
return new AbstractAction("Switch database") {
@Override
public void actionPerformed(ActionEvent e) {
INosqlDb db = databaseViewer.currentConnectedNosqlDatabase;
List<String> databasesNames = db.getDatabasesNames();
String selectedName = GuiUtilities.showComboDialog(databaseViewer, "Select database", "Select the database to switch to", databasesNames.toArray(new String[0]), db.getDbName());
if (selectedName != null && !selectedName.equals(db.getDbName())) {
ConnectionData connectionData = db.getConnectionData();
connectionData.connectionLabel = selectedName;
connectionData.connectionUrl = db.getDbEngineUrl() + "/" + selectedName;
databaseViewer.openDatabase(connectionData, false);
}
}
};
} else if (databaseViewer.currentConnectedSqlDatabase.getType() == EDb.POSTGIS || databaseViewer.currentConnectedSqlDatabase.getType() == EDb.POSTGRES) {
return new AbstractAction("Switch database") {
@Override
public void actionPerformed(ActionEvent e) {
ADb db = databaseViewer.currentConnectedSqlDatabase;
try {
List<String> databasesNames = PGDb.getDatabases(db);
ConnectionData connectionData = db.getConnectionData();
int lastSlash = connectionData.connectionUrl.lastIndexOf('/');
String engineUrl = connectionData.connectionUrl.substring(0, lastSlash);
String dbName = connectionData.connectionUrl.substring(lastSlash + 1);
String selectedName = GuiUtilities.showComboDialog(databaseViewer, "Select database", "Select the database to switch to", databasesNames.toArray(new String[0]), dbName);
if (selectedName != null && !selectedName.equals(dbName)) {
connectionData.connectionUrl = engineUrl + "/" + selectedName;
connectionData.connectionLabel = selectedName;
databaseViewer.openDatabase(connectionData, false);
}
} catch (Exception ex) {
GuiUtilities.handleError(databaseViewer, ex);
Logger.INSTANCE.e("Error", ex);
}
}
};
}
return null;
}
use of org.hortonmachine.dbs.nosql.INosqlDb in project hortonmachine by TheHortonMachine.
the class SqlTemplatesAndActions method getDropDatabaseAction.
public Action getDropDatabaseAction(GuiBridgeHandler guiBridge, DatabaseViewer databaseViewer) {
if (isNosql) {
return new AbstractAction("Drop current database") {
@Override
public void actionPerformed(ActionEvent e) {
INosqlDb db = databaseViewer.currentConnectedNosqlDatabase;
try {
boolean doDrop = GuiUtilities.showYesNoDialog(databaseViewer, "Are you sure you want to drop the current database '" + db.getDbName() + "'?\nThis can't be undone!");
if (doDrop) {
db.drop();
databaseViewer.closeCurrentDb(true);
}
} catch (Exception e1) {
GuiUtilities.handleError(databaseViewer, e1);
Logger.INSTANCE.e("Error", e1);
}
}
};
// } else if (databaseViewer.currentConnectedSqlDatabase.getType() == EDb.POSTGIS
// || databaseViewer.currentConnectedSqlDatabase.getType() == EDb.POSTGRES) {
// return new AbstractAction("Switch database"){
// @Override
// public void actionPerformed( ActionEvent e ) {
// // TODO?
// }
// };
}
return null;
}
use of org.hortonmachine.dbs.nosql.INosqlDb in project hortonmachine by TheHortonMachine.
the class SqlTemplatesAndActions method getSaveConnectionAction.
public Action getSaveConnectionAction(DatabaseViewer databaseViewer) {
return new AbstractAction("Save Connection") {
@SuppressWarnings("unchecked")
@Override
public void actionPerformed(ActionEvent e) {
try {
ConnectionData connectionData = null;
if (databaseViewer.currentConnectedSqlDatabase != null) {
ADb db = databaseViewer.currentConnectedSqlDatabase;
connectionData = db.getConnectionData();
} else if (databaseViewer.currentConnectedNosqlDatabase != null) {
INosqlDb db = databaseViewer.currentConnectedNosqlDatabase;
connectionData = db.getConnectionData();
}
String newName = GuiUtilities.showInputDialog(databaseViewer, "Enter a name for the saved connection", "db connection " + new DateTime().toString(HMConstants.dateTimeFormatterYYYYMMDDHHMMSS));
connectionData.connectionLabel = newName;
byte[] savedDbs = PreferencesHandler.getPreference(HM_SAVED_DATABASES, new byte[0]);
List<ConnectionData> connectionDataList = new ArrayList<>();
try {
connectionDataList = (List<ConnectionData>) convertFromBytes(savedDbs);
} catch (Exception e1) {
e1.printStackTrace();
}
connectionDataList.add(connectionData);
byte[] inBytes = convertObjectToBytes(connectionDataList);
PreferencesHandler.setPreference(HM_SAVED_DATABASES, inBytes);
} catch (Exception e1) {
e1.printStackTrace();
}
}
};
}
use of org.hortonmachine.dbs.nosql.INosqlDb in project hortonmachine by TheHortonMachine.
the class SqlTemplatesAndActions method getUpdateCollectionDocumentAction.
public Action getUpdateCollectionDocumentAction(GuiBridgeHandler guiBridge, DatabaseViewer databaseViewer) {
if (isNosql) {
return new AbstractAction("Update document by OID") {
@Override
public void actionPerformed(ActionEvent e) {
try {
if (databaseViewer.currentSelectedTable != null) {
INosqlDb db = databaseViewer.currentConnectedNosqlDatabase;
String oid = GuiUtilities.showInputDialog(databaseViewer, "Insert the document OID", "");
if (oid != null && oid.trim().length() > 0) {
oid = oid.trim();
String json = GuiUtilities.showInputAreaDialog(databaseViewer, "Add json to convert to document here.", "");
if (json != null) {
INosqlCollection collection = db.getCollection(databaseViewer.currentSelectedTable.tableName);
collection.updateByOid(oid, json);
}
}
} else {
GuiUtilities.showWarningMessage(databaseViewer, "Select a collection to insert the document to.");
}
} catch (Exception e1) {
GuiUtilities.handleError(databaseViewer, e1);
Logger.INSTANCE.e("Error", e1);
}
}
};
}
return null;
}
Aggregations