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);
}
}
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;
}
}
}
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);
}
}
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);
}
}
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();
}
}
}
Aggregations