Sybase Powerdesigner Conceptual Data Model 分析器

Sybase PowerDesigner是一个卓越的数据建模工具,它用Physical model描述特定数据库的数据模型,用Conceptual Model更抽象的描述数据库无关的数据模型。我们可以从概念模型入手进行建型,再根据不同的需要生成物理模型,进而生成库结构。也可以从现有数据库导出物理模型再转换成概念模型,然后转换成另一种数据库的物理模型......
在使用程序生成持久层的实体类和描述文件的时候,使用概念模型可以避免直接与不同的数据库打交道,当时代价是需要花点时间从数据库导出物理模型再转换成概念模型。下文提供分析Sybase CDM文件的代码,作为实体类生成工具的一个扩展。
首先是定义存储概念模型的类。

import namespaces


namespace Generator.Utils.CDM {
    
/// <summary>
    
/// Entity 的摘要说明。
    
/// </summary>

    public class Entity {

        
properties

        
public Entity() {
        }

    }

    
public class DataItem {
        
        
properties

        
        
public DataItem() {
        }


    }

    
public class EntityAttribute {

        
properties

        
public EntityAttribute() {
        }

    }

    
public class EntityIdentifier {

        
properties

        
public EntityIdentifier() {
        }

    }

    
public class EntityRelationship {

        
properties
        
        
public EntityRelationship() {
        }

    }

    
public class ConceptualDataModel {

        
properties

        
public ConceptualDataModel() {
            
//
            
// TODO: 在此处添加构造函数逻辑
            
//
        }

    }



}


然后是分析CDM文件的工具类
import namespaces

namespace Generator.Utils {
    
public delegate void ProgressStatus( String message);

    
public class SybaseCDMParser {

        
StatusChanged event

        
local variables

        
properties
        
        
constructors
        
        
public methods
        
        
helper methods
    
    }

}


最后是调用的示例代码:
            SybaseCDMParser parser = new SybaseCDMParser( fileName );
            parser.StatusChanged 
+= new ProgressStatus(this.parser_StatusChanged);
            ConceptualDataModel model 
= parser.processCDM();

            
foreachobject obj in model.Entities.Values ) {
                String entityString 
= String.Empty;
                Entity entity 
= (Entity)obj;

                entityString 
+= "Entity Code:" + entity.Code + ", Entity Name:" + entity.Name + "\r\n Attributes: ";
                
foreachobject attrObj in entity.EntityAttributes ) {
                    EntityAttribute attr 
= (EntityAttribute)attrObj;
                    entityString 
+= attr.DataItem.Code + "[" + attr.IsMandatory.ToString() + "], ";
                }

                entityString 
+= "\r\n Identifiers:";

                
foreachobject idenObj in entity.EntityIdentifiers ) {
                    EntityIdentifier iden 
= (EntityIdentifier)idenObj;
                    entityString 
+= iden.Code + "[" + iden.IsPrimaryKey.ToString() + "], ";
                }

                
                entityString 
+= "\r\n Relationships:";
                
foreachobject relObj in entity.FromEntityRelationships ) {
                    EntityRelationship rel 
= (EntityRelationship)relObj;
                    entityString 
+= rel.Code + "[" + rel.Entity1.Code + "], ";
                }

                entityString 
+= "\r\n";
                
foreachobject relObj in entity.ToEntityRelationships ) {
                    EntityRelationship rel 
= (EntityRelationship)relObj;
                    entityString 
+= rel.Code + "[" + rel.Entity2.Code + "], ";
                }

                entityString 
+= "\r\n";

                
this.textBox1.Text += "\r\n" + entityString;

posted @ 2005-03-29 23:06  Rayman  阅读(2493)  评论(0编辑  收藏  举报