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