use of org.pentaho.metastore.api.exceptions.MetaStoreElementExistException in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryMetaStore method createElement.
@Override
public void createElement(String namespace, IMetaStoreElementType elementType, IMetaStoreElement element) throws MetaStoreException, MetaStoreElementExistException {
try {
IMetaStoreElement found = getElementByName(namespace, elementType, element.getName());
if (found != null) {
throw new MetaStoreElementExistException(Arrays.asList(found), "The element with name '" + element.getName() + "' already exists");
}
delegate.insertElement(elementType, element);
repository.commit();
} catch (MetaStoreElementExistException e) {
throw e;
} catch (Exception e) {
repository.rollback();
throw new MetaStoreException("Unable to create element with name '" + element.getName() + "' of type '" + elementType.getName() + "'", e);
}
}
use of org.pentaho.metastore.api.exceptions.MetaStoreElementExistException in project pentaho-kettle by pentaho.
the class SharedObjectsMetaStore method createElement.
@Override
public void createElement(String namespace, IMetaStoreElementType elementType, IMetaStoreElement element) throws MetaStoreException, MetaStoreElementExistException {
try {
IMetaStoreElement exists = getElementByName(namespace, elementType, element.getId());
if (exists != null) {
throw new MetaStoreException("The shared objects meta store already contains an element with type name '" + elementType.getName() + "' and element name '" + element.getName());
}
if (elementType.getName().equals(databaseElementType.getName())) {
// convert the element to DatabaseMeta and store it in the shared objects file, then save the file
//
sharedObjects.storeObject(DatabaseMetaStoreUtil.loadDatabaseMetaFromDatabaseElement(this, element));
sharedObjects.saveToFile();
return;
}
throw new MetaStoreException("Storing elements with element type name '" + elementType.getName() + "' is not supported in the shared objects meta store");
} catch (Exception e) {
throw new MetaStoreException("Unexpected error creating an element in the shared objects meta store", e);
}
}
use of org.pentaho.metastore.api.exceptions.MetaStoreElementExistException in project pentaho-kettle by pentaho.
the class StarModelerPerspective method createSharedDatabase.
protected void createSharedDatabase(CCombo targetDatabase) {
Shell shell = Spoon.getInstance().getShell();
boolean retry = true;
while (retry) {
try {
DatabaseMeta dbMeta = new DatabaseMeta();
DatabaseDialog databaseDialog = new DatabaseDialog(shell, dbMeta);
if (databaseDialog.open() != null) {
// Add dbMeta to the shared databases...
//
IMetaStore metaStore = Spoon.getInstance().getMetaStore();
DatabaseMetaStoreUtil.createDatabaseElement(metaStore, dbMeta);
// Refresh the list...
//
final List<DatabaseMeta> sharedDatabases = DatabaseMetaStoreUtil.getDatabaseElements(metaStore);
String[] databaseNames = SharedDatabaseUtil.getSortedDatabaseNames(sharedDatabases);
targetDatabase.setItems(databaseNames);
targetDatabase.setText(dbMeta.getName());
}
retry = false;
} catch (MetaStoreElementExistException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Title"), BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Message"), e);
} catch (MetaStoreException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Title"), BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Message"), e);
retry = false;
}
}
}
Aggregations