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 @@ -26,10 +26,8 @@

import antlr.collections.AST;

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;

/**
Expand Down Expand Up @@ -86,7 +84,7 @@ private void mutateRowValueConstructorSyntax(int operandColumnSpan) {
setType( expansionConnectorType );
setText( expansionConnectorText );

String[] mutationTexts = extractMutationTexts( getOperand(), operandColumnSpan );
String[] mutationTexts = BinaryLogicOperatorNode.extractMutationTexts( getOperand(), operandColumnSpan );

AST container = this;
for ( int i = operandColumnSpan - 1; i > 0; i-- ) {
Expand Down Expand Up @@ -122,41 +120,4 @@ private static Type extractDataType(Node operand) {
}
return type;
}

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 ) {
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 );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,16 @@ else if ( operand.getType() == HqlSqlTokenTypes.VECTOR_EXPR ) {
}
else if ( operand instanceof SqlNode ) {
String nodeText = operand.getText();
if ( nodeText.startsWith( "(" ) ) {
nodeText = nodeText.substring( 1 );
if ( nodeText.startsWith( "(" ) && nodeText.endsWith( ")" ) ) {
nodeText = nodeText.substring( 1, nodeText.length() - 1 );
}
if ( nodeText.endsWith( ")" ) ) {
nodeText = nodeText.substring( 0, nodeText.length() - 1 );
String[] splits;
if ( count > 1 && "null".equalsIgnoreCase( nodeText ) ) {
splits = new String[count];
Arrays.fill( splits, "null" );
} else {
splits = StringHelper.split( ",", nodeText );
}
String[] splits = StringHelper.split( ", ", nodeText );
if ( count != splits.length ) {
throw new HibernateException( "SqlNode's text did not reference expected number of columns" );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,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 @@ -644,6 +644,15 @@ public String getColumnName() {
}
}

private String[] columnNames(String reference) {
try {
final int propertyIndex = elementPersister.getEntityMetamodel().getPropertyIndex(reference);
return ((Queryable)elementPersister).getSubclassPropertyColumnNameClosure()[propertyIndex];
} catch (Exception e) {
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 @@ -1960,7 +1960,7 @@ public String[] toColumns(String alias, String propertyName) throws QueryExcepti
}

public String[] toColumns(String propertyName) throws QueryException {
return propertyMapping.getColumnNames( propertyName );
return propertyMapping.toColumns( propertyName );
}

public Type toType(String propertyName) throws QueryException {
Expand Down Expand Up @@ -2127,7 +2127,7 @@ protected Type[] getSubclassPropertyTypeClosure() {
return subclassPropertyTypeClosure;
}

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

Expand Down Expand Up @@ -2605,10 +2605,18 @@ else if ( isAllOrDirtyOptLocking() && oldFields != null ) {
// this property belongs to the table, and it is not specifically
// excluded from optimistic locking by optimistic-lock="false"
String[] propertyColumnNames = getPropertyColumnNames( i );
String[] propertyColumnFormulas = propertyColumnFormulaTemplates[i];
String[] propertyColumnWriters = getPropertyColumnWriters( i );
boolean[] propertyNullness = types[i].toColumnNullness( oldFields[i], getFactory() );
for ( int k=0; k<propertyNullness.length; k++ ) {
if ( propertyNullness[k] ) {
if (propertyColumnNames[k] == null && propertyColumnFormulaTemplates[k] != null) {
String formula = StringHelper.replace(propertyColumnFormulas[k], Template.TEMPLATE + ".", "");
if (propertyNullness[k]) {
update.addWhereColumn(formula, "=" + (propertyColumnWriters[k] == null ? "?" : propertyColumnWriters[k]));
} else {
update.addWhereColumn(formula, " is null");
}
} else if ( propertyNullness[k] ) {
update.addWhereColumn( propertyColumnNames[k], "=" + propertyColumnWriters[k] );
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,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 @@ -170,6 +170,8 @@ public interface Queryable extends Loadable, PropertyMapping, Joinable {
*/
public DiscriminatorMetadata getTypeDiscriminatorMetadata();

String[][] getSubclassPropertyColumnNameClosure();

String[][] getSubclassPropertyFormulaTemplateClosure();

public static class Declarer {
Expand Down
Loading