public Object get(Object data) throws InvalidMappingException, SQLException, DataException, Exception
{
boolean first;
StringBuilder sql = new StringBuilder();
CormObjectField cf;
CormFieldSetter cfs;
ResultSet rs;
// Comprueba si el objeto proporcionado es un objeto CORM v�lido
if (!OrmFactory.isValidCormObject(data.getClass()))
{
throw new InvalidMappingException(data.getClass() + " is not a CORM object.");
}
// Configura la cl�usula SELECT
sql.append(SQL_SELECT);
sql.append(" ");
first = true;
for (Method method : data.getClass().getMethods())
{
cf = method.getAnnotation(CormObjectField.class);
if (cf != null)
{
sql.append((first ? "" : ", "));
sql.append(cf.dbTableColumn());
first = false;
}
}
sql.append(" ");
// Configura la cl�usula FROM
sql.append(SQL_FROM);
sql.append(" ");
sql.append(OrmFactory.getDbTableName(data.getClass()));
sql.append(" ");
// Genera la cl�usua WHERE
sql.append(getFilter(data));
// Memoriza la sent�ncia SQL generada
this.setLastSqlSentence(sql.toString());
// Ejecuta la sent�ncia SQL
this.getConnection().connect();
rs = this.getConnection().executeSql(sql.toString());
this.getConnection().disconnect();
// Recopila los datos en el objeto
if (rs.next())
{
for (Method method : data.getClass().getMethods())
{
if (method.isAnnotationPresent(CormFieldSetter.class))
{
cfs = method.getAnnotation(CormFieldSetter.class);
Class<?>[] argTypes = method.getParameterTypes();
if (argTypes.length > 0)
{
// Texto
if ((argTypes[0] == String.class) || (argTypes[0] == char.class))
{
method.invoke(data, rs.getString(cfs.dbTableColumn()));
}
// Enteros
else if (argTypes[0] == Integer.class || argTypes[0] == int.class)
{
method.invoke(data, rs.getInt(cfs.dbTableColumn()));
}
else if (argTypes[0] == Long.class || argTypes[0] == long.class)
{
method.invoke(data, rs.getLong(cfs.dbTableColumn()));
}
else if (argTypes[0] == Short.class || argTypes[0] == short.class)
{
method.invoke(data, rs.getShort(cfs.dbTableColumn()));
}
else if (argTypes[0] == Byte.class || argTypes[0] == byte.class)
{
method.invoke(data, rs.getByte(cfs.dbTableColumn()));
}
// Decimales
else if (argTypes[0] == Double.class || argTypes[0] == double.class)
{
method.invoke(data, rs.getDouble(cfs.dbTableColumn()));
}
else if (argTypes[0] == Float.class || argTypes[0] == float.class)
{
method.invoke(data, rs.getFloat(cfs.dbTableColumn()));
}
else if (argTypes[0] == BigDecimal.class)
{
method.invoke(data, rs.getBigDecimal(cfs.dbTableColumn()));
}
// Fechas y horas
else if (argTypes[0] == Date.class)
{
method.invoke(data, rs.getDate(cfs.dbTableColumn()));
}
else if (argTypes[0] == Time.class)
{
method.invoke(data, rs.getTime(cfs.dbTableColumn()));
}
else if (argTypes[0] == Timestamp.class)
{
method.invoke(data, rs.getTimestamp(cfs.dbTableColumn()));
}
// Booleanos
else if (argTypes[0] == boolean.class || argTypes[0] == Boolean.class)
{
method.invoke(data, rs.getBoolean(cfs.dbTableColumn()));
}
}
}
}