use of org.apache.commons.text.StringTokenizer in project jmix by jmix-framework.
the class SequencesImpl method executeScript.
protected Object executeScript(Sequence sequence, String sqlScript) {
JdbcTemplate jdbcTemplate = storeAwareLocator.getJdbcTemplate(getDataStore(sequence));
StringTokenizer tokenizer = new StringTokenizer(sqlScript, SequenceSupport.SQL_DELIMITER);
Object value = null;
while (tokenizer.hasNext()) {
String sql = tokenizer.nextToken();
try {
Object result = jdbcTemplate.execute(sql, (PreparedStatementCallback<Object>) ps -> {
if (ps.execute()) {
ResultSet rs = ps.getResultSet();
if (rs.next())
return rs.getLong(1);
}
return NO_RESULT;
});
if (result != NO_RESULT) {
value = result;
}
} catch (DataAccessException e) {
throw new IllegalStateException("Error executing SQL for getting next number", e);
}
}
return value;
}
use of org.apache.commons.text.StringTokenizer in project jmix by jmix-framework.
the class RestJsonTransformations method init.
protected void init() {
String configName = environment.getProperty(JMIX_REST_JSON_TRANSFORMATION_CONFIG_PROP_NAME);
StringTokenizer tokenizer = new StringTokenizer(configName);
for (String location : tokenizer.getTokenArray()) {
Resource resource = resources.getResource(location);
if (resource.exists()) {
InputStream stream = null;
try {
stream = resource.getInputStream();
loadConfig(Dom4j.readDocument(stream).getRootElement());
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(stream);
}
} else {
log.warn("Resource " + location + " not found, ignore it");
}
}
}
use of org.apache.commons.text.StringTokenizer in project jmix by jmix-framework.
the class RestQueriesConfiguration method init.
protected void init() {
String configName = environment.getProperty(JMIX_REST_QUERIES_CONFIG_PROP_NAME);
StringTokenizer tokenizer = new StringTokenizer(configName);
for (String location : tokenizer.getTokenArray()) {
Resource resource = resources.getResource(location);
if (resource.exists()) {
InputStream stream = null;
try {
stream = resource.getInputStream();
loadConfig(Dom4j.readDocument(stream).getRootElement());
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(stream);
}
} else {
log.warn("Resource {} not found, ignore it", location);
}
}
}
use of org.apache.commons.text.StringTokenizer in project jmix by jmix-framework.
the class RestServicesConfiguration method init.
protected void init() {
String configName = environment.getProperty(JMIX_REST_SERVICES_CONFIG_PROP_NAME);
StringTokenizer tokenizer = new StringTokenizer(configName);
for (String location : tokenizer.getTokenArray()) {
Resource resource = resources.getResource(location);
if (resource.exists()) {
try (InputStream stream = resource.getInputStream()) {
loadConfig(Dom4j.readDocument(stream).getRootElement());
} catch (IOException e) {
throw new RuntimeException("Error on parsing rest services config", e);
}
} else {
log.warn("Resource {} not found, ignore it", location);
}
}
}
use of org.apache.commons.text.StringTokenizer in project jmix by jmix-framework.
the class CubaMessages method searchMessage.
@Nullable
protected String searchMessage(String packs, String key, Locale locale, Locale truncatedLocale, Set<String> passedPacks) {
StringTokenizer tokenizer = new StringTokenizer(packs);
// noinspection unchecked
List<String> list = tokenizer.getTokenList();
Collections.reverse(list);
for (String pack : list) {
if (!enterPack(pack, locale, truncatedLocale, passedPacks))
continue;
String msg = searchOnePack(pack, key, locale, truncatedLocale, passedPacks);
if (msg != null)
return msg;
Locale tmpLocale = truncatedLocale;
while (tmpLocale != null) {
tmpLocale = truncateLocale(tmpLocale);
msg = searchOnePack(pack, key, locale, tmpLocale, passedPacks);
if (msg != null)
return msg;
}
}
if (log.isTraceEnabled()) {
String packName = new TextStringBuilder().appendWithSeparators(list, ",").toString();
log.trace("Resource '{}' not found", makeCacheKey(packName, key, locale, locale));
}
return null;
}
Aggregations