Search in sources :

Example 31 with MetaStoreException

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

the class KettleDatabaseRepositoryMetaStoreDelegate method insertElement.

public ObjectId insertElement(IMetaStoreElementType elementType, IMetaStoreElement element) throws MetaStoreException {
    try {
        LongObjectId elementId = repository.connectionDelegate.getNextID(quoteTable(KettleDatabaseRepository.TABLE_R_ELEMENT), quote(KettleDatabaseRepository.FIELD_ELEMENT_ID_ELEMENT));
        RowMetaAndData table = new RowMetaAndData();
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_ID_ELEMENT), elementId.longValue());
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_ELEMENT_ID_ELEMENT_TYPE), Long.valueOf(elementType.getId()));
        table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_ELEMENT_NAME), element.getName());
        repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_ELEMENT);
        repository.connectionDelegate.getDatabase().setValuesInsert(table);
        repository.connectionDelegate.getDatabase().insertRow();
        repository.connectionDelegate.getDatabase().closeInsert();
        element.setId(elementId.toString());
        // Now save the attributes
        // 
        insertAttributes(element.getChildren(), elementId, new LongObjectId(0L));
        if (log.isDebug()) {
            log.logDebug("Saved element with name [" + element.getName() + "]");
        }
        return elementId;
    } catch (Exception e) {
        throw new MetaStoreException("Unable to create new element with name '" + element.getName() + "'", e);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) LongObjectId(org.pentaho.di.repository.LongObjectId) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 32 with MetaStoreException

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

Example 33 with MetaStoreException

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

the class ModelMetaStoreUtil method populateElement.

private static IMetaStoreElement populateElement(IMetaStore metaStore, LogicalModel model) throws MetaStoreException {
    try {
        IMetaStoreElement element = metaStore.newElement();
        element.setName(model.getName(defaultLocale));
        element.addChild(metaStore.newAttribute(Attribute.ID_MODEL_DESCRIPTION.id, model.getDescription(defaultLocale)));
        IMetaStoreAttribute logicalTablesAttribute = metaStore.newAttribute(Attribute.ID_LOGICAL_TABLES.id, model.getDescription(defaultLocale));
        element.addChild(logicalTablesAttribute);
        for (LogicalTable logicalTable : model.getLogicalTables()) {
            IMetaStoreAttribute logicalTableAttribute = metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE.id, model.getDescription(defaultLocale));
            logicalTablesAttribute.addChild(logicalTableAttribute);
            // 
            // Save the ID as well as the name (for safety)
            // 
            logicalTableAttribute.addChild(metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE_ID.id, logicalTable.getId()));
            logicalTableAttribute.addChild(metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE_NAME.id, logicalTable.getName()));
        }
        return element;
    } catch (Exception e) {
        throw new MetaStoreException("Unable to populate metastore element from logical model", e);
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) LogicalTable(org.pentaho.metadata.model.LogicalTable) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException)

Example 34 with MetaStoreException

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

the class ModelMetaStoreUtil method buildLogicalModel.

/**
 * Inflate a logical model from a metastore element.
 *
 * @param metaStore The metastore to read from
 * @param element The element to read from
 * @return The Logical Model
 * @throws MetaStoreException in case something goes wrong
 */
public static LogicalModel buildLogicalModel(IMetaStore metaStore, IMetaStoreElement element) throws MetaStoreException {
    try {
        LogicalModel model = new LogicalModel();
        model.setName(new LocalizedString(defaultLocale, element.getName()));
        model.setDescription(new LocalizedString(defaultLocale, getChildString(element, Attribute.ID_MODEL_DESCRIPTION.id)));
        return model;
    } catch (Exception e) {
        throw new MetaStoreException("Unable to inflate logical model from metastore element", e);
    }
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException)

Example 35 with MetaStoreException

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

the class Spoon method closeRepository.

public void closeRepository() {
    if (rep != null) {
        // Prompt and close all tabs as user disconnected from the repo
        boolean shouldDisconnect = Spoon.getInstance().closeAllJobsAndTransformations(true);
        if (shouldDisconnect) {
            loadSessionInformation(null, false);
            if (rep != null) {
                rep.disconnect();
            }
            if (metaStore.getMetaStoreList().size() > 1) {
                try {
                    metaStore.getMetaStoreList().remove(0);
                    metaStore.setActiveMetaStoreName(metaStore.getMetaStoreList().get(0).getName());
                } catch (MetaStoreException e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.ErrorRemovingMetaStore.Title"), BaseMessages.getString(PKG, "Spoon.ErrorRemovingMetaStore.Message"), e);
                }
            }
            setRepository(null);
            setShellText();
            SpoonPluginManager.getInstance().notifyLifecycleListeners(SpoonLifeCycleEvent.REPOSITORY_DISCONNECTED);
            enableMenus();
        }
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog)

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