コード例 #1
0
	bool TransactionHandler::Insert(XNode* pxInsert, WebContext* pWebContext, FeatureWorkspace* pWorkspace)
	{	
		XNode* pxType = pxInsert->GetFirstChild();
		if(pxType==NULL)
		{
			return false;
		}

		GLogger* pLogger = augeGetLoggerInstance();
		GError*  pError  = augeGetErrorInstance();
		RESULTCODE rc = AG_FAILURE;

		const char* name = pxType->GetName();
		FeatureClass* pFeatureClass = NULL;
		pFeatureClass = pWorkspace->OpenFeatureClass(name);
		if(pFeatureClass==NULL)
		{
			char msg[AUGE_MSG_MAX];
			g_snprintf(msg, AUGE_MSG_MAX, "Fail to get FeatureClass [%s]", name);
			pLogger->Error(msg, __FILE__, __LINE__);
			pError->SetError(msg);
			return false;
		}

		Feature* pFeature = pFeatureClass->NewFeature();
		if(pFeature==NULL)
		{
			return false;
		}

		GField	*pField  = NULL;
		GFields	*pFields = pFeatureClass->GetFields();
		const char* fname = NULL;
		bool ok = true;

		GValue* pValue = NULL;
		XNode* pxNode = NULL;
		XNodeSet* pxNodeSet = pxType->GetChildren();
		pxNodeSet->Reset();
		while((pxNode=pxNodeSet->Next())!=NULL)
		{
			fname = pxNode->GetName();
			pField = pFields->GetField(fname);
			if(pField!=NULL)
			{
				pValue = CreateValue(pxNode, pField);
				if(pValue!=NULL)
				{
					pFeature->SetValue(fname, pValue);
				}
				else
				{
					char msg[AUGE_MSG_MAX];
					g_snprintf(msg, AUGE_MSG_MAX, "Field [%s]: Invalid Value", fname);
					pLogger->Error(msg, __FILE__, __LINE__);
					pError->SetError(msg);

					ok = false;
					break;
				}
			}
			else
			{
				char msg[AUGE_MSG_MAX];
				g_snprintf(msg, AUGE_MSG_MAX, "FeatureClss does not have Field [%s]", fname);
				pLogger->Error(msg, __FILE__, __LINE__);
				pError->SetError(msg);
				
				ok = false;
				break;
			}
		}
		pxNodeSet->Release();

		if(ok)
		{
			FeatureInsertCommand* cmd = pFeatureClass->CreateInsertCommand();
			rc = cmd->Insert(pFeature);
			AUGE_SAFE_RELEASE(cmd);	
		}		

		AUGE_SAFE_RELEASE(pFeature);		
		AUGE_SAFE_RELEASE(pFeatureClass);

		return !rc;
	}
コード例 #2
0
	bool TransactionHandler::Insert(XNode* pxInsert, WebContext* pWebContext, Map* pMap)
	{	
		XNode* pxLayer = pxInsert->GetFirstChild();
		if(pxLayer==NULL)
		{
			return false;
		}
		const char* name = pxLayer->GetName();
		Layer *pLayer = pMap->GetLayer(name);
		if(pLayer==NULL)
		{
			return false;
		}

		augeLayerType ltype = pLayer->GetType();
		if(ltype != augeLayerFeature)
		{
			return false;
		}

		FeatureLayer* pFeatureLayer = NULL;
		pFeatureLayer = static_cast<FeatureLayer*>(pLayer);
		
		FeatureClass* pFeatureClass = NULL;
		pFeatureClass = pFeatureLayer->GetFeatureClass();
		if(pFeatureClass==NULL)
		{
			return false;
		}

		Feature* pFeature = pFeatureClass->NewFeature();
		if(pFeature==NULL)
		{
			return false;
		}

		GField	*pField  = NULL;
		GFields	*pFields = pFeatureClass->GetFields();
		const char* fname = NULL;

		GValue* pValue = NULL;
		XNode* pxNode = NULL;
		XNodeSet* pxNodeSet = pxLayer->GetChildren();
		pxNodeSet->Reset();
		while((pxNode=pxNodeSet->Next())!=NULL)
		{
			fname = pxNode->GetName();
			pField = pFields->GetField(fname);
			if(pField!=NULL)
			{
				pValue = CreateValue(pxNode, pField);
				if(pValue!=NULL)
				{
					pFeature->SetValue(fname, pValue);
				}
			}
		}
		pxNodeSet->Release();

		FeatureInsertCommand* cmd = pFeatureClass->CreateInsertCommand();
		RESULTCODE rc = cmd->Insert(pFeature);
		
		AUGE_SAFE_RELEASE(pFeature);
		AUGE_SAFE_RELEASE(cmd);

		return !rc;
	}