Example #1
0
void GwsBinaryFeatureWriter::WriteAssociationProperty(FdoAssociationPropertyDefinition* apd,
                                                      FdoIFeatureReader* reader)
{
    if( apd->GetIsReadOnly() )
        return;

    FdoPtr<FdoDataPropertyDefinitionCollection> idents = apd->GetIdentityProperties();
    if( idents->GetCount() == 0 )
    {
        // Search for property values with names build from the association property name and the
        // associated class identity properties. For example if the associated class identifier is "Id" and the
        // association property name is "AssocProp", then we should search for a property value with
        // name: "AssocProp.Id". If that property value is found and set, then that means an association
        // exists between the new object(we are about to insert) and the object identified by the value
        // of the property value(AssocProp.Id)
        FdoPtr<FdoClassDefinition> cls = apd->GetAssociatedClass();
        idents = cls->GetIdentityProperties();
    }
    if( reader->IsNull( apd->GetName() ) )
        return;

    FdoPtr<FdoIFeatureReader> loc_reader = reader->GetFeatureObject( apd->GetName() );
    if( ! loc_reader->ReadNext() )
        return;
    for(int i=0; i<idents->GetCount(); i++ )
    {
        FdoPtr<FdoDataPropertyDefinition> prop = idents->GetItem( i );
        if( ! loc_reader->IsNull( prop->GetName() ) )
            WriteProperty( prop, loc_reader);
    }
}
const void* FdoRdbmsSQLDataReader::GetGeometry(FdoInt32 index, FdoInt32* len, bool noExcOnInvalid)
{
    ValidateIndex(index);
    if( ! mHasMoreRows )
        throw FdoCommandException::Create(NlsMsgGet(FDORDBMS_62, noMoreRows));

    if (mGeomIdx != index)
    {
        FdoIGeometry* geom = NULL;
        bool isSupportedType = false;
        bool isNull = false;

        mGeomIdx = index;
        if (mWkbBuffer)
            *mWkbBuffer = 0;
        mQueryResult->GetBinaryValue (index+1, sizeof(FdoIGeometry *), (char*)&geom, &isNull, NULL);

        if ( !isNull && geom && geom->GetDerivedType() != FdoGeometryType_None )
            isSupportedType = true;

        if ( !isNull && geom != NULL )
        {
            if ( isSupportedType )
            {
                FdoPtr<FdoFgfGeometryFactory>  gf = FdoFgfGeometryFactory::GetInstance();
                FdoPtr<FdoByteArray> fgf = gf->GetFgf(geom);
                if (fgf != NULL && fgf->GetCount() != 0)
                {
                    mWkbGeomLen = fgf->GetCount();
                    if (mWkbBufferLen < mWkbGeomLen)
                    {
                        delete[] mWkbBuffer;
                        mWkbBufferLen = mWkbGeomLen;
                        mWkbBuffer = new unsigned char[mWkbGeomLen];
                    }
                    memcpy(mWkbBuffer, fgf->GetData(), mWkbGeomLen);
                }
                else
                    mWkbGeomLen = 0;
            }
            else
                mWkbGeomLen = -1;
        }
        else // isNull indicator is not set by dbi_get_val_b for geometry columns
            mWkbGeomLen = 0;
    }
    *len = mWkbGeomLen;
    if (*len <= 0)
    {
        if (noExcOnInvalid)
            return NULL;
        else if (*len == 0)
            throw FdoCommandException::Create(NlsMsgGet1( FDORDBMS_385, "Property '%1$ls' value is NULL; use IsNull method before trying to access the property value", mColList[index].column ));
        else
            throw FdoCommandException::Create( NlsMsgGet(FDORDBMS_116, "Unsupported geometry type" ) );
    }

    return mWkbBuffer;
}
Example #3
0
bool GwsBinaryFeatureWriter::WriteAssociationProperty(FdoAssociationPropertyDefinition* apd,
                                                      FdoPropertyValueCollection* pvc)
{
    bool  errorIfSet = apd->GetIsReadOnly();
    bool  oneIdentIsNull = false;
    bool  written = false;

    FdoPtr<FdoDataPropertyDefinitionCollection> idents = apd->GetIdentityProperties();
    if( idents->GetCount() == 0 )
    {
        // Search for property values with names build from the association property name and the
        // associated class identity properties. For example if the associated class identifier is "Id" and the
        // association property name is "AssocProp", then we should search for a property value with
        // name: "AssocProp.Id". If that property value is found and set, then that means an association
        // exists between the new object(we are about to insert) and the object identified by the value
        // of the property value(AssocProp.Id)
        FdoPtr<FdoClassDefinition> cls = apd->GetAssociatedClass();
        idents = cls->GetIdentityProperties();
    }

    for(int i=0; i<idents->GetCount(); i++ )
    {
        FdoPtr<FdoDataPropertyDefinition> prop = idents->GetItem( i );
        std::wstring wstr = apd->GetName();
        wstr += L".";
        wstr += prop->GetName();
        FdoPtr<FdoPropertyValue> pv = pvc->FindItem( wstr.c_str() );
        if(pv != NULL)
        {
            if( errorIfSet )
                GWS_THROW(eGwsFailed); //cannot add readonly association property value

            if( oneIdentIsNull )
                GWS_THROW(eGwsFailed); //one of the identity properties is null

            WriteProperty(prop, pv, true);
            written = true;
            oneIdentIsNull = false;
        }
        else
        {
            if( written ) // we already written one or more identity and this one is null
                GWS_THROW(eGwsFailed);
            oneIdentIsNull = true;
        }
    }

    return written;
}
//
// The TRIM function requires special processing.
void FdoRdbmsMySqlFilterProcessor::ProcessTrimFunction( FdoFunction& expr)
{
    // Append the function name and the opening bracket.
    ProcessFunctionName(expr);
	AppendString( "( " );

    // Process the arguments. This is were the special processing is required.
    // If the call includes an operator (BOTH, LEADING, TRAILING), it is required
    // to add a FROM clause after the operation keyword.
    FdoPtr<FdoExpressionCollection> exprCol = expr.GetArguments();
    for ( int i=0; i<exprCol->GetCount(); i++ )
    {
        FdoPtr<FdoExpression>exp = exprCol->GetItem( i );
        if ( (i == 0) && (IsDataValue( exp )) )
        {
            FdoDataValue *dataValue = (static_cast<FdoDataValue *>(exp.p) );
            if ( dataValue->GetDataType() == FdoDataType_String )
            {
                FdoStringValue *stringValue = static_cast<FdoStringValue *>(dataValue);
                AppendString( stringValue->GetString() );
                AppendString( " FROM " );	

            }
            else
                throw FdoFilterException::Create(NlsMsgGet(FDORDBMS_29, "Unsupported FDO type in expression"));
        }
        else
            HandleExpr( exp );
	}
    AppendString( " )" );
}
void CGwsQueryResultDescriptors::appendPropertyNames (
    FdoIdentifierCollection       * propnamestoadd,
    FdoClassDefinition        * classDef,
    FdoStringCollection       * propnames,
    std::vector<CGwsPropertyDesc> & propdsc
)
{
    FdoPtr<FdoPropertyDefinitionCollection> properties;

    FdoPtr<FdoClassDefinition> baseClass = classDef->GetBaseClass ();
    if (baseClass != NULL) {
        appendPropertyNames (propnamestoadd, baseClass, propnames, propdsc);

    }

    properties = classDef->GetProperties ();
    if (properties == NULL)
        return;
    for (int i = 0; i < properties->GetCount (); i ++) {
        FdoPtr<FdoPropertyDefinition>   pFdoProperty = properties->GetItem (i);
        if (propnamestoadd == NULL ||
            propnamestoadd->IndexOf (pFdoProperty->GetName ()) >= 0)
            pushPropDefinition (pFdoProperty, propnames,propdsc);
    }
}
Example #6
0
MgReader* MgSelectCommand::ExecuteJoined(MgStringCollection* idPropNames, bool bForceOneToOne)
{
    Ptr<MgReader> ret;

    MG_FEATURE_SERVICE_TRY()

#ifdef DEBUG_FDO_JOIN
    FdoPtr<FdoIdentifierCollection> cmdPropNames = m_command->GetPropertyNames();
    for (FdoInt32 i = 0; i < cmdPropNames->GetCount(); i++)
    {
        FdoPtr<FdoIdentifier> ident = cmdPropNames->GetItem(i);
        STRING idStr = ident->ToString();
        ACE_DEBUG((LM_INFO, ACE_TEXT("\n(%t) [FdoISelect]: (%W)"), idStr.c_str()));
    }
#endif

    FdoPtr<FdoIFeatureReader> fdoReader = m_command->Execute();
    if (bForceOneToOne)
    {
        FdoPtr<FdoStringCollection> names = MgServerFeatureUtil::MgToFdoStringCollection(idPropNames, false);
        FdoPtr<FdoIFeatureReader> forcedReader = new MgFdoForcedOneToOneFeatureReader(fdoReader, names); 
        ret = new MgServerFeatureReader(m_connection, forcedReader, idPropNames);
    }
    else
    {
        ret = new MgServerFeatureReader(m_connection, fdoReader, idPropNames);
    }
    MG_FEATURE_SERVICE_CATCH_AND_THROW(L"MgSelectCommand.ExecuteJoined")

    return ret.Detach();
}
Example #7
0
MgReader* MgSelectCommand::Execute()
{
    FdoPtr<FdoIFeatureReader> reader;

    // Break up the filter into smaller chunks
    FdoPtr<MgFdoFilterCollection> subFilters = this->GetSubFilters();

    CHECKNULL((FdoISelect*)m_command, L"MgSelectCommand.Execute");

    // Execute queries using the smaller filters and collect the results of the queries into a reader collection.
    FdoPtr<MgFdoReaderCollection> frc = MgFdoReaderCollection::Create();

    for (FdoInt32 filterIndex = 0; filterIndex < subFilters->GetCount(); filterIndex++)
    {
        FdoPtr<FdoFilter> filter = subFilters->GetItem(filterIndex);
        m_command->SetFilter(filter);
        reader = m_command->Execute();

        frc->Add(reader);
    }

    FdoPtr<MgFdoFeatureReader> featureReader = new MgFdoFeatureReader(frc);
    CHECKNULL((FdoIFeatureReader*)featureReader, L"MgSelectCommand.Execute");

    return new MgServerFeatureReader(m_connection, featureReader);
}
Example #8
0
EGwsStatus GwsCommonFdoUtils::DescribeClassSC (
    FdoIConnection          * conn,
    const GWSQualifiedName &  classname,
    GwsSpatialContextDescription & desc
)
{
    FdoPtr<FdoFeatureSchema>   schema;
    FdoPtr<FdoClassDefinition> classDef;

    GwsCommonFdoUtils::GetClassDefinition (conn, classname, schema.p, classDef.p);


    for (; classDef != NULL ; classDef = classDef->GetBaseClass ()) {
        FdoPtr<FdoPropertyDefinitionCollection> propdsc = classDef->GetProperties ();
        // discover geometric property name. Use the first one if there are many.
        for (int idx = 0; idx < propdsc->GetCount(); idx ++) {
            FdoPtr<FdoPropertyDefinition>   prop;
            prop = propdsc->GetItem (idx);

            if (prop->GetPropertyType () == FdoPropertyType_GeometricProperty) {
                FdoGeometricPropertyDefinition* geomProp = static_cast<FdoGeometricPropertyDefinition*>(prop.p);
                FdoString* pSC = geomProp->GetSpatialContextAssociation();
                if(pSC != NULL) {
                    return GwsCommonFdoUtils::DescribeSC (conn, pSC, desc);
                }
            }
        }
    }
    return eGwsSCNotFound;
}
Example #9
0
GWSExtendedFeatureId GwsCommonFdoUtils::MakeFeatureId (
    const GWSQualifiedName            & classname,
    FdoPtr<FdoPropertyValueCollection>  ident,
    const wchar_t                     * ltname
)
{
    static_cast<void>(&(ltname)); // For "unreferenced formal parameter" warning

    static GWSExtendedFeatureId s_fid;

    try {
        CGwsDataValueCollection   *  keyvals = NULL;
        keyvals = (CGwsDataValueCollection *) CGwsDataValueCollection::Create ();

        int size = ident->GetCount ();

        for (int i = 0; i < size ; i++) {
            FdoPtr<FdoPropertyValue>    propval;
            FdoPtr<FdoDataValue>        value;
            propval = ident->GetItem (i);
            value = (FdoDataValue *) propval->GetValue ();
            keyvals->Add (value);

        }
        return GWSExtendedFeatureId (classname, keyvals);

    } catch (FdoException * e) {
        assert (false);
        e->Release ();
    }
    return s_fid;
}
Example #10
0
// Returns an FDO expression engine configured with the custom functions
// defined by stylization.
FdoExpressionEngine* ExpressionHelper::GetExpressionEngine(Renderer* renderer, RS_FeatureReader* reader)
{
    // get the user-defined functions
    FdoPtr<FdoExpressionEngineFunctionCollection> userDefinedFunctions = ExpressionHelper::GetExpressionEngineFunctions(renderer, reader);

    // create the engine
    FdoPtr<FdoIFeatureReader> fdoReader = reader? reader->GetInternalReader() : NULL;
    FdoPtr<FdoClassDefinition> classDef = fdoReader? fdoReader->GetClassDefinition() : FdoClass::Create();
    FdoExpressionEngine* exec = FdoExpressionEngine::Create(fdoReader, classDef, userDefinedFunctions);

    // now that we have the engine, set it on the functions that need it - for now
    // this is only the IF function
    for (int i=0; i<userDefinedFunctions->GetCount(); ++i)
    {
        FdoPtr<FdoExpressionEngineIFunction> func = userDefinedFunctions->GetItem(i);
        ExpressionFunctionIf* funcIf = dynamic_cast<ExpressionFunctionIf*>(func.p);
        if (funcIf)
        {
            funcIf->SetExpressionEngine(exec);
            break;
        }
    }

    return exec;
}
const FdoByte * FdoXmlFeatureReaderImpl::GetGeometry(FdoString* propertyName, FdoInt32 * count)
{
    FdoByte* data = NULL;
    FdoPtr<FdoByteArray> ba = this->GetGeometry(propertyName);
    if (NULL != ba.p)
    {
        data = ba->GetData();
        *count = ba->GetCount();
    }
    return data;
}
int CGwsQueryResultDescriptors::Contains (FdoString* propertyName)
{
    FdoPtr<FdoStringCollection> pPropNames = PropertyNames();
    for(int i=0;i<pPropNames->GetCount();i++)
    {
        FdoString* pComp = pPropNames->GetString(i);
        if( _wcsicmp( propertyName, pComp ) == 0)
            return i;
    }
    return -1;
}
/// <summary>Gets the geometry value of the specified property as a byte array in 
/// FGF format. Because no conversion is performed, the property must be
/// of Geometric type; otherwise, an exception is thrown. 
/// This method is a language-specific performance optimization that returns a
/// pointer to the array data, rather than to an object that encapsulates
/// the array.  The array's memory area is only guaranteed to be valid
/// until a call to ReadNext() or Close(), or the disposal of this reader
/// object.</summary>
/// <param name="identifier">Input the property name.</param> 
/// <param name="count">Output the number of bytes in the array.</param> 
/// <returns>Returns a pointer to the byte array in FGF format.</returns> 
const FdoByte* SuperMapFeatureReader::GetGeometry (FdoString* identifier, FdoInt32 * count)
{
	FdoPtr<FdoByteArray> byteArray = GetGeometry (identifier);
	if(NULL == byteArray)
	{
		return NULL;
	}
	FdoByte *ret = byteArray->GetData();
	*count = byteArray->GetCount();

	return ret;
}
Example #14
0
void MgFeatureNumericFunctions::Initialize(MgReader* reader, FdoFunction* customFunction, CREFSTRING propertyAlias)
{
    CHECKNULL((MgReader*)reader, L"MgFeatureNumericFunctions.Initialize");
    CHECKNULL((FdoFunction*)customFunction, L"MgFeatureNumericFunctions.Initialize");

    if(1 == reader->GetPropertyCount())
    {
        m_type = MgServerFeatureUtil::GetPropertyDefinition(reader, m_propertyName);
    }
    else
    {
        // Only get the property needed
        FdoPtr<FdoExpressionCollection> exprCol = customFunction->GetArguments();
        FdoInt32 cnt = exprCol->GetCount();
        FdoPtr<FdoExpression> expr;
        if(cnt == 1)
        {
            expr = exprCol->GetItem(0);
            FdoIdentifier* propName = dynamic_cast<FdoIdentifier*>(expr.p);
            CHECKNULL(propName, L"MgFeatureNumericFunctions.Initialize");
            m_propertyName = propName->GetName();
            m_type = reader->GetPropertyType(m_propertyName);
        }
        else
        {
            // Throw original exception
            m_type = MgServerFeatureUtil::GetPropertyDefinition(reader, m_propertyName);
        }
    }

    // TODO: Should we really check this, may be we can ignore ??
    // because we can only come to here if property type is numeric
    this->CheckSupportedPropertyType();

    // We must have an property alias
    // Though we can name a property with same name as function expression
    // But Fdo forces to have an alias. Therefore we implement this restriction.
    if (propertyAlias.empty())
    {
        STRING message = MgServerFeatureUtil::GetMessage(L"MgMissingPropertyAlias");

        MgStringCollection arguments;
        arguments.Add(message);
        throw new MgFeatureServiceException(L"MgFeatureDistribution.Initialize", __LINE__, __WFILE__, &arguments, L"", NULL);
    }

    m_reader = SAFE_ADDREF(reader);
    m_customFunction = FDO_SAFE_ADDREF(customFunction);
    m_propertyAlias = propertyAlias;
}
Example #15
0
FdoDataPropertyDefinitionCollection* GwsBinaryFeatureWriter::FindIDProps(FdoClassDefinition* fc)
{
    FdoPtr <FdoDataPropertyDefinitionCollection> idpdc = fc->GetIdentityProperties();
    FdoPtr<FdoClassDefinition> base = FDO_SAFE_ADDREF(fc);

    //go up class hierarchy to find base class (it has the identity properties)
    while ((base = base->GetBaseClass()) != NULL)
        idpdc = base->GetIdentityProperties();

    if (idpdc->GetCount() == 0)
        return NULL;

    return (FDO_SAFE_ADDREF (idpdc.p));
}
void SuperMapConnection::Flush()
{
	TRACE(_T("调用 SuperMapConnection::Flush ...\n"));
	
	FdoPtr<SuperMapLpFeatureSchemaCollection> schemas = GetLpSchemas();
	int count = schemas->GetCount();

	for(int i = 0; i < count; ++i)
	{
		FdoPtr<SuperMapLpFeatureSchema> lpSchema = schemas->GetItem(i);
		FdoPtr<SuperMapLpClassDefinitionCollection> classes = lpSchema->GetLpClasses();
		int class_count = classes->GetCount();

		for(int j = 0; j < class_count; ++j)
		{
			FdoPtr<SuperMapLpClassDefinition> lpClass = classes->GetItem(j);
			UGC::UGDataset* pDataset = lpClass->GetDataset();

			//以同样的方式打开该数据集以使其更新
			pDataset->Open();
		}
	}
}
Example #17
0
FdoStringCollection * CGwsPreparedFeatureQuery::GetOrderBy ()
{
    FdoPtr<FdoIdentifierCollection> ordering = ((FdoISelect *) m_pCommand.p)->GetOrdering ();
    FdoStringCollection           * orderBy  = NULL;

    if(NULL == ordering) return NULL;

    for (int i = 0; i < ordering->GetCount (); i ++) {
        FdoPtr<FdoIdentifier> ident = ordering->GetItem (i);
        if (orderBy == NULL) {
            orderBy  = FdoStringCollection::Create ();
        }
        orderBy->Add (ident->GetText ());
    }
    return orderBy;
}
Example #18
0
MgByteReader* MgdSqlDataReader::GetGeometry(CREFSTRING propertyName) 
{ 
	Ptr<MgByteReader> geom;
	MG_FEATURE_SERVICE_TRY()
    FdoPtr<FdoByteArray> byteArray = m_reader->GetGeometry(propertyName.c_str());
    INT32 len = (INT32)byteArray->GetCount();
    const FdoByte* data = byteArray->GetData();
    if (data != NULL)
    {
        Ptr<MgByte> mgBytes = new MgByte((BYTE_ARRAY_IN)data, len);
        Ptr<MgByteSource> bSource = new MgByteSource(mgBytes);
        bSource->SetMimeType(MgMimeType::Agf);
        geom = bSource->GetReader();
    }
	MG_FEATURE_SERVICE_CATCH_AND_THROW(L"MgdSqlDataReader::GetGeometry")
	return geom.Detach();
}
Example #19
0
MgByteReader* MgdSqlDataReader::GetCLOB(CREFSTRING propertyName)
{ 
	Ptr<MgByteReader> clob;
	MG_FEATURE_SERVICE_TRY()
    FdoPtr<FdoLOBValue> fdoVal = m_reader->GetLOB(propertyName.c_str());
    if (fdoVal != NULL)
    {
        FdoPtr<FdoByteArray> byteArray = fdoVal->GetData();
        if (byteArray != NULL)
        {
            FdoByte* bytes = byteArray->GetData();
            FdoInt32 len = byteArray->GetCount();
            Ptr<MgByteSource> byteSource = new MgByteSource((BYTE_ARRAY_IN)bytes,(INT32)len);
            clob = byteSource->GetReader();
        }
    }
	MG_FEATURE_SERVICE_CATCH_AND_THROW(L"MgdSqlDataReader::GetCLOB")
	return clob.Detach();
}
Example #20
0
FdoXmlLpSchemaCollection* FdoXmlSchemaManager::_schemas() {
    if (m_lpSchemas == NULL) {
        m_lpSchemas = FdoXmlLpSchemaCollection::Create(this);
        FdoInt32 count = m_fdoSchemas->GetCount();
        FdoPtr<FdoPhysicalSchemaMappingCollection> mappings = m_flags->GetSchemaMappings();
        if ( mappings == NULL ) 
            mappings = m_fdoSchemas->GetXmlSchemaMappings();

        FdoInt32 count1 = mappings->GetCount();
        FdoPtr<FdoXmlSchemaMapping> tempXmlMapping = FdoXmlSchemaMapping::Create(L"temp");
        for (int i = 0; i < count; i++) {
            FdoPtr<FdoFeatureSchema> schema = m_fdoSchemas->GetItem(i);
            FdoPtr<FdoXmlSchemaMapping> mapping = static_cast<FdoXmlSchemaMapping*>(mappings->GetItem(tempXmlMapping->GetProvider(), schema->GetName()));
            FdoPtr<FdoXmlLpSchema> lpSchema = FdoXmlLpSchema::Create(schema, mapping);
            m_lpSchemas->Add(lpSchema);
        }
    }
    return m_lpSchemas.p;

}
void FdoRdbmsMySqlFilterProcessor::ProcessToInt32Int64Function (FdoFunction& expr)
{
    // MySQL uses a different native function name for the expression functions
    // TOINT32, TOINT64. 
    AppendString(MYSQL_FUNCTION_TONUM);
    AppendString(OPEN_PARENTH);

    FdoPtr<FdoExpressionCollection> exprCol = expr.GetArguments();
    for(int i=0; i<exprCol->GetCount(); i++ )
    {
        if( i!= 0 )
            AppendString( L", " );

        FdoPtr<FdoExpression>exp = exprCol->GetItem( i );
        HandleExpr( exp );
    }

    // Add the keyword that performs the conversion and the closing bracket.
    AppendString( L", SIGNED)" );
}
void FdoRdbmsMySqlFilterProcessor::ProcessCurrentDateFunction (FdoFunction& expr)
{
    // MySQL uses a different native function name for the expression function
    // CurrentDate. 
    AppendString(MYSQL_FUNCTION_CURRENTDATE);
    AppendString(OPEN_PARENTH);

    // Note, that the function does not allow any arguments. However, if some
    // are given, they are added to the function call and it is left to MySQL
    // to deal with it.
    FdoPtr<FdoExpressionCollection> exprCol = expr.GetArguments();
    for(int i=0; i<exprCol->GetCount(); i++ )
    {
        if( i!= 0 )
            AppendString( L", " );

        FdoPtr<FdoExpression>exp = exprCol->GetItem( i );
        HandleExpr( exp );
    }
    AppendString( CLOSE_PARENTH );
}
Example #23
0
bool GwsCommonFdoUtils::GetGeometryName (FdoClassDefinition *pClassDef, std::wstring &name)
{
    if(pClassDef == NULL)
        return false;

    if(pClassDef->GetClassType() == FdoClassType_FeatureClass)
    {
        FdoFeatureClass* pFeatClass = dynamic_cast<FdoFeatureClass*>(pClassDef);
        if(!pFeatClass)
        {
            assert(false);
            return false;
        }

        FdoPtr<FdoGeometricPropertyDefinition> pgDef = pFeatClass->GetGeometryProperty();
        if (pgDef != NULL) {
            name = pgDef->GetName();
            return true;
        }
    }
    FdoInt32 idx;

    FdoPtr<FdoClassDefinition>  classDef = pClassDef;
    FDO_SAFE_ADDREF(pClassDef);
    for (; classDef != NULL ; classDef = classDef->GetBaseClass ())
    {
        FdoPtr<FdoPropertyDefinitionCollection> propdsc = classDef->GetProperties ();
        // discover geometric property name. Use the first one if there are many.
        for (idx = 0; idx < propdsc->GetCount(); idx ++) {
            FdoPtr<FdoPropertyDefinition>   prop;
            prop = propdsc->GetItem(idx);
            if (prop->GetPropertyType () == FdoPropertyType_GeometricProperty)
            {
                name = prop->GetName ();
                return true;
            }
        }
    }
    return false;
}
Example #24
0
WSTR GwsCommonFdoUtils::GetRevisionProperty (FdoClassDefinition * classdef)
{
    WSTR revision;

    // discover revision property. Revision property is defined
    // for a given class
    FdoPtr<FdoReadOnlyPropertyDefinitionCollection> pBaseProperties = classdef->GetBaseProperties();

    // See if property with this name already exists:
    for (int idx=0; pBaseProperties != NULL && idx < pBaseProperties->GetCount(); idx++)
    {
        FdoPtr<FdoPropertyDefinition> pBaseProperty;
        pBaseProperty = (FdoPropertyDefinition*)pBaseProperties->GetItem(idx);
        if (! _wcsicmp (pBaseProperty->GetName(), REVISIONNUMBER_PROPNAME))
        {
            revision = pBaseProperty->GetName();
            break;
        }
    }

    return revision;
}
Example #25
0
MgByteReader* MgdSqlDataReader::GetLOB(CREFSTRING propertyName)
{
    Ptr<MgByteReader> byteReader;

    try
    {
        // TODO: We need to switch to FdoIStreamReader when we have streaming capability in MgByteReader
        FdoPtr<FdoLOBValue> fdoVal = m_reader->GetLOB(propertyName.c_str());
        if (fdoVal != NULL)
        {
            FdoPtr<FdoByteArray> byteArray = fdoVal->GetData();
            if (byteArray != NULL)
            {
                FdoByte* bytes = byteArray->GetData();
                FdoInt32 len = byteArray->GetCount();
                Ptr<MgByteSource> byteSource = new MgByteSource((BYTE_ARRAY_IN)bytes,(INT32)len);
                // TODO: We need to differentiate between CLOB and BLOB
                // TODO: How do we fine the MimeType of data for CLOB
                byteSource->SetMimeType(MgMimeType::Binary);
                byteReader = byteSource->GetReader();
            }
        }
    }
    catch(...)
    {
        if(m_reader->IsNull(propertyName.c_str()))
        {
            MgStringCollection arguments;
            arguments.Add(propertyName);

            throw new MgNullPropertyValueException(L"MgdSqlDataReader::GetLOB",
                __LINE__, __WFILE__, &arguments, L"", NULL);
        }
        else
            throw;
    }
    return byteReader.Detach();
}
Example #26
0
FdoIGeometry* FdoXmlMultiGeometry::GetFdoGeometry()
{
	//create geometry collection
 	FdoPtr<FdoGeometryCollection> geometryCollection = FdoGeometryCollection::Create();
	
	for(vector<FdoXmlGeometry*>::iterator it = m_geometryCollection.begin();
		it != m_geometryCollection.end();
		it++)
	{
		FdoPtr<FdoIGeometry> fdoGeometry = (*it)->GetFdoGeometry();
		if(fdoGeometry != NULL)
			geometryCollection->Add(fdoGeometry);
	}

	//convert to FdoIMultiGeometry
	FdoPtr<FdoFgfGeometryFactory> factory = FdoFgfGeometryFactory::GetInstance();
	
    FdoPtr<FdoIGeometry> rv;
    if (geometryCollection->GetCount() != 0)
        rv = factory->CreateMultiGeometry(geometryCollection);
    return FDO_SAFE_ADDREF(rv.p);
	
}
///<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 ();
}
//
// Aggregate functions require special processing because of the optional
// first parameter. The value of this parameter may be ALL or DISTINCT.
void FdoRdbmsMySqlFilterProcessor::ProcessAggregateFunction (FdoFunction& expr)
{
    // Append the function name and the opening bracket.
    ProcessFunctionName(expr);
	AppendString( "( " );

    // Process the arguments. This is were the special processing is required as
    // it is required to have the parameters listed sequencially without a comma
    // between them.
    FdoPtr<FdoExpressionCollection> exprCol = expr.GetArguments();
    for (int i=0; i<exprCol->GetCount(); i++)
    {
        FdoPtr<FdoExpression>exp = exprCol->GetItem(i);
        if ((i == 0) && (IsDataValue(exp)))
        {
            FdoDataValue *dataValue = (static_cast<FdoDataValue *>(exp.p));
            if (dataValue->GetDataType() == FdoDataType_String)
            {
                // Omit ALL if specified as this keyword is not supported in
                // MySQL.
                FdoStringValue *stringValue = static_cast<FdoStringValue *>(dataValue);
                FdoStringP strValue = stringValue->GetString();
                if (FdoCommonOSUtil::wcsicmp(strValue, L"ALL") != 0)
                {
                    AppendString(stringValue->GetString());
                    AppendString(L" ");	
                }
            }
            else
                throw FdoFilterException::Create(NlsMsgGet(FDORDBMS_29, "Unsupported FDO type in expression"));
        }
        else
            HandleExpr(exp);
	}
    AppendString(" )");
}
Example #29
0
MgPropertyCollection* MgdUpdateFeaturesCommand::ExecuteInsert(MgResourceIdentifier* resource, CREFSTRING className, MgBatchPropertyCollection* batchPropertyValues, MgTransaction* trans)
{
    Ptr<MgPropertyCollection> ret;

    MG_FEATURE_SERVICE_TRY()

    CHECK_FEATURE_SOURCE_ARGUMENT(resource, L"MgdUpdateFeaturesCommand::ExecuteInsert");
	CHECKARGUMENTNULL(batchPropertyValues, L"MgdUpdateFeaturesCommand::ExecuteInsert");
	if (className.empty())
		throw new MgNullArgumentException(L"MgdUpdateFeaturesCommand::ExecuteInsert", __LINE__, __WFILE__, NULL, L"", NULL);
	
    ret = new MgPropertyCollection();

    Ptr<MgdFeatureConnection> connWrap;
	FdoPtr<FdoIConnection> conn;
    FdoPtr<FdoITransaction> fdoTrans;
    Ptr<MgdTransaction> mgTrans = dynamic_cast<MgdTransaction*>(trans);
    if (NULL != mgTrans)
    {
        SAFE_ADDREF(mgTrans.p);
        Ptr<MgResourceIdentifier> origFeatureSource = mgTrans->GetFeatureSource();
        //Check that the transaction originates from the same feature source
        if (origFeatureSource->ToString() != resource->ToString())
            throw new MgInvalidArgumentException(L"MgdUpdateFeaturesCommand::ExecuteInsert", __LINE__, __WFILE__, NULL, L"", NULL);

        connWrap = mgTrans->GetConnection(); //Connection is already open
        fdoTrans = mgTrans->GetFdoTransaction();
    }
    else
    {    
        connWrap = new MgdFeatureConnection(resource);
    }

    conn = connWrap->GetConnection();
	FdoPtr<FdoIInsert> insert = (FdoIInsert*)conn->CreateCommand(FdoCommandType_Insert);
	
	insert->SetFeatureClassName(className.c_str());

	FdoPtr<FdoPropertyValueCollection> propVals = insert->GetPropertyValues();
	
    if (NULL != fdoTrans.p)
        insert->SetTransaction(fdoTrans);

    //TODO: Support batch parameters, the main beneficiary of this API. Even then,
    //the value flipping approach employed here has performance benefits for certain
    //providers, like SQLite

    for (INT32 i = 0; i < batchPropertyValues->GetCount(); i++)
    {
        Ptr<MgPropertyCollection> propertyValues = batchPropertyValues->GetItem(i);

        //First feature, set up the FDO property value collection
        if (i == 0)
        {
            for (INT32 i = 0; i < propertyValues->GetCount(); i++)
	        {
		        Ptr<MgProperty> mgp = propertyValues->GetItem(i);
		        FdoPtr<FdoPropertyValue> pv = MgdFeatureUtil::MgPropertyToFdoProperty(mgp);

		        propVals->Add(pv);
	        }
        }
        else //Feature after the first
        {
            //Set all to null
            for (INT32 i = 0; i < propVals->GetCount(); i++)
            {
                FdoPtr<FdoPropertyValue> fp = propVals->GetItem(i);
                FdoPtr<FdoValueExpression> expr = fp->GetValue();
                FdoDataValue* fdv = dynamic_cast<FdoDataValue*>(expr.p);
                FdoGeometryValue* fgv = dynamic_cast<FdoGeometryValue*>(expr.p);
                if (fdv)
                {
                    fdv->SetNull();
                }
                else if (fgv)
                {
                    fgv->SetNullValue();
                }
            }

            //Now set the appropriate values. MgdFeatureUtil does the work
            for (INT32 i = 0; i < propertyValues->GetCount(); i++)
	        {
                Ptr<MgNullableProperty> mgp = (MgNullableProperty*)propertyValues->GetItem(i);
                if (!mgp->IsNull())
                {
                    FdoPtr<FdoPropertyValue> fp = propVals->GetItem(mgp->GetName().c_str());
                    MgdFeatureUtil::UpdateFdoPropertyValue(fp, mgp);
                }
            }
        }

        STRING sIndex;
        MgUtil::Int32ToString(i, sIndex);

        //Insert and stash the result in the property collection
	    FdoPtr<FdoIFeatureReader> insertRes = insert->Execute();

	    Ptr<MgFeatureReader> fr = new MgdFeatureReader(connWrap, insertRes);
        Ptr<MgFeatureProperty> fp = new MgFeatureProperty(sIndex, fr);
        ret->Add(fp);
    }

    MG_FEATURE_SERVICE_CATCH_AND_THROW_WITH_FEATURE_SOURCE(L"MgdUpdateFeaturesCommand::ExecuteInsert", resource)

    return ret.Detach();
}
Example #30
0
MgSpatialContextData* MgServerGetSpatialContexts::GetSpatialContextData(
    FdoISpatialContextReader* spatialReader, MgSpatialContextInfo* spatialContextInfo)
{
    Ptr<MgSpatialContextData> spatialData = new MgSpatialContextData();

    // Name must exist
    FdoString* name = spatialReader->GetName();
    CHECKNULL((FdoString*)name, L"MgServerGetSpatialContexts.GetSpatialContexts");
    spatialData->SetName(STRING(name));

    STRING coordSysName = L"";
    FdoString* csName = spatialReader->GetCoordinateSystem();

    Ptr<MgCoordinateSystemFactory> csFactory;
    // WKT for co-ordinate system
    FdoString* csWkt = NULL;
    STRING srsWkt = L"";

    bool haveValidCoordSys = false;
    if(NULL != csName && *csName != '\0')
    {
        coordSysName = STRING(csName);
    }
    else
    {
        csWkt = spatialReader->GetCoordinateSystemWkt();
        if (csWkt != NULL && *csWkt != '\0')
        {
            srsWkt = csWkt;
            try
            {
                csFactory = new MgCoordinateSystemFactory();
                coordSysName = csFactory->ConvertWktToCoordinateSystemCode(srsWkt);
                haveValidCoordSys = (coordSysName.size() != 0);
            }
            catch (MgException* e)
            {
                SAFE_RELEASE(e);
            }
            catch(...)
            {
            }
        }
    }

    bool spatialContextDefined = !coordSysName.empty();
    bool coordSysOverridden = false;

    // look for coordinate system override
    if (NULL != spatialContextInfo)
    {
        // Perform substitution of missing coordinate system with
        // the spatial context mapping defined in feature source document
        MgSpatialContextInfo::const_iterator iter = spatialContextInfo->find(name);

        if (spatialContextInfo->end() != iter)
        {
            csName = (iter->second).c_str();
            coordSysOverridden = true;
        }
    }

    if (csName != NULL && *csName != '\0')
    {
        spatialData->SetCoordinateSystem(STRING(csName));
    }

    // Desc for spatial context
    STRING desc = L"";

    // This flag is obsolete and will be deprecated.
    bool isActive = spatialReader->IsActive();

    if (coordSysOverridden)
    {
        srsWkt = csName;
        desc = MgServerFeatureUtil::GetMessage(L"MgCoordinateSystemOverridden");
    }
    else if (spatialContextDefined && !coordSysOverridden)
    {
        // avoid looking one more time after CS in case we have a valid one...
        if (!haveValidCoordSys)
        {
            csWkt = spatialReader->GetCoordinateSystemWkt();
            if(NULL != csWkt && *csWkt != '\0')
                srsWkt = csWkt;

            if (srsWkt.empty())
            {
                try
                {
                    if (csFactory == NULL)
                        csFactory = new MgCoordinateSystemFactory();

                    // Check if the spatial context coordinate system data represents an EPSG
                    // code. If this is the case the WKT data for the EPSG code has to be
                    // retrieved.
                    if (IsEpsgCodeRepresentation(csName))
                    {
                        // This is an EPSG code
                        FdoString* p = NULL;
                        if ((csName[0] == L'E') || (csName[0] == L'e'))
                            p = csName+5;
                        else
                            p = csName;

                        INT32 epsgCode = (INT32)wcstol(p, NULL, 10);

                        // Convert the EPSG numerical code to WKT
                        srsWkt = csFactory->ConvertEpsgCodeToWkt(epsgCode);
                    }
                    else
                    {
                        srsWkt = csFactory->ConvertCoordinateSystemCodeToWkt(STRING(csName));
                    }
                }
                catch (MgException* e)
                {
                    SAFE_RELEASE(e);
                }
                catch(...)
                {
                    // Just use the empty WKT.
                }
            }
        }
        FdoString* fdoDesc = spatialReader->GetDescription();
        if(NULL != fdoDesc)
            desc = STRING(fdoDesc);
    }

    // retrieve other values from spatialReader
    FdoSpatialContextExtentType extentType = spatialReader->GetExtentType();
    FdoPtr<FdoByteArray> byteArray = spatialReader->GetExtent();
    double xyTol = spatialReader->GetXYTolerance();
    double zTol = spatialReader->GetZTolerance();

    spatialData->SetCoordinateSystemWkt(srsWkt);
    spatialData->SetDescription(desc);
    spatialData->SetExtentType((INT32)extentType);

    if (byteArray.p != NULL)
    {
        INT32 size = (INT32)byteArray->GetCount();
        BYTE_ARRAY_IN bytes = (BYTE_ARRAY_IN)byteArray->GetData();
        Ptr<MgByte> extent = new MgByte(bytes, size);
        spatialData->SetExtent(extent);
    }

    // XY Tolerance
    spatialData->SetXYTolerance(xyTol);

    // Z Tolerance
    spatialData->SetZTolerance(zTol);

    // This flag is obsolete and will be deprecated.
    spatialData->SetActiveStatus(isActive);

    return spatialData.Detach();
}