|
/* 根据XDataDesc生成DB信息及Ident */
UINT32 SetDescToDBMAP(XDataDesc* lpDesc, XDataDesc* lpPrimayKey ,DESC_TO_DB_MAP *pstDescToDbMap)
{
UINT32 i, j, nCount, nSplit, nNum, nFld;
XDataDesc* lpTemp;
XTabDesc* lpTabDesc;
XDataDesc* lpCopyPk;
/* 校验参数是否正确 */
if ((NULL == lpDesc)||
(NULL == lpPrimayKey)||
(NULL == pstDescToDbMap)||
(NULL == pstDescToDbMap->pfTabToDb)||
(NULL == pstDescToDbMap->pfDescToMapId)||
(NULL == pstDescToDbMap->pfDescToTabName)||
(NULL == pstDescToDbMap->pfDescToFldName)||
(NULL == pstDescToDbMap->pfDescToPkFldName)||
(NULL == pstDescToDbMap->pfGetTabSplitUnit))
{
return 0xFFFFFFFF;
}
/* 优先进行递归调用自定义生成DBMAP的函数,同时统计XDataDesc中非自定义格式的个数 */
i = 0;
lpTemp = lpDesc;
while(NULL != lpTemp)
{
lpTemp = lpTemp->lpNext;
if ((lpTemp->nType >= DATA_TYPE_BUTT)||
(NULL == x_stDescMap[lpTemp->nType].pfDescToDbMap))
{
i++;
}
else
{
if (lpTemp->nType < DATA_TYPE_BUTT)
{
nCount = (*(x_stDescMap[lpTemp->nType].pfDescToDbMap))(lpTemp, lpPrimayKey, pstDescToDbMap);
if (0!= nCount)
{
return nCount;
}
}
}
}
/* 获取对表进行分割的单位 */
nSplit = (*(pstDescToDbMap->pfGetTabSplitUnit))(pstDescToDbMap->lpGetTabSplitUnit);
/* 获取表的主键个数 */
nCount = 0;
lpTemp = lpPrimayKey;
while(NULL != lpTemp)
{
lpTemp = lpTemp->lpNext;
nCount++;
}
/* 主键个数不能大于表分割的最小单位,大于就无法分割了 */
if (nCount >= nSplit)
{
return 0xFFFFFFFF;
}
/* 至少一个字段数 */
if (nCount + i == 0) /* 大于某个数值,也可以设置为非法 */
{
return 0xFFFFFFFF;
}
/* 计算需要分割成几张表,允许全是主键 */
nNum = (i / (nSplit - nCount)) + 1;
/* 对于余数为0的情况,需要减一 */
if (( 0 != i )&&( 0 == (i % (nSplit - nCount)) ))
{
nNum --;
} |
|