2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.vaadin
.util
;
11 import java
.sql
.DatabaseMetaData
;
12 import java
.sql
.SQLException
;
13 import java
.util
.Locale
;
15 import org
.apache
.log4j
.Logger
;
19 * The methods correctCase and isEscaped have been inspired from the
20 * org.dbunit.util.SQLHelper class
26 public class SQLUtils
{
28 private static final Logger logger
= Logger
.getLogger(SQLUtils
.class);
30 public static String
correctCase(final String databaseIdentifier
, DatabaseMetaData databaseMetaData
) throws SQLException
32 String resultIdentifier
= databaseIdentifier
;
33 String dbIdentifierQuoteString
= databaseMetaData
.getIdentifierQuoteString();
34 if(!isEscaped(databaseIdentifier
, dbIdentifierQuoteString
)){
35 if(databaseMetaData
.storesLowerCaseIdentifiers()) {
36 resultIdentifier
= databaseIdentifier
.toLowerCase(Locale
.ENGLISH
);
38 else if(databaseMetaData
.storesUpperCaseIdentifiers()) {
39 resultIdentifier
= databaseIdentifier
.toUpperCase(Locale
.ENGLISH
);
42 return resultIdentifier
;
46 private static final boolean isEscaped(String tableName
, String dbIdentifierQuoteString
) {
47 return tableName
!=null && dbIdentifierQuoteString
!= null && (tableName
.startsWith(dbIdentifierQuoteString
));