📄 cwmexample.java
字号:
// -----------------------------------------------------------------------
// Physical Model
// -----------------------------------------------------------------------
// DEFINING TABLES AND COLUMNS
// Create the product table:
Table prodTable = relationalPackage.getTable().createTable();
prodTable.setName("Product");
// Create the columns:
Column relUPC = relationalPackage.getColumn().createColumn();
relUPC.setName("UPC");
relUPC.setOwner(prodTable);
Column relProdDesc = relationalPackage.getColumn().createColumn();
relProdDesc.setName("Description");
relProdDesc.setOwner(prodTable);
Column relBrand = relationalPackage.getColumn().createColumn();
relBrand.setName("Brand");
relBrand.setOwner(prodTable);
Column relType = relationalPackage.getColumn().createColumn();
relType.setName("Type");
relType.setOwner(prodTable);
Column relCat = relationalPackage.getColumn().createColumn();
relCat.setName("Category");
relCat.setOwner(prodTable);
Column relColor = relationalPackage.getColumn().createColumn();
relColor.setName("Color");
relColor.setOwner(prodTable);
// Create the geography table:
Table geogTable = relationalPackage.getTable().createTable();
geogTable.setName("Geography");
// Create the columns:
Column relState = relationalPackage.getColumn().createColumn();
relState.setName("State");
relState.setOwner(geogTable);
Column relGeogDesc = relationalPackage.getColumn().createColumn();
relGeogDesc.setName("Description");
relGeogDesc.setOwner(geogTable);
Column relTerr = relationalPackage.getColumn().createColumn();
relTerr.setName("Territory");
relTerr.setOwner(geogTable);
Column relRegion = relationalPackage.getColumn().createColumn();
relRegion.setName("Region");
relRegion.setOwner(geogTable);
// Create the time table:
Table timeTable = relationalPackage.getTable().createTable();
timeTable.setName("Time");
// Create the columns:
Column relWeek = relationalPackage.getColumn().createColumn();
relWeek.setName("Week");
relWeek.setOwner(timeTable);
Column relStartDate = relationalPackage.getColumn().createColumn();
relStartDate.setName("Start Date");
relStartDate.setOwner(timeTable);
Column relEndDate = relationalPackage.getColumn().createColumn();
relEndDate.setName("End Date");
relEndDate.setOwner(timeTable);
Column relMonth = relationalPackage.getColumn().createColumn();
relMonth.setName("Month");
relMonth.setOwner(timeTable);
Column relQuarter = relationalPackage.getColumn().createColumn();
relQuarter.setName("Quarter");
relQuarter.setOwner(timeTable);
Column relYear = relationalPackage.getColumn().createColumn();
relYear.setName("Year");
relYear.setOwner(timeTable);
// Create the sales fact table:
Table salesFactTable = relationalPackage.getTable().createTable();
salesFactTable.setName("Sales Fact Table");
// Create the columns:
Column relSalesTimeId = relationalPackage.getColumn().createColumn();
relSalesTimeId.setName("Time");
relSalesTimeId.setOwner(salesFactTable);
Column relSalesGeogId = relationalPackage.getColumn().createColumn();
relSalesGeogId.setName("Geography");
relSalesGeogId.setOwner(salesFactTable);
Column relSalesProdId = relationalPackage.getColumn().createColumn();
relSalesProdId.setName("Product");
relSalesProdId.setOwner(salesFactTable);
Column relSales = relationalPackage.getColumn().createColumn();
relSales.setName("Sales");
relSales.setOwner(salesFactTable);
Column relCost = relationalPackage.getColumn().createColumn();
relCost.setName("Cost");
relCost.setOwner(salesFactTable);
// Create the population fact table:
Table popFactTable = relationalPackage.getTable().createTable();
popFactTable.setName("Population Fact Table");
// Create the columns:
Column relpopTimeId = relationalPackage.getColumn().createColumn();
relpopTimeId.setName("Time");
relpopTimeId.setOwner(popFactTable);
Column relpopGeogId = relationalPackage.getColumn().createColumn();
relpopGeogId.setName("Geography");
relpopGeogId.setOwner(popFactTable);
Column relTotalRevenue = relationalPackage.getColumn().createColumn();
relTotalRevenue.setName("Total Revenue");
relTotalRevenue.setOwner(popFactTable);
// Add keys to product table:
PrimaryKey prodPrimaryKey = relationalPackage.getPrimaryKey().createPrimaryKey();
prodTable.addOwnedElement(prodPrimaryKey);
prodPrimaryKey.addFeature(relUPC);
// Add keys to sales fact table:
PrimaryKey salesPrimaryKey = relationalPackage.getPrimaryKey().createPrimaryKey();
salesFactTable.addOwnedElement(salesPrimaryKey);
salesPrimaryKey.addFeature(relSalesTimeId);
salesPrimaryKey.addFeature(relSalesGeogId);
salesPrimaryKey.addFeature(relSalesProdId);
// Add foreign keys:
ForeignKey salesToProd = relationalPackage.getForeignKey().createForeignKey();
salesFactTable.addOwnedElement(salesToProd);
salesToProd.addFeature(relSalesProdId);
salesToProd.setUniqueKey(prodPrimaryKey);
// -----------------------------------------------------------------------
// Physical Deployment Models
// -----------------------------------------------------------------------
// CREATE DEPLOYMENT GROUP
DeploymentGroup deploy1 = olapPackage.getDeploymentGroup().createDeploymentGroup();
dimensionalSchema.addOwnedElement(deploy1);
// -----------------------------------------------------------------------
// Mapping between the Models
// -----------------------------------------------------------------------
// MAPPING THE LOGICAL MODEL
TransformationMap standardProdHierTM = transformationPackage.getTransformationMap().createTransformationMap();
ClassifierMap standardProdHierCM = transformationPackage.getClassifierMap().createClassifierMap();
standardProdHierTM.addOwnedElement(standardProdHierCM);
// Create the featuremaps and assign target and sources:
FeatureMap stdProdHierFMId = transformationPackage.getFeatureMap().createFeatureMap();
standardProdHierCM.addFeatureMap(stdProdHierFMId);
stdProdHierFMId.addTarget(stdId);
stdProdHierFMId.addSource(catHLRId);
stdProdHierFMId.addSource(typeHLRId);
stdProdHierFMId.addSource(brandHLRId);
stdProdHierFMId.addSource(upcHLRId);
FeatureMap stdProdHierFMDesc = transformationPackage.getFeatureMap().createFeatureMap();
standardProdHierCM.addFeatureMap(stdProdHierFMDesc);
stdProdHierFMDesc.addTarget(stdLongDescription);
stdProdHierFMDesc.addSource(catHLRLongDescription);
stdProdHierFMDesc.addSource(typeHLRLongDescription);
stdProdHierFMDesc.addSource(brandHLRLongDescription);
stdProdHierFMDesc.addSource(upcHLRLongDescription);
FeatureMap stdProdHierFMParent = transformationPackage.getFeatureMap().createFeatureMap();
standardProdHierCM.addFeatureMap(stdProdHierFMParent);
stdProdHierFMParent.addTarget(stdParent);
stdProdHierFMParent.addSource(typeHLRparent);
stdProdHierFMParent.addSource(brandHLRparent);
stdProdHierFMParent.addSource(upcHLRparent);
// ...
}
/**
* Demonstrates the CWM use for warehousing. <p>
*
* From [1], example of Chapter 7 "Web-Enabled Data Warehouse Model".
*
* @throws Exception cannot run tests
*/
public void createWebEnabledDataWarehouseModel() throws Exception {
// Create CWM factory and get required packages:
CWMCompletePackage cwmFactory = new CWMCompletePackage();
OlapPackage olapPkg = cwmFactory.getOlap();
javax.olap.serversidemetadata.SchemaClass schemaClass = olapPkg.getSchema();
javax.olap.serversidemetadata.Schema schema = schemaClass.createSchema();
schema.setName( "WebDW" );
// Create Time Dimensions:
DimensionClass dimensionClass = olapPkg.getDimension();
Dimension timeDimension = dimensionClass.createDimension();
timeDimension.setName( "Time" );
timeDimension.setIsTime( true );
// Add the Time Dimension to the OLAP Schema:
Collection<Dimension> dimCol = schema.getDimension();
dimCol.add( timeDimension );
timeDimension.setSchema( schema );
// Get neccessary class factories:
CorePackage corePkg = cwmFactory.getCore();
KeysIndexesPackage keysIndexesPkg = cwmFactory.getKeysIndexes();
AttributeClass attributeClass = corePkg.getAttribute();
DataTypeClass dataTypeClass = corePkg.getDataType();
UniqueKeyClass uniqueKeyClass = keysIndexesPkg.getUniqueKey();
StereotypeClass stereotypeClass = corePkg.getStereotype();
TaggedValueClass taggedValueClass = corePkg.getTaggedValue();
// Create the primary key of the Time Dimension using the
// "surrogate key" pattern. Note that the data types we
// create here will be reused by other attributes.
DataType integerType = dataTypeClass.createDataType();
integerType.setName( "Integer" );
Attribute keyAttribute = attributeClass.createAttribute();
keyAttribute.setName( "TimeID" );
keyAttribute.setType( integerType );
keyAttribute.setNamespace( timeDimension );
List<Attribute> featureList = timeDimension.getFeature();
featureList.add( keyAttribute );
UniqueKey uniqueKey = uniqueKeyClass.createUniqueKey();
uniqueKey.setName( "TimeUK" );
List<Attribute> keyFeatureList = uniqueKey.getFeature();
keyFeatureList.add( keyAttribute );
uniqueKey.setNamespace( timeDimension );
Collection<ModelElement> ownedElements = timeDimension.getOwnedElement();
ownedElements.add( uniqueKey );
// Create the "surrogate key" stereotype, as required by
// the "surrogate key" pattern.
// Note that this stereotype will be reused by other
// dimension keys.
Stereotype surrogateKeyStereotype = stereotypeClass.createStereotype();
surrogateKeyStereotype.setName( "SurrogateKey" );
Collection<UniqueKey> extendedElements = surrogateKeyStereotype.getExtendedElement();
extendedElements.add( uniqueKey );
TaggedValue surrogateKeyTaggedValue = taggedValueClass.createTaggedValue();
surrogateKeyTaggedValue.setTag( "encoding" );
surrogateKeyTaggedValue.setValue( "serial integer" );
surrogateKeyTaggedValue.setStereotype( surrogateKeyStereotype );
Collection<TaggedValue> requiredTags = surrogateKeyStereotype.getRequiredTag();
requiredTags.add( surrogateKeyTaggedValue );
// Create the non-key attributes and add them to the Time Dimension.
// Note that the data types created here will be re-used by the
// other attributes.
DataType booleanType = dataTypeClass.createDataType();
booleanType.setName( "Boolean" );
DataType stringType = dataTypeClass.createDataType();
stringType.setName( "String" );
Attribute nonKeyAttribute = attributeClass.createAttribute();
nonKeyAttribute.setName( "DateType" );
nonKeyAttribute.setType( stringType );
nonKeyAttribute.setNamespace( timeDimension );
featureList.add( nonKeyAttribute );
nonKeyAttribute = attributeClass.createAttribute();
nonKeyAttribute.setName( "CalendarType" );
nonKeyAttribute.setType( stringType );
nonKeyAttribute.setNamespace( timeDimension );
featureList.add( nonKeyAttribute );
nonKeyAttribute = attributeClass.createAttribute();
nonKeyAttribute.setName( "DayOfWeek" );
nonKeyAttribute.setType( integerType );
nonKeyAttribute.setNamespace( timeDimension );
featureList.add( nonKeyAttribute );
nonKeyAttribute = attributeClass.createAttribute();
nonKeyAttribute.setName( "DayNumberInWeek" );
nonKeyAttribute.setType( integerType );
nonKeyAttribute.setNamespace( timeDimension );
featureList.add( nonKeyAttribute );
nonKeyAttribute = attributeClass.createAttribute();
nonKeyAttribute.setName( "DayNumberInMonth" );
nonKeyAttribute.setType( integerType );
nonKeyAttribute.setNamespace( timeDimension );
featureList.add( nonKeyAttribute );
// ...
nonKeyAttribute = attributeClass.createAttribute();
nonKeyAttribute.setName( "Workday" );
nonKeyAttribute.setType( booleanType );
nonKeyAttribute.setNamespace( timeDimension );
featureList.add( nonKeyAttribute );
// ...
nonKeyAttribute = attributeClass.createAttribute();
nonKeyAttribute.setName( "Second" );
nonKeyAttribute.setType( integerType );
nonKeyAttribute.setNamespace( timeDimension );
featureList.add( nonKeyAttribute );
nonKeyAttribute = attributeClass.createAttribute();
nonKeyAttribute.setName( "Timespan" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -