use of org.eclipse.scout.rt.platform.holders.LongHolder in project scout.rt by eclipse.
the class AbstractSqlService method execCustomBindFunction.
/**
* Custom functions that can be used in sql statements as binds or sql style independent functions
* <p>
* Default functions are<br>
* ::level(permissionClass) --> int //to resolve a permissin level by executing a permission<br>
* ::level(permissionLevel) --> int //to resolve a permissin level by its id<br>
* ::code(codeClass or codeTypeClass) --> the ID of the code or code type<br>
* ::text(textId) --> the text in the user sessions language
* <p>
* Examples:<br>
* ::level(UpdatePersonPermission)<br>
* ::level(UpdatePersonPermission.LEVEL_OWN)<br>
* <br>
* ::code(CompanyAddressCodeType.MainAddressCode)<br>
* ::code(MainAddressCode)<br>
* <br>
* ::text(SalutationMr)
* <p>
*
* @return a plain object value or in case of a null value preferrably a {@link IHolder} of the correct value type
*/
@ConfigOperation
@Order(40)
protected Object execCustomBindFunction(String functionName, String[] args, Object[] bindBases) {
if ("level".equals(functionName)) {
if (args.length != 1) {
throw new IllegalArgumentException("expected 1 argument for function '" + functionName + "'");
}
String permissionClassName = args[0];
String levelField = null;
// eventually a level id?
int levelDot = permissionClassName.indexOf(".LEVEL_");
if (levelDot >= 0) {
levelField = permissionClassName.substring(levelDot + 1);
permissionClassName = permissionClassName.substring(0, levelDot);
}
Class permissionClass = loadBundleClassLenient(m_permissionNameToDescriptor, permissionClassName);
IAccessControlService accessControlService = BEANS.get(IAccessControlService.class);
Object ret = tryGetPermissionLevel(permissionClass, levelField, accessControlService);
return ret != null ? ret : new LongHolder();
} else if ("code".equals(functionName)) {
if (args.length != 1) {
throw new IllegalArgumentException("expected 1 argument for function '" + functionName + "'");
}
String codeClassName = args[0];
Class codeClass = loadBundleClassLenient(m_codeNameToDescriptor, codeClassName);
if (codeClass == null) {
throw new ProcessingException("Cannot find class for code '{}", new Object[] { args[0] });
}
try {
Object ret = codeClass.getField("ID").get(null);
return ret != null ? ret : new LongHolder();
} catch (Exception t) {
throw new ProcessingException("ID of code '{}'", new Object[] { args[0], t });
}
} else if ("text".equals(functionName)) {
if (args.length < 1) {
throw new IllegalArgumentException("expected at least 1 argument for function '" + functionName + "'");
}
String ret = TEXTS.get(args[0]);
return ret != null ? ret : new StringHolder();
} else {
throw new IllegalArgumentException("undefined function '" + functionName + "'");
}
}
use of org.eclipse.scout.rt.platform.holders.LongHolder in project scout.rt by eclipse.
the class BindValueTest method testNullBindWithLongHolder.
@Test
public void testNullBindWithLongHolder() throws Exception {
m_sqlService.clearProtocol();
// actual behaviour
m_sqlService.select("SELECT A FROM T WHERE A = :a", new NVPair("a", new LongHolder()));
String actual = m_sqlService.getProtocol().toString();
// expected behaviour
VerboseMock m = new VerboseMock(new StringBuffer());
m.log(Connection.class, "prepareStatement", "SELECT A FROM T WHERE A = ?");
m.log(PreparedStatement.class, "setObject", 1, null, Types.BIGINT);
m.log(PreparedStatement.class, "executeQuery");
m.log(ResultSet.class, "getFetchSize");
m.log(ResultSet.class, "next");
m.log(ResultSet.class, "close");
String expected = m.getProtocol().toString();
// check
assertEquals(expected, actual);
}
use of org.eclipse.scout.rt.platform.holders.LongHolder in project scout.rt by eclipse.
the class StatementProcessorTest method testSelectLike.
@Test
public void testSelectLike() throws Exception {
AbstractSqlService sqlService = new AbstractSqlService() {
};
BeanInstanceUtil.initializeBeanInstance(sqlService);
StatementProcessor sp = new StatementProcessor(sqlService, "SELECT BP_NR FROM FLM_BP WHERE BP_NO LIKE :bpNo INTO :bpNr", new Object[] { new NVPair("bpNo", "12"), new NVPair("bpNr", new LongHolder()) });
sp.simulate();
String sqlPlainTextDump = sp.createSqlDump(false, true);
assertFalse(sqlPlainTextDump.contains("UNPARSED"));
}
Aggregations