/** * Returns an {@link ArrayParams} contains all the values in the given array. */ static ArrayParams array(Object... values) { return new ArrayParams(values); }
/** * Returns an {@link ArrayParams} contains all the values in the given array. */ static ArrayParams of(Object[] array) { return new ArrayParams(array); }
protected Params params(Object[] args) { return null == args ? null : new ArrayParams(args); }
/** * Returns an {@link ArrayParams} contains all the elements in the given collection. */ static ArrayParams of(@SuppressWarnings("rawtypes") Collection c) { return new ArrayParams(null == c ? null : c.toArray()); }
/** * Sets a {@link ArrayParams} for jdbc placeholders in this CriteriaQuery. */ default CriteriaQuery<T> params(Object[] args) { return params(new ArrayParams(args)); }
/** * Sets a {@link ArrayParams} for jdbc placeholders in this query. */ default Query<T> params(Object[] args) { return params(new ArrayParams(args)); }
@Override public CriteriaQuery<T> where(String expression, Object... args) { Args.notEmpty(expression = Strings.trim(expression), "where expression"); where = expression; if (null != args && args.length > 0) { if (args.length == 1 && args[0] instanceof ArrayParams) { this.whereParameters = (ArrayParams) args[0]; } else { this.whereParameters = new ArrayParams(args); } } return this; }
@Override public int executeNamedUpdate(String sqlKey, Object[] args) { return ensureGetSqlCommand(sqlKey).executeUpdate(simpleSqlContext, new ArrayParams(args)); }
protected Params createParameters(SqlContext context, Object params){ ParamsFactory factory = context.getOrmContext().getParameterStrategy(); if(null == params){ return EmptyParams.INSTANCE; } if(!params.getClass().isArray()){ return factory.createParams(params); } Object[] values = Objects2.toObjectArray(params); if(values.length == 1){ return factory.createParams(values[0]); } return new ArrayParams(values); }
@Override @SuppressWarnings({"rawtypes","unchecked"}) public Params createIdParameters(OrmContext context, EntityMapping em, Object id) throws InvalidParametersException { if(null == id){ throw new InvalidParametersException("The id value must not be null"); } String[] keys = em.getKeyFieldNames(); if(id.getClass().isArray()){ Object[] array = Converts.toObjectArray(id); if(array.length != keys.length){ throw new InvalidParameterException("The passed in array's length " + array.length + " not equals to keys size " + keys.length); } return new ArrayParams(Converts.toObjectArray(id)); }else if(id instanceof Map){ return new MapParams((Map)id); }else { if(null != em.getEntityClass() && em.getEntityClass().isAssignableFrom(id.getClass())){ return new BeanParams(id); }else if(keys.length == 1){ return new ArrayParams(id); }else{ throw new UnsupportedParametersException("The class '" + id.getClass().getName() + "' not supported as id parameter"); } } }