Is _applyMaxStringIndexLengthLimitation() method implemented correctly??Is _applyMaxStringIndexLengthLimitation() method implemented correctly??https://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1211614632024-03-29T15:58:34Z2024-03-29T15:58:34ZIs _applyMaxStringIndexLengthLimitation() method implemented correctly??Rupal Chatterjeehttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1211614622021-10-04T17:03:56Z2021-09-22T10:15:09Z<p>Hello Everyone,</p>
<p>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.</p>
<pre>
<code class="language-java">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();
} </code></pre>
<p> </p>
<p>As per the implementation, if the query contains anything that
matches <strong>[$COLUMN_LENGTH:</strong> and the column length value
is greater than the value mentioned in <em>
<strong>database.string.index.max.length[DB_NAME]</strong></em>
property, it will replace the matched value in the query with <strong>(stringIndexMaxLength)</strong>.</p>
<p>Is this correct implementation??? Because for Oracle database and <em>
<strong>database.string.index.max.length[oracle]=1000</strong></em>,
it is generating a creating index query as below and ending up
throwing an exception <u>
<em>ORA-00904: "SAMLSPENTITYID": invalid identifier_</em></u></p>
<pre>
<code class="language-java">From:
create index IX_87463CFB on SamlIdpSpConnection (companyId, samlSpEntityId[$COLUMN_LENGTH:1024$]);
To:
create index IX_87463CFB on SamlIdpSpConnection (companyId, samlSpEntityId(1000));</code></pre>
<p> </p>
<p>With Regards</p>
<p>Rupal Chatterjee<