service and how to call a static method of injection; about jpa of Specification-defined functions to achieve the oracle decode

How to call implanted in a static method service

{Class ClassA Public 

  public
static ClassA class classA with;

  @Resource
  Private Service Service;
  // the principles of engineering load at startup, before loading the static method, so that injection method in a static method can call it @PostConstruct
public void the init () { class classA with = the this ;
     classA.service-Service =;
}
}

Specification on jpa custom function

The method of the self-defined source, notes, not say 
. 1
/ ** 2 * for the Create The Execution of expression The AN A Database . 3 * function. . 4 * @param name function name . 5 * @param type Result type expected . 6 * @param args function arguments The 7 * @return expression The 8 * / 9 <T> Expression <T> function (String name, Class <T> of the type, 10 Expression ... args <?>);
We talk about this class, that is 
ParameterizedFunctionExpression, is how to achieve dynamic combination of sort criteria , achieve decode

<T> Expression<T> function(String name, Class<T> type,
Expression<?>... args);

 

// this is the function implementation actually call; he is calling the class constructor ParameterizedFunctionExpression

@Override
public <T> Expression<T> function(String name, Class<T> returnType, Expression<?>... arguments) {
return new ParameterizedFunctionExpression<T>( this, returnType, name, arguments );
}

 

// ParameterizedFunctionExpression constructor

public ParameterizedFunctionExpression(
CriteriaBuilderImpl criteriaBuilder,
Class<X> javaType,
String functionName,
Expression<?>... argumentExpressions) {
super( criteriaBuilder, javaType, functionName );
this.argumentExpressions = Arrays.asList( argumentExpressions );
this.isStandardJpaFunction = STANDARD_JPA_FUNCTION_NAMES.contains( functionName.toUpperCase(Locale.ROOT) );
}

 

//achieve

Expression<Integer> expression = null;

// store ordering conditions

List<Expression<?>> argumentExpressions = new ArrayList<Expression<?>>();

// sort field

argumentExpressions.add(cb.literal("grade");

// sort order
argumentExpressions.add (cb.literal (1));

expression = new ParameterizedFunctionExpression<Integer>((CriteriaBuilderImpl) cb, Integer.class, "decode",
argumentExpressions);

 

Guess you like

Origin www.cnblogs.com/xiaoshahai/p/11516870.html