Skip to content

Commit

Permalink
Move tests from cfg, dialect, id/enhanced, jdbc to orm/test and fix S…
Browse files Browse the repository at this point in the history
…QL Server 2005 limit handler issue, as well as sqm function return type resolver issue
  • Loading branch information
beikov committed Mar 16, 2021
1 parent 222e3fb commit 3f2afe6
Show file tree
Hide file tree
Showing 24 changed files with 448 additions and 431 deletions.
Expand Up @@ -8,6 +8,7 @@

import org.hibernate.boot.TempTableDdlTransactionHandling;
import org.hibernate.dialect.function.CommonFunctionFactory;
import org.hibernate.dialect.function.CurrentFunction;
import org.hibernate.dialect.function.IndividualLeastGreatestEmulation;
import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.identity.InformixIdentityColumnSupport;
Expand Down Expand Up @@ -63,7 +64,7 @@ public InformixDialect(DialectResolutionInfo info) {
private final LimitHandler limitHandler;

public InformixDialect() {
this(7);
this( 7 );
}

/**
Expand Down Expand Up @@ -394,6 +395,16 @@ public String toBooleanValueString(boolean bool) {
return bool ? "'t'" : "'f'";
}

@Override
public String currentDate() {
return "today";
}

@Override
public String currentTimestamp() {
return "current";
}

@Override
public String translateDatetimeFormat(String format) {
//Informix' own variation of MySQL
Expand Down
Expand Up @@ -238,13 +238,25 @@ private String selectAliases(String sql, int afterSelectOffset, int fromOffset,
String alias;
if ( asIndex == 0 ) {
expression = selectElement.trim();
//no alias found, need to generate and insert it!
alias = StringHelper.generateAlias( "col", unique++ );
int diff = result.length() - sql.length();
if ( result.charAt( nextOffset + diff - 1 ) == ' ' ) {
diff--;
if (expression.equals( "*" ) || expression.endsWith( ".*" )) {
alias = "";
}
else {
int aliasIndex = getAliasIndex( expression );
if ( aliasIndex == -1 ) {
//no alias found, need to generate and insert it!
alias = StringHelper.generateAlias( "col", unique++ );
int diff = result.length() - sql.length();
if ( result.charAt( nextOffset + diff - 1 ) == ' ' ) {
diff--;
}
result.insert( nextOffset + diff, " as " + alias );
}
else {
alias = expression.substring( aliasIndex ).trim();
expression = expression.substring( 0, aliasIndex ).trim();
}
}
result.insert( nextOffset + diff, " as " + alias);
}
else {
expression = selectElement.substring( 0, asIndex ).trim();
Expand All @@ -263,6 +275,48 @@ private String selectAliases(String sql, int afterSelectOffset, int fromOffset,
return String.join( ", ", aliases );
}

private int getAliasIndex(String sql) {
int endOffset = -1;
int depth = 0;
boolean quoted = false;
boolean doubleQuoted = false;
for ( int offset = sql.length() - 1; offset > endOffset; ) {
int nextQuote = sql.lastIndexOf('\'', offset);
if ( nextQuote < 0 || nextQuote < endOffset ) {
nextQuote = endOffset;
}
if ( !quoted ) {
for ( int index = offset; index > nextQuote; index-- ) {
final char c = sql.charAt( index );
switch ( c ) {
case '(':
depth--;
break;
case ')':
depth++;
break;
case '"':
doubleQuoted = !doubleQuoted;
break;
case '[':
doubleQuoted = false;
break;
case ']':
doubleQuoted = true;
break;
default:
if ( Character.isWhitespace( c ) && depth == 0 && !doubleQuoted ) {
return index + 1;
}
}
}
}
quoted = !quoted;
offset = nextQuote - 1;
}
return -1;
}

enum Keyword {

SELECT ("select(\\s+(distinct|all))?"),
Expand Down
Expand Up @@ -82,7 +82,7 @@ public SelfRenderingFunctionSqlAstExpression convertToSqlAst(SqmToSqlAstConverte
public SqmExpressable<T> getNodeType() {
SqmExpressable<T> nodeType = super.getNodeType();
if ( nodeType == null ) {
resolveResultType( nodeBuilder().getTypeConfiguration() );
nodeType = (SqmExpressable<T>) resolveResultType( nodeBuilder().getTypeConfiguration() );
}

return nodeType;
Expand Down

This file was deleted.

141 changes: 0 additions & 141 deletions hibernate-core/src/test/java/org/hibernate/dialect/Mocks.java

This file was deleted.

Expand Up @@ -4,17 +4,18 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.cfg;
package org.hibernate.orm.test.cfg;

import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import javax.persistence.Persistence;

import org.hibernate.cfg.AvailableSettings;

import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
Expand Down

0 comments on commit 3f2afe6

Please sign in to comment.