Example usage for org.apache.commons.lang ArrayUtils isEmpty

List of usage examples for org.apache.commons.lang ArrayUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils isEmpty.

Prototype

public static boolean isEmpty(boolean[] array) 

Source Link

Document

Checks if an array of primitive booleans is empty or null.

Usage

From source file:nl.strohalm.cyclos.dao.accounts.transactions.TransferDAOImpl.java

@Override
public Transfer loadTransferByTraceNumber(final String traceNumber, final Long clientId,
        final Relationship... fetch) {
    final Map<String, Object> namedParameters = new HashMap<String, Object>();

    List<Relationship> toFetch = ArrayUtils.isEmpty(fetch) ? null : Arrays.asList(fetch);
    final StringBuilder hql = HibernateHelper.getInitialQuery(getEntityType(), "t", toFetch);
    HibernateHelper.addParameterToQuery(hql, namedParameters, "traceNumber", traceNumber);
    HibernateHelper.addParameterToQuery(hql, namedParameters, "clientId", clientId);
    return uniqueResult(hql.toString(), namedParameters);
}

From source file:nl.strohalm.cyclos.dao.BaseDAOImpl.java

@Override
@SuppressWarnings("unchecked")
public <T extends E> T load(final Long id, final Relationship... fetch) {
    if (id == null) {
        throw new EntityNotFoundException(getEntityType());
    }/*w  w w. j av a  2 s. c o m*/
    try {
        // Determine the best way to load an entity.
        // 1. No second level cache and fetch is used: hql query - bypasses the cache, but can include relationships in a single select
        // 2. With cache: load - probably a cache hit. Then fetch the relationships if any
        T entity = null;
        if (!hasCache && !ArrayUtils.isEmpty(fetch)) {
            // Perform a query
            final Map<String, Object> namedParams = new HashMap<String, Object>();
            final StringBuilder hql = HibernateHelper.getInitialQuery(getEntityType(), "e",
                    Arrays.asList(fetch));
            HibernateHelper.addParameterToQuery(hql, namedParams, "e.id", id);
            final List<E> list = list(ResultType.LIST, hql.toString(), namedParams, PageParameters.unique(),
                    fetch);
            if (list.isEmpty()) {
                throw new EntityNotFoundException(this.getEntityType(), id);
            } else {
                // We must call the fetch DAO anyway because there may be other fetches not retrieved by the hql
                entity = (T) list.iterator().next();
            }
        } else {
            // Perform a normal load
            try {
                // Although there are no fetch relationships we must call the fetch DAO
                // to initialize the entity itself
                entity = (T) getHibernateTemplate().load(getEntityType(), id);
            } catch (final ObjectNotFoundException e) {
                throw new EntityNotFoundException(this.getEntityType(), id);
            }
        }

        return fetchDao.fetch(entity, fetch);
    } catch (final ApplicationException e) {
        throw e;
    } catch (final ObjectNotFoundException e) {
        throw new EntityNotFoundException(getEntityType(), id);
    } catch (final Exception e) {
        throw new DaoException(e);
    }
}

From source file:nl.strohalm.cyclos.dao.FetchDAOImpl.java

/**
 * Does the actual fetch from the database
 *///from w ww.  j  a  v  a 2 s.  co m
@SuppressWarnings("unchecked")
private <E extends Entity> E doFetch(final E inputEntity, final Relationship... fetch) {
    if (inputEntity == null || inputEntity.getId() == null) {
        throw new UnexpectedEntityException();
    }
    E entity;

    // Discover the entity real class and id
    final Class<? extends Entity> entityType = EntityHelper.getRealClass(inputEntity);
    final Long id = inputEntity.getId();

    // Load and initialize the entity
    try {
        entity = (E) getHibernateTemplate().load(entityType, id);
        entity = (E) hibernateQueryHandler.initialize(entity);
    } catch (final ObjectRetrievalFailureException e) {
        throw new EntityNotFoundException(entityType, id);
    } catch (final ObjectNotFoundException e) {
        throw new EntityNotFoundException(entityType, id);
    }

    // ... and fetch each relationship
    if (!ArrayUtils.isEmpty(fetch)) {
        for (final Relationship relationship : fetch) {
            if (relationship == null) {
                continue;
            }
            try {
                final String name = relationship.getName();
                Object bean = entity;
                String first = PropertyHelper.firstProperty(name);
                String nested = PropertyHelper.nestedPath(name);
                while (bean != null && first != null) {
                    final Object value = hibernateQueryHandler.initializeProperty(bean, first);
                    bean = value;
                    first = PropertyHelper.firstProperty(nested);
                    nested = PropertyHelper.nestedPath(nested);
                }
            } catch (final PropertyException e) {
                // Ok - nonexisting property. Probably fetching a relationship that only exists in one of the subclasses, and trying to use it no
                // another one
            } catch (final Exception e) {
                throw new PropertyException(entity, relationship.getName(), e);
            }
        }
    }
    return entity;
}

From source file:nl.strohalm.cyclos.dao.members.AdminNotificationPreferenceDAOImpl.java

@Override
public AdminNotificationPreference load(final Administrator admin, final Relationship... fetch)
        throws DaoException {
    AdminNotificationPreference preference = uniqueResult(
            "select p from " + getEntityType().getName() + " p where p.admin = :admin",
            Collections.singletonMap("admin", admin));
    if (preference == null) {
        throw new EntityNotFoundException(getEntityType());
    }//from w w w .j  a  v  a  2 s. co m
    if (!ArrayUtils.isEmpty(fetch)) {
        preference = getFetchDao().fetch(preference, fetch);
    }
    return preference;
}

From source file:nl.strohalm.cyclos.dao.members.MessageDAOImpl.java

@Override
public void assignPendingToSendByGroups(final Message message, final Collection<MemberGroup> groups) {
    final Long[] groupIds = EntityHelper.toIds(groups);
    if (ArrayUtils.isEmpty(groupIds)) {
        return;/*from  ww  w  .  j a v a  2  s.com*/
    }
    runNative(new JDBCCallback() {
        @Override
        public void execute(final JDBCWrapper jdbc) throws SQLException {
            final StringBuilder sql = new StringBuilder();

            sql.append("insert into messages");
            sql.append(
                    " (date,subject,type,direction,is_read,is_replied,is_html,from_member_id,category_id,body,email_sent,to_member_id)");
            sql.append(" select ?,?,?,?,?,?,?,?,?,?,?,id");
            sql.append(" from members m");
            sql.append(" where m.group_id in (");
            final String[] placeHolders = new String[groupIds.length];
            Arrays.fill(placeHolders, "?");
            sql.append(StringUtils.join(placeHolders, ","));
            sql.append(")");

            final List<Object> params = new ArrayList<Object>();
            params.add(message.getDate());
            params.add(message.getSubject());
            params.add(message.getType().getValue());
            params.add(Message.Direction.INCOMING.getValue());
            params.add(false);
            params.add(false);
            params.add(message.isHtml());
            params.add(null);
            params.add(message.getCategory().getId());
            params.add(message.getBody());
            params.add(false);
            params.addAll(Arrays.asList(groupIds));

            jdbc.execute(sql.toString(), params.toArray());
        }
    });
}

From source file:nl.strohalm.cyclos.entities.accounts.fees.account.AccountFeeLogQuery.java

public void setStatusList(final AccountFeeLog.Status... status) {
    setStatusCollection(ArrayUtils.isEmpty(status) ? null : Arrays.asList(status));
}

From source file:nl.strohalm.cyclos.utils.customizedfile.BaseCustomizedFileHandler.java

protected final synchronized void deleteLocally(final String path) {
    final String realPath = context.getRealPath(path);
    final File file = new File(realPath);
    file.delete();/*from   www  .ja  v  a2s . c  o  m*/
    LOG.debug("Deleted file " + file);
    // Delete the parent directory if empty
    final File dir = file.getParentFile();
    if (ArrayUtils.isEmpty(dir.listFiles())) {
        LOG.debug("Deleted empty dir " + dir);
        dir.delete();
    }
}

From source file:nl.strohalm.cyclos.utils.JDBCWrapper.java

/**
 * Set the given positional parameters on a prepared statement, guessing the argument types
 *//* w  w  w.j a v  a2 s.  co  m*/
private static void setParameters(final PreparedStatement ps, final Object... parameters) throws SQLException {
    if (ps == null || ArrayUtils.isEmpty(parameters)) {
        return;
    }
    for (int i = 0; i < parameters.length; i++) {
        final Object object = parameters[i];
        final int index = i + 1;
        if (object instanceof Number) {
            ps.setBigDecimal(index, CoercionHelper.coerce(BigDecimal.class, object));
        } else if ((object instanceof Calendar) || (object instanceof Date)) {
            final Calendar cal = CoercionHelper.coerce(Calendar.class, object);
            ps.setTimestamp(index, new Timestamp(cal.getTimeInMillis()));
        } else if (object instanceof Boolean) {
            ps.setBoolean(index, (Boolean) object);
        } else {
            ps.setString(index, CoercionHelper.coerce(String.class, object));
        }
    }
}

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandlerImpl.java

/**
 * Builds an action string, appending parameters if detailed logging is enabled
 *//*from  ww w.  ja  v  a 2  s .co  m*/
private String buildActionString(final TraceLogDTO params, final boolean logParameters) {
    final String remoteAddress = params.getRemoteAddress();
    final User user = params.getUser();
    final String requestMethod = params.getRequestMethod();
    final String sessionId = params.getSessionId();
    final String path = params.getPath();
    final Map<String, String[]> parameters = params.getParameters();

    final StringBuilder sb = new StringBuilder();
    appendValue(sb, remoteAddress);
    sb.append(SEPARATOR);
    appendValue(sb, sessionId);
    sb.append(SEPARATOR);
    sb.append(user == null ? "<unknown user>" : user.getUsername()).append(SEPARATOR);
    sb.append(StringUtils.rightPad(requestMethod == null ? "" : requestMethod, 6, ' ')).append(SEPARATOR);
    if (path != null) {
        sb.append(path);
        if (logParameters) {
            // Append the arguments
            sb.append(SEPARATOR);
            boolean first = true;
            for (Map.Entry<String, String[]> entry : parameters.entrySet()) {
                String name = entry.getKey();
                if (first) {
                    first = false;
                } else {
                    sb.append(", ");
                }
                String[] value = entry.getValue();
                if (ArrayUtils.isEmpty(value)) {
                    // Nothing to log
                    continue;
                }
                sb.append(name).append('=');

                if (FormatObject.shouldMask(name)) {
                    sb.append(FormatObject.MASKED_VALUE);
                } else {
                    if (value.length == 1) {
                        appendValue(sb, value[0]);
                    } else {
                        sb.append('[');
                        for (int i = 0; i < value.length; i++) {
                            if (i > 0) {
                                sb.append(',');
                            }
                            appendValue(sb, value[i]);
                        }
                        sb.append(']');
                    }
                }
            }
        }
    }
    return sb.toString();
}

From source file:nl.strohalm.cyclos.utils.lucene.Filters.java

/**
 * Returns all filters in a OR operation
 *///w ww .j  av  a  2s.  c o  m
private static Filter chain(final int logic, Filter... filters) {
    filters = normalize(filters);
    if (ArrayUtils.isEmpty(filters)) {
        return null;
    }
    return new ChainedFilter(filters, logic);
}