use of org.pentaho.di.shared.SharedObjects in project pentaho-kettle by pentaho.
the class SharedDatabaseUtil method addSharedDatabase.
/**
* Add a database to the list of shared databases in ~/.kettle/shared.xml
*
* @param databaseMeta
* @throws KettleException in case there is an error
* @throws KettleObjectExistsException if a database with the same name already exists
*/
public static void addSharedDatabase(DatabaseMeta databaseMeta) throws KettleObjectExistsException, KettleException {
// First verify existence...
//
List<DatabaseMeta> sharedDatabases = loadSharedDatabases();
DatabaseMeta found = DatabaseMeta.findDatabase(sharedDatabases, databaseMeta.getName());
if (found != null) {
throw new KettleObjectExistsException("A database with name '" + databaseMeta.getName() + "' already exists in the shared databases list.");
}
try {
SharedObjects sharedObjects = new SharedObjects();
sharedObjects.storeObject(databaseMeta);
sharedObjects.saveToFile();
} catch (Exception e) {
throw new KettleException("It was not possible to add database '" + databaseMeta.getName() + "' to the shared.xml file");
}
}
use of org.pentaho.di.shared.SharedObjects in project pentaho-kettle by pentaho.
the class StarModelDialog method addDimensionsTab.
private void addDimensionsTab() {
wDimensionsTab = new CTabItem(wTabFolder, SWT.NONE);
wDimensionsTab.setText(BaseMessages.getString(PKG, "StarModelDialog.DimensionsTab.Label"));
FormLayout dimensionsLayout = new FormLayout();
dimensionsLayout.marginWidth = Const.MARGIN;
dimensionsLayout.marginHeight = Const.MARGIN;
Composite wDimensionsComp = new Composite(wTabFolder, SWT.NONE);
props.setLook(wDimensionsComp);
wDimensionsComp.setLayout(dimensionsLayout);
Label wlTables = new Label(wDimensionsComp, SWT.RIGHT);
wlTables.setText(BaseMessages.getString(PKG, "StarModelDialog.Tables.Label"));
props.setLook(wlTables);
FormData fdlAttributes = new FormData();
fdlAttributes.left = new FormAttachment(0, 0);
fdlAttributes.top = new FormAttachment(0, 0);
wlTables.setLayoutData(fdlAttributes);
// A few buttons to edit the list
//
Button newTableButton = new Button(wDimensionsComp, SWT.PUSH);
newTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.NewTable"));
newTableButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (newTable(shell, logicalModel)) {
refreshTablesList();
}
}
});
Button copyTableButton = new Button(wDimensionsComp, SWT.PUSH);
copyTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.CopyTable"));
copyTableButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (wTablesList.getSelectionIndex() < 0)
return;
TableItem item = wTablesList.table.getSelection()[0];
String tableName = item.getText(1);
if (copyTable(shell, logicalModel, tableName)) {
refreshTablesList();
}
}
});
Button editTableButton = new Button(wDimensionsComp, SWT.PUSH);
editTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.EditTable"));
editTableButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (wTablesList.getSelectionIndex() < 0)
return;
TableItem item = wTablesList.table.getSelection()[0];
String tableName = item.getText(1);
if (editTable(tableName)) {
refreshTablesList();
}
}
});
Button delTableButton = new Button(wDimensionsComp, SWT.PUSH);
delTableButton.setText(BaseMessages.getString(PKG, "StarModelDialog.Button.DeleteTable"));
delTableButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (wTablesList.getSelectionIndex() < 0)
return;
TableItem item = wTablesList.table.getSelection()[0];
String tableName = item.getText(1);
if (deleteTable(tableName)) {
refreshTablesList();
}
}
});
BaseStepDialog.positionBottomButtons(wDimensionsComp, new Button[] { newTableButton, copyTableButton, editTableButton, delTableButton }, margin, null);
final int FieldsRows = logicalModel.getLogicalTables().size();
List<DatabaseMeta> sharedDatabases = new ArrayList<DatabaseMeta>();
try {
SharedObjects sharedObjects = new SharedObjects();
for (SharedObjectInterface sharedObject : sharedObjects.getObjectsMap().values()) {
if (sharedObject instanceof DatabaseMeta) {
sharedDatabases.add((DatabaseMeta) sharedObject);
}
}
} catch (Exception e) {
LogChannel.GENERAL.logError("Unable to load shared objects", e);
}
// The dimensions and fact of the model
//
ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.Name.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.Description.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false, true), new ColumnInfo(BaseMessages.getString(PKG, "StarModelDialog.ColumnInfo.TableType.Label"), ColumnInfo.COLUMN_TYPE_TEXT, false, true) };
wTablesList = new TableView(new Variables(), wDimensionsComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, null, props);
FormData fdTablesList = new FormData();
fdTablesList.left = new FormAttachment(0, 0);
fdTablesList.top = new FormAttachment(wlTables, margin);
fdTablesList.right = new FormAttachment(100, 0);
fdTablesList.bottom = new FormAttachment(newTableButton, -margin);
wTablesList.setLayoutData(fdTablesList);
wTablesList.setReadonly(true);
wTablesList.table.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
if (wTablesList.getSelectionIndex() < 0)
return;
TableItem item = wTablesList.table.getSelection()[0];
String tableName = item.getText(1);
if (editTable(tableName)) {
refreshTablesList();
// refreshRelationshipsList();
}
}
});
FormData fdTablesComp = new FormData();
fdTablesComp.left = new FormAttachment(0, 0);
fdTablesComp.top = new FormAttachment(0, 0);
fdTablesComp.right = new FormAttachment(100, 0);
fdTablesComp.bottom = new FormAttachment(100, 0);
wDimensionsComp.setLayoutData(fdTablesComp);
wDimensionsComp.layout();
wDimensionsTab.setControl(wDimensionsComp);
}
use of org.pentaho.di.shared.SharedObjects in project pentaho-kettle by pentaho.
the class Spoon method unShareObject.
protected void unShareObject(SharedObjectInterface sharedObject) {
MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_WARNING);
// "Are you sure you want to stop sharing?"
mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.StopSharing.Message"));
// Warning!
mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.StopSharing.Title"));
int answer = mb.open();
if (answer == SWT.YES) {
sharedObject.setShared(false);
EngineMetaInterface meta = getActiveMeta();
try {
if (meta != null) {
SharedObjects sharedObjects = null;
if (meta instanceof TransMeta) {
sharedObjects = ((TransMeta) meta).getSharedObjects();
}
if (meta instanceof JobMeta) {
sharedObjects = ((JobMeta) meta).getSharedObjects();
}
if (sharedObjects != null) {
sharedObjects.removeObject(sharedObject);
sharedObjects.saveToFile();
}
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorWritingSharedObjects.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorWritingSharedObjects.Message"), e);
}
refreshTree();
}
}
use of org.pentaho.di.shared.SharedObjects in project pentaho-kettle by pentaho.
the class Spoon method loadRepositoryObjects.
/**
* @deprecated is this ever used?
* functionality seems covered in loadSessionInformation
*/
public void loadRepositoryObjects(TransMeta transMeta) {
// Load common database info from active repository...
if (rep != null) {
try {
SharedObjects sharedObjects = rep.readTransSharedObjects(transMeta);
sharedObjectsFileMap.put(sharedObjects.getFilename(), sharedObjects);
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Error.UnableToLoadSharedObjects.Title"), BaseMessages.getString(PKG, "Spoon.Error.UnableToLoadSharedObjects.Message"), e);
}
}
}
use of org.pentaho.di.shared.SharedObjects in project pentaho-kettle by pentaho.
the class Spoon method loadSessionInformation.
private void loadSessionInformation(Repository repository, boolean saveOldDatabases) {
JobMeta[] jobMetas = getLoadedJobs();
for (JobMeta jobMeta : jobMetas) {
for (int i = 0; i < jobMeta.nrDatabases(); i++) {
jobMeta.getDatabase(i).setObjectId(null);
}
// Set for the existing job the ID at -1!
jobMeta.setObjectId(null);
// Keep track of the old databases for now.
List<DatabaseMeta> oldDatabases = jobMeta.getDatabases();
// In order to re-match the databases on name (not content), we
// need to load the databases from the new repository.
// NOTE: for purposes such as DEVELOP - TEST - PRODUCTION
// cycles.
// first clear the list of databases and slave servers
jobMeta.setDatabases(new ArrayList<DatabaseMeta>());
jobMeta.setSlaveServers(new ArrayList<SlaveServer>());
// Read them from the new repository.
try {
SharedObjects sharedObjects = repository != null ? repository.readJobMetaSharedObjects(jobMeta) : jobMeta.readSharedObjects();
sharedObjectsFileMap.put(sharedObjects.getFilename(), sharedObjects);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorReadingSharedObjects.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorReadingSharedObjects.Message", makeTabName(jobMeta, true)), e);
}
// Then we need to re-match the databases at save time...
for (DatabaseMeta oldDatabase : oldDatabases) {
DatabaseMeta newDatabase = DatabaseMeta.findDatabase(jobMeta.getDatabases(), oldDatabase.getName());
// If it exists, change the settings...
if (newDatabase != null) {
//
// A database connection with the same name exists in
// the new repository.
// Change the old connections to reflect the settings in
// the new repository
//
oldDatabase.setDatabaseInterface(newDatabase.getDatabaseInterface());
} else {
if (saveOldDatabases) {
//
// The old database is not present in the new
// repository: simply add it to the list.
// When the job gets saved, it will be added
// to the repository.
//
jobMeta.addDatabase(oldDatabase);
}
}
}
if (repository != null) {
try {
// For the existing job, change the directory too:
// Try to find the same directory in the new repository...
RepositoryDirectoryInterface rdi = repository.findDirectory(jobMeta.getRepositoryDirectory().getPath());
if (rdi != null && !rdi.getPath().equals("/")) {
jobMeta.setRepositoryDirectory(rdi);
} else {
// the root is the default!
jobMeta.setRepositoryDirectory(repository.loadRepositoryDirectoryTree());
}
} catch (KettleException ke) {
rep = null;
new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorConnectingRepository.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorConnectingRepository.Message", Const.CR), ke);
}
}
}
TransMeta[] transMetas = getLoadedTransformations();
for (TransMeta transMeta : transMetas) {
for (int i = 0; i < transMeta.nrDatabases(); i++) {
transMeta.getDatabase(i).setObjectId(null);
}
// Set for the existing transformation the ID at -1!
transMeta.setObjectId(null);
// Keep track of the old databases for now.
List<DatabaseMeta> oldDatabases = transMeta.getDatabases();
// In order to re-match the databases on name (not content), we
// need to load the databases from the new repository.
// NOTE: for purposes such as DEVELOP - TEST - PRODUCTION
// cycles.
// first clear the list of databases, partition schemas, slave
// servers, clusters
transMeta.setDatabases(new ArrayList<DatabaseMeta>());
transMeta.setPartitionSchemas(new ArrayList<PartitionSchema>());
transMeta.setSlaveServers(new ArrayList<SlaveServer>());
transMeta.setClusterSchemas(new ArrayList<ClusterSchema>());
// Read them from the new repository.
try {
SharedObjects sharedObjects = repository != null ? repository.readTransSharedObjects(transMeta) : transMeta.readSharedObjects();
sharedObjectsFileMap.put(sharedObjects.getFilename(), sharedObjects);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorReadingSharedObjects.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorReadingSharedObjects.Message", makeTabName(transMeta, true)), e);
}
// Then we need to re-match the databases at save time...
for (DatabaseMeta oldDatabase : oldDatabases) {
DatabaseMeta newDatabase = DatabaseMeta.findDatabase(transMeta.getDatabases(), oldDatabase.getName());
// If it exists, change the settings...
if (newDatabase != null) {
//
// A database connection with the same name exists in
// the new repository.
// Change the old connections to reflect the settings in
// the new repository
//
oldDatabase.setDatabaseInterface(newDatabase.getDatabaseInterface());
} else {
if (saveOldDatabases) {
//
// The old database is not present in the new
// repository: simply add it to the list.
// When the transformation gets saved, it will be added
// to the repository.
//
transMeta.addDatabase(oldDatabase);
}
}
}
if (repository != null) {
try {
// For the existing transformation, change the directory too:
// Try to find the same directory in the new repository...
RepositoryDirectoryInterface rdi = repository.findDirectory(transMeta.getRepositoryDirectory().getPath());
if (rdi != null && !rdi.getPath().equals("/")) {
transMeta.setRepositoryDirectory(rdi);
} else {
// the root is the default!
transMeta.setRepositoryDirectory(repository.loadRepositoryDirectoryTree());
}
} catch (KettleException ke) {
rep = null;
new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorConnectingRepository.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorConnectingRepository.Message", Const.CR), ke);
}
}
}
}
Aggregations