1 19 20 package org.apache.cayenne.access.types; 21 22 import java.sql.CallableStatement ; 23 import java.sql.PreparedStatement ; 24 import java.sql.ResultSet ; 25 26 import org.apache.commons.lang.builder.ToStringBuilder; 27 import org.apache.cayenne.map.DbAttribute; 28 import org.apache.cayenne.validation.BeanValidationFailure; 29 import org.apache.cayenne.validation.ValidationResult; 30 31 39 public abstract class AbstractType implements ExtendedType { 40 41 47 public static boolean validateNull( 48 Object source, 49 String property, 50 Object value, 51 DbAttribute dbAttribute, 52 ValidationResult validationResult) { 53 if (dbAttribute.isMandatory() && value == null) { 54 validationResult.addFailure(new BeanValidationFailure(source, property, "'" 55 + property 56 + "' must be not null")); 57 return false; 58 } 59 60 return true; 61 } 62 63 68 public void setJdbcObject( 69 PreparedStatement st, 70 Object val, 71 int pos, 72 int type, 73 int precision) throws Exception { 74 75 if (precision != -1) { 76 st.setObject(pos, val, type, precision); 77 } 78 else { 79 st.setObject(pos, val, type); 80 } 81 } 82 83 public abstract String getClassName(); 84 85 public abstract Object materializeObject(CallableStatement rs, int index, int type) 86 throws Exception ; 87 88 public abstract Object materializeObject(ResultSet rs, int index, int type) 89 throws Exception ; 90 91 97 public boolean validateProperty( 98 Object source, 99 String property, 100 Object value, 101 DbAttribute dbAttribute, 102 ValidationResult validationResult) { 103 return true; 104 } 105 106 public String toString() { 107 return new ToStringBuilder(this).append("className", getClassName()).toString(); 108 } 109 110 } 111 | Popular Tags |