7 #include "Reflex/Type.h"
10 static std::string s_sequenceName(
"CONTAINER_ID");
11 return s_sequenceName;
15 std::string
ret(
"C_");
16 return ret+containerName;
22 std::string
ret(containerName);
29 static std::string s_mappingSequenceName(
"MAPPING_ELEMENT_ID");
30 return s_mappingSequenceName;
36 static std::string s_propertyName(
"mapping");
37 return s_propertyName;
42 return (mappingProperty ==
"Blob" || mappingProperty ==
"blob" || mappingProperty ==
"BLOB" );
47 const std::string& classVersion ){
48 return className+
".V"+classVersion;
53 size_t idx = classId.find(
'.');
54 if( idx != std::string::npos ){
55 ret = classId.substr( idx+2 );
62 return className+
"."+baseClassVersion();
68 static std::string classVersion(
"BASE");
73 std::pair<bool,std::string>
ret(
false,
"");
74 size_t cut = classId.find(
"."+baseClassVersion() );
75 if( cut != std::string::npos ){
77 ret.second = classId.substr(0,cut);
85 std::string classVersion(className);
86 classVersion.append(
"_default");
93 static std::string s_propertyName(
"class_version");
94 return s_propertyName;
101 char versionTrailer ){
102 std::ostringstream os;
104 os <<
"_" << versionTrailer;
105 if ( iteration > 0 ) {
106 if ( iteration < 10 ) os <<
"0";
107 if ( iteration < 100 ) os <<
"0";
118 return newMappingVersion( containerName, iteration,
'M' );
126 std::string contDependencyName = containerName+
"_"+
className;
127 return newMappingVersion( contDependencyName, iteration,
'D' );
132 const std::string& scope ){
133 std::stringstream scopedName;
134 if(!scope.empty()) scopedName << scope <<
"::";
135 scopedName << variableName;
136 return scopedName.str();
141 unsigned int index ){
142 std::ostringstream arrayElementLabel;
143 arrayElementLabel << arrayVariable <<
"[" << index <<
"]";
144 return arrayElementLabel.str();
149 std::ostringstream arrayElementLabel;
150 arrayElementLabel <<
"I" << arrayIndex;
151 return arrayElementLabel.str();
156 std::stringstream contentTypeName;
157 contentTypeName <<
"A" << array.ArrayLength();
158 return contentTypeName.str();
162 static std::string s_cv(
"CV");
167 static std::string s_ck(
"CK");
173 const std::string& scope ){
174 std::stringstream scopedName;
175 if(!scope.empty()) scopedName << formatName(scope, ClassNameLengthForSchema) <<
"_";
176 scopedName << variableName;
177 return scopedName.str();
183 static std::string
validChars(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-0123456789");
185 for(
size_t i=0;
i<s.size();
i++){
187 std::stringstream mess;
188 mess <<
" code="<<code<<
" in string ["<<s<<
"] found a wrong char=["<<s[
i]<<
"].";
201 unsigned int digitsForPostfix = 3;
202 if(index<10) digitsForPostfix = 2;
203 size_t newSize = initialName.size()+digitsForPostfix;
204 if(newSize > maxLength) newSize = maxLength;
205 unsigned int cutSize = newSize - digitsForPostfix;
206 std::stringstream newStr(
"");
207 if( initialName[cutSize-1]==
'_' ) cutSize -= 1;
208 std::string cutString = initialName.substr(0, cutSize );
209 newStr << cutString <<
"_";
210 if( indexTrailer !=0 ) newStr<< indexTrailer;
221 return newNameForSchemaObject( initialName, index, maxLength,
'D' );
229 return newNameForSchemaObject( initialName, index, maxL,
'A' );
234 std::string varName( variableName );
237 std::transform(varName.begin(), varName.end(),varName.begin(),up);
238 size_t cutPoint = varName.size();
239 if(cutPoint && varName[varName.size()-1] ==
'_' ) cutPoint -= 1;
240 if(!cutPoint)
return "";
242 if(varName.size() && varName[0]==
'_' ) start = 1;
243 return varName.substr(start,cutPoint);
248 if( !maxL )
return "";
249 if( className.size() < maxL )
return className;
250 std::vector< size_t> uppers;
251 for(
size_t i=0;
i<className.size();
i++) {
252 if(::isupper(className[
i]) || ::isdigit(className[i]) ) uppers.push_back(i);
254 std::stringstream shName;
255 size_t usize = uppers.size();
258 size_t cut = maxL-usize;
259 if( usize && (cut > uppers[0]) ) cut = uppers[0];
260 shName << className.substr( start, cut );
261 size_t left = maxL-cut-usize;
262 if( usize > 1) left = 0;
264 for(
size_t i=0;
i<usize;
i++){
265 size_t st = uppers[
i];
267 shName << className.substr(st,left+1);
270 size_t maxIndex = className.size();
271 if( shName.str().size()<maxL && curs < maxIndex ){
272 size_t more = maxL - shName.str().size();
273 size_t max = curs+more;
274 if(max > className.size()) max = className.size();
275 for(
size_t j=curs;
j<max-1;
j++ ){
276 shName << className[
j];
282 shName << className[0];
283 for(
size_t i=0 ;
i<maxL-1;
i++) {
284 if( uppers[
i] != 0 ) shName << className[uppers[
i]];
294 if( !maxLength )
return "";
295 std::string cn = scopedClassName;
297 size_t ns = cn.rfind(
"::");
298 if( ns!= std::string::npos ){
299 cn = scopedClassName.substr( ns+2 );
300 sn = scopedClassName.substr( 0, ns );
304 while( ns != std::string::npos ){
305 cn = cn.replace( ns, 1,
"_");
314 while( ns != std::string::npos ){
315 sn = sn.replace( ns, 2,
"_");
319 if( sn[sn.size()-1]==
'_' ) sn = sn.substr(0,sn.size()-1);
321 if( sn ==
"std" ) sn =
"";
323 size_t currSize = sn.size()+cn.size()+1;
324 if( currSize > maxLength+1 ){
326 size_t maxScopeLen = maxLength/3;
327 if( maxScopeLen ==0 ) maxScopeLen = 1;
328 if( maxScopeLen > 1 ) maxScopeLen -= 1;
329 if( sn.size() > maxScopeLen ){
330 sn = sn.substr( 0,maxScopeLen );
332 size_t availableSize = maxLength-sn.size();
333 if( sn.size() ) availableSize -= 1;
334 cn =shortNameByUpperCase( cn, availableSize );
336 std::string
ret = sn;
337 if(!ret.empty()) ret +=
"_";
345 if( !maxLength )
return "";
346 std::string newName(
"");
347 size_t ind0 = templateClassName.find(
'<',0);
348 if( ind0 != std::string::npos ){
349 size_t ind1 = templateClassName.rfind(
'>');
350 std::string templArg = templateClassName.substr( ind0+1, ind1-ind0-1 );
351 std::string
prefix = shortScopedName( templateClassName.substr( 0, ind0 ), maxLength );
352 size_t currSize = templArg.size()+prefix.size()+1;
353 if( currSize > maxLength+1 ){
355 size_t prefixL = maxLength/3;
356 if( prefixL == 0 ) prefixL = 1;
357 if( prefixL >1 ) prefixL -=1;
358 prefix = shortScopedName( prefix, prefixL );
360 size_t templMaxSize = maxLength-prefix.size()-1;
361 templArg = nameFromTemplate( templArg, templMaxSize );
362 newName = prefix+
"_"+ templArg;
364 newName = shortScopedName( templateClassName, maxLength );
373 return "ORA_C_"+nameForSchema(formatName( itemName, MaxTableNameLength-5 ));
379 return std::string(
"ID");
385 return std::string(
"REF_ID");
390 const std::string& scopeName,
393 std::ostringstream totalString;
394 int scopeMaxSize = MaxColumnNameLength/4-1;
395 int extraSize = MaxColumnNameLength-variableName.size()-2;
396 if( extraSize>0 && extraSize>scopeMaxSize ) scopeMaxSize = extraSize;
397 if( !scopeName.empty() ) {
398 size_t scopeCut = scopeName.size();
399 if( scopeCut> (
size_t)scopeMaxSize ) scopeCut = scopeMaxSize;
400 totalString << scopeName.substr(0,scopeCut);
403 size_t varMaxSize = MaxColumnNameLength-totalString.str().size();
405 size_t fp = variableName.find(
'[');
406 if( fp != std::string::npos ){
408 std::string arrayVar = variableName.substr(0,fp);
409 std::string indexVar = variableName.substr(fp);
410 for(
size_t ind = 0; ind!=std::string::npos; ind=indexVar.find(
'[',ind+1 ) ){
411 indexVar = indexVar.replace(ind,1,
"I");
413 for(
size_t ind = indexVar.find(
']'); ind!=std::string::npos; ind=indexVar.find(
']',ind+1 ) ){
414 indexVar = indexVar.replace(ind,1,
"_");
416 size_t arrayVarCut = 0;
417 size_t varCut = variableName.size()+1;
418 if( varCut>varMaxSize ) varCut = varMaxSize;
419 if( varCut>(indexVar.size()+1) ) arrayVarCut = varCut-indexVar.size()-1;
420 totalString << arrayVar.substr(0,arrayVarCut);
421 totalString <<
"_" << indexVar;
423 size_t varCut = variableName.size();
424 if( varCut>varMaxSize ) varCut = varMaxSize;
426 totalString << variableName.substr(0,varCut);
429 std::stringstream
ret;
430 if(forData) ret <<
"D";
431 ret << nameForSchema(totalString.str());
433 return formatName(ret.str(),MaxColumnNameLength);
438 const std::string& scope,
441 std::stringstream
ret;
442 ret <<
"R" << columnNameForVariable( variableName, scope,
false )<<
"_OID"<<
index;
448 const std::string& scope )
450 std::stringstream
ret;
451 ret <<
"R" << columnNameForVariable( variableName, scope,
false )<<
"_NAME";
457 const std::string& scope )
459 std::stringstream
ret;
460 ret <<
"M" << columnNameForVariable( variableName, scope,
false );
466 const std::string& scope )
468 std::stringstream
ret;
469 ret <<
"RID_" << columnNameForVariable( variableName, scope,
false );
476 return std::string(
"POS");
482 std::stringstream
ret;
483 ret << tableName <<
"_ID_FK";
484 if( index ) ret <<
"_"<<
index;
490 return nameFromTemplate( variableName, maxLength );
static std::string columnNameForRefId(const std::string &variableName, const std::string &scope)
static std::string variableNameForArrayIndex(const std::string &arrayVariable, unsigned int index)
static std::string scopedVariableName(const std::string &variableName, const std::string &scope)
variable name manipulation
static std::string newMappingVersionForContainer(const std::string &containerName, int iteration)
mapping versions
static std::string variableNameForContainerKey()
static std::string variableNameForArrayColumn(unsigned int arrayIndex)
static std::string variableNameForContainerValue()
static std::string newNameForDepSchemaObject(const std::string &initialName, unsigned int index, size_t maxLength)
static std::string baseIdForClass(const std::string &className)
static std::string scopedVariableForSchemaObjects(const std::string &variableName, const std::string &scope)
static std::string validChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-0123456789")
static std::string shortScopedName(const std::string &scopedClassName, size_t maxLength)
static std::string columnNameForRefColumn()
static std::string columnNameForVariable(const std::string &variableName, const std::string &scope, bool forData=true)
static std::string mappingPropertyNameInDictionary()
class related parameters
static std::string columnNameForPosition()
const T & max(const T &a, const T &b)
static std::string shortNameByUpperCase(const std::string &className, size_t maxLength)
static std::string sequenceNameForMapping()
static std::string defaultClassVersion(const std::string &className)
static std::string newMappingVersion(const std::string &itemName, int iteration, char versionTrailer)
static std::string columnNameForOID(const std::string &variableName, const std::string &scope, unsigned int index)
static std::string newNameForArraySchemaObject(const std::string &initialName, unsigned int index, size_t maxLength)
static bool isMappedToBlob(const std::string &mappingProperty)
static std::string columnNameForId()
static std::string classVersionFromId(const std::string &classId)
static std::pair< bool, std::string > classNameFromBaseId(const std::string &classId)
void checkString(const std::string &s, int code, bool thro=true)
static std::string columnNameForRefMetadata(const std::string &variableName, const std::string &scope)
static std::string nameFromTemplate(const std::string templateClassName, size_t maxLength)
static std::string baseClassVersion()
static std::string columnNameForNamedReference(const std::string &variableName, const std::string &scope)
static std::string nameForSchema(const std::string &variableName)
static std::string classId(const std::string &className, const std::string &classVersion)
static std::string sequenceNameForContainer(const std::string &containerName)
static std::string tableNameForItem(const std::string &itemName)
schema object naming
static std::string sequenceNameForContainerId()
sequence names
void throwException(const std::string &message, const std::string &methodName)
static std::string newMappingVersionForDependentClass(const std::string &containerName, const std::string &className, int iteration)
static std::string sequenceNameForDependentClass(const std::string &containerName, const std::string &className)
static std::string classVersionPropertyNameInDictionary()
static std::string newNameForSchemaObject(const std::string &initialName, unsigned int index, size_t maxLength, char indexTrailer=0)
functions for new schema object name generation
static std::string formatName(const std::string &variableName, size_t maxLength)
formatting for variable names to schema object names
static std::string fkNameForIdentity(const std::string &tableName, int index=0)
std::string className(const T &t)