Is _applyMaxStringIndexLengthLimitation() method implemented correctly??

Jamie Sammons, modified 4 Years ago. New Member Post: 1 Join Date: 9/22/21 Recent Posts

Hello Everyone,

I was going through the source code of Liferay libraries to find out the root cause of the issue, I faced during upgradation of our Liferay version from 7.2 to 7.3. Finally I came across this _applyMaxStringIndexLengthLimitation(String template) method implemented in com.liferay.portal.dao.db.BaseDB abstract class.

private String _applyMaxStringIndexLengthLimitation(String template) {
    if (!template.contains("[$COLUMN_LENGTH:"))
      return template; 
    DBType dbType = getDBType();
    int stringIndexMaxLength = GetterUtil.getInteger(PropsUtil.get("database.string.index.max.length", new Filter(dbType.getName())), -1);
    Matcher matcher = _columnLengthPattern.matcher(template);
    if (stringIndexMaxLength < 0)
      return matcher.replaceAll(""); 
    StringBuffer sb = new StringBuffer();
    String replacement = "\\(" + stringIndexMaxLength + "\\)";
    while (matcher.find()) {
      int length = Integer.valueOf(matcher.group(1)).intValue();
      if (length > stringIndexMaxLength) {
        matcher.appendReplacement(sb, replacement);
        continue;
      } 
      matcher.appendReplacement(sb, "");
    } 
    matcher.appendTail(sb);
    return sb.toString();
  } 

 

As per the implementation, if the query contains anything that matches [$COLUMN_LENGTH: and the column length value is greater than the value mentioned in  database.string.index.max.length[DB_NAME] property, it will replace the matched value in the query with (stringIndexMaxLength).

Is this correct implementation??? Because for Oracle database and database.string.index.max.length[oracle]=1000, it is generating a creating index query as below and ending up throwing an exception  ORA-00904: "SAMLSPENTITYID": invalid identifier_

From:
create index IX_87463CFB on SamlIdpSpConnection (companyId, samlSpEntityId[$COLUMN_LENGTH:1024$]);

To:
create index IX_87463CFB on SamlIdpSpConnection (companyId, samlSpEntityId(1000));

 

With Regards

Rupal Chatterjee