'''
Created on Oct 14, 2011

@author: Pravin
'''
import appconfig as config
if config.env==config.SL:
    from orangescape.utils import basicutil
else:
    from orangescape.model.server.util import basicutil

PK_COL_LEN = 100
TBL_PREFIX = 'tbl'
SYS_PREFIX = 'sys'
TMP_PREFIX = 'temp'

MYSQL_COL_SIZE = 64

ATTACHMENT_TBL_NAME = 'Attachment'
VERSION_TBL_NAME = 'Version'
MODEL_VERSION_TBL_NAME = 'ModelVersion'

def getValidTableName(tableName):
    return str.lower(tableName)

def getValidSchemaName(schemaName):
    return str.lower(schemaName)

def getValidColumnName(colName):
    if len(colName)>= MYSQL_COL_SIZE:
        hashed_cellId = basicutil.calcCheckSum(colName)
        return 'Co'+hashed_cellId
    return colName

def getValidIndexName(indexName):
    hashed_cellId = basicutil.calcCheckSum(indexName)
    return hashed_cellId

def getPKName(metadata):
    return metadata.getSheetName()+'_Id'

def getOneToManyName(refCell, childMetadata):
    return refCell.getCellName()+'_'+childMetadata.getSheetName()

def getManyToOneName(refCell):
    return refCell.getSheetId()+'_obj'