void FdoSchemaRollbackTest::ModAcadSchema( FdoIConnection* connection )
{
	/* Test modifying an existing schema */

	FdoPtr<FdoIDescribeSchema>  pDescCmd = (FdoIDescribeSchema*) connection->CreateCommand(FdoCommandType_DescribeSchema);
	pDescCmd->SetSchemaName( L"Electric'l" );
	FdoFeatureSchemasP pSchemas = pDescCmd->Execute();

	FdoPtr<FdoIApplySchema>  pCmd = (FdoIApplySchema*) connection->CreateCommand(FdoCommandType_ApplySchema);

	FdoPtr<FdoFeatureSchema> pSchema = pSchemas->GetItem( L"Acad" );

	FdoPtr<FdoFeatureClass> pClass = (FdoFeatureClass*) (FdoClassesP(pSchema->GetClasses())->GetItem(L"AcDbEntity"));
	FdoPtr<FdoClass> pRefClass = (FdoClass*) (FdoClassesP(pSchema->GetClasses())->GetItem(L"Entity"));

	// Test delete of property 

	FdoPtr<FdoDataPropertyDefinition> pProp = (FdoDataPropertyDefinition*) (FdoPropertiesP(pClass->GetProperties())->GetItem(L"ColourIndex"));
	pProp->Delete();

	pProp = (FdoDataPropertyDefinition*) (FdoPropertiesP(pRefClass->GetProperties())->GetItem(L"ColourIndex"));
	pProp->Delete();

	// Test adding data property to existing class.

	pProp = FdoDataPropertyDefinition::Create( L"Plot Style", L"" );
	pProp->SetDataType( FdoDataType_String );
	pProp->SetLength(20);
	pProp->SetNullable(!mCanAddNotNullCol);
	FdoPropertiesP(pClass->GetProperties())->Add( pProp );

	pProp = FdoDataPropertyDefinition::Create( L"Plot Style", L"" );
	pProp->SetDataType( FdoDataType_String );
	pProp->SetLength(20);
	pProp->SetNullable(!mCanAddNotNullCol);
	FdoPropertiesP(pRefClass->GetProperties())->Add( pProp );

	pClass = (FdoFeatureClass*) (FdoClassesP(pSchema->GetClasses())->GetItem(L"AcDbHatch"));
	FdoPtr<FdoObjectPropertyDefinition> pObjProp = (FdoObjectPropertyDefinition*) FdoPropertiesP(pClass->GetProperties())->GetItem(L"edges");
	pObjProp->Delete();

	pRefClass = (FdoClass*) (FdoClassesP(pSchema->GetClasses())->GetItem(L"AcDbVertexData"));
	pObjProp = (FdoObjectPropertyDefinition*) FdoPropertiesP(pRefClass->GetProperties())->GetItem(L"point");
	pObjProp->Delete();

	pCmd->SetFeatureSchema( pSchema );
	pCmd->Execute();
}
///<summary>Executes the destroy schema command, which removes the schema, class
///definitions, relation definitions, and all instance data from the DataStore.
///If elements in other schemas refer to the schema to be destroyed
///an exception is thrown.</summary>
/// <returns>Returns nothing</returns> 
void SuperMapDestroySchemaCommand::Execute ()
{
	TRACE(_T("µ÷ÓÃ SuperMapDestroySchemaCommand::Execute [%ls]¡£\n"), m_SchemaName);
    FdoPtr<FdoFeatureSchema> schema = FdoFeatureSchema::Create (m_SchemaName, L"");
    schema->Delete ();
    FdoPtr<FdoIApplySchema> apply = (FdoIApplySchema*)mConnection->CreateCommand (FdoCommandType_ApplySchema);
    apply->SetFeatureSchema (schema);
    apply->Execute ();
}
void SuperMapApplySchemaCommand::DeleteSchema ()
{
	TRACE(_T("************SuperMapApplySchemaCommand::DeleteSchema ()"));

	//获取已经存在的LpSchema
	FdoPtr<SuperMapLpFeatureSchemaCollection> lpSchemas = mConnection->GetLpSchemas();
	FdoPtr<SuperMapLpFeatureSchema> lpSchema = lpSchemas->GetItem(m_Schema->GetName());

	//删除LpSchema(自动从LpSchemas collection中移除)
	lpSchema->Delete(mConnection);
}
///<summary>Executes the destroy schema command, which removes the schema, class
///definitions, relation definitions, and all instance data from the DataStore.
///If elements in other schemas refer to the schema to be destroyed
///an exception is thrown.</summary>
/// <returns>Returns nothing</returns> 
void ArcSDEDestroySchemaCommand::Execute ()
{
    FdoPtr<ArcSDEConnection> connection;
    
    // verify the connection
    connection = static_cast<ArcSDEConnection*>(GetConnection ());
    if (connection == NULL)
        throw FdoException::Create (NlsMsgGet (ARCSDE_CONNECTION_NOT_ESTABLISHED, "Connection not established."));

    FdoPtr<FdoIDescribeSchema> describe = (FdoIDescribeSchema*)connection->CreateCommand (FdoCommandType_DescribeSchema);
    describe->SetSchemaName (mSchemaName->GetName ());
    FdoPtr<FdoFeatureSchemaCollection> schemas = describe->Execute ();
    FdoPtr<FdoFeatureSchema> schema = schemas->GetItem (0);
    FdoPtr<FdoClassCollection> classes = schema->GetClasses ();
    // for now, to delete a schema, just delete all the classes
    for (int i = 0; i < classes->GetCount (); i++)
    {
        FdoPtr<FdoClassDefinition> feature = classes->GetItem (i);
        feature->Delete ();
    }
    FdoPtr<FdoIApplySchema> apply = (FdoIApplySchema*)connection->CreateCommand (FdoCommandType_ApplySchema);
    apply->SetFeatureSchema (schema);
    apply->Execute ();
}
void FdoSchemaRollbackTest::ModElectricSchema( FdoIConnection* connection )
{
	/* Test modifying an existing schema */

	FdoPtr<FdoIDescribeSchema>  pDescCmd = (FdoIDescribeSchema*) connection->CreateCommand(FdoCommandType_DescribeSchema);
	pDescCmd->SetSchemaName( L"Electric'l" );
	FdoFeatureSchemasP pSchemas = pDescCmd->Execute();

	FdoPtr<FdoIApplySchema>  pCmd = (FdoIApplySchema*) connection->CreateCommand(FdoCommandType_ApplySchema);

	FdoPtr<FdoFeatureSchema> pSchema = pSchemas->GetItem( L"Electric'l" );

	FdoPtr<FdoFeatureClass> pClass = (FdoFeatureClass*) (FdoClassesP(pSchema->GetClasses())->GetItem(L"Transformer"));
	pClass->Delete();

	// Add a new non-inherited class that will later be removed.

	pClass = FdoFeatureClass::Create( L"Pole", L"" );
	pClass->SetIsAbstract(false);

	FdoPtr<FdoDataPropertyDefinition> pProp = FdoDataPropertyDefinition::Create( L"FeatureId", L"" );
	pProp->SetDataType( FdoDataType_Int64 );
	pProp->SetIsAutoGenerated(true);
	pProp->SetNullable(false);
	FdoPropertiesP(pClass->GetProperties())->Add( pProp );
	FdoDataPropertiesP(pClass->GetIdentityProperties())->Add( pProp );

	pProp = FdoDataPropertyDefinition::Create( L"Height", L"" );
	pProp->SetDataType( FdoDataType_Double );
	pProp->SetNullable(false);
	FdoPropertiesP(pClass->GetProperties())->Add( pProp );

	FdoClassesP(pSchema->GetClasses())->Add( pClass );

	/* The following 3 classes tests adding nested object properties to an FdoClass,
	 * instead of an FdoFeatureClass.
	 */

	// class for nested object property

	FdoPtr<FdoClass> pStClass = FdoClass::Create( L"Street", L"" );
	pStClass->SetIsAbstract(false);

	pProp = FdoDataPropertyDefinition::Create( L"Name", L"" );
	pProp->SetDataType( FdoDataType_String );
	pProp->SetLength( 30 );
	pProp->SetNullable(false);
	FdoPropertiesP(pStClass->GetProperties())->Add( pProp );

	pProp = FdoDataPropertyDefinition::Create( L"Type", L"" );
	pProp->SetDataType( FdoDataType_String );
	pProp->SetLength( 30 );
	pProp->SetNullable(false);
	FdoPropertiesP(pStClass->GetProperties())->Add( pProp );

	FdoClassesP(pSchema->GetClasses())->Add( pStClass );

	// Class for top object property ( includes nested property )

	FdoPtr<FdoClass> pAddrClass = FdoClass::Create( L"'Address", L"" );
	pAddrClass->SetIsAbstract(false);

	pProp = FdoDataPropertyDefinition::Create( L"Number", L"" );
	pProp->SetDataType( FdoDataType_Int32 );
	pProp->SetNullable(false);
	FdoPropertiesP(pAddrClass->GetProperties())->Add( pProp );

	FdoPtr<FdoObjectPropertyDefinition> pObjProp = FdoObjectPropertyDefinition::Create( L"street", L"" );
	pObjProp->SetClass( pStClass );
	pObjProp->SetObjectType( FdoObjectType_Value );
	FdoPropertiesP(pAddrClass->GetProperties())->Add( pObjProp );

	FdoClassesP(pSchema->GetClasses())->Add( pAddrClass );

	// Class that contains top object property

	FdoPtr<FdoClass> pEmpClass = FdoClass::Create( L"Employee", L"" );
	pEmpClass->SetIsAbstract(false);

	pProp = FdoDataPropertyDefinition::Create( L"First Name", L"" );
	pProp->SetDataType( FdoDataType_String );
	pProp->SetLength( 30 );
	pProp->SetNullable(false);
	FdoPropertiesP(pEmpClass->GetProperties())->Add( pProp );
	FdoDataPropertiesP(pEmpClass->GetIdentityProperties())->Add( pProp );

	pProp = FdoDataPropertyDefinition::Create( L"Last Name", L"" );
	pProp->SetDataType( FdoDataType_String );
	pProp->SetLength( 30 );
	pProp->SetNullable(false);
	FdoPropertiesP(pEmpClass->GetProperties())->Add( pProp );
	FdoDataPropertiesP(pEmpClass->GetIdentityProperties())->Add( pProp );

	pObjProp = FdoObjectPropertyDefinition::Create( L"home' address", L"" );
	pObjProp->SetClass( pAddrClass );
	pObjProp->SetObjectType( FdoObjectType_Value );
	FdoPropertiesP(pEmpClass->GetProperties())->Add( pObjProp );

	FdoClassesP(pSchema->GetClasses())->Add( pEmpClass );

	pCmd->SetFeatureSchema( pSchema );
	pCmd->Execute();
}