use of org.pentaho.metastore.api.IMetaStoreElementType 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);
}
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class DatabaseMetaStoreUtil method createDatabaseElement.
public static void createDatabaseElement(IMetaStore metaStore, DatabaseMeta databaseMeta) throws MetaStoreException {
//
if (!metaStore.namespaceExists(PentahoDefaults.NAMESPACE)) {
metaStore.createNamespace(PentahoDefaults.NAMESPACE);
}
// If the database connection element type doesn't exist, create it
//
IMetaStoreElementType elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
if (elementType == null) {
elementType = populateDatabaseElementType(metaStore);
metaStore.createElementType(PentahoDefaults.NAMESPACE, elementType);
}
// populate an element, store it.
//
IMetaStoreElement databaseElement = populateDatabaseElement(metaStore, databaseMeta);
// Store the element physically
//
metaStore.createElement(PentahoDefaults.NAMESPACE, databaseElement.getElementType(), databaseElement);
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class DatabaseMetaStoreUtil method populateDatabaseElementType.
public static IMetaStoreElementType populateDatabaseElementType(IMetaStore metaStore) throws MetaStoreException {
// The new type will typically have an ID so all we need to do is give the type a name and a description.
//
IMetaStoreElementType elementType = metaStore.newElementType(PentahoDefaults.NAMESPACE);
// Name and description...
//
elementType.setName(PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
elementType.setDescription(PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_DESCRIPTION);
return elementType;
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class TestSharedObjectsMetaStore method testSharedObjectsMetaStore.
public void testSharedObjectsMetaStore() throws Exception {
KettleEnvironment.init();
File sharedObjectsFile = File.createTempFile("shared-objects", ".xml");
String sharedObjectsFilename = sharedObjectsFile.toString();
sharedObjectsFile.delete();
SharedObjects sharedObjects = new SharedObjects(sharedObjectsFilename);
SharedObjectsMetaStore metaStore = new SharedObjectsMetaStore(sharedObjects);
List<IMetaStoreElementType> elementTypes = metaStore.getElementTypes(namespace);
assertEquals(1, elementTypes.size());
IMetaStoreElementType databaseElementType = metaStore.getElementType(namespace, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
assertNotNull(databaseElementType);
List<IMetaStoreElement> elements = metaStore.getElements(namespace, databaseElementType);
assertEquals(0, elements.size());
DatabaseMeta databaseMeta = new DatabaseMeta(databaseMetaXml);
// add it to shared objects, see if we find the element (SharedObjects --> MetaStore)
//
sharedObjects.storeObject(databaseMeta);
elements = metaStore.getElements(namespace, databaseElementType);
assertEquals(1, elements.size());
IMetaStoreElement databaseElement = elements.get(0);
// Remove it again...
sharedObjects.removeObject(databaseMeta);
elements = metaStore.getElements(namespace, databaseElementType);
assertEquals(0, elements.size());
// Add it to the meta store, see if it shows in the shared objects (MetaStore --> SharedObjects)
//
metaStore.createElement(namespace, databaseElementType, databaseElement);
elements = metaStore.getElements(namespace, databaseElementType);
assertEquals(1, elements.size());
assertNotNull(sharedObjects.getSharedDatabase(databaseMeta.getName()));
}
use of org.pentaho.metastore.api.IMetaStoreElementType in project pentaho-kettle by pentaho.
the class PurRepositoryIT method testMetaStoreElementTypes.
@Test
public void testMetaStoreElementTypes() throws MetaStoreException {
IMetaStore metaStore = repository.getMetaStore();
assertNotNull(metaStore);
String ns = PentahoDefaults.NAMESPACE;
// We start with a clean slate...
//
assertEquals(1, metaStore.getNamespaces().size());
assertEquals(true, metaStore.namespaceExists(ns));
// Now create an element type
//
IMetaStoreElementType elementType = metaStore.newElementType(ns);
elementType.setName(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME);
elementType.setDescription(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION);
metaStore.createElementType(ns, elementType);
IMetaStoreElementType verifyElementType = metaStore.getElementType(ns, elementType.getId());
assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME, verifyElementType.getName());
assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION, verifyElementType.getDescription());
verifyElementType = metaStore.getElementTypeByName(ns, PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME);
assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME, verifyElementType.getName());
assertEquals(PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION, verifyElementType.getDescription());
// Get the list of element type ids.
//
List<String> ids = metaStore.getElementTypeIds(ns);
assertNotNull(ids);
assertEquals(1, ids.size());
assertEquals(elementType.getId(), ids.get(0));
//
try {
metaStore.deleteNamespace(ns);
fail("The namespace deletion didn't cause an exception because there are still an element type in it");
} catch (MetaStoreDependenciesExistsException e) {
assertNotNull(e.getDependencies());
assertEquals(1, e.getDependencies().size());
assertEquals(elementType.getId(), e.getDependencies().get(0));
}
metaStore.deleteElementType(ns, elementType);
assertEquals(0, metaStore.getElementTypes(ns).size());
metaStore.deleteNamespace(ns);
}
Aggregations