Search in sources :

Example 26 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryMetaStore method deleteElementType.

@Override
public void deleteElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException, MetaStoreDependenciesExistsException {
    try {
        Collection<RowMetaAndData> elementTypeRows = delegate.getElements(new LongObjectId(new StringObjectId(elementType.getId())));
        if (!elementTypeRows.isEmpty()) {
            List<String> dependencies = new ArrayList<String>();
            for (RowMetaAndData elementTypeRow : elementTypeRows) {
                Long elementTypeId = elementTypeRow.getInteger(KettleDatabaseRepository.FIELD_ELEMENT_TYPE_ID_ELEMENT_TYPE);
                dependencies.add(Long.toString(elementTypeId));
            }
            throw new MetaStoreDependenciesExistsException(dependencies, "The namespace to delete, '" + namespace + "' is not empty");
        }
        delegate.deleteElementType(new LongObjectId(new StringObjectId(elementType.getId())));
        repository.commit();
    } catch (MetaStoreDependenciesExistsException e) {
        throw e;
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException(e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ArrayList(java.util.ArrayList) LongObjectId(org.pentaho.di.repository.LongObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) 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 27 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryMetaStore method deleteElement.

@Override
public void deleteElement(String namespace, IMetaStoreElementType elementType, String elementId) throws MetaStoreException {
    try {
        IMetaStoreElementType type = getElementTypeByName(namespace, elementType.getName());
        if (type == null) {
            throw new MetaStoreException("Unable to find element type with name '" + elementType.getName() + "'");
        }
        delegate.deleteElement(new LongObjectId(new StringObjectId(elementId)));
        repository.commit();
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException("Unable to delete element with id '" + elementId + "' of type '" + elementType.getName() + "'", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) LongObjectId(org.pentaho.di.repository.LongObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) 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 28 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryMetaStore method createElementType.

// Handle the element types
public void createElementType(String namespace, IMetaStoreElementType elementType) throws MetaStoreException, MetaStoreElementTypeExistsException {
    try {
        ObjectId namespaceId = delegate.verifyNamespace(namespace);
        // See if the element already exists in this namespace
        // 
        IMetaStoreElementType existingType = getElementTypeByName(namespace, elementType.getName());
        if (existingType != null) {
            throw new MetaStoreElementTypeExistsException(Arrays.asList(existingType), "Can not create element type with id '" + elementType.getId() + "' because it already exists");
        }
        KDBRMetaStoreElementType newElementType = new KDBRMetaStoreElementType(delegate, namespace, namespaceId, elementType.getName(), elementType.getDescription());
        newElementType.save();
        elementType.setId(newElementType.getId());
        repository.commit();
    } catch (MetaStoreElementTypeExistsException e) {
        throw e;
    } catch (MetaStoreException e) {
        repository.rollback();
        throw e;
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException(e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException) 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 29 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryMetaStore method getElementTypes.

@Override
public List<IMetaStoreElementType> getElementTypes(String namespace) throws MetaStoreException {
    try {
        LongObjectId namespaceId = delegate.getNamespaceId(namespace);
        if (namespaceId == null) {
            return new ArrayList<IMetaStoreElementType>();
        }
        Collection<RowMetaAndData> elementTypeRows = delegate.getElementTypes(namespaceId);
        List<IMetaStoreElementType> list = new ArrayList<IMetaStoreElementType>();
        for (RowMetaAndData elementTypeRow : elementTypeRows) {
            KDBRMetaStoreElementType elementType = delegate.parseElementType(namespace, namespaceId, elementTypeRow);
            list.add(elementType);
        }
        return list;
    } catch (Exception e) {
        throw new MetaStoreException("Unable to get list of element types for namespace '" + namespace + "'", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ArrayList(java.util.ArrayList) LongObjectId(org.pentaho.di.repository.LongObjectId) 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 30 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException 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)

Aggregations

MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)43 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)18 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)18 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)17 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)17 LongObjectId (org.pentaho.di.repository.LongObjectId)12 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)11 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)9 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)8 StringObjectId (org.pentaho.di.repository.StringObjectId)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 ObjectId (org.pentaho.di.repository.ObjectId)5 IMetaStore (org.pentaho.metastore.api.IMetaStore)5 DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)4 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)4 List (java.util.List)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 NamedClusterOsgi (org.pentaho.di.core.osgi.api.NamedClusterOsgi)2