Search in sources :

Example 6 with PropertyServiceUnexpectedException

use of org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException in project summerb by skarpushin.

the class PropertyServiceImpl method findSubjectProperty.

@Override
public String findSubjectProperty(String appName, String domainName, String subjectId, String name) {
    checkArgumentsHaveText(appName, domainName, subjectId, name);
    try {
        long appId = appNameAlias.getAliasFor(appName);
        long domainId = domainNameAlias.getAliasFor(domainName);
        long propertyNameId = propertyNameAlias.getAliasFor(name);
        return propertyDao.findSubjectProperty(appId, domainId, subjectId, propertyNameId);
    } catch (Throwable t) {
        throw new PropertyServiceUnexpectedException("Failed to find subject property", t);
    }
}
Also used : PropertyServiceUnexpectedException(org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException)

Example 7 with PropertyServiceUnexpectedException

use of org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException in project summerb by skarpushin.

the class StringIdAliasServiceEagerImpl method loadAllAliases.

protected final BiMap<String, Long> loadAllAliases() {
    try {
        BiMap<String, Long> ret = HashBiMap.create();
        long maxOffset = -2;
        for (long offset = 0; maxOffset == -2 || offset < maxOffset; offset = offset + EAGER_LOAD_BATCH_SIZE) {
            PagerParams pagerParams = new PagerParams(offset, EAGER_LOAD_BATCH_SIZE);
            PaginatedList<AliasEntry> loadedAliases = stringIdAliasDao.loadAllAliases(pagerParams);
            maxOffset = loadedAliases.getTotalResults() - 1;
            for (Entry<String, Long> entry : loadedAliases.getItems()) {
                ret.put(entry.getKey(), entry.getValue());
            }
        }
        return ret;
    } catch (Throwable t) {
        String msg = "Failed to eagerly load alias map";
        log.error(msg, t);
        throw new PropertyServiceUnexpectedException(msg, t);
    }
}
Also used : PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) PropertyServiceUnexpectedException(org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException) AliasEntry(org.summerb.microservices.properties.impl.dao.AliasEntry)

Example 8 with PropertyServiceUnexpectedException

use of org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException in project summerb by skarpushin.

the class StringIdAliasServiceEagerImpl method registerAlias.

/**
 * Will register alias (or retrieve already stored, only - useful for multi
 * server installation - environment - AKA webfarm)
 */
protected final synchronized long registerAlias(String str) {
    // WARNING: This method must be called only after getALiasFor invoked at
    // least once, otherwise NullPointerException might happen
    Long ret = aliases.get(str);
    // sanity check if someone has already stored it
    if (ret != null) {
        return ret.longValue();
    }
    long alias;
    try {
        try {
            alias = doCreateAlias(str);
        } catch (DuplicateKeyException dke) {
            log.debug("Looks like alias already exist in database, will load it");
            ret = stringIdAliasDao.findAliasFor(str);
            if (ret == null) {
                throw new PropertyServiceUnexpectedException("Failed to create alias because of duplicate, but later was unable to find that duplicate.");
            }
            alias = ret.longValue();
        }
    } catch (Throwable t) {
        throw new PropertyServiceUnexpectedException("Failed to store alias", t);
    }
    // store it locally
    aliases.put(str, alias);
    // ret
    return alias;
}
Also used : PropertyServiceUnexpectedException(org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException)

Example 9 with PropertyServiceUnexpectedException

use of org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException in project summerb by skarpushin.

the class PropertyServiceImpl method deleteSubjectsProperties.

@Override
@Transactional(rollbackFor = Throwable.class)
public void deleteSubjectsProperties(String appName, String domainName, List<String> subjectsIds) {
    if (CollectionUtils.isEmpty(subjectsIds)) {
        return;
    }
    checkArgumentsHaveText(appName, domainName);
    try {
        long appId = appNameAlias.getAliasFor(appName);
        long domainId = domainNameAlias.getAliasFor(domainName);
        for (String subjectId : subjectsIds) {
            propertyDao.deleteSubjectProperties(appId, domainId, subjectId);
        }
    } catch (Throwable t) {
        throw new PropertyServiceUnexpectedException("Failed to delete subject properties", t);
    }
}
Also used : PropertyServiceUnexpectedException(org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with PropertyServiceUnexpectedException

use of org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException in project summerb by skarpushin.

the class PropertyServiceImpl method findSubjectsProperty.

@Override
public Map<String, String> findSubjectsProperty(String appName, String domainName, List<String> subjectsIds, String name) {
    if (CollectionUtils.isEmpty(subjectsIds)) {
        return new HashMap<String, String>();
    }
    checkArgumentsHaveText(appName, domainName, name);
    try {
        long appId = appNameAlias.getAliasFor(appName);
        long domainId = domainNameAlias.getAliasFor(domainName);
        long propertyNameId = propertyNameAlias.getAliasFor(name);
        Map<String, String> ret = new HashMap<String, String>();
        for (String subjectId : subjectsIds) {
            String value = propertyDao.findSubjectProperty(appId, domainId, subjectId, propertyNameId);
            if (value != null) {
                ret.put(subjectId, value);
            }
        }
        return ret;
    } catch (Throwable t) {
        throw new PropertyServiceUnexpectedException("Failed to find subject property", t);
    }
}
Also used : HashMap(java.util.HashMap) PropertyServiceUnexpectedException(org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException)

Aggregations

PropertyServiceUnexpectedException (org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException)11 Transactional (org.springframework.transaction.annotation.Transactional)5 HashMap (java.util.HashMap)2 Map (java.util.Map)1 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)1 PagerParams (org.summerb.approaches.jdbccrud.api.dto.PagerParams)1 NamedProperty (org.summerb.microservices.properties.api.dto.NamedProperty)1 AliasEntry (org.summerb.microservices.properties.impl.dao.AliasEntry)1