Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 9696 invoked from network); 1 Sep 2005 14:16:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Sep 2005 14:16:40 -0000 Received: (qmail 14168 invoked by uid 500); 1 Sep 2005 14:16:37 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 14106 invoked by uid 500); 1 Sep 2005 14:16:36 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 14093 invoked by uid 99); 1 Sep 2005 14:16:36 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Sep 2005 07:16:36 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [196.23.48.130] (HELO incubeta.com) (196.23.48.130) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Sep 2005 07:16:50 -0700 Received: from [192.168.0.99] by incubeta.com (MDaemon.PRO.v8.1.1.R) with ESMTP id md50000440886.msg for ; Thu, 01 Sep 2005 16:13:47 +0200 Message-ID: <43170D38.5010205@incubeta.com> Date: Thu, 01 Sep 2005 16:16:24 +0200 From: Jaco van Niekerk User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: commons-dev@jakarta.apache.org Subject: BasicRowProcessor - Enum to INT mapping Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated-Sender: jaco.v@incubeta.com X-Spam-Processed: incfecpt01, Thu, 01 Sep 2005 16:13:47 +0200 (not processed: message from valid local sender) X-MDRemoteIP: 192.168.0.99 X-Return-Path: jaco.v@incubeta.com X-MDaemon-Deliver-To: commons-dev@jakarta.apache.org X-MDAV-Processed: incfecpt01, Thu, 01 Sep 2005 16:13:49 +0200 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Regarding DbUtils, I've made a small mod to my copy of the DbUtils code. We often map int table fields to enum ordinals, where the enum if for example a status, type etc. Would it be possible to add this to the current BasicRowProcessor? It's a low impact feature, but would require us to re-compile the feature in with every new release of dbutils. /** * Calls the setter method on the target object for the given property. * If no setter method exists for the property, this method does nothing. * @param target The object to set the property on. * @param prop The property to set. * @param value The value to pass into the setter. * @throws SQLException if an error occurs setting the property. */ private void callSetter( Object target, PropertyDescriptor prop, Object value) throws SQLException { Method setter = prop.getWriteMethod(); if (setter == null) { return; } // ****************************************** // new line to call new method getEnumValue() value = getEnumValue(prop, value); Class[] params = setter.getParameterTypes(); try { // Don't call setter if the value object isn't the right type if (this.isCompatibleType(value, params[0])) { setter.invoke(target, new Object[] { value }); } } catch (IllegalArgumentException e) { e.printStackTrace(); throw new SQLException( "Cannot set " + prop.getName() + ": " + e.getMessage()); } catch (IllegalAccessException e) { e.printStackTrace(); throw new SQLException( "Cannot set " + prop.getName() + ": " + e.getMessage()); } catch (InvocationTargetException e) { e.printStackTrace(); throw new SQLException( "Cannot set " + prop.getName() + ": " + e.getMessage()); } } /** * If the bean property is an enum, and the data type an int, this method * return the enum in the integers index position. */ private Object getEnumValue(PropertyDescriptor prop, Object value) { Class propType = prop.getPropertyType(); Class superClass = prop.getPropertyType().getSuperclass(); if (superClass == null) { // no super class, can't be an enum return value; } if (superClass.toString().indexOf("java.lang.Enum") == -1) { // not an enum return value; } Object[] enums = propType.getEnumConstants(); if (enums != null) { if (value instanceof Integer) { try { // replace the current Integer value with the relative Enum value value = enums[(Integer) value]; } catch (ArrayIndexOutOfBoundsException e) { // illegal value } } } return value; } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org