Package com.taobao.tdhs.client.easy

Examples of com.taobao.tdhs.client.easy.Insert


        processResponse(response, true);
    }

    private void doInsert(com.taobao.tdhs.client.statement.Statement s, ParseSQL parseSQL, String tableName,
                          String dbName) throws SQLException {
        Insert insert = s.insert().use(dbName).from(tableName);
        List<Entry<String, String>> insertEntries = parseSQL.getInsertEntries();
        if (insertEntries == null || insertEntries.isEmpty()) {
            throw new TDHSSQLException("no value to insert!", parseSQL.getSql());
        }
        for (Entry<String, String> e : insertEntries) {
            if (StringUtils.isBlank(e.getKey()) || StringUtils.isBlank(e.getValue())) {
                throw new TDHSSQLException("insert column and values can't be empty!", parseSQL.getSql());
            }
            String field = StringUtil.escapeField(StringUtils.trim(e.getKey()));
            if (field == null) {
                throw new TDHSSQLException("insert column is error!", parseSQL.getSql());
            }
            String value = StringUtils.trim(e.getValue());
            if (StringUtils.equalsIgnoreCase("null", value)) {
                insert.valueSetNull(field);
            } else if (StringUtils.equalsIgnoreCase("now()", value)) {
                insert.valueSetNow(field);
            } else {
                value = StringUtil.escapeValue(value);
                if (value == null) {
                    throw new TDHSSQLException("insert value is error!", parseSQL.getSql());
                }
                if (StringUtils.startsWith(value, BYTE_PARAMETER_PREFIX)) {
                    int pidx = ConvertUtil.safeConvertInt(StringUtils.substring(value, BYTE_PARAMETER_PREFIX.length()),
                            -1);
                    if (byteParameters.containsKey(pidx)) {
                        insert.value(field, byteParameters.get(pidx));
                    } else {
                        insert.value(field, value);
                    }
                } else {
                    insert.value(field, value);
                }
            }
        }
        TDHSResponse response = null;
        try {
            response = insert.insert();
        } catch (TDHSException e) {
            throw new SQLException(e);
        }
        processResponse(response, null, true, true);
    }
View Full Code Here

TOP

Related Classes of com.taobao.tdhs.client.easy.Insert

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.