OrderBy* GetFeatureRequest::ParserOrderBy(XElement* pxOrderBy)
	{
		OrderBy* pOrderBy = NULL;
		FilterFactory* pFilterFactory = augeGetFilterFactoryInstance();

		if(!pxOrderBy->HasChildren())
		{
			return NULL;
		}

		pOrderBy = pFilterFactory->CreateOrderBy();

		char field_name[AUGE_NAME_MAX];
		const char* property_name = NULL;
		XNode* pxNode = NULL;
		XNodeSet* pxNodeSet = pxOrderBy->GetChildren("PropertyName");

		pxNodeSet->Reset();
		while((pxNode=pxNodeSet->Next())!=NULL)
		{
			property_name = pxNode->GetContent();
			if(strlen(property_name)>0)
			{
				ParseFieldName(property_name, field_name, AUGE_NAME_MAX);
				pOrderBy->AddField(field_name);
			}
		}
		pxNodeSet->Release();

		XAttribute* pxAttr = pxOrderBy->GetAttribute("order");
		if(pxAttr!=NULL)
		{
			const char* order = pxAttr->GetValue();
			if(order!=NULL)
			{
				if(g_stricmp(order,"desc")==0)
				{
					pOrderBy->SetOrder(augeOrderDesc);
				}
				//pxAttr->Release();
			}
		}
		return pOrderBy;
	}
	g_int TransactionHandler::Update(XNode* pxUpdate, WebContext* pWebContext, FeatureClass* pFeatureClass)
	{
		int count = 0;

		GFilter* pFilter = NULL;
		XNode* pxFilter = pxUpdate->GetFirstChild("Filter");
		if(pxFilter!=NULL)
		{
			FilterFactory *factory = augeGetFilterFactoryInstance();
			FilterReader  *reader  = factory->CreateFilerReader(pFeatureClass->GetFields());
			pFilter = reader->Read((XElement*)pxFilter);
		}
		
		XNodeSet* pxPropertySet = NULL;
		pxPropertySet = pxUpdate->GetChildren("Property");
		if(pxPropertySet==NULL)
		{
			if(pFilter!=NULL)
			{
				pFilter->Release();
				pFilter = NULL;
			}
			pFeatureClass->Release();
			return AG_FAILURE;
		}
		
		const char* str= NULL;
		const char* fname = NULL;
		augeFieldType ftype = augeFieldTypeNone;

		GField* pField = NULL;
		GValue* pValue = NULL;
		EnumString* pFieldNames = new EnumString();
		EnumValue*  pValues = new EnumValue();

		XNode* pxName = NULL;
		XNode* pxValue = NULL;
		XNode* pxProp = NULL;
		pxPropertySet->Reset();
		while((pxProp = pxPropertySet->Next())!=NULL)
		{
			pxName = pxProp->GetFirstChild("Name");
			pxValue= pxProp->GetFirstChild("Value");
			fname = pxName->GetContent();

			pField = pFeatureClass->GetField(fname);
			if(pField==NULL)
			{
				continue;
			}

			ftype = pField->GetType();
			switch(ftype)
			{					 
			case augeFieldTypeShort:
				{
					str = pxValue->GetContent();
					pValue = new GValue((short)atoi(str));
				}
				break;
			case augeFieldTypeInt:
				{
					str = pxValue->GetContent();
					pValue = new GValue((int)atoi(str));
				}
				break;
			case augeFieldTypeLong:
				{
					str = pxValue->GetContent();
					pValue = new GValue((long)atoi(str));
				}
				break;
			case augeFieldTypeInt64:
				{
					str = pxValue->GetContent();
					pValue = new GValue((int64)atoi(str));
				}
				break;
			case augeFieldTypeFloat:
				{
					str = pxValue->GetContent();
					pValue = new GValue((float)atof(str));
				}
				break;
			case augeFieldTypeDouble:
				{
					str = pxValue->GetContent();
					pValue = new GValue((double)atof(str));
				}
				break;
			case augeFieldTypeChar:			 
				{
					str = pxValue->GetContent();
					pValue = new GValue(str[0]);
				}
				break;
			case augeFieldTypeString:
				{
					const char* text = pxValue->GetContent();
					if(text==NULL)
					{
						pValue = new GValue("");
					}
					else
					{
						pValue = new GValue(text);
					}
					
				}
				break;
			case augeFieldTypeTime:	
				{
					const char* text = pxValue->GetContent();
					if(text!=NULL)
					{
						TIME_STRU tim;
						memset(&tim,0, sizeof(TIME_STRU));
						sscanf(text,"%d-%2d-%2d %2d:%2d:%2d",&(tim.usYear),&(tim.usMonth),&(tim.usDay),&(tim.usHour),&(tim.usMinute),&(tim.usSecond));
						pValue = new GValue(&tim,true);
					}
				}
				break;
			case augeFieldTypeBool:			 
				{

				}
				break;
			case augeFieldTypeBLOB:			 
				{

				}
				break;
			case augeFieldTypeGeometry:
				{
					/*Geometry *pGeometry = pFeature->GetGeometry();
					if(pGeometry!=NULL)
					{
						const char* wkt = pGeometry->AsText(true);
						if(wkt!=NULL)
						{
							g_snprintf(str, AUGE_BUFFER_MAX,"%d",srid);

							fields.append(fname);
							values.append("st_geomfromtext(");
							values.append("'");
							values.append(wkt);
							values.append("',");
							values.append(str);
							values.append(")");
						}
					}*/
				}
				break;
			}

			if(pValue!=NULL)
			{
				pFieldNames->Add(fname);
				pValues->Add(pValue);
			}
		}
		count = pFeatureClass->UpdateFeature(pFieldNames, pValues, pFilter);
		
		pxPropertySet->Release();
		pFieldNames->Release();
		pValues->Release();
		if(pFilter!=NULL)
		{
			pFilter->Release();
			pFilter = NULL;
		}

		//return AG_SUCCESS;
		return 1;//count;
	}
	GQuery* GetFeatureRequest::ParseXmlQuery(FeatureClass* pFeatureClass)
	{
		if(m_pxDoc==NULL)
		{
			return NULL;
		}

		XElement* pxRoot = m_pxDoc->GetRootNode();
		XElement* pxQuery = (XElement*)pxRoot->GetFirstChild("Query");
		if(pxQuery==NULL)
		{
			return NULL;
		}

		FilterFactory* pFilterFactory = augeGetFilterFactoryInstance();
		GQuery* pQuery = pFilterFactory->CreateQuery();
		if(pQuery==NULL)
		{
			return NULL;
		}

		XElement* pxFilter = (XElement*)pxQuery->GetFirstChild("Filter");
		if(pxFilter!=NULL)
		{
			GFilter* pFilter = NULL;
			FilterReader* reader = pFilterFactory->CreateFilerReader(pFeatureClass->GetFields());
			pFilter = reader->Read(pxFilter);
			pQuery->SetFilter(pFilter);

		}

		XElement* pxOrderBy = (XElement*)pxQuery->GetFirstChild("OrderBy");
		if(pxOrderBy!=NULL)
		{
			OrderBy* pOrderBy = ParserOrderBy(pxOrderBy);
			if(pOrderBy!=NULL)
			{
				pQuery->SetOrderBy(pOrderBy);
			}
		}

		//PropertyName
		char field_name[AUGE_NAME_MAX];
		const char* property_name;
		XNode* pxNode = NULL;
		XNodeSet* pxNodeSet = pxQuery->GetChildren("PropertyName");
		pxNodeSet->Reset();
		while((pxNode=pxNodeSet->Next())!=NULL)
		{
			property_name = pxNode->GetContent();
			ParseFieldName(property_name, field_name, AUGE_NAME_MAX);
			WebContext* pWebContext = augeGetWebContextInstance();
			pQuery->AddSubField(pWebContext->ParameterEncoding(field_name));
		}

		if(m_max_features>0)
		{
			pQuery->SetMaxFeatures(m_max_features);
		}
		if(m_offset>0)
		{
			pQuery->SetOffset(m_offset);
		}
		
		pxNodeSet->Release();

		return pQuery;
	}