Example usage for org.apache.ibatis.jdbc SQL SQL

List of usage examples for org.apache.ibatis.jdbc SQL SQL

Introduction

In this page you can find the example usage for org.apache.ibatis.jdbc SQL SQL.

Prototype

SQL

Source Link

Usage

From source file:com.github.abel533.entity.CommonProvider.java

License:Open Source License

/**
 * ?//w  ww.ja  v  a 2  s. c o m
 *
 * @param params
 * @return
 */
public String delete(final Map<String, Object> params) {
    return new SQL() {
        {
            Object entity = getEntity(params);
            Class<?> entityClass = getEntityClass(params);
            EntityHelper.EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
            MetaObject metaObject = MapperTemplate.forObject(entity);
            DELETE_FROM(entityTable.getName());
            boolean hasValue = false;
            for (EntityHelper.EntityColumn column : entityTable.getEntityClassColumns()) {
                Object value = metaObject.getValue(column.getProperty());
                if (value == null) {
                    continue;
                } else if (column.getJavaType().equals(String.class)) {
                    if (isNotEmpty((String) value)) {
                        WHERE(column.getColumn() + "=#{record." + column.getProperty() + "}");
                        hasValue = true;
                    }
                } else {
                    WHERE(column.getColumn() + "=#{record." + column.getProperty() + "}");
                    hasValue = true;
                }
            }
            if (!hasValue) {
                throw new UnsupportedOperationException("delete???!");
            }
        }
    }.toString();
}

From source file:com.github.abel533.entity.CommonProvider.java

License:Open Source License

/**
 * //from  www.  j ava 2 s.c o  m
 *
 * @param params
 * @return
 */
public String deleteByPrimaryKey(final Map<String, Object> params) {
    return new SQL() {
        {
            Object entity = getEntity(params);
            Class<?> entityClass = getEntityClass(params);
            EntityHelper.EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
            DELETE_FROM(entityTable.getName());
            if (entityTable.getEntityClassPKColumns().size() == 1) {
                EntityHelper.EntityColumn column = entityTable.getEntityClassPKColumns().iterator().next();
                notNullKeyProperty(column.getProperty(), entity);
                WHERE(column.getColumn() + "=#{key}");
            } else {
                applyWherePk(this, MapperTemplate.forObject(entity), entityTable.getEntityClassPKColumns(),
                        "key");
            }
        }
    }.toString();
}

From source file:com.github.abel533.entity.CommonProvider.java

License:Open Source License

/**
 * /* w  w w . j  a v  a 2s. c om*/
 *
 * @param params
 * @return
 */
public String updateByPrimaryKey(final Map<String, Object> params) {
    return new SQL() {
        {
            Object entity = getEntity(params);
            Class<?> entityClass = getEntityClass(params);
            EntityHelper.EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
            MetaObject metaObject = MapperTemplate.forObject(entity);
            UPDATE(entityTable.getName());
            for (EntityHelper.EntityColumn column : entityTable.getEntityClassColumns()) {
                //?ID?...?
                if (!column.isId()) {
                    SET(column.getColumn() + "=#{record." + column.getProperty() + "}");
                }
            }
            applyWherePk(this, metaObject, entityTable.getEntityClassPKColumns(), "record");
        }
    }.toString();
}

From source file:com.github.abel533.entity.CommonProvider.java

License:Open Source License

/**
 * ?//from w w w  .  j a  v a2 s . c o  m
 *
 * @param params
 * @return
 */
public String updateByPrimaryKeySelective(final Map<String, Object> params) {
    return new SQL() {
        {
            Object entity = getEntity(params);
            Class<?> entityClass = getEntityClass(params);
            EntityHelper.EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
            MetaObject metaObject = MapperTemplate.forObject(entity);
            UPDATE(entityTable.getName());
            for (EntityHelper.EntityColumn column : entityTable.getEntityClassColumns()) {
                Object value = metaObject.getValue(column.getProperty());
                //?ID?...?
                if (value != null && !column.isId()) {
                    SET(column.getColumn() + "=#{record." + column.getProperty() + "}");
                }
            }
            applyWherePk(this, metaObject, entityTable.getEntityClassPKColumns(), "record");
        }
    }.toString();
}

From source file:com.github.abel533.entity.CommonProvider.java

License:Open Source License

public String countByExample(final Map<String, Object> params) {
    return new SQL() {
        {/* ww  w  .  ja v  a2  s.c  om*/
            MetaObject example = getExample(params);
            Class<?> entityClass = getEntityClass(params);
            EntityHelper.EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
            SELECT("count(*)");
            FROM(entityTable.getName());
            applyWhere(this, example);
        }
    }.toString();
}

From source file:com.github.abel533.entity.CommonProvider.java

License:Open Source License

public String deleteByExample(final Map<String, Object> params) {
    return new SQL() {
        {//from   www. ja  v  a2s  . c  om
            MetaObject example = getExample(params);
            Class<?> entityClass = getEntityClass(params);
            EntityHelper.EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
            DELETE_FROM(entityTable.getName());
            applyWhere(this, example);
        }
    }.toString();
}

From source file:com.github.abel533.entity.CommonProvider.java

License:Open Source License

public String selectByExample(final Map<String, Object> params) {
    return new SQL() {
        {/*from  w ww .java  2  s .c  om*/
            MetaObject example = getExample(params);
            Class<?> entityClass = getEntityClass(params);
            EntityHelper.EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
            SELECT(EntityHelper.getAllColumns(entityClass));
            FROM(entityTable.getName());
            applyWhere(this, example);
            applyOrderBy(this, example, EntityHelper.getOrderByClause(entityClass).toString());
        }
    }.toString();
}

From source file:com.github.abel533.entity.CommonProvider.java

License:Open Source License

public String updateByExampleSelective(final Map<String, Object> params) {
    return new SQL() {
        {//w  ww .j  a  v a 2  s.com
            Object entity = getEntity(params);
            MetaObject example = getExample(params);
            Class<?> entityClass = getEntityClass(params);
            EntityHelper.EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
            MetaObject metaObject = MapperTemplate.forObject(entity);
            UPDATE(entityTable.getName());
            for (EntityHelper.EntityColumn column : entityTable.getEntityClassColumns()) {
                Object value = metaObject.getValue(column.getProperty());
                //?ID?...?
                if (value != null) {
                    SET(column.getColumn() + "=#{record." + column.getProperty() + "}");
                }
            }
            applyWhere(this, example);
        }
    }.toString();
}

From source file:com.github.abel533.entity.CommonProvider.java

License:Open Source License

public String updateByExample(final Map<String, Object> params) {
    return new SQL() {
        {/*from   w  w  w  .  j  av  a 2 s.  c om*/
            Object entity = getEntity(params);
            MetaObject example = getExample(params);
            Class<?> entityClass = getEntityClass(params);
            EntityHelper.EntityTable entityTable = EntityHelper.getEntityTable(entityClass);
            MetaObject metaObject = MapperTemplate.forObject(entity);
            UPDATE(entityTable.getName());
            for (EntityHelper.EntityColumn column : entityTable.getEntityClassColumns()) {
                //?ID?...?
                if (!column.isId()) {
                    SET(column.getColumn() + "=#{record." + column.getProperty() + "}");
                }
            }
            applyWhere(this, example);
        }
    }.toString();
}

From source file:com.hbc.api.trade.order.mapping.gen.OrderBeanSqlProvider.java

/**
 * This method was generated by MyBatis Generator.
 * This method corresponds to the database table `trade_order`
 *
 * @mbggenerated/* www .  j av a 2  s. c  om*/
 */
public String countByExample(OrderBeanExample example) {
    SQL sql = new SQL();
    sql.SELECT("count(*)").FROM("`trade_order`");
    applyWhere(sql, example, false);
    return sql.toString();
}