Search in sources :

Example 1 with InsertBuilder

use of io.leopard.jdbc.builder.InsertBuilder in project leopard by tanhaichao.

the class WeixinPayDaoMysqlImpl method add.

@Override
public boolean add(String paymentId, String outTradeNo) {
    InsertBuilder builder = new InsertBuilder("weixin_pay_log");
    builder.setString("paymentId", paymentId);
    builder.setString("outTradeNo", outTradeNo);
    builder.setDate("posttime", new Date());
    return jdbc.insertForBoolean(builder);
}
Also used : InsertBuilder(io.leopard.jdbc.builder.InsertBuilder) Date(java.util.Date)

Example 2 with InsertBuilder

use of io.leopard.jdbc.builder.InsertBuilder in project leopard by tanhaichao.

the class ImageDaoMysqlImpl method add.

@Override
public boolean add(Image image) {
    InsertBuilder builder = new InsertBuilder("image");
    builder.setString("imageId", image.getImageId());
    builder.setString("parentId", image.getParentId());
    builder.setString("uri", image.getUri());
    builder.setInt("displayOrder", image.getDisplayOrder());
    builder.setLong("uid", image.getUid());
    builder.setDate("posttime", image.getPosttime());
    return jdbc.insertForBoolean(builder);
}
Also used : InsertBuilder(io.leopard.jdbc.builder.InsertBuilder)

Example 3 with InsertBuilder

use of io.leopard.jdbc.builder.InsertBuilder in project leopard by tanhaichao.

the class JdbcMysqlImpl method insert.

@Override
public boolean insert(String tableName, Object bean) {
    InsertBuilder builder = new InsertBuilder(tableName);
    Field[] fields = bean.getClass().getDeclaredFields();
    for (Field field : fields) {
        String fieldName = field.getName();
        Class<?> type = field.getType();
        field.setAccessible(true);
        Object obj;
        try {
            obj = field.get(bean);
        }// }
         catch (IllegalAccessException e) {
            throw new InvalidDataAccessApiUsageException(e.getMessage());
        }
        if (String.class.equals(type)) {
            builder.setString(fieldName, (String) obj);
        } else if (boolean.class.equals(type) || Boolean.class.equals(type)) {
            builder.setBool(fieldName, (Boolean) obj);
        } else if (int.class.equals(type) || Integer.class.equals(type)) {
            builder.setInt(fieldName, (Integer) obj);
        } else if (long.class.equals(type) || Long.class.equals(type)) {
            builder.setLong(fieldName, (Long) obj);
        } else if (float.class.equals(type) || Float.class.equals(type)) {
            builder.setFloat(fieldName, (Float) obj);
        } else if (double.class.equals(type) || Double.class.equals(type)) {
            builder.setDouble(fieldName, (Double) obj);
        } else if (Date.class.equals(type)) {
            builder.setDate(fieldName, (Date) obj);
        } else if (List.class.equals(type)) {
            builder.setString(fieldName, obj.toString());
        } else {
            throw new InvalidDataAccessApiUsageException("未知数据类型[" + type.getName() + "].");
        }
    }
    return this.insertForBoolean(builder);
}
Also used : InsertBuilder(io.leopard.jdbc.builder.InsertBuilder) Field(java.lang.reflect.Field) InvalidDataAccessApiUsageException(org.springframework.dao.InvalidDataAccessApiUsageException) List(java.util.List)

Example 4 with InsertBuilder

use of io.leopard.jdbc.builder.InsertBuilder in project leopard by tanhaichao.

the class InsertBuilderTest method getSql.

@Test
public void getSql() {
    InsertBuilder builder = new InsertBuilder("table");
    builder.setString("username", "hctan");
    builder.setString("nickname", "ahai");
    String sql = builder.getSql();
    System.out.println("sql:" + sql);
    Assert.assertEquals("INSERT INTO table(username, nickname) values(?, ?);", sql);
    try {
        new InsertBuilder("table").getSql();
        Assert.fail("怎么没有抛异常?");
    } catch (NullPointerException e) {
    }
}
Also used : InsertBuilder(io.leopard.jdbc.builder.InsertBuilder) Test(org.junit.Test)

Example 5 with InsertBuilder

use of io.leopard.jdbc.builder.InsertBuilder in project leopard by tanhaichao.

the class TokenDaoMysqlImpl method add.

@Override
public boolean add(Token token) {
    InsertBuilder builder = new InsertBuilder("token");
    builder.setString("tokenId", token.getTokenId());
    builder.setString("category", token.getCategory());
    builder.setString("target", token.getTarget());
    builder.setString("account", token.getAccount());
    builder.setString("token", token.getToken());
    builder.setBool("used", token.isUsed());
    builder.setDate("posttime", token.getPosttime());
    builder.setDate("expiryTime", token.getExpiryTime());
    builder.setDate("lmodify", token.getLmodify());
    return jdbc.insertForBoolean(builder);
}
Also used : InsertBuilder(io.leopard.jdbc.builder.InsertBuilder)

Aggregations

InsertBuilder (io.leopard.jdbc.builder.InsertBuilder)7 NullInsertBuilder (io.leopard.jdbc.builder.NullInsertBuilder)1 Field (java.lang.reflect.Field)1 Date (java.util.Date)1 List (java.util.List)1 Test (org.junit.Test)1 InvalidDataAccessApiUsageException (org.springframework.dao.InvalidDataAccessApiUsageException)1