Make use of better method names

This commit is contained in:
Yoryos Valotasios 2010-11-06 15:39:44 +02:00
parent d390f85544
commit 69ed7a9b88
2 changed files with 10 additions and 10 deletions

View File

@ -129,31 +129,31 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
int distinctIndex = sql.indexOf( DISTINCT );
if (distinctIndex > 0) {
sql.delete(distinctIndex, distinctIndex + DISTINCT.length() + 1);
sql.append(" group by").append(getSelectFieldsWithoutAs(sql));
sql.append(" group by").append(getSelectFieldsWithoutAliases(sql));
}
}
/**
* This utility method searches the given sql query for the fields of the select statement and
* returns them without the as statement. See {@link SQLServerDialectTestCase#testGetSelectFieldsWithoutAs()}
* returns them without the aliases. See {@link SQLServerDialectTestCase#testGetSelectFieldsWithoutAliases()}
*
* @param an sql query
* @return the fields of the select statement without their alias
*/
protected static CharSequence getSelectFieldsWithoutAs(StringBuilder sql) {
protected static CharSequence getSelectFieldsWithoutAliases(StringBuilder sql) {
String select = sql.substring( sql.indexOf(SELECT) + SELECT.length(), sql.indexOf(FROM));
// Strip the as clauses
return stripAsStatement( select );
return stripAliases( select );
}
/**
* Utility method that strips the as statements. See {@link SQLServerDialectTestCase#testStripAsStatement()}
* Utility method that strips the aliases. See {@link SQLServerDialectTestCase#testStripAliases()}
*
* @param a string to replace the as statements
* @return a string without the as statements
*/
protected static String stripAsStatement(String str) {
protected static String stripAliases(String str) {
return str.replaceAll( "\\sas[^,]+(,?)", "$1" );
}

View File

@ -10,15 +10,15 @@ import junit.framework.TestCase;
*/
public class SQLServerDialectTestCase extends TestCase {
public void testStripAsStatement() {
public void testStripAliases() {
String input = "some_field1 as f1, some_fild2 as f2, _field3 as f3 ";
assertEquals( "some_field1, some_fild2, _field3", SQLServerDialect.stripAsStatement(input) );
assertEquals( "some_field1, some_fild2, _field3", SQLServerDialect.stripAliases(input) );
}
public void testGetSelectFieldsWithoutAs() {
public void testGetSelectFieldsWithoutAliases() {
StringBuilder input = new StringBuilder( "select some_field1 as f12, some_fild2 as f879, _field3 as _f24674_3 from...." );
String output = SQLServerDialect.getSelectFieldsWithoutAs( input ).toString();
String output = SQLServerDialect.getSelectFieldsWithoutAliases( input ).toString();
assertEquals( " some_field1, some_fild2, _field3", output );
}