All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ebeaninternal.server.querydefn.DefaultUpdateQuery Maven / Gradle / Ivy

There is a newer version: 15.8.0
Show newest version
package io.ebeaninternal.server.querydefn;

import io.ebean.ExpressionList;
import io.ebean.ProfileLocation;
import io.ebean.Query;
import io.ebean.UpdateQuery;
import io.ebean.core.type.ScalarType;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanProperty;

/**
 * Default implementation of UpdateQuery.
 */
public final class DefaultUpdateQuery implements UpdateQuery {

  private final OrmUpdateProperties values = new OrmUpdateProperties();
  private final DefaultOrmQuery query;
  private final BeanDescriptor descriptor;

  public DefaultUpdateQuery(DefaultOrmQuery query) {
    this.query = query;
    this.descriptor = query.descriptor();
    query.setUpdateProperties(values);
  }

  @Override
  public UpdateQuery set(String property, Object value) {
    if (value == null) {
      values.setNull(property);
    } else {
      final BeanProperty beanProperty = descriptor.beanProperty(property);
      final ScalarType scalarType = (beanProperty == null) ? null: beanProperty.scalarType();
      values.set(property, value, scalarType);
    }
    return this;
  }

  @Override
  public 

UpdateQuery set(Query.Property

property, P value) { return set(property.toString(), value); } @Override public UpdateQuery setNull(Query.Property property) { return setNull(property.toString()); } @Override public UpdateQuery setNull(String property) { values.setNull(property); return this; } @Override public UpdateQuery setRaw(String propertyExpression) { values.setRaw(propertyExpression); return this; } @Override public UpdateQuery setRaw(String propertyExpression, Object... vals) { values.setRaw(propertyExpression, vals); return this; } @Override public UpdateQuery setProfileLocation(ProfileLocation profileLocation) { query.setProfileLocation(profileLocation); return this; } @Override public UpdateQuery setLabel(String label) { query.setLabel(label); return this; } @Override public ExpressionList where() { return query.where(); } @Override public int update() { return query.update(); } }