I'm very new to torque and some new to Java, I'd like to learn new
skills by using them on real projects.
At this time I choose to learn Torque, I have data to use to populate
certain tables on my DB.
The ne_q table has a lot of data to be distributed among other tables,
i.e. the employees data, I wrote this to populate the
employees(empleados) table.
I added a method doSelectEmpleados() to NeQPeer to store the data needed
on an object.
And a method doInsertNeQEmpleados() to Empleados.java to insert the data.
Then I call the doInsertNeQEmpleados() method from somewhere else. This
works fine, but I'd like to have some feedbakc to know how this could be
improved.
I have only one problem on doInsertNeQEmpleados(), when the line
empleado.setIdUmed(Integer.parseInt(record.getValue("id_umed").asString()));
receives a null from the table, maybe this could be fixed with an If
sentence, but I wrote this around 5:00 A.M, I will try to fix this later.
Thanks in advance for your feedback, i think torque is a great tool.
------------ NeQPeer.java --------------
import java.util.List;
import org.apache.torque.TorqueException;
public class NeQPeer
extends mx.gob.ssatam.om.BaseNeQPeer
{
public static List doSelectEmpleados() throws TorqueException
{
String SQL = "select trim(rfc) as rfc, null as curp, " +
"trim(right(right(nombre,length(nombre)-locate('
',nombre)),length(right(nombre,length(nombre)-locate(' ',nombre))) -
locate(' ',right(nombre,length(nombre)-locate(' ',nombre))))) as nombre, " +
"trim(left(nombre,locate(' ',nombre)-1)) as apaterno,
trim(left(right(nombre,length(nombre)-locate(' ',nombre)),locate('
',right(nombre,length(nombre)-locate(' ',nombre)))-1)) as amaterno, " +
"1 as id_umed, case tiponom when 'F' then 8 when 'H' then 4 when 'R'
then 6 when 'N' then 5 end as tipo_nomina " +
"from ne_q order by nce;";
List records = NeQPeer.executeQuery(SQL);
return records;
}
}
----------- Empleados.java -----------
import java.util.*;
import org.apache.torque.TorqueException;
import com.workingdogs.village.Record;
import com.workingdogs.village.DataSetException;
import mx.gob.ssatam.om.NeQPeer.*;
import org.apache.torque.om.Persistent;
public class Empleados
extends mx.gob.ssatam.om.BaseEmpleados
implements Persistent
{
public static void doInsertNeQEmpleados() throws TorqueException,
DataSetException
{
List records = NeQPeer.doSelectEmpleados();
for (Iterator i = records.iterator(); i.hasNext();)
{
Record record = (Record) i.next();
Empleados empleado = new Empleados();
empleado.setRfc(record.getValue("rfc").asString());
empleado.setCurp(record.getValue("curp").asString());
empleado.setNombre(record.getValue("nombre").asString());
empleado.setApaterno(record.getValue("apaterno").asString());
empleado.setAmaterno(record.getValue("amaterno").asString());
empleado.setIdUmed(Integer.parseInt(record.getValue("id_umed").asString()));
empleado.setTipoNomina(Integer.parseInt(record.getValue("tipo_nomina").asString()));
EmpleadosPeer.doInsert(empleado);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]