void FdoSchemaRollbackTest::CreateElectricSchema( FdoIConnection* connection ) { FdoPtr<FdoIDescribeSchema> pDescCmd = (FdoIDescribeSchema*) connection->CreateCommand(FdoCommandType_DescribeSchema); pDescCmd->SetSchemaName( L"Acad" ); FdoPtr<FdoFeatureSchemaCollection> pAcadSchema = pDescCmd->Execute(); FdoPtr<FdoClassDefinition> pEntClass = FdoClassesP(FdoFeatureSchemaP(pAcadSchema->GetItem( L"Acad" ))->GetClasses())->GetItem( L"Entity" ); FdoPtr<FdoIApplySchema> pCmd = (FdoIApplySchema*) connection->CreateCommand(FdoCommandType_ApplySchema); /* A schema with dictionary */ FdoPtr<FdoFeatureSchema> pSchema = FdoFeatureSchema::Create( L"Electric'l", L"Electrical '' schema'" ); pAcadSchema->Add( pSchema ); FdoSADP(pSchema->GetAttributes())->Add( L"'Author", L"Thomas O'Edison" ); /* An abstract base class */ FdoPtr<FdoFeatureClass> pDevClass = FdoFeatureClass::Create( L"ElectricDevice", L"electic base class" ); pDevClass->SetIsAbstract(true); FdoPtr<FdoDataPropertyDefinition> pProp = FdoDataPropertyDefinition::Create( L"FeatId", L"id" ); pProp->SetDataType( FdoDataType_Int64 ); pProp->SetNullable(false); pProp->SetIsAutoGenerated(true); FdoPropertiesP(pDevClass->GetProperties())->Add( pProp ); FdoDataPropertiesP(pDevClass->GetIdentityProperties())->Add( pProp ); // Test nested object properties (ElectricDevice.graphic.xdata) where graphic's class has an id. FdoPtr<FdoObjectPropertyDefinition> pObjProp = FdoObjectPropertyDefinition::Create( L"graphic", L"Acad entity" ); pObjProp->SetObjectType( FdoObjectType_Value ); pObjProp->SetClass( pEntClass ); FdoPropertiesP(pDevClass->GetProperties())->Add( pObjProp ); // Test geometry property FdoPtr<FdoGeometricPropertyDefinition> pGeomProp = FdoGeometricPropertyDefinition::Create( L"Geometry", L"location and shape" ); pGeomProp->SetGeometryTypes( FdoGeometricType_Point | FdoGeometricType_Curve ); FdoPropertiesP(pDevClass->GetProperties())->Add( pGeomProp ); pDevClass->SetGeometryProperty( pGeomProp ); FdoClassesP(pSchema->GetClasses())->Add( pDevClass ); /* Subclass with dictionary */ FdoPtr<FdoFeatureClass> pClass = FdoFeatureClass::Create( L"Transformer", L"" ); pClass->SetIsAbstract(false); pClass->SetBaseClass( pDevClass ); FdoSADP(pClass->GetAttributes())->Add( L"Rules' DLL", L"transformer.dll" ); FdoSADP(pClass->GetAttributes())->Add( L"Entrypoint", L"start_transformer" ); // Add data properties of various types pProp = FdoDataPropertyDefinition::Create( L"Voltage", L"voltage" ); FdoSADP(pProp->GetAttributes())->Add( L"Calculable", L"yes" ); pProp->SetDataType( FdoDataType_Decimal ); pProp->SetPrecision(10); pProp->SetScale(2); pProp->SetNullable(false); FdoPropertiesP(pClass->GetProperties())->Add( pProp ); pProp = FdoDataPropertyDefinition::Create( L"Phase", L"A, B or C" ); pProp->SetDataType( FdoDataType_String ); pProp->SetLength(1); pProp->SetNullable(false); FdoPropertiesP(pClass->GetProperties())->Add( pProp ); pProp = FdoDataPropertyDefinition::Create( L"InstallDate", L"" ); pProp->SetDataType( FdoDataType_DateTime ); pProp->SetNullable(true); FdoPropertiesP(pClass->GetProperties())->Add( pProp ); pProp = FdoDataPropertyDefinition::Create( L"LastInspectDate", L"" ); pProp->SetDataType( FdoDataType_DateTime ); pProp->SetNullable(true); FdoPropertiesP(pClass->GetProperties())->Add( pProp ); pProp = FdoDataPropertyDefinition::Create( L"LastRepairDate", L"" ); pProp->SetDataType( FdoDataType_DateTime ); pProp->SetNullable(true); FdoPropertiesP(pClass->GetProperties())->Add( pProp ); pProp = FdoDataPropertyDefinition::Create( L"PartNum", L"" ); pProp->SetDataType( FdoDataType_Int16 ); pProp->SetNullable(true); FdoPropertiesP(pClass->GetProperties())->Add( pProp ); pProp = FdoDataPropertyDefinition::Create( L"Volume", L"" ); pProp->SetDataType( FdoDataType_Single ); pProp->SetNullable(false); FdoPropertiesP(pClass->GetProperties())->Add( pProp ); FdoClassesP(pSchema->GetClasses())->Add( pClass ); pClass = FdoFeatureClass::Create( L"Conductor", L"" ); pClass->SetIsAbstract(false); pClass->SetBaseClass( pDevClass ); pProp = FdoDataPropertyDefinition::Create( L"underground", L"" ); pProp->SetDataType( FdoDataType_Boolean ); pProp->SetNullable(false); FdoPropertiesP(pClass->GetProperties())->Add( pProp ); FdoClassesP(pSchema->GetClasses())->Add( pClass ); pCmd->SetFeatureSchema( pSchema ); pCmd->Execute(); }
void FdoSchemaRollbackTest::CreateAcadSchema( FdoIConnection* connection ) { FdoPtr<FdoIApplySchema> pCmd = (FdoIApplySchema*) connection->CreateCommand(FdoCommandType_ApplySchema); FdoFeatureSchemasP pSchemas = FdoFeatureSchemaCollection::Create(NULL); FdoPtr<FdoFeatureSchema> pSchema = FdoFeatureSchema::Create( L"Acad", L"AutoCAD schema" ); pSchemas->Add( pSchema ); // Id'less class for Object Properties only FdoPtr<FdoClass> pXData = FdoClass::Create( L"AcXData", L"Xdata" ); pXData->SetIsAbstract(false); FdoPtr<FdoDataPropertyDefinition> pXDataSeq = FdoDataPropertyDefinition::Create( L"Seq", L"seq" ); pXDataSeq->SetDataType( FdoDataType_Int32 ); pXDataSeq->SetNullable(false); FdoPropertiesP(pXData->GetProperties())->Add( pXDataSeq ); FdoPtr<FdoDataPropertyDefinition> pProp = FdoDataPropertyDefinition::Create( L"Datavalue", L"datavalue" ); pProp->SetDataType( FdoDataType_String ); pProp->SetLength(4000); pProp->SetNullable(false); FdoPropertiesP(pXData->GetProperties())->Add( pProp ); FdoClassesP(pSchema->GetClasses())->Add( pXData ); // More Id'less classes used to test unique table name generation FdoPtr<FdoClass> pCoordVal = FdoClass::Create( L"AcDbVertexCoordinateValue", L"" ); pCoordVal->SetIsAbstract(false); FdoPtr<FdoDataPropertyDefinition> pCoordValSeq = FdoDataPropertyDefinition::Create( L"Seq", L"seq" ); pCoordValSeq->SetDataType( FdoDataType_Int32 ); pCoordValSeq->SetNullable(false); FdoPropertiesP(pCoordVal->GetProperties())->Add( pCoordValSeq ); pProp = FdoDataPropertyDefinition::Create( L"Value", L"" ); pProp->SetDataType( FdoDataType_Double ); pProp->SetNullable(false); FdoPropertiesP(pCoordVal->GetProperties())->Add( pProp ); FdoClassesP(pSchema->GetClasses())->Add( pCoordVal ); FdoPtr<FdoClass> pVertex = FdoClass::Create( L"AcDbVertexData", L"" ); pVertex->SetIsAbstract(false); FdoPtr<FdoDataPropertyDefinition> pVertexSeq = FdoDataPropertyDefinition::Create( L"Seq", L"seq" ); pVertexSeq->SetDataType( FdoDataType_Int32 ); pVertexSeq->SetNullable(false); FdoPropertiesP(pVertex->GetProperties())->Add( pVertexSeq ); FdoPtr<FdoObjectPropertyDefinition> pObjProp = FdoObjectPropertyDefinition::Create( L"point", L"" ); pObjProp->SetClass( pCoordVal ); pObjProp->SetIdentityProperty( pCoordValSeq ); pObjProp->SetObjectType( FdoObjectType_Collection ); FdoPropertiesP(pVertex->GetProperties())->Add( pObjProp ); FdoClassesP(pSchema->GetClasses())->Add( pVertex ); // A non-abstract base class FdoPtr<FdoFeatureClass> pEntClass = FdoFeatureClass::Create( L"AcDbEntity", L"AutoCAD entity base class" ); pEntClass->SetIsAbstract(false); pProp = FdoDataPropertyDefinition::Create( L"FeatId", L"id" ); pProp->SetDataType( FdoDataType_Int64 ); pProp->SetNullable(false); pProp->SetIsAutoGenerated(true); FdoPropertiesP(pEntClass->GetProperties())->Add( pProp ); FdoDataPropertiesP(pEntClass->GetIdentityProperties())->Add( pProp ); pProp = FdoDataPropertyDefinition::Create( L"Layer", L"Acad layer" ); pProp->SetDataType( FdoDataType_String ); pProp->SetLength(10); pProp->SetNullable(true); FdoPropertiesP(pEntClass->GetProperties())->Add( pProp ); pProp = FdoDataPropertyDefinition::Create( L"ColourIndex", L"Acad Colour" ); pProp->SetDataType( FdoDataType_Byte ); pProp->SetNullable(false); FdoPropertiesP(pEntClass->GetProperties())->Add( pProp ); pObjProp = FdoObjectPropertyDefinition::Create( L"xdata", L"xdata" ); pObjProp->SetClass( pXData ); pObjProp->SetIdentityProperty( pXDataSeq ); pObjProp->SetObjectType( FdoObjectType_OrderedCollection ); pObjProp->SetOrderType( FdoOrderType_Ascending ); FdoPropertiesP(pEntClass->GetProperties())->Add( pObjProp ); FdoClassesP(pSchema->GetClasses())->Add( pEntClass ); FdoPtr<FdoClass> pEntRefClass = FdoClass::Create( L"Entity", L"Embedded entity base class" ); pEntRefClass->SetIsAbstract(false); pProp = FdoDataPropertyDefinition::Create( L"FeatId", L"id" ); pProp->SetDataType( FdoDataType_Int64 ); pProp->SetNullable(false); FdoPropertiesP(pEntRefClass->GetProperties())->Add( pProp ); FdoDataPropertiesP(pEntRefClass->GetIdentityProperties())->Add( pProp ); pProp = FdoDataPropertyDefinition::Create( L"Layer", L"Acad layer" ); pProp->SetDataType( FdoDataType_String ); pProp->SetLength(10); pProp->SetNullable(true); FdoPropertiesP(pEntRefClass->GetProperties())->Add( pProp ); pProp = FdoDataPropertyDefinition::Create( L"ColourIndex", L"Acad Colour" ); pProp->SetDataType( FdoDataType_Byte ); pProp->SetNullable(true); FdoPropertiesP(pEntRefClass->GetProperties())->Add( pProp ); pObjProp = FdoObjectPropertyDefinition::Create( L"xdata", L"xdata" ); pObjProp->SetClass( pXData ); pObjProp->SetIdentityProperty( pXDataSeq ); pObjProp->SetObjectType( FdoObjectType_OrderedCollection ); pObjProp->SetOrderType( FdoOrderType_Ascending ); FdoPropertiesP(pEntRefClass->GetProperties())->Add( pObjProp ); FdoClassesP(pSchema->GetClasses())->Add( pEntRefClass ); // A sub-class to test Object and Data property inheritance. FdoPtr<FdoFeatureClass> pPlineClass = FdoFeatureClass::Create( L"AcDb3dPolyline", L"AutoCAD 3d polyline" ); pPlineClass->SetIsAbstract(false); pPlineClass->SetBaseClass( pEntClass ); FdoClassesP(pSchema->GetClasses())->Add( pPlineClass ); pProp = FdoDataPropertyDefinition::Create( L"Width", L"line width" ); pProp->SetDataType( FdoDataType_Double ); pProp->SetPrecision(10); pProp->SetScale(5); pProp->SetNullable(false); FdoPropertiesP(pPlineClass->GetProperties())->Add( pProp ); pCmd->SetFeatureSchema( pSchema ); pCmd->Execute(); pProp = FdoDataPropertyDefinition::Create( L"Closed", L"is first and last points the same" ); pProp->SetDataType( FdoDataType_Boolean ); pProp->SetNullable(!mCanAddNotNullCol); FdoPropertiesP(pPlineClass->GetProperties())->Add( pProp ); pObjProp = FdoObjectPropertyDefinition::Create( L"vertices", L"" ); pObjProp->SetClass( pVertex ); pObjProp->SetIdentityProperty( pVertexSeq ); pObjProp->SetObjectType( FdoObjectType_Collection ); FdoPropertiesP(pPlineClass->GetProperties())->Add( pObjProp ); FdoPtr<FdoClass> pPlineRefClass = FdoClass::Create( L"Polyline", L"Embedded 3d polyline" ); pPlineRefClass->SetIsAbstract(false); pPlineRefClass->SetBaseClass( pEntRefClass ); FdoClassesP(pSchema->GetClasses())->Add( pPlineRefClass ); pProp = FdoDataPropertyDefinition::Create( L"Width", L"line width" ); pProp->SetDataType( FdoDataType_Double ); pProp->SetPrecision(10); pProp->SetScale(5); pProp->SetNullable(false); FdoPropertiesP(pPlineRefClass->GetProperties())->Add( pProp ); pProp = FdoDataPropertyDefinition::Create( L"Closed", L"is first and last points the same" ); pProp->SetDataType( FdoDataType_Boolean ); pProp->SetNullable(false); FdoPropertiesP(pPlineRefClass->GetProperties())->Add( pProp ); pObjProp = FdoObjectPropertyDefinition::Create( L"vertices", L"" ); pObjProp->SetClass( pVertex ); pObjProp->SetIdentityProperty( pVertexSeq ); pObjProp->SetObjectType( FdoObjectType_Collection ); FdoPropertiesP(pPlineRefClass->GetProperties())->Add( pObjProp ); // The following tests object property nesting to 3 levels. FdoPtr<FdoFeatureClass> pHatchClass = FdoFeatureClass::Create( L"AcDbHatch", L"AutoCAD hatched polygon" ); pHatchClass->SetIsAbstract(false); pHatchClass->SetBaseClass( pEntClass ); pObjProp = FdoObjectPropertyDefinition::Create( L"edges", L"" ); pObjProp->SetClass( pPlineRefClass ); pObjProp->SetObjectType( FdoObjectType_Collection ); FdoPropertiesP(pHatchClass->GetProperties())->Add( pObjProp ); FdoClassesP(pSchema->GetClasses())->Add( pHatchClass ); pCmd->SetFeatureSchema( pSchema ); pCmd->Execute(); }