📄 cwmexample.java
字号:
// Add UPC attributes:
Attribute UPCId = corePackage.getAttribute().createAttribute();
UPCId.setName("ID");
UPCId.setOwner(UPC);
Attribute UPCLName = corePackage.getAttribute().createAttribute();
UPCLName.setName("Long Name");
UPCLName.setOwner(UPC);
Attribute UPCSName = corePackage.getAttribute().createAttribute();
UPCSName.setName("Short Name");
UPCSName.setOwner(UPC);
// Create manufacturer level:
Level manufacturer = olapPackage.getLevel().createLevel();
manufacturer.setName("Brand");
product.addMemberSelection(manufacturer);
// Create size level:
Level size = olapPackage.getLevel().createLevel();
size.setName("Size");
product.addMemberSelection(size);
// Create geography dimension levels:
// Create region level:
Level region = olapPackage.getLevel().createLevel();
region.setName("Region");
geog.addMemberSelection(region);
// Add region attributes:
Attribute name = corePackage.getAttribute().createAttribute();
name.setName("Name");
name.setOwner(region);
// Create territory level:
Level territory = olapPackage.getLevel().createLevel();
territory.setName("Territory");
geog.addMemberSelection(territory);
// Add territory attributes:
Attribute territoryId = corePackage.getAttribute().createAttribute();
territoryId.setName("Id");
territoryId.setOwner(territory);
Attribute territoryName = corePackage.getAttribute().createAttribute();
territoryName.setName("Name");
territoryName.setOwner(territory);
// Create state level:
Level state = olapPackage.getLevel().createLevel();
state.setName("state");
geog.addMemberSelection(state);
// Add state attributes:
Attribute stateName = corePackage.getAttribute().createAttribute();
stateName.setName("Name");
stateName.setOwner(state);
Attribute stateLongitude = corePackage.getAttribute().createAttribute();
stateLongitude.setName("Longitude");
stateLongitude.setOwner(state);
Attribute stateLatitude = corePackage.getAttribute().createAttribute();
stateLatitude.setName("Latitude");
stateLatitude.setOwner(state);
// Create time dimension levels:
// Create year level:
Level year = olapPackage.getLevel().createLevel();
year.setName("Year");
time.addMemberSelection(year);
// Add year attributes:
Attribute yearId = corePackage.getAttribute().createAttribute();
yearId.setName("Id");
yearId.setOwner(year);
Attribute yearDate = corePackage.getAttribute().createAttribute();
yearDate.setName("Date");
yearDate.setOwner(year);
Attribute yearTimeSpan = corePackage.getAttribute().createAttribute();
yearTimeSpan.setName("Span");
yearTimeSpan.setOwner(year);
// Create quarter level:
Level quarter = olapPackage.getLevel().createLevel();
quarter.setName("Quarter");
time.addMemberSelection(quarter);
// Add quarter attributes:
Attribute quarterId = corePackage.getAttribute().createAttribute();
quarterId.setName("Id");
quarterId.setOwner(quarter);
Attribute quarterDate = corePackage.getAttribute().createAttribute();
quarterDate.setName("Date");
quarterDate.setOwner(quarter);
Attribute quarterTimeSpan = corePackage.getAttribute().createAttribute();
quarterTimeSpan.setName("Span");
quarterTimeSpan.setOwner(quarter);
// Create month level:
Level month = olapPackage.getLevel().createLevel();
month.setName("Month");
time.addMemberSelection(month);
// Add month attributes:
Attribute monthId = corePackage.getAttribute().createAttribute();
monthId.setName("Id");
monthId.setOwner(month);
Attribute monthDate = corePackage.getAttribute().createAttribute();
monthDate.setName("Date");
monthDate.setOwner(month);
Attribute monthTimeSpan = corePackage.getAttribute().createAttribute();
monthTimeSpan.setName("Span");
monthTimeSpan.setOwner(month);
// Create week level:
Level week = olapPackage.getLevel().createLevel();
week.setName("Week");
time.addMemberSelection(week);
// Add week attributes:
Attribute weekId = corePackage.getAttribute().createAttribute();
weekId.setName("Id");
weekId.setOwner(week);
Attribute weekDate = corePackage.getAttribute().createAttribute();
weekDate.setName("Date");
weekDate.setOwner(week);
Attribute weekTimeSpan = corePackage.getAttribute().createAttribute();
weekTimeSpan.setName("Span");
weekTimeSpan.setOwner(week);
// DEFINING HIERARCHIES AND HIERARCHICAL ATTRIBUTE
// Create standard product hierarchy:
LevelBasedHierarchy prodStdH = olapPackage.getLevelBasedHierarchy().createLevelBasedHierarchy();
prodStdH.setName("Standard");
product.addHierarchy(prodStdH);
// Create hierarchy attributes:
Attribute stdId = corePackage.getAttribute().createAttribute();
stdId.setName("Id");
stdId.setOwner(prodStdH);
Attribute stdLongDescription = corePackage.getAttribute().createAttribute();
stdLongDescription.setName("Long Description");
stdLongDescription.setOwner(prodStdH);
Attribute stdParent = corePackage.getAttribute().createAttribute();
stdParent.setName("Parent");
stdParent.setOwner(prodStdH);
// Create Level 0 hierarchyLevelRelationships:
javax.olap.serversidemetadata.HierarchyLevelAssociation catHLR = olapPackage.getHierarchyLevelAssociation().createHierarchyLevelAssociation();
catHLR.setName("Category");
catHLR.setCurrentLevel(category);
prodStdH.addHierarchyLevelAssociation(catHLR);
Attribute catHLRId = corePackage.getAttribute().createAttribute();
catHLRId.setName("Id");
catHLRId.setOwner(catHLR);
Attribute catHLRLongDescription = corePackage.getAttribute().createAttribute();
catHLRLongDescription.setName("Long Description");
catHLRLongDescription.setOwner(catHLR);
// Create Level 1 hierarchyLevelRelationships:
javax.olap.serversidemetadata.HierarchyLevelAssociation typeHLR = olapPackage.getHierarchyLevelAssociation().createHierarchyLevelAssociation();
typeHLR.setName("Type");
typeHLR.setCurrentLevel(type);
prodStdH.addHierarchyLevelAssociation(typeHLR);
Attribute typeHLRId = corePackage.getAttribute().createAttribute();
typeHLRId.setName("Id");
typeHLRId.setOwner(typeHLR);
Attribute typeHLRLongDescription = corePackage.getAttribute().createAttribute();
typeHLRLongDescription.setName("Long Description");
typeHLRLongDescription.setOwner(typeHLR);
Attribute typeHLRparent = corePackage.getAttribute().createAttribute();
typeHLRparent.setName("Parent");
typeHLRparent.setOwner(typeHLR);
// Create Level 2 hierarchyLevelRelationships:
javax.olap.serversidemetadata.HierarchyLevelAssociation brandHLR = olapPackage.getHierarchyLevelAssociation().createHierarchyLevelAssociation();
brandHLR.setName("Brand");
brandHLR.setCurrentLevel(brand);
prodStdH.addHierarchyLevelAssociation(brandHLR);
Attribute brandHLRId = corePackage.getAttribute().createAttribute();
brandHLRId.setName("Id");
brandHLRId.setOwner(brandHLR);
Attribute brandHLRLongDescription = corePackage.getAttribute().createAttribute();
brandHLRLongDescription.setName("Long Description");
brandHLRLongDescription.setOwner(brandHLR);
Attribute brandHLRparent = corePackage.getAttribute().createAttribute();
brandHLRparent.setName("Parent");
brandHLRparent.setOwner(brandHLR);
// Create Level 3 hierarchyLevelRelationships:
javax.olap.serversidemetadata.HierarchyLevelAssociation upcHLR = olapPackage.getHierarchyLevelAssociation().createHierarchyLevelAssociation();
upcHLR.setName("UPC");
upcHLR.setCurrentLevel(UPC);
prodStdH.addHierarchyLevelAssociation(upcHLR);
Attribute upcHLRId = corePackage.getAttribute().createAttribute();
upcHLRId.setName("Id");
upcHLRId.setOwner(upcHLR);
Attribute upcHLRLongDescription = corePackage.getAttribute().createAttribute();
upcHLRLongDescription.setName("Long Description");
upcHLRLongDescription.setOwner(upcHLR);
Attribute upcHLRShortDescription = corePackage.getAttribute().createAttribute();
upcHLRShortDescription.setName("Short Description");
upcHLRShortDescription.setOwner(upcHLR);
Attribute upcHLRparent = corePackage.getAttribute().createAttribute();
upcHLRparent.setName("Parent");
upcHLRparent.setOwner(upcHLR);
// ...
// ADD DIMENSIONS TO THE SCHEMA
// Create an overall holding schema:
javax.olap.serversidemetadata.Schema dimensionalSchema = olapPackage.getSchema().createSchema();
dimensionalSchema.addDimension(product);
dimensionalSchema.addDimension(geog);
dimensionalSchema.addDimension(time);
// DEFINING CUBES AND MEASURES
// Create the cube:
javax.olap.serversidemetadata.Cube salesCube = olapPackage.getCube().createCube();
salesCube.setName("Sales Cube");
// Add attributes and measures to the cube:
// Add attribute that will represent each dimension and key of the cube:
Attribute timeAttr = corePackage.getAttribute().createAttribute();
timeAttr.setName("Time");
timeAttr.setOwner(salesCube);
Attribute geogAttr = corePackage.getAttribute().createAttribute();
geogAttr.setName("Geog");
geogAttr.setOwner(salesCube);
Attribute prodAttr = corePackage.getAttribute().createAttribute();
prodAttr.setName("Prod");
prodAttr.setOwner(salesCube);
// Add measures:
Measure sales = olapPackage.getMeasure().createMeasure();
sales.setName("Sales");
sales.setOwner(salesCube);
Measure cost = olapPackage.getMeasure().createMeasure();
cost.setName("Cost");
cost.setOwner(salesCube);
Measure Profit = olapPackage.getMeasure().createMeasure();
Profit.setName("Profit");
Profit.setOwner(salesCube);
// Create the three cube dimension associations:
CubeDimensionAssociation timeAsso = olapPackage.getCubeDimensionAssociation().createCubeDimensionAssociation();
timeAsso.setDimension(time);
salesCube.addCubeDimensionAssociation(timeAsso);
CubeDimensionAssociation geogAsso = olapPackage.getCubeDimensionAssociation().createCubeDimensionAssociation();
geogAsso.setDimension(geog);
salesCube.addCubeDimensionAssociation(geogAsso);
CubeDimensionAssociation prodAsso = olapPackage.getCubeDimensionAssociation().createCubeDimensionAssociation();
prodAsso.setDimension(product);
salesCube.addCubeDimensionAssociation(prodAsso);
// Create second cube:
javax.olap.serversidemetadata.Cube populationCube = olapPackage.getCube().createCube();
populationCube.setName("Population Cube");
// Add attributes and measures to the cube:
// Add attribute that will represent each dimension and key of the cube:
Attribute poptimeAttr = corePackage.getAttribute().createAttribute();
poptimeAttr.setName("Time");
poptimeAttr.setOwner(populationCube);
Attribute popgeogAttr = corePackage.getAttribute().createAttribute();
popgeogAttr.setName("Geog");
popgeogAttr.setOwner(populationCube);
// Add measures:
Measure totalRevenue = olapPackage.getMeasure().createMeasure();
totalRevenue.setName("Total Revenue");
totalRevenue.setOwner(populationCube);
// Create the three cube dimension associations:
CubeDimensionAssociation poptimeAsso = olapPackage.getCubeDimensionAssociation().createCubeDimensionAssociation();
poptimeAsso.setDimension(time);
populationCube.addCubeDimensionAssociation(poptimeAsso);
CubeDimensionAssociation popgeogAsso = olapPackage.getCubeDimensionAssociation().createCubeDimensionAssociation();
popgeogAsso.setDimension(geog);
populationCube.addCubeDimensionAssociation(popgeogAsso);
// ADD CUBES TO THE SCHEMA
dimensionalSchema.addCube(salesCube);
dimensionalSchema.addCube(populationCube);
// ADDING KEYS TO THE DIMENSIONS
UniqueKey prodKey = keysIndexes.getUniqueKey().createUniqueKey();
prodKey.addFeature(prodId);
product.addOwnedElement(prodKey);
UniqueKey geogKey = keysIndexes.getUniqueKey().createUniqueKey();
geogKey.addFeature(prodId);
product.addOwnedElement(geogKey);
UniqueKey timeKey = keysIndexes.getUniqueKey().createUniqueKey();
timeKey.addFeature(prodId);
product.addOwnedElement(timeKey);
// ADDING KEYS TO THE CUBES
// Create keys on the cube:
UniqueKey salesCubeKey = keysIndexes.getUniqueKey().createUniqueKey();
salesCubeKey.addFeature(timeAttr);
salesCubeKey.addFeature(geogAttr);
salesCubeKey.addFeature(prodAttr);
salesCube.addOwnedElement(salesCubeKey);
// Create keys on the cube:
UniqueKey popCubeKey = keysIndexes.getUniqueKey().createUniqueKey();
popCubeKey.addFeature(poptimeAttr);
popCubeKey.addFeature(popgeogAttr);
salesCube.addOwnedElement(popCubeKey);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -