Example usage for org.springframework.util StringUtils quoteIfString

List of usage examples for org.springframework.util StringUtils quoteIfString

Introduction

In this page you can find the example usage for org.springframework.util StringUtils quoteIfString.

Prototype

@Nullable
public static Object quoteIfString(@Nullable Object obj) 

Source Link

Document

Turn the given Object into a String with single quotes if it is a String ; keeping the Object as-is else.

Usage

From source file:org.springmodules.cache.provider.AbstractCacheProviderFacade.java

/**
 * @see CacheProviderFacade#cancelCacheUpdate(Serializable)
 *///from   w w w .j a v a2  s .  co  m
public final void cancelCacheUpdate(Serializable key) throws CacheException {
    if (logger.isDebugEnabled()) {
        logger.debug("Attempt to cancel a cache update using the key <" + StringUtils.quoteIfString(key) + ">");
    }

    try {
        onCancelCacheUpdate(key);

    } catch (CacheException exception) {
        handleCatchedException(exception);
    }
}

From source file:org.springmodules.cache.provider.AbstractCacheProviderFacade.java

/**
 * @see CacheProviderFacade#getFromCache(Serializable,CachingModel)
 *//*from w  ww .  j  a  v  a2s  . com*/
public final Object getFromCache(Serializable key, CachingModel model) throws CacheException {

    if (logger.isDebugEnabled()) {
        logger.debug("Attempt to retrieve a cache entry using key <" + StringUtils.quoteIfString(key)
                + "> and cache model <" + model + ">");
    }

    Object cachedObject = null;

    try {
        if (model != null) {
            cachedObject = onGetFromCache(key, model);

            // deserialize the value if required
            if (cachedObject != null) {
                cachedObject = deserializeValueIfNecessary(cachedObject);
            }
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Retrieved cache element <" + StringUtils.quoteIfString(cachedObject) + ">");
        }

    } catch (CacheException exception) {
        handleCatchedException(exception);
    }
    return cachedObject;
}

From source file:org.springmodules.cache.integration.AbstractIntegrationTests.java

protected final void assertCacheEntryFromCacheIsNull(Object cacheEntry, Serializable key) {
    assertNull("There should not be any object stored under the key <" + StringUtils.quoteIfString(key) + ">",
            cacheEntry);/* w w  w. ja  v a2s  .co m*/
}

From source file:org.springmodules.cache.provider.AbstractCacheProviderFacade.java

/**
 * @see CacheProviderFacade#putInCache(Serializable,CachingModel,Object)
 * @see #makeSerializableIfNecessary(Object)
 *///from  ww w.  j a  v a 2s. co m
public final void putInCache(Serializable key, CachingModel model, Object obj) throws CacheException {
    if (logger.isDebugEnabled()) {
        logger.debug("Attempt to store the object <" + obj + "> in the cache using key <"
                + StringUtils.quoteIfString(key) + "> and model <" + model + ">");
    }

    try {
        Object newCacheElement = makeSerializableIfNecessary(obj);

        if (model != null) {
            onPutInCache(key, model, newCacheElement);
            logger.debug("Object was successfully stored in the cache");
        }
    } catch (CacheException exception) {
        handleCatchedException(exception);
    }
}

From source file:org.springmodules.cache.provider.AbstractCacheProviderFacade.java

/**
 * @see CacheProviderFacade#removeFromCache(Serializable,CachingModel)
 *//*from w ww.  j  ava 2 s . c  o  m*/
public final void removeFromCache(Serializable key, CachingModel model) throws CacheException {
    if (logger.isDebugEnabled()) {
        logger.debug("Attempt to remove an entry from the cache using key <" + StringUtils.quoteIfString(key)
                + "> and model <" + model + ">");
    }

    if (model != null) {
        try {
            onRemoveFromCache(key, model);
            logger.debug("Object removed from the cache");

        } catch (CacheException exception) {
            handleCatchedException(exception);
        }
    }
}

From source file:org.springmodules.cache.impl.Element.java

/**
 * @see Object#toString()/* w w w . j  a  va  2s  . c  o m*/
 */
public String toString() {
    return Objects.identityToString(this).append("[key=").append(StringUtils.quoteIfString(key)).append(", ")
            .append("value=").append(StringUtils.quoteIfString(value)).append(", ").append("creationTime=")
            .append(new Date(creationTime)).append(", ").append("timeToLive=").append(timeToLive).append("]")
            .toString();
}

From source file:org.springmodules.util.Objects.java

/**
 * Returns a string representation of the contents of the specified array. The
 * string representation consists of a list of the array's elements, enclosed
 * in curly braces (<code>"{}"</code>). Adjacent elements are separated by
 * the characters <code>", "</code> (a comma followed by a space). Returns
 * <code>"null"</code> if <code>array</code> is <code>null</code>.
 * /*w  w  w .  j  a  v a2 s.  c  o m*/
 * @param array
 *          the array whose string representation to return.
 * @return a string representation of <code>array</code>.
 */
public static String nullSafeToString(Object[] array) {
    if (array == null)
        return NULL_ARRAY;

    int length = array.length;
    if (length == 0)
        return EMPTY_ARRAY;

    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < length; i++) {
        if (i == 0)
            buffer.append(ARRAY_START);
        else
            buffer.append(ARRAY_ELEMENT_SEPARATOR);

        buffer.append(StringUtils.quoteIfString(array[i]));
    }

    buffer.append(ARRAY_END);
    return buffer.toString();
}