8
15
public class PgDiffUtils {
18
* Array of reserved keywords. Non-reserved keywords are excluded. Source
19
* http://www.postgresql.org/docs/9.0/static/sql-keywords-appendix.html.
21
private static final String[] KEYWORDS = new String[]{
107
"CURRENT_DEFAULT_TRANSFORM_GROUP",
113
"CURRENT_TRANSFORM_GROUP_FOR_TYPE",
146
"DLURLCOMPLETEWRITE",
11
480
* Creates a new PgDiffUtils object.
13
482
private PgDiffUtils() {
18
* If <code>quoteName</code> is true then returns quoted name
19
* otherwise returns the original name.
486
* If name contains only lower case characters and digits and is not
487
* keyword, it is returned not quoted, otherwise the string is returned
21
490
* @param name name
22
* @param quoteName whether the name should be quoted
24
* @return if <code>quoteName</code> is true then returns quoted name
25
* otherwise returns the original name
491
* @param excludeKeywords whether check against keywords should be skipped
493
* @return quoted string if needed, otherwise not quoted string
27
495
public static String getQuotedName(final String name,
28
final boolean quoteName) {
29
return quoteName ? ("\"" + name + "\"") : name;
496
final boolean excludeKeywords) {
497
if (name.indexOf('-') != -1 || name.indexOf('.') != -1) {
498
return '"' + name + '"';
501
for (int i = 0; i < name.length(); i++) {
502
final char chr = name.charAt(i);
504
if (Character.isUpperCase(chr)) {
505
return '"' + name + '"';
509
if (excludeKeywords) {
513
final String upperName = name.toUpperCase(Locale.ENGLISH);
515
for (final String keyword : KEYWORDS) {
516
if (keyword.equals(upperName)) {
517
return '"' + name + '"';
525
* If name contains only lower case characters and digits and is not
526
* keyword, it is returned not quoted, otherwise the string is returned
531
* @return quoted string if needed, otherwise not quoted string
533
public static String getQuotedName(final String name) {
534
return getQuotedName(name, false);