1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
|
/*
* Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// Oracle - initial API and implementation
//
package org.eclipse.persistence.jpa.jpql;
import java.util.List;
import java.util.Map;
import org.eclipse.persistence.jpa.jpql.parser.Expression;
import org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable;
import org.eclipse.persistence.jpa.jpql.parser.JPQLGrammar;
import org.eclipse.persistence.jpa.jpql.parser.SimpleSelectStatement;
/**
* This helper is used by {@link AbstractSemanticValidator} in order to retrieve JPA information.
* This helper allows third party adopter to write an instance of this helper that directly access
* the JPA information without having to implement Hermes SPI, which can improve performance.
* <p>
* {@link org.eclipse.persistence.jpa.jpql.tools.GenericSemanticValidatorHelper
* GenericSemanticValidatorHelper} is a default implementation that uses Hermes SPI.
* <p>
* Provisional API: This interface is part of an interim API that is still under development and
* expected to change significantly before reaching stability. It is available at this early stage
* to solicit feedback from pioneering adopters on the understanding that any code that uses this
* API will almost certainly be broken (repeatedly) as the API evolves.
*
* @version 2.5
* @since 2.4
* @author Pascal Filion
*/
public interface SemanticValidatorHelper {
/**
* Collects the identification variables that are defined in the <code>FROM</code> clause of the
* current query and from the parent queries.
*
* @param identificationVariables The {@link Map} used to store the variables
*/
void collectAllDeclarationIdentificationVariables(Map<String, List<IdentificationVariable>> identificationVariables);
/**
* Collects the identification variables that are defined in the <code>FROM</code> clause of the
* current query.
*
* @param identificationVariables The {@link Map} used to store the variables
*/
void collectLocalDeclarationIdentificationVariables(Map<String, List<IdentificationVariable>> identificationVariables);
/**
* Disposes this context, which is the current context being used by a subquery. Once it is
* disposed, any information retrieved will be for the subquery's parent query.
*/
void disposeSubqueryContext();
/**
* Returns the name of the all entities that are present in the context of a persistence unit.
*
* @return The list of entity names
*/
String[] entityNames();
/**
* Returns the ordered list of {@link JPQLQueryDeclaration}, which contain the information
* contained in the query's <code>FROM</code> clause.
*
* @return The list of {@link JPQLQueryDeclaration} of the current query that was parsed and from
* the parent queries
*/
List<JPQLQueryDeclaration> getAllDeclarations();
/**
* Returns the constructors for the given type. All public, protected, default (package) access,
* and private constructors should be included.
* <p>
* If it was going through Hermes SPI, the type of the argument would be {@link
* org.eclipse.persistence.jpa.jpql.tools.spi.IType IType} and the return type would be {@link
* org.eclipse.persistence.jpa.jpql.tools.spi.IConstructor IConstructor}.
*
* @return The declared constructors
*/
Object[] getConstructors(Object type);
/**
* Returns the ordered list of {@link JPQLQueryDeclaration}, which contain the information
* contained in the query's <code>FROM</code> clause.
*
* @return The list of {@link JPQLQueryDeclaration} of the current query that was parsed
*/
List<JPQLQueryDeclaration> getDeclarations();
/**
* Retrieves the embeddable with the given type.
*
* @param type The Java type of the embeddable to retrieve
* @return The embeddable for the given type if it's representing an embeddable; <code>null</code>
* otherwise
*/
Object getEmbeddable(Object type);
/**
* Retrieves the entity with the given entity name.
*
* @param entityName The abstract schema name of the entity to retrieve
* @return The entity with the given name; <code>null</code> otherwise
*/
Object getEntityNamed(String entityName);
/**
* Returns the constant names for the given {@link Enum} type.
* <p>
* If it was going through Hermes SPI, the type of the argument would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IType IType}.
*
* @param type The {@link Enum} type
* @return The list of constant names
*/
String[] getEnumConstants(Object type);
/**
* Returns the {@link JPQLGrammar} that defines how the JPQL query was parsed.
*
* @return The {@link JPQLGrammar} that was used to parse the JPQL query
*/
JPQLGrammar getGrammar();
/**
* Returns the managed type by resolving the given {@link Expression}.
* <p>
* If it was going through Hermes SPI, the return type would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IManagedType IManagedType}.
*/
Object getManagedType(Expression expression);
/**
* Returns the mapping with the given name.
* <p>
* If it was going through Hermes SPI, the type of the argument would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IManagedType IManagedType}
* and the return type would be {@link
* org.eclipse.persistence.jpa.jpql.tools.spi.IMapping IMapping}.
*
* @param managedType The managed type that has a mapping with the given name
* @param name The name of the mapping to retrieve
* @return Either the mapping or <code>null</code> if it could not be found
*/
Object getMappingNamed(Object managedType, String name);
/**
* Returns the type of the given mapping object.
* <p>
* If it was going through Hermes SPI, the type of the argument would be {@link
* org.eclipse.persistence.jpa.jpql.tools.spi.IMapping IMapping} and the return type
* would be {@link org.eclipse.persistence.jpa.jpql.tools.spi.IType IType}.
*
* @param mapping The mapping object
* @return The type of the given mapping
*/
Object getMappingType(Object mapping);
/**
* Returns the list of type declarations representing the given constructor's parameter types.
* If this is the default constructor, then an empty array should be returned.
* <p>
* If it was going through Hermes SPI, the type of the argument would be {@link
* org.eclipse.persistence.jpa.jpql.tools.spi.IConstructor IConstructor} and the return type would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration ITypeDeclaration}.
*
* @param constructor The constructor to return its parameter types
* @return The list of parameter types or an empty list
*/
Object[] getMethodParameterTypeDeclarations(Object constructor);
/**
* Returns the reference managed type from the given relationship mapping.
* <p>
* If it was going through Hermes SPI, the type of the argument would be {@link
* org.eclipse.persistence.jpa.jpql.tools.spi.IMapping IMapping} and the return type would be {@link
* org.eclipse.persistence.jpa.jpql.tools.spi.IManagedType IManagedType}.
*
* @param relationshipMapping The relationship mapping
* @return The managed type referenced by the given relationship mapping
*/
Object getReferenceManagedType(Object relationshipMapping);
/**
* Returns the type by resolving the given {@link Expression}.
* <p>
* If it was going through Hermes SPI, the return type would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IType IType}.
*
* @param expression The {@link Expression} to resolve
* @return The type of the given {@link Expression} or <code>null</code> if it could not be
* validated
*/
Object getType(Expression expression);
/**
* Returns the type defined for the Java member.
* <p>
* If it was going through Hermes SPI, the type of the argument would be {@link
* org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration ITypeDeclaration} and the return type would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IType IType}.
*
* @return The type defined for the Java member
*/
Object getType(Object typeDeclaration);
/**
* Retrieves the class with the given fully qualified name.
* <p>
* If it was going through Hermes SPI, an {@link org.eclipse.persistence.jpa.jpql.tools.spi.IType
* IType} would be returned.
*
* @param typeName The fully qualified name of the class to retrieve
* @return The class to retrieve
*/
Object getType(String typeName);
/**
* Returns the type declaration for the given {@link Expression}'s type.
* <p>
* If it was going through Hermes SPI, the type of the argument would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration ITypeDeclaration}.
*
* @param expression The {@link Expression} to resolve
* @return Either the type declaration that was resolved for the given {@link Expression}
*/
Object getTypeDeclaration(Expression expression);
/**
* Returns the helper that gives access to the most common class metadata.
*
* @return A helper containing a collection of methods related to class metadata
*/
ITypeHelper getTypeHelper();
/**
* Returns the fully qualified class name of the given type.
* <p>
* If it was going through Hermes SPI, the type of the argument would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IType IType}.
*
* @param type The type to retrieve its name
* @return The name of the class represented by this one
*/
String getTypeName(Object type);
/**
* Determines whether type 1 is an instance of type 2.
* <p>
* If it was going through Hermes SPI, the type of the arguments would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IType IType}.
*
* @param type1 The type to check if it is an instance of type 2
* @param type2 The type used to determine if the class represented by type 1 is an instance
* of with one
* @return <code>true</code> if type 1 is an instance of the type 2; <code>false</code> otherwise
*/
boolean isAssignableTo(Object type1, Object type2);
/**
* Determines whether the given identification variable is defining a join or a collection member
* declaration expressions.
*
* @param variableName The identification variable to check for what it maps
* @return <code>true</code> if the given identification variable maps a collection-valued field
* defined in a <code>JOIN</code> or <code>IN</code> expression; <code>false</code> if it's not
* defined or it's mapping an abstract schema name
*/
boolean isCollectionIdentificationVariable(String variableName);
/**
* Determines whether the given mapping is a collection type mapping.
* <p>
* If it was going through Hermes SPI, the type of the arguments would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IMapping IMapping}.
*
* @param mapping The mapping object to verify if it represents a collection mapping
* @return <code>true</code> if the given mapping is a collection mapping; <code>false</code>
* otherwise
*/
boolean isCollectionMapping(Object mapping);
/**
* Determines whether the given mapping is an embeddable type mapping.
* <p>
* If it was going through Hermes SPI, the type of the arguments would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IMapping IMapping}.
*
* @param mapping The mapping object to verify if it represents an embeddable mapping
* @return <code>true</code> if the given mapping is an embeddable mapping; <code>false</code>
* otherwise
*/
boolean isEmbeddableMapping(Object mapping);
/**
* Determines whether the given type represents an {@link Enum}.
* <p>
* If it was going through Hermes SPI, the type of the argument would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IType IType}.
*
* @return <code>true</code> if the given type is an {@link Enum}; <code>false</code> otherwise
*/
boolean isEnumType(Object type);
/**
* Determines whether an identification variable can be used in a comparison expression when the
* operator is either {@literal '<', '<=', '>', '>='}.
*
* @param expression The {@link IdentificationVariable} that is mapped to either an entity, a
* singled-object value field, a collection-valued object field
* @return <code>true</code> if it can be used in a ordering comparison expression; <code>false</code>
* if it can't
*/
boolean isIdentificationVariableValidInComparison(IdentificationVariable expression);
/**
* Determines whether the given managed type actually exists.
* <p>
* If it was going through Hermes SPI, the type of the argument would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IManagedType IManagedType}.
*
* @return <code>true</code> if the given managed type can be located; <code>false</code> if it
* could not be found
*/
boolean isManagedTypeResolvable(Object managedType);
/**
* Determines whether the given mapping is a property type mapping.
* <p>
* If it was going through Hermes SPI, the type of the arguments would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IMapping IMapping}.
*
* @param mapping The mapping object to verify if it represents a property mapping
* @return <code>true</code> if the given mapping is a property mapping; <code>false</code> otherwise
*/
boolean isPropertyMapping(Object mapping);
/**
* Determines whether the given mapping is a relationship type mapping.
* <p>
* If it was going through Hermes SPI, the type of the arguments would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IMapping IMapping}.
*
* @param mapping The mapping object to verify if it represents a relationship mapping
* @return <code>true</code> if the given mapping is a relationship mapping; <code>false</code> otherwise
*/
boolean isRelationshipMapping(Object mapping);
/**
* Determines if the given variable is a result variable.
*
* @param variableName The variable to check if it's a result variable
* @return <code>true</code> if the given variable is defined as a result variable;
* <code>false</code> otherwise
*/
boolean isResultVariable(String variableName);
/**
* Determines whether the given mapping is a transient attribute.
* <p>
* If it was going through Hermes SPI, the type of the arguments would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IMapping IMapping}.
*
* @param mapping The mapping object to verify if it represents a transient attribute
* @return <code>true</code> if the given attribute is a transient mapping; <code>false</code> otherwise
*/
boolean isTransient(Object mapping);
/**
* Determines whether type declaration 1 is an instance of type declaration 2.
* <p>
* If it was going through Hermes SPI, the type of the arguments would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration ITypeDeclaration}.
*
* @param typeDeclaration1 The type declaration to check if it is an instance of type declaration 2
* @param typeDeclaration2 The type used to determine if the class represented by type
* declaration 1 is an instance of with one
* @return <code>true</code> if type declaration 1 is an instance of the type declaration 2;
* <code>false</code> otherwise
*/
boolean isTypeDeclarationAssignableTo(Object typeDeclaration1, Object typeDeclaration2);
/**
* Determines whether the given type actually exists.
* <p>
* If it was going through Hermes SPI, the type of the argument would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IType IType}.
*
* @return <code>true</code> if the actual class exists; <code>false</code> otherwise
*/
boolean isTypeResolvable(Object type);
/**
* Changes the state of this helper to use the given subquery.
*
* @param expression The parsed tree representation of the subquery that will become the current query
* @see #disposeSubqueryContext()
*/
void newSubqueryContext(SimpleSelectStatement expression);
/**
* Returns the mapping for the field represented by the given {@link Expression}.
* <p>
* If it was going through Hermes SPI, the return type would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IMapping IMapping}.
*
* @param expression The {@link Expression} representing a state field path expression or a
* collection-valued path expression
* @return Either the mapping or <code>null</code> if none exists
*/
Object resolveMapping(Expression expression);
/**
* Returns the mapping that should be a persistence field from the entity defined by the given
* identification variable.
* <p>
* If it was going through Hermes SPI, the return type would be
* {@link org.eclipse.persistence.jpa.jpql.tools.spi.IMapping IMapping}.
*
* @param identificationVariable The identification variable that is defined in the <code>FROM</code>
* clause of the query (which can be in the current subquery) or in one of the parent queries.
* @param name The name of the persistent field to retrieve
* @return The persistence field with the given name or <code>null</code> if it could not be found
*/
Object resolveMapping(String identificationVariable, String name);
}
|