Search in sources :

Example 1 with MetaStoreElementExistException

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);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)

Example 2 with MetaStoreElementExistException

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);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)

Example 3 with MetaStoreElementExistException

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;
        }
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) Shell(org.eclipse.swt.widgets.Shell) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog)

Aggregations

MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)3 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)3 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)2 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)2 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)2 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)2 Shell (org.eclipse.swt.widgets.Shell)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 DatabaseDialog (org.pentaho.di.ui.core.database.dialog.DatabaseDialog)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)1 IMetaStore (org.pentaho.metastore.api.IMetaStore)1