That's what I want to achieve in SQL:
SET CURRENT APPLICATION COMPATIBILITY = 'V11R1';
SET SCHEMA.VAR_GL = 'Value';
SELECT * FROM SCHEMA.VIEW;
The SCHEMA.VIEW is declared as:
SELECT * FROM SCHEMA.TABLE WHERE field = VAR_GL
I have to mark the public method on the controller with @Transactional annotation to execute the queries together in one db session.
public interface Controller {
@Transactional
List<Options> loadOptions();
}
public class ControllerImpl implements Controller {
@Autowired
private DomainRepository repo;
@Override
public List<Option> loadOptions() {
this.repo.setCompatibilityMode();
this.repo.setGlobalVariableA("Value");
List<Option> list = this.repo.loadDropdown();
return list;
}
In my jpa repository I need a method for each global variable:
public interface DomainRepository extends JpaCrudRepository<Option, OptionPK> {
@Modifying
@Query(value = "SET CURRENT APPLICATION COMPATIBILITY = 'V11R1'", nativeQuery = true)
void setCompatibilityMode();
}
@Modifying
@Query(value = "set SCHEMA.VAR_GL = :value", nativeQuery = true)
void setGlobalVariableA(@Param("value") String value);
@Query(value = "SELECT * FROM SCHEMA.VIEW", nativeQuery = true)
List<Option> loadDropdown();
}
That's how it works. I'd like to improve this solution further but I have no idea how to make the variable query more reusable by making the variable name a parameter.