Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.QueryException;
import org.hibernate.engine.spi.QueryParameters;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
Expand Down Expand Up @@ -120,7 +119,7 @@ public DeleteExecutor(HqlSqlWalker walker) {
}
columnNames = columns.toArray( new String[0] );
}
catch (MappingException e) {
catch (QueryException e) {
// Property not found, due to IdClasses are not properly handled in metamodel HHH-12996
columnNames = persister.getIdentifierColumnNames();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
*/
package org.hibernate.hql.internal.ast.tree;

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.hql.internal.antlr.HqlSqlTokenTypes;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.type.Type;

import antlr.collections.AST;
Expand Down Expand Up @@ -102,40 +100,4 @@ private static Type extractDataType(Node operand) {
return null;
}

private static String[] extractMutationTexts(Node operand, int count) {
if ( operand instanceof ParameterNode ) {
String[] rtn = new String[count];
for ( int i = 0; i < count; i++ ) {
rtn[i] = "?";
}
return rtn;
}
else if ( operand.getType() == HqlSqlTokenTypes.VECTOR_EXPR ) {
final String[] rtn = new String[ operand.getNumberOfChildren() ];
AST node = operand.getFirstChild();
int x = 0;
while ( node != null ) {
rtn[ x++ ] = node.getText();
node = node.getNextSibling();
}
return rtn;
}
else if ( operand instanceof SqlNode ) {
String nodeText = operand.getText();
if ( nodeText.startsWith( "(" ) ) {
nodeText = nodeText.substring( 1 );
}
if ( nodeText.endsWith( ")" ) ) {
nodeText = nodeText.substring( 0, nodeText.length() - 1 );
}
String[] splits = StringHelper.split( ", ", nodeText );
if ( count != splits.length ) {
throw new HibernateException( "SqlNode's text did not reference expected number of columns" );
}
return splits;
}
else {
throw new HibernateException( "don't know how to extract row value elements from node : " + operand );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
*/
package org.hibernate.hql.internal.ast.tree;

import java.util.Arrays;

import org.hibernate.HibernateException;
import org.hibernate.hql.internal.antlr.HqlSqlTokenTypes;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.type.Type;

import antlr.SemanticException;
import antlr.collections.AST;

/**
* Partial implementation of SelectExpression for all the nodes that aren't constructors.
Expand Down Expand Up @@ -55,4 +61,40 @@ public void setScalarColumn(int i) throws SemanticException {
public int getScalarColumnIndex() {
return scalarColumnIndex;
}

protected static String[] extractMutationTexts(Node operand, int count) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ( operand instanceof ParameterNode ) {
String[] rtn = new String[count];
Arrays.fill( rtn, "?" );
return rtn;
}
else if ( operand.getType() == HqlSqlTokenTypes.VECTOR_EXPR ) {
String[] rtn = new String[operand.getNumberOfChildren()];
int x = 0;
AST node = operand.getFirstChild();
while ( node != null ) {
rtn[x++] = node.getText();
node = node.getNextSibling();
}
return rtn;
}
else if ( operand instanceof SqlNode ) {
String nodeText = operand.getText();
if ( nodeText.startsWith( "(" ) ) {
nodeText = nodeText.substring( 1 );
}
if ( nodeText.endsWith( ")" ) ) {
nodeText = nodeText.substring( 0, nodeText.length() - 1 );
}
String[] splits = StringHelper.split( ",", nodeText );
if ( count != splits.length ) {
throw new HibernateException( "SqlNode's text did not reference expected number of columns" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest creating a complete exception with more detail, like:

throw new HibernateException( String.format("sqlNode's text did not reference expected number of columns (expecting: %d, actual: %d)", count, splits.length));

}
return splits;
}
else {
throw new HibernateException( "dont know how to extract row value elements from node : " + operand );
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
*/
package org.hibernate.hql.internal.ast.tree;

import java.util.Arrays;

import org.hibernate.HibernateException;
import org.hibernate.TypeMismatchException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.hql.internal.antlr.HqlSqlTokenTypes;
import org.hibernate.hql.internal.ast.QuerySyntaxException;
import org.hibernate.hql.internal.ast.util.ColumnHelper;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.param.ParameterSpecification;
import org.hibernate.type.OneToOneType;
import org.hibernate.type.StandardBasicTypes;
Expand Down Expand Up @@ -239,41 +235,6 @@ private static void copyReferencedTables(Node from, SqlFragment to) {
}
}

protected static String[] extractMutationTexts(Node operand, int count) {
if ( operand instanceof ParameterNode ) {
String[] rtn = new String[count];
Arrays.fill( rtn, "?" );
return rtn;
}
else if ( operand.getType() == HqlSqlTokenTypes.VECTOR_EXPR ) {
String[] rtn = new String[operand.getNumberOfChildren()];
int x = 0;
AST node = operand.getFirstChild();
while ( node != null ) {
rtn[x++] = node.getText();
node = node.getNextSibling();
}
return rtn;
}
else if ( operand instanceof SqlNode ) {
String nodeText = operand.getText();
if ( nodeText.startsWith( "(" ) ) {
nodeText = nodeText.substring( 1 );
}
if ( nodeText.endsWith( ")" ) ) {
nodeText = nodeText.substring( 0, nodeText.length() - 1 );
}
String[] splits = StringHelper.split( ", ", nodeText );
if ( count != splits.length ) {
throw new HibernateException( "SqlNode's text did not reference expected number of columns" );
}
return splits;
}
else {
throw new HibernateException( "dont know how to extract row value elements from node : " + operand );
}
}

protected Type extractDataType(Node operand) {
Type type = null;
if ( operand instanceof SqlNode ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ public SqlValueReference[] map(String reference) {
formulaTemplates = elementFormulaTemplates;
}
else {
columnNames = elementPropertyMapping.toColumns( reference );
columnNames = columnNames( reference );
formulaTemplates = formulaTemplates( reference, columnNames.length );
}

Expand Down Expand Up @@ -670,6 +670,20 @@ public String getColumnName() {
}
}

private String[] columnNames(String reference) {
if ( elementPersister == null ) {
return elementPropertyMapping.toColumns( reference );
}

final Integer propertyIndex = elementPersister.getEntityMetamodel().getPropertyIndexOrNull( reference );
if ( propertyIndex != null ) {
return ( (Queryable) elementPersister ).getSubclassPropertyColumnNameClosure()[propertyIndex];
}
else {
return elementPropertyMapping.toColumns( reference );
}
}

private String[] formulaTemplates(String reference, int expectedSize) {
try {
final int propertyIndex = elementPersister.getEntityMetamodel().getPropertyIndex( reference );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ public String[] toColumns(String alias, String propertyName) throws QueryExcepti
*/
@Override
public String[] toColumns(String propertyName) throws QueryException {
return propertyMapping.getColumnNames( propertyName );
return propertyMapping.toColumns( propertyName );
}

/**
Expand Down Expand Up @@ -2224,7 +2224,8 @@ protected Type[] getSubclassPropertyTypeClosure() {
return subclassPropertyTypeClosure;
}

protected String[][] getSubclassPropertyColumnNameClosure() {
@Override
public String[][] getSubclassPropertyColumnNameClosure() {
return subclassPropertyColumnNameClosure;
}

Expand Down Expand Up @@ -2820,17 +2821,36 @@ else if ( isAllOrDirtyOptLocking() && oldFields != null ) {
String[] propertyColumnNames = getPropertyColumnNames( i );
String[] propertyColumnWriters = getPropertyColumnWriters( i );
boolean[] propertyNullness = types[i].toColumnNullness( oldFields[i], getFactory() );
String[] propertyColumnFormulaTemplates = this.propertyColumnFormulaTemplates[i];
for ( int k = 0; k < propertyNullness.length; k++ ) {
if ( propertyNullness[k] ) {
update.addWhereColumn( propertyColumnNames[k], "=" + propertyColumnWriters[k] );
final String propertyColumnFormulaTemplate = propertyColumnFormulaTemplates[k];
final String propertyColumnName = propertyColumnNames[k];
if ( propertyColumnName == null && propertyColumnFormulaTemplate != null ) {
final String formula = StringHelper.replace(
propertyColumnFormulaTemplate,
Template.TEMPLATE + ".",
""
);
if ( propertyNullness[k] ) {
final String propertyColumnWriter = propertyColumnWriters[k];
update.addWhereColumn(
formula,
"=" + ( propertyColumnWriter == null ? "?" : propertyColumnWriter )
);
}
else {
update.addWhereColumn( formula, " is null" );
}
}
else if ( propertyNullness[k] ) {
update.addWhereColumn( propertyColumnName, "=" + propertyColumnWriters[k] );
}
else {
update.addWhereColumn( propertyColumnNames[k], " is null" );
update.addWhereColumn( propertyColumnName, " is null" );
}
}
}
}

}

if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public String[] toColumns(String propertyName) throws QueryException {
String[] result = new String[columns.length];
for ( int i = 0; i < columns.length; i++ ) {
if ( columnReaders[i] == null ) {
result[i] = StringHelper.replace( formulaTemplates[i], Template.TEMPLATE, "" );
result[i] = StringHelper.replace( formulaTemplates[i], Template.TEMPLATE + ".", "" );
}
else {
result[i] = columnReaders[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public interface Queryable extends Loadable, PropertyMapping, Joinable {

String[][] getSubclassPropertyFormulaTemplateClosure();

String[][] getSubclassPropertyColumnNameClosure();

public static class Declarer {
public static final Declarer CLASS = new Declarer( "class" );
public static final Declarer SUBCLASS = new Declarer( "subclass" );
Expand Down
Loading