Пример #1
0
bool DataSourceInterface::executeInsertInternal(Query& query, void* entity) {
	DataSourceEntityMapping dsemp = mapping->getDataSourceEntityMapping(query.getClassName());
	ClassInfo clas = reflector->getClassInfo(query.getClassName(), appName);

	if(dsemp.isIdGenerate() && dsemp.getIdgendbEntityType()!="identity") {
		assignId(dsemp, clas, entity);
	}

	bool flag = executeInsert(query, entity);

	if(flag && dsemp.isIdGenerate() && dsemp.getIdgendbEntityType()=="identity") {
		assignId(dsemp, clas, entity);
	}

	return flag;
}
Пример #2
0
DataSourceInterface* DataSourceManager::getImpl(string name) {
	string appName = CommonUtils::getAppName();
	StringUtil::trim(name);
	if(name=="") {
		name = defDsnName;
	}
	name = appName + name;
	if(dsns.find(name)==dsns.end())
	{
		throw "Data Source Not found...";
	}
	DataSourceManager* dsnMgr = dsns[name];
	DataSourceInterface* t = NULL;
	if(StringUtil::toLowerCopy(dsnMgr->props.getType())=="sql")
	{
#ifdef INC_SDORM_SQL
		t = new SQLDataSourceImpl(dsnMgr->pool, &dsnMgr->mapping);
#endif
	}
	else if(StringUtil::toLowerCopy(dsnMgr->props.getType())=="mongo")
	{
#ifdef INC_SDORM_MONGO
		t = new MongoDBDataSourceImpl(dsnMgr->pool, &dsnMgr->mapping);
#endif
	}
	if(t == NULL)
	{
		return NULL;
	}
	t->appName = dsnMgr->mapping.getAppName();
	t->dlib = dlopen(INTER_LIB_FILE, RTLD_NOW);
	if(t->dlib == NULL)
	{
		cerr << dlerror() << endl;
		throw "Cannot load application shared library";
	}
	t->reflector = new Reflector(t->dlib);
	map<string, DataSourceEntityMapping>::iterator it;
	for(it=dsnMgr->mapping.getDseMap().begin();it!=dsnMgr->mapping.getDseMap().end();++it)
	{
		DataSourceEntityMapping dsemp = it->second;
		if(dsemp.isIdGenerate())
		{
			t->init(dsemp, true);
		}
	}
	return t;
}