Skip to content

Commit

Permalink
Added condition for embeddable
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaypaul-ibm committed Nov 8, 2024
1 parent b8361df commit 1c8cdbf
Showing 1 changed file with 16 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,18 @@
import java.util.List;

/**
* JPQL exclusive ID(), VERSION() functions/expressions are transformed there to
* StateFieldPathExpression.
* It should be used in the future for another JPQL functions/expressions which
* are not available at the DB level.
* E.g. For Entity e with idAttr as a primary key:
* <code>SELECT ID(e) FROM Entity e -> SELECT e.idAttr FROM Entity e</code>
* For Entity e with versionAttr as a version attribute:
* <code>SELECT VERSION(e) FROM Entity e -> SELECT e.versionAttr FROM Entity e</code>
* JPQL exclusive ID(), VERSION() functions/expressions are transformed there to StateFieldPathExpression.
* It should be used in the future for another JPQL functions/expressions which are not available at the DB level.
* E.g. For Entity e with idAttr as a primary key: <code>SELECT ID(e) FROM Entity e -> SELECT e.idAttr FROM Entity e</code>
* For Entity e with versionAttr as a version attribute: <code>SELECT VERSION(e) FROM Entity e -> SELECT e.versionAttr FROM Entity e</code>
*
* @author Radek Felcman
* @since 5.0
*/
public abstract class JPQLFunctionsAbstractBuilder extends EclipseLinkAnonymousExpressionVisitor {

/**
* The {@link JPQLQueryContext} is used to query information about the
* application metadata and
* The {@link JPQLQueryContext} is used to query information about the application metadata and
* cached information.
*/
final JPQLQueryContext queryContext;
Expand All @@ -54,27 +49,20 @@ protected JPQLFunctionsAbstractBuilder(JPQLQueryContext queryContext) {
}

/**
* For Entity e with idAttr as a primary key:
* <code>SELECT ID(e) FROM Entity e -> SELECT e.idAttr FROM Entity e</code>
* For Entity e with idAttr as a primary key: <code>SELECT ID(e) FROM Entity e -> SELECT e.idAttr FROM Entity e</code>
*
* @param expression The {@link IdExpression} to visit
*/
@Override
public void visit(IdExpression expression) {
System.out.println("INSIDE VISIT *******");
//Fetch identification variable info
IdentificationVariable identificationVariable = (IdentificationVariable) expression.getExpression();
String variableText = identificationVariable.getText();
String variableName = identificationVariable.getVariableName();
// Get id attribute name

//Get id attribute name
ClassDescriptor descriptor = this.queryContext.getDeclaration(variableName).getDescriptor();
List<DatabaseField> primaryKeyFields = descriptor.getPrimaryKeyFields();
// String idAttributeName = getIdAttributeNameByField(descriptor.getMappings(),
// primaryKeyFields.get(0));
// StateFieldPathExpression stateFieldPathExpression = new
// StateFieldPathExpression(expression.getParent(), variableText + "." +
// idAttributeName);
// expression.setStateFieldPathExpression(stateFieldPathExpression);
// expression.getStateFieldPathExpression().accept(this);
List<DatabaseField> primaryKeyFields = descriptor.getPrimaryKeyFields()
if (!isEmbeddable(descriptor.getMappings())) {
for (DatabaseField primaryKeyField : primaryKeyFields) {
String idAttributeName = getIdAttributeNameByField(descriptor.getMappings(), primaryKeyField);
Expand All @@ -98,27 +86,24 @@ public void visit(IdExpression expression) {
}

/**
* For Entity e with versionAttr as a version attribute:
* <code>SELECT VERSION(e) FROM Entity e -> SELECT e.versionAttr FROM Entity e</code>
* For Entity e with versionAttr as a version attribute: <code>SELECT VERSION(e) FROM Entity e -> SELECT e.versionAttr FROM Entity e</code>
*
* @param expression The {@link VersionExpression} to visit
*/
@Override
public void visit(VersionExpression expression) {
// Fetch identification variable info
//Fetch identification variable info
IdentificationVariable identificationVariable = (IdentificationVariable) expression.getExpression();
String variableText = identificationVariable.getText();
String variableName = identificationVariable.getVariableName();

// Get version attribute name
//Get version attribute name
ClassDescriptor descriptor = this.queryContext.getDeclaration(variableName).getDescriptor();
String versionAttributeName = ((VersionLockingPolicy) descriptor.getOptimisticLockingPolicy())
.getVersionMapping().getAttributeName();
StateFieldPathExpression stateFieldPathExpression = new StateFieldPathExpression(expression.getParent(),
variableText + "." + versionAttributeName);
String versionAttributeName = ((VersionLockingPolicy) descriptor.getOptimisticLockingPolicy()).getVersionMapping().getAttributeName();
StateFieldPathExpression stateFieldPathExpression = new StateFieldPathExpression(expression.getParent(), variableText + "." + versionAttributeName);
expression.setStateFieldPathExpression(stateFieldPathExpression);

// Continue with created StateFieldPathExpression
//Continue with created StateFieldPathExpression
expression.getStateFieldPathExpression().accept(this);
}

Expand Down

0 comments on commit 1c8cdbf

Please sign in to comment.