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(
"D_");
30 static std::string s_mappingSequenceName(
"MAPPING_ELEMENT_ID");
31 return s_mappingSequenceName;
37 static std::string s_propertyName(
"mapping");
38 return s_propertyName;
43 return (mappingProperty ==
"Blob" || mappingProperty ==
"blob" || mappingProperty ==
"BLOB" );
48 static std::string s_propertyName(
"persistency");
49 return s_propertyName;
54 return (persistencyProperty ==
"loose_on_reading" || persistencyProperty ==
"LOOSE_ON_READING" );
59 return (persistencyProperty ==
"loose_on_writing" || persistencyProperty ==
"LOOSE_ON_WRITING" );
64 const std::string& classVersion ){
65 return className+
".V"+classVersion;
70 size_t idx = classId.find(
'.');
71 if( idx != std::string::npos ){
72 ret = classId.substr( idx+2 );
79 return className+
"."+baseClassVersion();
85 static std::string classVersion(
"BASE");
90 std::pair<bool,std::string>
ret(
false,
"");
91 size_t cut = classId.find(
"."+baseClassVersion() );
92 if( cut != std::string::npos ){
94 ret.second = classId.substr(0,cut);
102 std::string classVersion(className);
103 classVersion.append(
"_default");
110 static std::string s_propertyName(
"class_version");
111 return s_propertyName;
118 char versionTrailer ){
119 std::ostringstream os;
121 os <<
"_" << versionTrailer;
122 if ( iteration > 0 ) {
123 if ( iteration < 10 ) os <<
"0";
124 if ( iteration < 100 ) os <<
"0";
135 return newMappingVersion( containerName, iteration,
'M' );
143 std::string contDependencyName = containerName+
"_"+
className;
144 return newMappingVersion( contDependencyName, iteration,
'D' );
149 const std::string& scope ){
150 std::stringstream scopedName;
151 if(!scope.empty()) scopedName << scope <<
"::";
152 scopedName << variableName;
153 return scopedName.str();
158 unsigned int index ){
159 std::ostringstream arrayElementLabel;
160 arrayElementLabel << arrayVariable <<
"[" << index <<
"]";
161 return arrayElementLabel.str();
166 std::ostringstream arrayElementLabel;
167 arrayElementLabel <<
"I" << arrayIndex;
168 return arrayElementLabel.str();
173 std::stringstream contentTypeName;
174 contentTypeName <<
"A" << array.ArrayLength();
175 return contentTypeName.str();
179 static std::string s_cv(
"CV");
184 static std::string s_ck(
"CK");
190 const std::string& scope ){
191 std::stringstream scopedName;
192 if(!scope.empty()) scopedName << formatName(scope, ClassNameLengthForSchema) <<
"_";
193 scopedName << variableName;
194 return scopedName.str();
200 static std::string
validChars(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-0123456789");
202 for(
size_t i=0;
i<s.size();
i++){
204 std::stringstream mess;
205 mess <<
" code="<<code<<
" in string ["<<s<<
"] found a wrong char=["<<s[
i]<<
"].";
218 unsigned int digitsForPostfix = 3;
219 if(index<10) digitsForPostfix = 2;
220 size_t newSize = initialName.size()+digitsForPostfix;
221 if(newSize > maxLength) newSize = maxLength;
222 unsigned int cutSize = newSize - digitsForPostfix;
223 std::stringstream newStr(
"");
224 if( initialName[cutSize-1]==
'_' ) cutSize -= 1;
225 std::string cutString = initialName.substr(0, cutSize );
226 newStr << cutString <<
"_";
227 if( indexTrailer !=0 ) newStr<< indexTrailer;
238 return newNameForSchemaObject( initialName, index, maxLength,
'D' );
246 return newNameForSchemaObject( initialName, index, maxL,
'A' );
251 std::string varName( variableName );
254 std::transform(varName.begin(), varName.end(),varName.begin(),up);
255 size_t cutPoint = varName.size();
256 if(cutPoint && varName[varName.size()-1] ==
'_' ) cutPoint -= 1;
257 if(!cutPoint)
return "";
259 if(varName.size() && varName[0]==
'_' ) start = 1;
260 return varName.substr(start,cutPoint);
265 if( !maxL )
return "";
266 if( className.size() < maxL )
return className;
267 std::vector< size_t> uppers;
268 for(
size_t i=0;
i<className.size();
i++) {
269 if(::isupper(className[
i]) || ::isdigit(className[i]) ) uppers.push_back(i);
271 std::stringstream shName;
272 size_t usize = uppers.size();
275 size_t cut = maxL-usize;
276 if( usize && (cut > uppers[0]) ) cut = uppers[0];
277 shName << className.substr( start, cut );
278 size_t left = maxL-cut-usize;
279 if( usize > 1) left = 0;
281 for(
size_t i=0;
i<usize;
i++){
282 size_t st = uppers[
i];
284 shName << className.substr(st,left+1);
287 size_t maxIndex = className.size();
288 if( shName.str().size()<maxL && curs < maxIndex ){
289 size_t more = maxL - shName.str().size();
290 size_t max = curs+more;
291 if(max > className.size()) max = className.size();
292 for(
size_t j=curs;
j<max-1;
j++ ){
293 shName << className[
j];
299 shName << className[0];
300 for(
size_t i=0 ;
i<maxL-1;
i++) {
301 if( uppers[
i] != 0 ) shName << className[uppers[
i]];
311 if( !maxLength )
return "";
312 std::string cn = scopedClassName;
314 size_t ns = cn.rfind(
"::");
315 if( ns!= std::string::npos ){
316 cn = scopedClassName.substr( ns+2 );
317 sn = scopedClassName.substr( 0, ns );
321 while( ns != std::string::npos ){
322 cn = cn.replace( ns, 1,
"_");
331 while( ns != std::string::npos ){
332 sn = sn.replace( ns, 2,
"_");
336 if( sn[sn.size()-1]==
'_' ) sn = sn.substr(0,sn.size()-1);
338 if( sn ==
"std" ) sn =
"";
340 size_t currSize = sn.size()+cn.size()+1;
341 if( currSize > maxLength+1 ){
343 size_t maxScopeLen = maxLength/3;
344 if( maxScopeLen ==0 ) maxScopeLen = 1;
345 if( maxScopeLen > 1 ) maxScopeLen -= 1;
346 if( sn.size() > maxScopeLen ){
347 sn = sn.substr( 0,maxScopeLen );
349 size_t availableSize = maxLength-sn.size();
350 if( sn.size() ) availableSize -= 1;
351 cn =shortNameByUpperCase( cn, availableSize );
353 std::string
ret = sn;
354 if(!ret.empty()) ret +=
"_";
362 if( !maxLength )
return "";
363 std::string tempClassName(templateClassName);
364 size_t indComas = tempClassName.find(
',',0);
365 std::vector<size_t> vComas;
366 while(indComas != std::string::npos) {
367 vComas.push_back(indComas);
368 indComas = tempClassName.find(
',',indComas+1);
370 typedef std::vector<size_t>::const_iterator vSizeIter;
371 vSizeIter vBegin = vComas.begin();
372 vSizeIter vEnd = vComas.end();
373 for(vSizeIter
i = vBegin;
i != vEnd; ++
i) {
374 tempClassName.replace(*
i, 1, 1,
'_');
376 std::string newName(
"");
377 size_t ind0 = tempClassName.find(
'<',0);
378 if( ind0 != std::string::npos ){
379 size_t ind1 = tempClassName.rfind(
'>');
380 std::string templArg = tempClassName.substr( ind0+1, ind1-ind0-1 );
381 std::string
prefix = shortScopedName( tempClassName.substr( 0, ind0 ), maxLength );
382 size_t currSize = templArg.size()+prefix.size()+1;
383 if( currSize > maxLength+1 ){
385 size_t prefixL = maxLength/3;
386 if( prefixL == 0 ) prefixL = 1;
387 if( prefixL >1 ) prefixL -=1;
388 prefix = shortScopedName( prefix, prefixL );
390 size_t templMaxSize = maxLength-prefix.size()-1;
391 templArg = nameFromTemplate( templArg, templMaxSize );
392 newName = prefix+
"_"+ templArg;
394 newName = shortScopedName( tempClassName, maxLength );
403 return "ORA_C_"+nameForSchema(formatName( itemName, MaxTableNameLength-5 ));
409 return std::string(
"ID");
415 return std::string(
"REF_ID");
420 const std::string& scopeName,
423 std::ostringstream totalString;
424 int scopeMaxSize = MaxColumnNameLength/4-1;
425 int extraSize = MaxColumnNameLength-variableName.size()-2;
426 if( extraSize>0 && extraSize>scopeMaxSize ) scopeMaxSize = extraSize;
427 if( !scopeName.empty() ) {
428 size_t scopeCut = scopeName.size();
429 if( scopeCut> (
size_t)scopeMaxSize ) scopeCut = scopeMaxSize;
430 totalString << scopeName.substr(0,scopeCut);
433 size_t varMaxSize = MaxColumnNameLength-totalString.str().size();
435 size_t fp = variableName.find(
'[');
436 if( fp != std::string::npos ){
438 std::string arrayVar = variableName.substr(0,fp);
439 std::string indexVar = variableName.substr(fp);
440 for(
size_t ind = 0; ind!=std::string::npos; ind=indexVar.find(
'[',ind+1 ) ){
441 indexVar = indexVar.replace(ind,1,
"I");
443 for(
size_t ind = indexVar.find(
']'); ind!=std::string::npos; ind=indexVar.find(
']',ind+1 ) ){
444 indexVar = indexVar.replace(ind,1,
"_");
446 size_t arrayVarCut = 0;
447 size_t varCut = variableName.size()+1;
448 if( varCut>varMaxSize ) varCut = varMaxSize;
449 if( varCut>(indexVar.size()+1) ) arrayVarCut = varCut-indexVar.size()-1;
450 totalString << arrayVar.substr(0,arrayVarCut);
451 totalString <<
"_" << indexVar;
453 size_t varCut = variableName.size();
454 if( varCut>varMaxSize ) varCut = varMaxSize;
456 totalString << variableName.substr(0,varCut);
459 std::stringstream
ret;
460 if(forData) ret <<
"D";
461 ret << nameForSchema(totalString.str());
463 return formatName(ret.str(),MaxColumnNameLength);
468 const std::string& scope,
471 std::stringstream
ret;
472 ret <<
"R" << columnNameForVariable( variableName, scope,
false )<<
"_OID"<<
index;
478 const std::string& scope )
480 std::stringstream
ret;
481 ret <<
"R" << columnNameForVariable( variableName, scope,
false )<<
"_NAME";
487 const std::string& scope )
489 std::stringstream
ret;
490 ret <<
"M" << columnNameForVariable( variableName, scope,
false );
496 const std::string& scope )
498 std::stringstream
ret;
499 ret <<
"RID_" << columnNameForVariable( variableName, scope,
false );
506 return std::string(
"POS");
512 return prefix + dataColumnName.substr(1);
518 std::stringstream
ret;
519 ret << tableName <<
"_ID_FK";
520 if( index ) ret <<
"_"<<
index;
526 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 persistencyPropertyNameInDictionary()
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 bool isLooseOnReading(const std::string &persistencyProperty)
static std::string columnNameForBlobMetadata(const std::string &dataColumnName)
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 bool isLooseOnWriting(const std::string &persistencyProperty)
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)