Search in sources :

Example 11 with StringTokenizer

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;
}
Also used : DataAccessException(org.springframework.dao.DataAccessException) TransactionDefinition(org.springframework.transaction.TransactionDefinition) Autowired(org.springframework.beans.factory.annotation.Autowired) DbmsSpecifics(io.jmix.data.persistence.DbmsSpecifics) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) StringUtils(org.apache.commons.lang3.StringUtils) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) BigDecimal(java.math.BigDecimal) ResultSet(java.sql.ResultSet) BigInteger(java.math.BigInteger) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Sequence(io.jmix.data.Sequence) StringTokenizer(org.apache.commons.text.StringTokenizer) PreparedStatementCallback(org.springframework.jdbc.core.PreparedStatementCallback) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SequenceSupport(io.jmix.data.persistence.SequenceSupport) Set(java.util.Set) EntityManager(javax.persistence.EntityManager) Component(org.springframework.stereotype.Component) Query(javax.persistence.Query) List(java.util.List) Stores(io.jmix.core.Stores) Sequences(io.jmix.data.Sequences) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Preconditions(com.google.common.base.Preconditions) TransactionCallback(org.springframework.transaction.support.TransactionCallback) Pattern(java.util.regex.Pattern) StoreAwareLocator(io.jmix.data.StoreAwareLocator) StringTokenizer(org.apache.commons.text.StringTokenizer) ResultSet(java.sql.ResultSet) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataAccessException(org.springframework.dao.DataAccessException)

Example 12 with StringTokenizer

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");
        }
    }
}
Also used : StringTokenizer(org.apache.commons.text.StringTokenizer) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException)

Example 13 with StringTokenizer

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);
        }
    }
}
Also used : StringTokenizer(org.apache.commons.text.StringTokenizer) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException)

Example 14 with StringTokenizer

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);
        }
    }
}
Also used : StringTokenizer(org.apache.commons.text.StringTokenizer) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException)

Example 15 with StringTokenizer

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;
}
Also used : StringTokenizer(org.apache.commons.text.StringTokenizer) TextStringBuilder(org.apache.commons.text.TextStringBuilder) Nullable(javax.annotation.Nullable)

Aggregations

StringTokenizer (org.apache.commons.text.StringTokenizer)43 IOException (java.io.IOException)9 Resource (org.springframework.core.io.Resource)9 ArrayList (java.util.ArrayList)8 InputStream (java.io.InputStream)7 Element (org.dom4j.Element)5 AppContextInitializedEvent (com.haulmont.cuba.core.sys.events.AppContextInitializedEvent)3 File (java.io.File)3 TextStringBuilder (org.apache.commons.text.TextStringBuilder)3 Events (com.haulmont.cuba.core.global.Events)2 Properties (java.util.Properties)2 Nullable (javax.annotation.Nullable)2 Preconditions (com.google.common.base.Preconditions)1 Resources (com.haulmont.cuba.core.global.Resources)1 CubaClassPathXmlApplicationContext (com.haulmont.cuba.core.sys.CubaClassPathXmlApplicationContext)1 DesktopResources (com.haulmont.cuba.desktop.DesktopResources)1 ComponentDecorator (com.haulmont.cuba.desktop.theme.ComponentDecorator)1 Specification (io.github.linuxforhealth.api.Specification)1 Stores (io.jmix.core.Stores)1 Sequence (io.jmix.data.Sequence)1