public static String getQueryDefault( Class<? extends AbstractEntity> entityClass, Map<String, BeanProperty> map, AbstractDto dto, Integer campoOrdenacao) { String select = "SELECT o FROM " + entityClass.getSimpleName() + " o WHERE 0=0"; StringBuffer where = new StringBuffer(); for (String key : map.keySet()) { BeanProperty prop = map.get(key); if (prop.getType().equals(String.class)) { where.append(" AND UPPER(o." + prop.getName() + ") LIKE UPPER(:" + prop.getName() + ")"); } else { where.append(" AND o." + prop.getName() + " = :" + prop.getName()); } } if (campoOrdenacao != null) { where.append(" ORDER BY " + campoOrdenacao); } String query = select + where.toString(); return query; }
protected JsonSerializer<Object> getSer(BeanProperty prop) throws JsonMappingException { JsonSerializer<Object> ser = null; // 26-Jul-2013, tatu: This is ugly, should NOT require cast... if (prop instanceof BeanPropertyWriter) { ser = ((BeanPropertyWriter) prop).getSerializer(); } if (ser == null) { ser = getProvider().findValueSerializer(prop.getType(), prop); } return ser; }
public static void setParemeters(Query query, Map<String, BeanProperty> props) { for (String key : props.keySet()) { BeanProperty prop = props.get(key); if (prop.getType().equals(String.class)) { query.setParameter(prop.getName(), "%" + prop.getValue() + "%"); } else { query.setParameter(prop.getName(), prop.getValue()); } } }
protected JsonSchema propertySchema(BeanProperty prop) throws JsonMappingException { if (prop == null) { throw new IllegalArgumentException("Null property"); } SchemaFactoryWrapper visitor = wrapperFactory.getWrapper(getProvider()); JsonSerializer<Object> ser = getSer(prop); if (ser != null) { JavaType type = prop.getType(); if (type == null) { throw new IllegalStateException("Missing type for property '" + prop.getName() + "'"); } ser.acceptJsonFormatVisitor(visitor, type); } return visitor.finalSchema(); }
Converter<?> provide(BeanProperty property, Genson genson) { Type type = property.getType(); for (Iterator<? extends ContextualFactory<?>> it = contextualFactories.iterator(); it.hasNext(); ) { ContextualFactory<?> factory = it.next(); Converter<?> object = null; Type factoryType = lookupGenericType(ContextualFactory.class, factory.getClass()); factoryType = expandType(factoryType, factory.getClass()); Type factoryParameter = typeOf(0, factoryType); if (type instanceof Class<?> && ((Class<?>) type).isPrimitive()) type = wrap((Class<?>) type); if (match(type, factoryParameter, false) && (object = factory.create(property, genson)) != null) { return object; } } return null; }
/** {@inheritDoc} */ public void setValue(Object instance, String propertyName, Object value) { BeanProperty bp = getBeanProperty(instance, propertyName); if (bp != null) { if (bp.isWrite()) { try { Class desiredPropClass = bp.getType(); TypeMarshaller marshaller = TypeMarshallingContext.getTypeMarshaller(); value = marshaller.convert(value, desiredPropClass); ClassUtil.validateAssignment(instance, propertyName, value); bp.set(instance, value); } catch (Exception e) { SerializationContext context = getSerializationContext(); // Log ignore failed property set errors if (Log.isWarn() && logPropertyErrors(context)) { Logger log = Log.getLogger(LOG_CATEGORY); log.warn( "Failed to set property {0} on type {1}.", new Object[] {propertyName, getAlias(instance)}, e); } if (!ignorePropertyErrors(context)) { // Failed to get property '{propertyName}' on type '{className}'. MessageException ex = new MessageException(); ex.setMessage( FAILED_PROPERTY_WRITE_ERROR, new Object[] {propertyName, getAlias(instance)}); ex.setRootCause(e); throw ex; } } } else { SerializationContext context = getSerializationContext(); if (Log.isWarn() && logPropertyErrors(context)) { Logger log = Log.getLogger(LOG_CATEGORY); log.warn( "Property {0} not writable on class {1}", new Object[] {propertyName, getAlias(instance)}); } if (!ignorePropertyErrors(context)) { // Property '{propertyName}' not writable on class '{alias}'. MessageException ex = new MessageException(); ex.setMessage( NON_WRITABLE_PROPERTY_ERROR, new Object[] {propertyName, getAlias(instance)}); throw ex; } } } else { SerializationContext context = getSerializationContext(); if (Log.isWarn() && logPropertyErrors(context)) { Logger log = Log.getLogger(LOG_CATEGORY); log.warn( "Ignoring set property {0} for type {1} as a setter could not be found.", new Object[] {propertyName, getAlias(instance)}); } if (!ignorePropertyErrors(context)) { // Property '{propertyName}' not found on class '{alias}'. MessageException ex = new MessageException(); ex.setMessage(UNKNOWN_PROPERTY_ERROR, new Object[] {propertyName, getAlias(instance)}); throw ex; } } }
/** {@inheritDoc} */ public Class getType(Object instance, String propertyName) { if (instance == null || propertyName == null) return null; BeanProperty bp = getBeanProperty(instance, propertyName); return bp == null ? null : bp.getType(); }