use of org.pentaho.metastore.api.IMetaStoreElement in project pentaho-kettle by pentaho.
the class SharedObjectsMetaStore method createElement.
@Override
public void createElement(String namespace, IMetaStoreElementType elementType, IMetaStoreElement element) throws MetaStoreException, MetaStoreElementExistException {
try {
IMetaStoreElement exists = getElementByName(namespace, elementType, element.getId());
if (exists != null) {
throw new MetaStoreException("The shared objects meta store already contains an element with type name '" + elementType.getName() + "' and element name '" + element.getName());
}
if (elementType.getName().equals(databaseElementType.getName())) {
// convert the element to DatabaseMeta and store it in the shared objects file, then save the file
//
sharedObjects.storeObject(DatabaseMetaStoreUtil.loadDatabaseMetaFromDatabaseElement(this, element));
sharedObjects.saveToFile();
return;
}
throw new MetaStoreException("Storing elements with element type name '" + elementType.getName() + "' is not supported in the shared objects meta store");
} catch (Exception e) {
throw new MetaStoreException("Unexpected error creating an element in the shared objects meta store", e);
}
}
use of org.pentaho.metastore.api.IMetaStoreElement 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.IMetaStoreElement 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.IMetaStoreElement in project pentaho-kettle by pentaho.
the class PurRepositoryIT method testMetaStoreElements.
@Test
public void testMetaStoreElements() throws MetaStoreException {
// Set up a namespace
//
String ns = PentahoDefaults.NAMESPACE;
IMetaStore metaStore = repository.getMetaStore();
if (!metaStore.namespaceExists(ns)) {
metaStore.createNamespace(ns);
}
// And 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);
// Now we play with elements...
//
IMetaStoreElement oneElement = populateElement(metaStore, elementType, "Element One");
metaStore.createElement(ns, elementType, oneElement);
IMetaStoreElement verifyOneElement = metaStore.getElement(ns, elementType, oneElement.getId());
assertNotNull(verifyOneElement);
validateElement(verifyOneElement, "Element One");
assertEquals(1, metaStore.getElements(ns, elementType).size());
IMetaStoreElement twoElement = populateElement(metaStore, elementType, "Element Two");
metaStore.createElement(ns, elementType, twoElement);
IMetaStoreElement verifyTwoElement = metaStore.getElement(ns, elementType, twoElement.getId());
assertNotNull(verifyTwoElement);
assertEquals(2, metaStore.getElements(ns, elementType).size());
try {
metaStore.deleteElementType(ns, elementType);
fail("Delete element type failed to properly detect element dependencies");
} catch (MetaStoreDependenciesExistsException e) {
List<String> ids = e.getDependencies();
assertEquals(2, ids.size());
assertTrue(ids.contains(oneElement.getId()));
assertTrue(ids.contains(twoElement.getId()));
}
metaStore.deleteElement(ns, elementType, oneElement.getId());
assertEquals(1, metaStore.getElements(ns, elementType).size());
metaStore.deleteElement(ns, elementType, twoElement.getId());
assertEquals(0, metaStore.getElements(ns, elementType).size());
}
use of org.pentaho.metastore.api.IMetaStoreElement 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);
}
}
Aggregations