Search in sources :

Example 6 with MetaStoreException

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

the class KettleDatabaseRepositoryMetaStore method createNamespace.

@Override
public void createNamespace(String namespace) throws MetaStoreException, MetaStoreNamespaceExistsException {
    try {
        ObjectId namespaceId = delegate.getNamespaceId(namespace);
        if (namespaceId != null) {
            throw new MetaStoreNamespaceExistsException("Namespace with name '" + namespace + "' already exists");
        }
        // insert namespace into R_NAMESPACE
        // 
        delegate.insertNamespace(namespace);
        repository.commit();
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException(e);
    }
}
Also used : MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) 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 7 with MetaStoreException

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

the class KettleDatabaseRepositoryMetaStore method getElementType.

@Override
public IMetaStoreElementType getElementType(String namespace, String elementTypeId) throws MetaStoreException {
    try {
        ObjectId namespaceId = delegate.getNamespaceId(namespace);
        if (namespaceId == null) {
            return null;
        }
        RowMetaAndData elementTypeRow = delegate.getElementType(new LongObjectId(new StringObjectId(elementTypeId)));
        return delegate.parseElementType(namespace, namespaceId, elementTypeRow);
    } catch (Exception e) {
        throw new MetaStoreException("Unable to get element type with id '" + elementTypeId + "' in namespace '" + namespace + "'", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) 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 8 with MetaStoreException

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

the class SharedObjectsMetaStore method deleteElement.

@Override
public void deleteElement(String namespace, IMetaStoreElementType elementType, String elementId) throws MetaStoreException {
    try {
        if (elementType.getName().equals(databaseElementType.getName())) {
            sharedObjects.removeObject(DatabaseMetaStoreUtil.loadDatabaseMetaFromDatabaseElement(this, getElement(namespace, elementType, elementId)));
            sharedObjects.saveToFile();
            return;
        }
    } catch (Exception e) {
        throw new MetaStoreException("Unexpected error deleting an element in the shared objects meta store", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) 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 9 with MetaStoreException

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

the class DatabaseMetaStoreUtil method getDatabaseElements.

public static List<DatabaseMeta> getDatabaseElements(IMetaStore metaStore) throws MetaStoreException {
    List<DatabaseMeta> databases = new ArrayList<DatabaseMeta>();
    // If the data type doesn't exist, it's an empty list...
    // 
    IMetaStoreElementType elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
    if (elementType == null) {
        return databases;
    }
    List<IMetaStoreElement> elements = metaStore.getElements(PentahoDefaults.NAMESPACE, elementType);
    for (IMetaStoreElement element : elements) {
        try {
            DatabaseMeta databaseMeta = loadDatabaseMetaFromDatabaseElement(metaStore, element);
            databases.add(databaseMeta);
        } catch (Exception e) {
            throw new MetaStoreException("Unable to load database from element with name '" + element.getName() + "' and type '" + elementType.getName() + "'", e);
        }
    }
    return databases;
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) ArrayList(java.util.ArrayList) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

Example 10 with MetaStoreException

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

the class DatabaseMetaStoreUtil method populateDatabaseElement.

public static IMetaStoreElement populateDatabaseElement(IMetaStore metaStore, DatabaseMeta databaseMeta) throws MetaStoreException {
    if (!metaStore.namespaceExists(PentahoDefaults.NAMESPACE)) {
        throw new MetaStoreException("Namespace '" + PentahoDefaults.NAMESPACE + "' doesn't exist.");
    }
    // If the data type doesn't exist, error out...
    // 
    IMetaStoreElementType elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
    if (elementType == null) {
        throw new MetaStoreException("Unable to find the database connection type");
    }
    elementType = populateDatabaseElementType(metaStore);
    // generate a new database element and populate it with metadata
    // 
    IMetaStoreElement element = metaStore.newElement(elementType, databaseMeta.getName(), null);
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PLUGIN_ID, databaseMeta.getPluginId()));
    element.setName(databaseMeta.getName());
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DESCRIPTION, databaseMeta.getDescription()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_ACCESS_TYPE, databaseMeta.getAccessTypeDesc()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_HOSTNAME, databaseMeta.getHostname()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PORT, databaseMeta.getDatabasePortNumberString()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DATABASE_NAME, databaseMeta.getDatabaseName()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_USERNAME, databaseMeta.getUsername()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PASSWORD, metaStore.getTwoWayPasswordEncoder().encode(databaseMeta.getPassword())));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_SERVERNAME, databaseMeta.getServername()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DATA_TABLESPACE, databaseMeta.getDataTablespace()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_INDEX_TABLESPACE, databaseMeta.getIndexTablespace()));
    IMetaStoreAttribute attributesChild = metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_ATTRIBUTES, null);
    element.addChild(attributesChild);
    // Now add a list of all the attributes set on the database connection...
    // 
    Properties attributes = databaseMeta.getAttributes();
    Enumeration<Object> keys = databaseMeta.getAttributes().keys();
    while (keys.hasMoreElements()) {
        String code = (String) keys.nextElement();
        String attribute = (String) attributes.get(code);
        // Add it to the attributes child
        // 
        attributesChild.addChild(metaStore.newAttribute(code, attribute));
    }
    // Extra information for 3rd-party tools:
    // 
    // The driver class
    // 
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_DRIVER_CLASS, databaseMeta.getDriverClass()));
    // 
    try {
        element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_JDBC_URL, databaseMeta.getURL()));
    } catch (Exception e) {
        throw new MetaStoreException("Unable to assemble URL from database '" + databaseMeta.getName() + "'", e);
    }
    return element;
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Properties(java.util.Properties) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

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