List of usage examples for org.apache.commons.lang3 ExtendedArrayUtils length
public static final int length(boolean... array)
From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImpl.java
@Override @SuppressWarnings("synthetic-access") public void setProperties(final String id, final Map<String, ?> props) { if (StringUtils.isEmpty(id)) { throw new IllegalArgumentException( "setProperties(" + getEntityClass().getSimpleName() + ") no identifier"); }/*from w w w . ja v a 2 s. c o m*/ if (ExtendedMapUtils.isEmpty(props)) { throw new IllegalArgumentException( "setProperties(" + getEntityClass().getSimpleName() + ")[" + id + "] no properties"); } validatePropertyValues(id, props); Object internalId = findInternalId(id); if (internalId == null) { internalId = createEntityEntry(id); } removeEntityProperties(id); Class<?> idType = internalId.getClass(); InternalIdSetter idSetter = InternalIdSetter.SETTERS_MAP.get(idType); if (idSetter == null) { throw new UnsupportedOperationException("setProperties(" + getEntityClass().getSimpleName() + ")[" + id + "]" + " no identifier setter for type " + idType.getSimpleName()); } @SuppressWarnings("unchecked") Map<String, Object>[] batchValues = new Map[props.size()]; int batchIndex = 0; final Object assignedId = internalId; for (Map.Entry<String, ?> pe : props.entrySet()) { final String propName = pe.getKey(); Object orgValue = pe.getValue(); final Class<?> propType = JdbcOperationsUtils.resolveEffectivePropertyType(orgValue); final Object propValue = JdbcOperationsUtils.resolveEffectivePropertyValue(orgValue); batchValues[batchIndex] = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER) { private static final long serialVersionUID = 1L; { if (!conversionService.canConvert(propType, String.class)) { throw new UnsupportedOperationException( "setProperties(" + id + ")" + " cannot convert " + propName + "[" + propType.getSimpleName() + "]" + " to string for value=" + propValue); } put(PROP_OWNER_COL, assignedId); put(PROP_NAME_COL, propName); put(PROP_TYPE_COL, propType.getName()); put(PROP_VALUE_COL, conversionService.convert(propValue, String.class)); } }; batchIndex++; } try { int[] changeSet = jdbcAccessor.batchUpdate( "INSERT INTO " + ENTITY_PROPERTIES_TABLE + " (" + PROP_OWNER_COL + "," + PROP_NAME_COL + "," + PROP_TYPE_COL + "," + PROP_VALUE_COL + ")" + " VALUES(:" + PROP_OWNER_COL + ",:" + PROP_NAME_COL + ",:" + PROP_TYPE_COL + ",:" + PROP_VALUE_COL + ")", batchValues); if (logger.isDebugEnabled()) { logger.debug("setProperties(" + getEntityClass().getSimpleName() + ")[" + id + "] batch size=" + ExtendedArrayUtils.length(changeSet)); } } catch (RuntimeException e) { logger.warn("setProperties(" + getEntityClass().getSimpleName() + ")[" + id + "]" + " failed (" + e.getClass().getSimpleName() + ") to insert props=" + props + ": " + e.getMessage()); throw e; } }