Search in sources :

Example 1 with BeanHandler

use of org.apache.commons.dbutils.handlers.BeanHandler in project notes by KevinBlandy.

the class UtilsDemo method find.

public static void find() throws SQLException {
    // ����QueryRunner���󴫵����ӳض���
    QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
    // ����SQLģ��
    String sql = "select * from users where userName=?";
    // ��������
    Object[] params = { "Kevin" };
    // ����SQLģ��Ͳ���,ִ�в�ѯ��䷵�ض���/���߼��ϸ��ݵڶ�����������
    User user = qr.query(sql, new BeanHandler(User.class), params);
}
Also used : BeanHandler(org.apache.commons.dbutils.handlers.BeanHandler) QueryRunner(org.apache.commons.dbutils.QueryRunner)

Example 2 with BeanHandler

use of org.apache.commons.dbutils.handlers.BeanHandler in project metacat by Netflix.

the class MySqlLookupService method get.

/**
     * Returns the lookup for the given <code>name</code>.
     *
     * @param name lookup name
     * @return lookup
     */
@Override
public Lookup get(final String name) {
    Lookup result;
    final Connection connection = DBUtil.getReadConnection(getDataSource());
    try {
        final ResultSetHandler<Lookup> handler = new BeanHandler<>(Lookup.class);
        result = new QueryRunner().query(connection, SQL_GET_LOOKUP, handler, name);
        if (result != null) {
            result.setValues(getValues(result.getId()));
        }
    } catch (Exception e) {
        final String message = String.format("Failed to get the lookup for name %s", name);
        log.error(message, e);
        throw new UserMetadataServiceException(message, e);
    } finally {
        DBUtil.closeReadConnection(connection);
    }
    return result;
}
Also used : UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) Connection(java.sql.Connection) BeanHandler(org.apache.commons.dbutils.handlers.BeanHandler) Lookup(com.netflix.metacat.common.server.model.Lookup) QueryRunner(org.apache.commons.dbutils.QueryRunner) SQLException(java.sql.SQLException) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException)

Example 3 with BeanHandler

use of org.apache.commons.dbutils.handlers.BeanHandler in project metacat by Netflix.

the class MySqlTagService method get.

/**
     * Returns the TagItem for the given <code>name</code>.
     *
     * @param name tag name
     * @return TagItem
     */
public TagItem get(final String name) {
    TagItem result = null;
    final Connection connection = DBUtil.getReadConnection(getDataSource());
    try {
        final ResultSetHandler<TagItem> handler = new BeanHandler<>(TagItem.class);
        result = new QueryRunner().query(connection, SQL_GET_TAG_ITEM, handler, name);
        if (result != null) {
            result.setValues(getValues(result.getId()));
        }
    } catch (Exception e) {
        final String message = String.format("Failed to get the tag item for name %s", name);
        log.error(message, e);
        throw new UserMetadataServiceException(message, e);
    } finally {
        DBUtil.closeReadConnection(connection);
    }
    return result;
}
Also used : UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException) TagItem(com.netflix.metacat.common.server.model.TagItem) Connection(java.sql.Connection) BeanHandler(org.apache.commons.dbutils.handlers.BeanHandler) QueryRunner(org.apache.commons.dbutils.QueryRunner) SQLException(java.sql.SQLException) UserMetadataServiceException(com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException)

Aggregations

QueryRunner (org.apache.commons.dbutils.QueryRunner)3 BeanHandler (org.apache.commons.dbutils.handlers.BeanHandler)3 UserMetadataServiceException (com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 Lookup (com.netflix.metacat.common.server.model.Lookup)1 TagItem (com.netflix.metacat.common.server.model.TagItem)1