void HarvesterFactory::handleDatabaseJobComplete(void* ref,DatabaseResult* result) { QueryContainerBase* asyncContainer = reinterpret_cast<QueryContainerBase*>(ref); switch(asyncContainer->mQueryType) { case HFQuery_ResourceData: { uint32 count = (uint32)result->getRowCount(); HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(asyncContainer->mObject); if(count) { DataBinding* binding = mDatabase->createDataBinding(2); binding->addField(DFT_uint64,offsetof(HarvesterHopperItem,ResourceID),8,0); binding->addField(DFT_float,offsetof(HarvesterHopperItem,Quantity),4,1); HResourceList* hRList = harvester->getResourceList(); hRList->resize(hRList->size()+count); HarvesterHopperItem hopperTemp; for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&hopperTemp); hRList->push_back(std::make_pair(hopperTemp.ResourceID,hopperTemp.Quantity)); } } QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_AttributeData,asyncContainer->mClient,asyncContainer->mId); asynContainer->mId = harvester->getId(); asynContainer->mObject = harvester; mDatabase->executeSqlAsync(this,asynContainer,"SELECT attributes.name,sa.value,attributes.internal" " FROM %s.structure_attributes sa" " INNER JOIN %s.attributes ON (sa.attribute_id = attributes.id)" " WHERE sa.structure_id = %" PRIu64 " ORDER BY sa.order", mDatabase->galaxy(),mDatabase->galaxy(),harvester->getId()); } break; case HFQuery_AttributeData: { HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(asyncContainer->mObject); //_buildAttributeMap(harvester,result); Attribute_QueryContainer attribute; uint64 count = result->getRowCount(); //int8 str[256]; //BStringVector dataElements; for(uint64 i = 0; i < count; i++) { result->getNextRow(mAttributeBinding,(void*)&attribute); harvester->addInternalAttribute(attribute.mKey,std::string(attribute.mValue.getAnsi())); } harvester->setLoadState(LoadState_Loaded); LOG(info) << "Loaded harvester with id [" << harvester->getId() << "]"; asyncContainer->mOfCallback->handleObjectReady(harvester,asyncContainer->mClient); } break; case HFQuery_MainData: { QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_ResourceData,asyncContainer->mClient,asyncContainer->mId); HarvesterObject* harvester = new(HarvesterObject); _createHarvester(result,harvester); asynContainer->mObject = harvester; asynContainer->mClient = asyncContainer->mClient; //asyncContainer->mOfCallback->handleObjectReady(harvester,asyncContainer->mClient); //now request the associated resource container count int8 sql[250]; sprintf(sql,"SELECT hr.resourceID, hr.quantity FROM %s.harvester_resources hr WHERE hr.ID = '%" PRIu64 "' ",mDatabase->galaxy(),harvester->getId()); mDatabase->executeSqlAsync(this,asynContainer,sql); } break; default: break; } mQueryContainerPool.free(asyncContainer); }
void HarvesterFactory::handleDatabaseJobComplete(void* ref,swganh::database::DatabaseResult* result) { QueryContainerBase* asyncContainer = reinterpret_cast<QueryContainerBase*>(ref); switch(asyncContainer->mQueryType) { case HFQuery_ResourceData: { uint32 count = (uint32)result->getRowCount(); HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(asyncContainer->mObject); if(count) { swganh::database::DataBinding* binding = mDatabase->createDataBinding(2); binding->addField(swganh::database::DFT_uint64,offsetof(HarvesterHopperItem,ResourceID),8,0); binding->addField(swganh::database::DFT_float,offsetof(HarvesterHopperItem,Quantity),4,1); HResourceList* hRList = harvester->getResourceList(); hRList->resize(hRList->size()+count); HarvesterHopperItem hopperTemp; for(uint64 i=0; i <count; i++) { result->getNextRow(binding,&hopperTemp); hRList->push_back(std::make_pair(hopperTemp.ResourceID,hopperTemp.Quantity)); } } QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_AttributeData,asyncContainer->mClient,asyncContainer->mId); asynContainer->mId = harvester->getId(); asynContainer->mObject = harvester; mDatabase->executeSqlAsync(this,asynContainer,"SELECT attributes.name,sa.value,attributes.internal" " FROM %s.structure_attributes sa" " INNER JOIN %s.attributes ON (sa.attribute_id = attributes.id)" " WHERE sa.structure_id = %"PRIu64" ORDER BY sa.order", mDatabase->galaxy(),mDatabase->galaxy(),harvester->getId()); } break; case HFQuery_AttributeData: { HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(asyncContainer->mObject); //_buildAttributeMap(harvester,result); Attribute_QueryContainer attribute; uint64 count = result->getRowCount(); //int8 str[256]; //BStringVector dataElements; for(uint64 i = 0; i < count; i++) { result->getNextRow(mAttributeBinding,(void*)&attribute); harvester->addInternalAttribute(BString(attribute.mKey.c_str()),attribute.mValue); } QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_AdminData,asyncContainer->mClient,asyncContainer->mId); asynContainer->mId = harvester->getId(); asynContainer->mObject = harvester; std::stringstream sql; sql << "SELECT sad.PlayerID, sad.AdminType, c.firstname FROM " << mDatabase->galaxy() << ".structure_admin_data sad INNER JOIN " << mDatabase->galaxy() << ".characters c ON (c.id = sad.PlayerID) WHERE StructureID = " << harvester->getId() << ";"; mDatabase->executeSqlAsync(this, asynContainer, sql.str()); } break; case HFQuery_AdminData: { HarvesterObject* harvester = dynamic_cast<HarvesterObject*>(asyncContainer->mObject); std::unique_ptr<sql::ResultSet>& result_set = result->getResultSet(); while (result_set->next()) { std::string type = result_set->getString(2); if(type == "ADMIN") { harvester->admin_data_.admin_add_(result_set->getInt64(1), result_set->getString(3)); LOG(info) << " added Admin to harvester : " << harvester->getId(); } else if(type == "BAN") { harvester->admin_data_.ban_add_(result_set->getInt64(1), result_set->getString(3)); LOG(info) << " added ban to harvester : " << harvester->getId(); } else if(type == "ENTRY") { harvester->admin_data_.entry_add_(result_set->getInt64(1), result_set->getString(3)); LOG(info) << " added entry to harvester : " << harvester->getId(); } else if(type == "HOPPER") { harvester->admin_data_.entry_add_(result_set->getInt64(1), result_set->getString(3)); LOG(info) << " added entry to harvester : " << harvester->getId(); } } harvester->admin_data_.structure_id_ = harvester->getId(); harvester->admin_data_.owner_id_ = harvester->getOwner(); harvester->setLoadState(LoadState_Loaded); LOG(info) << "Loaded harvester with id [" << harvester->getId() << "]"; asyncContainer->mOfCallback->handleObjectReady(harvester,asyncContainer->mClient); } break; case HFQuery_MainData: { QueryContainerBase* asynContainer = new(mQueryContainerPool.ordered_malloc()) QueryContainerBase(asyncContainer->mOfCallback,HFQuery_ResourceData,asyncContainer->mClient,asyncContainer->mId); HarvesterObject* harvester = new(HarvesterObject); _createHarvester(result,harvester); asynContainer->mObject = harvester; asynContainer->mClient = asyncContainer->mClient; //asyncContainer->mOfCallback->handleObjectReady(harvester,asyncContainer->mClient); //now request the associated resource container count int8 sql[250]; sprintf(sql,"SELECT hr.resourceID, hr.quantity FROM %s.harvester_resources hr WHERE hr.ID = '%"PRIu64"' ",mDatabase->galaxy(),harvester->getId()); mDatabase->executeSqlAsync(this,asynContainer,sql); } break; default: break; } mQueryContainerPool.free(asyncContainer); }