📄 cwmexample.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/**
* Title: XELOPES Data Mining Library
* Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
* Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
* Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
* @author Carsten Weisse
* @author Michael Thess
* @version 1.2
*/
package com.prudsys.pdm.Examples;
import java.util.Collection;
import java.util.List;
import java.util.Vector;
import javax.olap.OlapPackage;
import javax.olap.metadata.CubeDimensionAssociation;
import javax.olap.metadata.Dimension;
import javax.olap.metadata.DimensionClass;
import javax.olap.metadata.Level;
import javax.olap.metadata.LevelBasedHierarchy;
import javax.olap.metadata.Measure;
import javax.olap.metadata.MeasureClass;
import javax.olap.serversidemetadata.Cube;
import javax.olap.serversidemetadata.CubeClass;
import javax.olap.serversidemetadata.DeploymentGroup;
import org.omg.cwm.analysis.transformation.ClassifierMap;
import org.omg.cwm.analysis.transformation.FeatureMap;
import org.omg.cwm.analysis.transformation.TransformationMap;
import org.omg.cwm.analysis.transformation.TransformationPackage;
import org.omg.cwm.foundation.keysindexes.KeysIndexesPackage;
import org.omg.cwm.foundation.keysindexes.UniqueKey;
import org.omg.cwm.foundation.keysindexes.UniqueKeyClass;
import org.omg.cwm.foundation.typemapping.TypeMappingPackage;
import org.omg.cwm.foundation.typemapping.TypeSystem;
import org.omg.cwm.foundation.typemapping.TypeSystemClass;
import org.omg.cwm.objectmodel.core.Attribute;
import org.omg.cwm.objectmodel.core.AttributeClass;
import org.omg.cwm.objectmodel.core.CorePackage;
import org.omg.cwm.objectmodel.core.DataType;
import org.omg.cwm.objectmodel.core.DataTypeClass;
import org.omg.cwm.objectmodel.core.ModelElement;
import org.omg.cwm.objectmodel.core.Stereotype;
import org.omg.cwm.objectmodel.core.StereotypeClass;
import org.omg.cwm.objectmodel.core.TaggedValue;
import org.omg.cwm.objectmodel.core.TaggedValueClass;
import org.omg.cwm.resource.relational.Catalog;
import org.omg.cwm.resource.relational.Column;
import org.omg.cwm.resource.relational.ForeignKey;
import org.omg.cwm.resource.relational.PrimaryKey;
import org.omg.cwm.resource.relational.RelationalPackage;
import org.omg.cwm.resource.relational.SQLSimpleType;
import org.omg.cwm.resource.relational.Schema;
import org.omg.cwm.resource.relational.Table;
import com.prudsys.pdm.Cwm.CWMCompletePackage;
/**
* Example of how to use the CWM classes via JMI interface.
*
* Includes the examples of the book
* [1] J. Poole, D. Chang, D. Tolbert, D. Mellor, Common Warehouse Metamodel,
* Developer's Guide, Wiley Publishing, Indianapolis, 2003.
*/
public class CwmExample extends BasisExample {
/**
* Empty constructor.
*/
public CwmExample() {
}
/**
* Demonstrates the use of the Relational CWM package. Just creates
* one table with one column. <p>
*
* From [1], example of Chapter 5 "Data Warehouse Management Model".
*
* @throws Exception cannot run tests
*/
public void createDataWarehouseManagementModel() throws Exception {
// Create CWM factory:
CWMCompletePackage cwmFactory = new CWMCompletePackage();
// Create Relational package:
RelationalPackage relPkg = cwmFactory.getRelational();
// SIMPLE TYPE META DATA:
Vector<SQLSimpleType> dtv = new Vector<SQLSimpleType>();
// -- we must simulate JDBC result set since we have no database
SQLSimpleType type = relPkg.getSQLSimpleType().createSQLSimpleType();
type.setName("Integer");
type.setTypeNumber( new Long(java.sql.Types.INTEGER) );
dtv.addElement(type);
type = relPkg.getSQLSimpleType().createSQLSimpleType();
type.setName("Double");
type.setTypeNumber( new Long(java.sql.Types.DOUBLE) );
dtv.addElement(type);
type = relPkg.getSQLSimpleType().createSQLSimpleType();
type.setName("Character");
type.setTypeNumber( new Long(java.sql.Types.CHAR) );
dtv.addElement(type);
type = relPkg.getSQLSimpleType().createSQLSimpleType();
type.setName("Varchar");
type.setTypeNumber( new Long(java.sql.Types.VARCHAR) );
dtv.addElement(type);
// CATALOG AND SCHEMA:
// Catalog meta data:
String catName = "CWMODS";
Catalog cat = relPkg.getCatalog().createCatalog();
cat.setName(catName);
// Schema meta data:
Vector<Schema> sv = new Vector<Schema>();
// -- simulate JDBC result set
String schName = "CWM";
org.omg.cwm.resource.relational.Schema sch = relPkg.getSchema().createSchema();
sch.setName(schName);
sv.addElement(sch);
// Assign schemata to catalog:
for (int j = 0; j < sv.size(); j++) {
org.omg.cwm.resource.relational.Schema sch2 = sv.elementAt(j);
cat.addOwnedElement(sch2);
sch.setNamespace(cat);
}
// TABLE AND COLUMN:
Vector<Table> tiv = new Vector<Table>();
// -- simulate JDBC result set
String tabName = "STORE";
Table tab = relPkg.getTable().createTable();
tab.setName(tabName);
// Export column meta data owned by the table:
Vector<Column> cv = new Vector<Column>();
// -- simulate nested JDBC result set
Column col = relPkg.getColumn().createColumn();
col.setName("STORE_ID");
col.setLength( new Long(10) );
int ctn = java.sql.Types.INTEGER;
for (int j = 0; j < dtv.size(); j++) {
SQLSimpleType type2 = dtv.elementAt(j);
if (type2.getTypeNumber().equals( new java.lang.Long(ctn) )) {
col.setType(type2);
}
}
tab.addFeature(col);
col.setOwner(tab);
cv.addElement(col);
// export other meta data (e.g., primary key) owned by the table
// which references the table here
tiv.addElement(tab);
// Associate table with schema meta data:
for (int j = 0; j < tiv.size(); j++) {
ModelElement tabInd = tiv.elementAt(j);
sch.addOwnedElement(tabInd);
tabInd.setNamespace(sch);
}
System.out.print("schema: " + sch);
}
/**
* Demonstrates the CWM use for warehousing. <p>
*
* From [1], example of Chapter 6 "Dimensional Model".
*
* @throws Exception cannot run tests
*/
public void createDimensionalModel() throws Exception {
// Create CWM factory and get required packages:
CWMCompletePackage cwmComplete = new CWMCompletePackage();
OlapPackage olapPackage = cwmComplete.getOlap();
RelationalPackage relationalPackage = cwmComplete.getRelational();
TransformationPackage transformationPackage = cwmComplete.getTransformation();
CorePackage corePackage = cwmComplete.getCore();
KeysIndexesPackage keysIndexes = cwmComplete.getKeysIndexes();
// -----------------------------------------------------------------------
// Logical Model
// -----------------------------------------------------------------------
// CREATE THE DIMENSIONAL OBJECTS
// Create product dimension:
Dimension product = olapPackage.getDimension().createDimension();
product.setName("Product");
// Create product attributes:
Attribute prodId = corePackage.getAttribute().createAttribute();
prodId.setName("ID");
Attribute prodSDesc = corePackage.getAttribute().createAttribute();
prodSDesc.setName("Short Description");
Attribute prodMDesc = corePackage.getAttribute().createAttribute();
prodMDesc.setName("Medium Description");
Attribute prodLDesc = corePackage.getAttribute().createAttribute();
prodLDesc.setName("Long Description");
// Add attributes to the dimension:
product.addFeature(prodId);
product.addFeature(prodSDesc);
product.addFeature(prodMDesc);
product.addFeature(prodLDesc);
// Create geography dimension:
Dimension geog = olapPackage.getDimension().createDimension();
geog.setName("Geography");
// Create geography attributes:
Attribute geogId = corePackage.getAttribute().createAttribute();
geogId.setName("ID");
Attribute geogDesc = corePackage.getAttribute().createAttribute();
geogDesc.setName("Description");
Attribute geogLongitude = corePackage.getAttribute().createAttribute();
geogLongitude.setName("Longitude");
Attribute geogLatitude = corePackage.getAttribute().createAttribute();
geogLatitude.setName("Latitude");
// Add attributes to the dimension:
geog.addFeature(prodId);
geog.addFeature(prodSDesc);
geog.addFeature(geogLongitude);
geog.addFeature(geogLatitude);
// Create time dimension:
Dimension time = olapPackage.getDimension().createDimension();
time.setName("Time");
// Create time attributes:
Attribute timeId = corePackage.getAttribute().createAttribute();
timeId.setName("ID");
Attribute timeSpan = corePackage.getAttribute().createAttribute();
timeSpan.setName("Time Span");
Attribute endingData = corePackage.getAttribute().createAttribute();
endingData.setName("Ending Data");
// Add attributes to the dimension:
time.addFeature(prodId);
time.addFeature(prodSDesc);
time.addFeature(endingData);
// CREATE LEVELS AND LEVEL ATTRIBUTE
// Create product dimension levels:
// Create category level:
Level category = olapPackage.getLevel().createLevel();
category.setName("Category");
product.addMemberSelection(category);
// Add category attributes:
Attribute categoryId = corePackage.getAttribute().createAttribute();
categoryId.setName("ID");
categoryId.setOwner(category);
Attribute categoryDesc = corePackage.getAttribute().createAttribute();
categoryDesc.setName("Description");
categoryDesc.setOwner(category);
// Create type level:
Level type = olapPackage.getLevel().createLevel();
type.setName("Type");
product.addMemberSelection(type);
// Add type attributes:
Attribute typeId = corePackage.getAttribute().createAttribute();
typeId.setName("ID");
typeId.setOwner(type);
Attribute typeName = corePackage.getAttribute().createAttribute();
typeName.setName("Name");
typeName.setOwner(type);
// Create brand level:
Level brand = olapPackage.getLevel().createLevel();
brand.setName("Brand");
product.addMemberSelection(brand);
// Add brand attributes:
Attribute brandId = corePackage.getAttribute().createAttribute();
brandId.setName("ID");
brandId.setOwner(brand);
Attribute brandName = corePackage.getAttribute().createAttribute();
brandName.setName("Name");
brandName.setOwner(brand);
Attribute brandSName = corePackage.getAttribute().createAttribute();
brandSName.setName("Short Name");
brandSName.setOwner(brand);
// Create UPC level:
Level UPC = olapPackage.getLevel().createLevel();
UPC.setName("UPC");
product.addMemberSelection(UPC);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -