Search in sources :

Example 21 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class StarModelerPerspective method save.

@Override
public boolean save(EngineMetaInterface meta, String fname, boolean isExport) {
    try {
        // 
        if (meta instanceof StarDomain) {
            StarDomain starDomain = (StarDomain) meta;
            // Make sure we pick the active MetaStore to save to, otherwise it's hard to verify
            // 
            IMetaStore metaStore = Spoon.getInstance().metaStore.getActiveMetaStore();
            LogChannel.GENERAL.logBasic("Saving star domain to meta store: " + metaStore.getName());
            // Save the name and description of the shared dimension in the metastore
            // 
            StarDomainMetaStoreUtil.saveStarDomain(metaStore, starDomain);
            // 
            for (LogicalTable sharedDimension : starDomain.getSharedDimensions()) {
                SharedDimensionMetaStoreUtil.saveSharedDimension(metaStore, sharedDimension, defaultLocale);
            }
            meta.clearChanged();
            Spoon.getInstance().enableMenus();
            return true;
        }
    } catch (Exception e) {
        new ErrorDialog(Spoon.getInstance().getShell(), "Error saving model", "There was an error while saving the model:", e);
    }
    return false;
}
Also used : ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) LogicalTable(org.pentaho.metadata.model.LogicalTable) IMetaStore(org.pentaho.metastore.api.IMetaStore) XulException(org.pentaho.ui.xul.XulException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleException(org.pentaho.di.core.exception.KettleException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)

Example 22 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class JobGenerator method getUniqueLogicalTables.

/**
 * Get a list of all unique physical table names wrapped in their logical tables
 * @return
 */
protected List<LogicalTable> getUniqueLogicalTables() {
    List<LogicalTable> tables = new ArrayList<LogicalTable>();
    List<String> phTabs = new ArrayList<String>();
    for (LogicalModel model : domain.getLogicalModels()) {
        for (LogicalTable table : model.getLogicalTables()) {
            String phTable = ConceptUtil.getString(table, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
            if (!Utils.isEmpty(phTable)) {
                if (!phTabs.contains(phTable)) {
                    phTabs.add(phTable);
                    tables.add(table);
                }
            }
        }
    }
    return tables;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) ArrayList(java.util.ArrayList) LogicalTable(org.pentaho.metadata.model.LogicalTable)

Example 23 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class StarModelDialog method getRelationshipsFromFact.

protected void getRelationshipsFromFact() {
    logicalRelationships = new ArrayList<LogicalRelationship>();
    getFactColumns();
    for (LogicalColumn column : factTable.getLogicalColumns()) {
        String dimensionName = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_DIMENSION_NAME);
        if (!Utils.isEmpty(dimensionName)) {
            LogicalTable dimensionTable = ConceptUtil.findDimensionWithName(logicalModel, dimensionName, locale);
            if (dimensionTable != null) {
                LogicalColumn tk = ConceptUtil.findLogicalColumn(dimensionTable, AttributeType.TECHNICAL_KEY);
                if (tk == null) {
                    tk = ConceptUtil.findLogicalColumn(dimensionTable, AttributeType.SMART_TECHNICAL_KEY);
                }
                if (tk != null) {
                    LogicalTable fromTable = factTable;
                    LogicalColumn fromColumn = column;
                    LogicalTable toTable = dimensionTable;
                    LogicalColumn toColumn = tk;
                    LogicalRelationship relationship = new LogicalRelationship(logicalModel, fromTable, toTable, fromColumn, toColumn);
                    logicalRelationships.add(relationship);
                }
            }
        }
    }
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalTable(org.pentaho.metadata.model.LogicalTable) LogicalRelationship(org.pentaho.metadata.model.LogicalRelationship)

Example 24 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class StarModelDialog method newTable.

protected boolean newTable(Shell shell, LogicalModel logicalModel) {
    LogicalTable logicalTable = new LogicalTable(logicalModel, null);
    logicalTable.setId(UUID.randomUUID().toString());
    logicalTable.setName(new LocalizedString(locale, "New table"));
    logicalTable.setDescription(new LocalizedString(locale, "New table description"));
    DimensionTableDialog dialog = new DimensionTableDialog(shell, logicalTable, locale);
    if (dialog.open() != null) {
        logicalModel.addLogicalTable(logicalTable);
        return true;
    }
    return false;
}
Also used : LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Example 25 with LogicalTable

use of org.pentaho.metadata.model.LogicalTable in project pentaho-kettle by pentaho.

the class StarModelDialog method copyTable.

protected boolean copyTable(Shell shell, LogicalModel logicalModel, String tableName) {
    LogicalTable originalTable = findLogicalTable(tableName);
    if (originalTable != null) {
        // Copy
        // 
        LogicalTable logicalTable = new LogicalTable();
        logicalTable.setId(UUID.randomUUID().toString());
        logicalTable.setName(new LocalizedString(locale, ConceptUtil.getName(originalTable, locale) + " (Copy)"));
        logicalTable.setDescription(new LocalizedString(locale, ConceptUtil.getDescription(originalTable, locale) + " (Copy)"));
        logicalTable.setProperty(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME, originalTable.getProperty(DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME));
        logicalTable.setProperty(DefaultPropertyID.TABLE_TYPE.getId(), originalTable.getProperty(DefaultPropertyID.TABLE_TYPE.getId()));
        for (LogicalColumn column : originalTable.getLogicalColumns()) {
            logicalTable.getLogicalColumns().add((LogicalColumn) column.clone());
        }
        DimensionTableDialog dialog = new DimensionTableDialog(shell, logicalTable, locale);
        if (dialog.open() != null) {
            logicalModel.addLogicalTable(logicalTable);
            return true;
        }
    }
    return false;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Aggregations

LogicalTable (org.pentaho.metadata.model.LogicalTable)34 Test (org.junit.Test)14 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)13 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)12 LogicalModel (org.pentaho.metadata.model.LogicalModel)11 ArrayList (java.util.ArrayList)7 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)6 Domain (org.pentaho.metadata.model.Domain)5 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)5 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)5 TableType (org.pentaho.metadata.model.concept.types.TableType)5 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)4 SqlPhysicalColumn (org.pentaho.metadata.model.SqlPhysicalColumn)4 KettleException (org.pentaho.di.core.exception.KettleException)3 TransMeta (org.pentaho.di.trans.TransMeta)3 Category (org.pentaho.metadata.model.Category)3 LogicalRelationship (org.pentaho.metadata.model.LogicalRelationship)3 List (java.util.List)2 TableItem (org.eclipse.swt.widgets.TableItem)2 Matchers.anyString (org.mockito.Matchers.anyString)2