List of usage examples for java.sql ResultSet getDate
java.sql.Date getDate(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Date
object in the Java programming language. From source file:com.mimp.hibernate.HiberEtapa.java
public ArrayList<ExpedienteFamilia> getListaEsperaAdopcionInter() { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();// w w w.j a v a2 s .c om final ArrayList<ExpedienteFamilia> allEspera = new ArrayList(); Work work = new Work() { @Override public void execute(Connection connection) throws SQLException { String hql = "{call HE_GET_LISTA_ESPERA_INTER(?)}"; CallableStatement statement = connection.prepareCall(hql); statement.registerOutParameter(1, OracleTypes.CURSOR); statement.execute(); temp_expediente = (ResultSet) statement.getObject(1); while (temp_expediente.next()) { ExpedienteFamilia expFamilia = new ExpedienteFamilia(); Familia fam = new Familia(); Unidad unidad = new Unidad(); Personal personal = new Personal(); expFamilia.setIdexpedienteFamilia(temp_expediente.getLong(1)); if (temp_expediente.getLong(2) != 0) { String hql2 = "{call HE_GETFAMILIA(?, ?)}"; CallableStatement statement2 = connection.prepareCall(hql2); statement2.setLong(1, temp_expediente.getLong(2)); statement2.registerOutParameter(2, OracleTypes.CURSOR); statement2.execute(); temp2 = (ResultSet) statement2.getObject(2); while (temp2.next()) { fam.setIdfamilia(temp2.getLong(1)); expFamilia.setFamilia(fam); } temp2.close(); statement2.close(); } if (temp_expediente.getLong(3) != 0) { String hql3 = "{call HE_GET_UNIDAD(?, ?)}"; CallableStatement statement3 = connection.prepareCall(hql3); statement3.setLong(1, temp_expediente.getLong(3)); statement3.registerOutParameter(2, OracleTypes.CURSOR); statement3.execute(); temp2 = (ResultSet) statement3.getObject(2); while (temp2.next()) { unidad.setIdunidad(temp2.getLong(1)); unidad.setDepartamento(temp2.getString("DEPARTAMENTO")); expFamilia.setUnidad(unidad); } temp2.close(); statement3.close(); } expFamilia.setNumero(temp_expediente.getLong(4)); expFamilia.setExpediente(temp_expediente.getString(5)); expFamilia.setHt(temp_expediente.getString(6)); expFamilia.setNumeroExpediente(temp_expediente.getString(7)); expFamilia.setFechaIngresoDga(temp_expediente.getDate(8)); expFamilia.setEstado(temp_expediente.getString(9)); expFamilia.setTupa(temp_expediente.getDate(10)); expFamilia.setNacionalidad(temp_expediente.getString(11)); expFamilia.setRnsa(temp_expediente.getShort(12)); expFamilia.setRnaa(temp_expediente.getShort(13)); expFamilia.setTipoFamilia(temp_expediente.getString(14)); expFamilia.setTipoListaEspera(temp_expediente.getString(15)); expFamilia.setHtFicha(temp_expediente.getString(16)); expFamilia.setnFicha(temp_expediente.getString(17)); expFamilia.setFechaIngresoFicha(temp_expediente.getDate(18)); Set<Evaluacion> listaEv = new HashSet<Evaluacion>(); String hql2 = "{call HE_GET_LISTA_EVALUACIONES(?,?)}"; CallableStatement statement2 = connection.prepareCall(hql2); statement2.setLong(1, expFamilia.getIdexpedienteFamilia()); statement2.registerOutParameter(2, OracleTypes.CURSOR); statement2.execute(); ResultSet rs2 = (ResultSet) statement2.getObject(2); while (rs2.next()) { Evaluacion tempEval = new Evaluacion(); tempEval.setIdevaluacion(rs2.getLong("IDEVALUACION")); tempEval.setExpedienteFamilia(expFamilia); tempEval.setTipo(rs2.getString("TIPO")); tempEval.setFechaAsignacion(rs2.getDate("FECHA_ASIGNACION")); tempEval.setResultado(rs2.getString("RESULTADO")); tempEval.setFechaResultado(rs2.getDate("FECHA_RESULTADO")); tempEval.setObservacion(rs2.getString("OBSERVACION")); tempEval.setSustento(rs2.getString("SUSTENTO")); tempEval.setNDesignacion(rs2.getString("N_DESIGNACION")); tempEval.setNumEval(rs2.getString("NUM_EVAL")); Set<Resolucion> listaRe = new HashSet<Resolucion>(); if (tempEval.getTipo().equals("legal")) { String hql3 = "{call HE_GET_RESOLUCION_APTA(?,?)}"; CallableStatement statement3 = connection.prepareCall(hql3); statement3.setLong(1, tempEval.getIdevaluacion()); statement3.registerOutParameter(2, OracleTypes.CURSOR); statement3.execute(); ResultSet rs3 = (ResultSet) statement3.getObject(2); if (rs3.next()) { Resolucion tempResol = new Resolucion(); tempResol.setIdresolucion(rs3.getLong("IDRESOLUCION")); tempResol.setTipo(rs3.getString("TIPO")); tempResol.setNumero(rs3.getString("NUMERO")); tempResol.setFechaResol(rs3.getDate("FECHA_RESOL")); tempResol.setFechaNotificacion(rs3.getDate("FECHA_NOTIFICACION")); tempResol.setEvaluacion(tempEval); listaRe.add(tempResol); } rs3.close(); statement3.close(); } tempEval.setResolucions(listaRe); listaEv.add(tempEval); } rs2.close(); statement2.close(); expFamilia.setEvaluacions(listaEv); allEspera.add(expFamilia); } temp_expediente.close(); statement.close(); } }; session.doWork(work); return allEspera; }
From source file:com.mimp.hibernate.HiberEtapa.java
public ArrayList<Designacion> getListaDesignaciones(String numDesig) { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();//from w ww . j a va2 s.c o m final String nDesig = numDesig; final ArrayList<Designacion> allDesig = new ArrayList(); Work work = new Work() { @Override public void execute(Connection connection) throws SQLException { ExpedienteNna expnna; String hql = "{call HE_LISTADESIG_BY_NDESIG(?,?)}"; CallableStatement statement = connection.prepareCall(hql); statement.setString(1, nDesig); statement.registerOutParameter(2, OracleTypes.CURSOR); statement.execute(); ResultSet rs = (ResultSet) statement.getObject(2); while (rs.next()) { Designacion tempDesig = new Designacion(); ExpedienteFamilia tempEF = new ExpedienteFamilia(); Nna tempNna = new Nna(); Personal tempPerso = new Personal(); tempDesig.setIddesignacion(rs.getLong(1)); tempDesig.setNDesignacion(rs.getString(5)); tempDesig.setPrioridad(rs.getLong(6)); tempDesig.setFechaPropuesta(rs.getDate(7)); tempDesig.setFechaConsejo(rs.getDate(8)); tempDesig.setAceptacionConsejo(rs.getShort(9)); tempDesig.setTipoPropuesta(rs.getString(10)); tempDesig.setObs(rs.getString(11)); tempPerso.setIdpersonal(rs.getLong(4)); tempEF.setIdexpedienteFamilia(rs.getLong(2)); tempEF.setExpediente(rs.getString("EXPEDIENTE")); tempEF.setHt(rs.getString("HT")); tempEF.setNumeroExpediente(rs.getString("NUMERO_EXPEDIENTE")); tempEF.setFechaIngresoDga(rs.getDate("FECHA_INGRESO_DGA")); tempEF.setEstado(rs.getString("ESTADO")); tempEF.setTupa(rs.getDate("TUPA")); tempEF.setNacionalidad(rs.getString("NACIONALIDAD")); tempEF.setRnsa(rs.getShort("RNSA")); tempEF.setRnaa(rs.getShort("RNAA")); tempEF.setTipoFamilia(rs.getString("TIPO_FAMILIA")); tempEF.setTipoListaEspera(rs.getString("TIPO_LISTA_ESPERA")); tempEF.setHtFicha(rs.getString("HTFICHA")); tempEF.setnFicha(rs.getString("NFICHA")); tempEF.setFechaIngresoFicha(rs.getDate("FECHA_INGRESO_FICHA")); tempNna.setIdnna(rs.getLong("IDNNA")); tempNna.setNombre(rs.getString("NOMBRE")); tempNna.setApellidoP(rs.getString("APELLIDO_P")); tempNna.setApellidoM(rs.getString("APELLIDO_M")); tempNna.setSexo(rs.getString("SEXO")); tempNna.setFechaNacimiento(rs.getDate("FECHA_NACIMIENTO")); tempNna.setEdadAnhos(rs.getShort("EDAD_ANHOS")); tempNna.setEdadMeses(rs.getShort("EDAD_MESES")); tempNna.setActaNacimiento(rs.getShort("ACTA_NACIMIENTO")); tempNna.setCondicionSalud(rs.getString("CONDICION_SALUD")); tempNna.setDepartamentoNacimiento(rs.getString("DEPARTAMENTO_NACIMIENTO")); tempNna.setProvinciaNacimiento(rs.getString("PROVINCIA_NACIMIENTO")); tempNna.setDistritoNacimiento(rs.getString("DISTRITO_NACIMIENTO")); tempNna.setPaisNacimiento(rs.getString("PAIS_NACIMIENTO")); tempNna.setLugarNac(rs.getString("LUGAR_NAC")); tempNna.setFechaResolAbandono(rs.getDate("FECHA_RESOL_ABANDONO")); tempNna.setFechaResolConsentida(rs.getDate("FECHA_RESOL_CONSENTIDA")); tempNna.setClasificacion(rs.getString("CLASIFICACION")); tempNna.setIncesto(rs.getShort("INCESTO")); tempNna.setMental(rs.getShort("MENTAL")); tempNna.setEpilepsia(rs.getShort("EPILEPSIA")); tempNna.setAbuso(rs.getShort("ABUSO")); tempNna.setSifilis(rs.getShort("SIFILIS")); tempNna.setSeguiMedico(rs.getShort("SEGUI_MEDICO")); tempNna.setOperacion(rs.getShort("OPERACION")); tempNna.setHiperactivo(rs.getShort("HIPERACTIVO")); tempNna.setEspecial(rs.getShort("ESPECIAL")); tempNna.setEnfermo(rs.getShort("ENFERMO")); tempNna.setMayor(rs.getShort("MAYOR")); tempNna.setAdolescente(rs.getShort("ADOLESCENTE")); tempNna.setHermano(rs.getShort("HERMANO")); tempNna.setNn(rs.getShort("NN")); tempNna.setObservaciones(rs.getString("OBSERVACIONES")); tempNna.setNResolAband(rs.getString("N_RESOL_ABAND")); tempNna.setNResolCons(rs.getString("N_RESOL_CONS")); tempDesig.setExpedienteFamilia(tempEF); tempDesig.setNna(tempNna); tempDesig.setPersonal(tempPerso); allDesig.add(tempDesig); } rs.close(); statement.close(); } }; session.doWork(work); return allDesig; }
From source file:com.mimp.hibernate.HiberEtapa.java
public ArrayList<Designacion> getListaDesignacionesEstadoAdopcion(String numDesig) { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();// w w w . ja v a2s . co m final String nDesig = numDesig; final ArrayList<Designacion> allDesig = new ArrayList(); Work work = new Work() { @Override public void execute(Connection connection) throws SQLException { ExpedienteNna expnna; String hql = "{call HE_DESIG_EST_ADOP(?,?)}"; CallableStatement statement = connection.prepareCall(hql); statement.setString(1, nDesig); statement.registerOutParameter(2, OracleTypes.CURSOR); statement.execute(); ResultSet rs = (ResultSet) statement.getObject(2); while (rs.next()) { Designacion tempDesig = new Designacion(); ExpedienteFamilia tempEF = new ExpedienteFamilia(); Nna tempNna = new Nna(); Personal tempPerso = new Personal(); tempDesig.setIddesignacion(rs.getLong(1)); tempDesig.setNDesignacion(rs.getString(5)); tempDesig.setPrioridad(rs.getLong(6)); tempDesig.setFechaPropuesta(rs.getDate(7)); tempDesig.setFechaConsejo(rs.getDate(8)); tempDesig.setAceptacionConsejo(rs.getShort(9)); tempDesig.setTipoPropuesta(rs.getString(10)); tempDesig.setObs(rs.getString(11)); tempPerso.setIdpersonal(rs.getLong(4)); tempEF.setIdexpedienteFamilia(rs.getLong(2)); tempEF.setExpediente(rs.getString("EXPEDIENTE")); tempEF.setHt(rs.getString("HT")); tempEF.setNumeroExpediente(rs.getString("NUMERO_EXPEDIENTE")); tempEF.setFechaIngresoDga(rs.getDate("FECHA_INGRESO_DGA")); tempEF.setEstado(rs.getString("ESTADO")); tempEF.setTupa(rs.getDate("TUPA")); tempEF.setNacionalidad(rs.getString("NACIONALIDAD")); tempEF.setRnsa(rs.getShort("RNSA")); tempEF.setRnaa(rs.getShort("RNAA")); tempEF.setTipoFamilia(rs.getString("TIPO_FAMILIA")); tempEF.setTipoListaEspera(rs.getString("TIPO_LISTA_ESPERA")); tempEF.setHtFicha(rs.getString("HTFICHA")); tempEF.setnFicha(rs.getString("NFICHA")); tempEF.setFechaIngresoFicha(rs.getDate("FECHA_INGRESO_FICHA")); tempNna.setIdnna(rs.getLong("IDNNA")); tempNna.setNombre(rs.getString("NOMBRE")); tempNna.setApellidoP(rs.getString("APELLIDO_P")); tempNna.setApellidoM(rs.getString("APELLIDO_M")); tempNna.setSexo(rs.getString("SEXO")); tempNna.setFechaNacimiento(rs.getDate("FECHA_NACIMIENTO")); tempNna.setEdadAnhos(rs.getShort("EDAD_ANHOS")); tempNna.setEdadMeses(rs.getShort("EDAD_MESES")); tempNna.setActaNacimiento(rs.getShort("ACTA_NACIMIENTO")); tempNna.setCondicionSalud(rs.getString("CONDICION_SALUD")); tempNna.setDepartamentoNacimiento(rs.getString("DEPARTAMENTO_NACIMIENTO")); tempNna.setProvinciaNacimiento(rs.getString("PROVINCIA_NACIMIENTO")); tempNna.setDistritoNacimiento(rs.getString("DISTRITO_NACIMIENTO")); tempNna.setPaisNacimiento(rs.getString("PAIS_NACIMIENTO")); tempNna.setLugarNac(rs.getString("LUGAR_NAC")); tempNna.setFechaResolAbandono(rs.getDate("FECHA_RESOL_ABANDONO")); tempNna.setFechaResolConsentida(rs.getDate("FECHA_RESOL_CONSENTIDA")); tempNna.setClasificacion(rs.getString("CLASIFICACION")); tempNna.setIncesto(rs.getShort("INCESTO")); tempNna.setMental(rs.getShort("MENTAL")); tempNna.setEpilepsia(rs.getShort("EPILEPSIA")); tempNna.setAbuso(rs.getShort("ABUSO")); tempNna.setSifilis(rs.getShort("SIFILIS")); tempNna.setSeguiMedico(rs.getShort("SEGUI_MEDICO")); tempNna.setOperacion(rs.getShort("OPERACION")); tempNna.setHiperactivo(rs.getShort("HIPERACTIVO")); tempNna.setEspecial(rs.getShort("ESPECIAL")); tempNna.setEnfermo(rs.getShort("ENFERMO")); tempNna.setMayor(rs.getShort("MAYOR")); tempNna.setAdolescente(rs.getShort("ADOLESCENTE")); tempNna.setHermano(rs.getShort("HERMANO")); tempNna.setNn(rs.getShort("NN")); tempNna.setObservaciones(rs.getString("OBSERVACIONES")); tempNna.setNResolAband(rs.getString("N_RESOL_ABAND")); tempNna.setNResolCons(rs.getString("N_RESOL_CONS")); tempDesig.setExpedienteFamilia(tempEF); tempDesig.setNna(tempNna); tempDesig.setPersonal(tempPerso); allDesig.add(tempDesig); } rs.close(); statement.close(); } }; session.doWork(work); return allDesig; }
From source file:edu.ku.brc.specify.conversion.BasicSQLUtils.java
/** * @param fromConn// www. j a v a 2 s .c o m * @param toConn * @param sql * @param fromTableName * @param toTableName * @param colNewToOldMap * @param verbatimDateMapper * @param newColDefValues * @param sourceServerType * @param destServerType * @return */ public static boolean copyTable(final Connection fromConn, final Connection toConn, final String sql, final String countSQL, final String fromTableName, final String toTableName, final Map<String, String> colNewToOldMap, final Map<String, String> verbatimDateMapper, final Map<String, String> newColDefValues, final SERVERTYPE sourceServerType, final SERVERTYPE destServerType) { //Timestamp now = new Timestamp(System.currentTimeMillis()); IdMapperMgr idMapperMgr = IdMapperMgr.getInstance(); if (frame != null) { frame.setDesc("Copying Table " + fromTableName); } log.info("Copying Table " + fromTableName); List<String> fromFieldNameList = getFieldNamesFromSchema(fromConn, fromTableName); String sqlStr = sql + " ORDER BY " + fromTableName + "." + fromFieldNameList.get(0); log.debug(sqlStr); int numRecs; if (countSQL == null) { numRecs = getNumRecords(fromConn, fromTableName); } else { numRecs = getCountAsInt(fromConn, countSQL); } setProcess(0, numRecs); DBTableInfo tblInfo = DBTableIdMgr.getInstance().getInfoByTableName(toTableName); Statement updateStatement = null; String id = ""; try { updateStatement = toConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); if (BasicSQLUtils.myDestinationServerType != BasicSQLUtils.SERVERTYPE.MS_SQLServer) { BasicSQLUtils.removeForeignKeyConstraints(toConn, BasicSQLUtils.myDestinationServerType); } //HashMap<String, Integer> newDBFieldHash = new HashMap<String, Integer>(); List<FieldMetaData> newFieldMetaData = getFieldMetaDataFromSchema(toConn, toTableName); //int inx = 1; //for (FieldMetaData fmd : newFieldMetaData) //{ // newDBFieldHash.put(fmd.getName(), inx++); //} Statement stmt = fromConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); //System.out.println(sqlStr); ResultSet rs = stmt.executeQuery(sqlStr); ResultSetMetaData rsmd = rs.getMetaData(); Vector<Integer> dateColumns = new Vector<Integer>(); //System.out.println(toTableName); Hashtable<String, Integer> fromHash = new Hashtable<String, Integer>(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { String colName = rsmd.getColumnName(i); fromHash.put(colName, i); //System.out.println(rsmd.getColumnName(i)+" -> "+i); if (rsmd.getColumnType(i) == java.sql.Types.DATE || colName.toLowerCase().endsWith("date") || colName.toLowerCase().startsWith("date")) { //System.out.println("Date: "+rsmd.getColumnName(i)+" -> "+i); dateColumns.add(i); } } Hashtable<String, String> oldNameToNewNameHash = new Hashtable<String, String>(); if (colNewToOldMap != null) { for (String newName : colNewToOldMap.keySet()) { String oldName = colNewToOldMap.get(newName); System.out .println("Mapping oldName[" + (oldName == null ? newName : oldName) + " -> " + newName); oldNameToNewNameHash.put(oldName == null ? newName : oldName, newName); } } // System.out.println("Num Cols: "+rsmd.getColumnCount()); Map<String, PartialDateConv> dateMap = new Hashtable<String, PartialDateConv>(); String insertSQL = null; // Get the columns that have dates in case we get a TimestampCreated date that is null // and then we can go looking for an older date to try to figure it out Integer timestampModifiedInx = fromHash.get("TimestampModified"); Integer timestampCreatedInx = fromHash.get("TimestampCreated"); boolean isAccessionTable = fromTableName.equals("accession"); boolean hasInstIdCol = fromTableName.equals("permit") || fromTableName.equals("journal") || fromTableName.equals("referencework"); StringBuffer str = new StringBuffer(1024); int count = 0; while (rs.next()) { boolean skipRecord = false; dateMap.clear(); // Start by going through the resultset and converting all dates from Integers // to real dates and keep the verbatium date information if it is a partial date for (int i : dateColumns) { String oldColName = rsmd.getColumnName(i); Integer oldColIndex = fromHash.get(oldColName); if (oldColIndex == null) { log.error("Couldn't find new column for old column for date for Table[" + fromTableName + "] Col Name[" + newFieldMetaData.get(i).getName() + "]"); continue; } if (oldColIndex > newFieldMetaData.size()) { continue; } String newColName = colNewToOldMap != null ? oldNameToNewNameHash.get(oldColName) : null; if (newColName == null) { newColName = oldColName; } Object dataObj = rs.getObject(i); if (dataObj instanceof Integer) { PartialDateConv datep = new PartialDateConv(); getPartialDate((Integer) dataObj, datep); // fills in Verbatim also dateMap.put(newColName, datep); } } // OK here we make sure that both the created dated ad modified date are not null // and we copy the date if one has a value and the other does not. Date timestampCreatedCached = now; Date timestampModifiedCached = now; if (timestampModifiedInx != null && timestampCreatedInx != null) { timestampModifiedCached = rs.getDate(timestampModifiedInx); timestampCreatedCached = rs.getDate(timestampCreatedInx); if (timestampModifiedCached == null && timestampCreatedCached == null) { timestampCreatedCached = Calendar.getInstance().getTime(); timestampModifiedCached = Calendar.getInstance().getTime(); } else if (timestampModifiedCached == null && timestampCreatedCached != null) { timestampModifiedCached = new Date(timestampCreatedCached.getTime()); } else { timestampCreatedCached = timestampModifiedCached != null ? new Date(timestampModifiedCached.getTime()) : new Date(); } } else { if (timestampModifiedInx != null) { timestampModifiedCached = rs.getDate(timestampModifiedInx); if (timestampModifiedCached == null) { timestampModifiedCached = now; } } if (timestampCreatedInx != null) { timestampCreatedCached = rs.getDate(timestampCreatedInx); if (timestampCreatedCached == null) { timestampCreatedCached = now; } } } str.setLength(0); if (insertSQL == null) { StringBuffer fieldList = new StringBuffer(); fieldList.append("( "); for (int i = 0; i < newFieldMetaData.size(); i++) { if ((i > 0) && (i < newFieldMetaData.size())) { fieldList.append(", "); } String newFieldName = newFieldMetaData.get(i).getName(); fieldList.append(newFieldName + " "); } fieldList.append(")"); str.append("INSERT INTO " + toTableName + " " + fieldList + " VALUES ("); insertSQL = str.toString(); log.debug(str); } else { str.append(insertSQL); } id = rs.getString(1); // For each column in the new DB table... for (int i = 0; i < newFieldMetaData.size(); i++) { FieldMetaData newFldMetaData = newFieldMetaData.get(i); String newColName = newFldMetaData.getName(); String oldMappedColName = null; //System.out.println("["+newColName+"]"); // Get the Old Column Index from the New Name // String oldName = colNewToOldMap != null ? colNewToOldMap.get(newColName) : newColName; Integer columnIndex = fromHash.get(newColName); if (columnIndex == null && colNewToOldMap != null) { oldMappedColName = colNewToOldMap.get(newColName); if (oldMappedColName != null) { columnIndex = fromHash.get(oldMappedColName); } else if (isOptionOn(SHOW_NAME_MAPPING_ERROR) && (ignoreMappingFieldNames == null || ignoreMappingFieldNames.get(newColName) == null)) { String msg = "No Map for table [" + fromTableName + "] from New Name[" + newColName + "] to Old Name[" + oldMappedColName + "]"; log.error(msg); writeErrLog(msg); } } else { oldMappedColName = newColName; } String verbatimDateFieldName = null; if (verbatimDateMapper != null) { verbatimDateFieldName = verbatimDateMapper.get(newColName); } //System.out.println("new["+newColName+"] old["+oldMappedColName+"]"); if (columnIndex != null) { if (i > 0) str.append(", "); Object dataObj = rs.getObject(columnIndex); if (idMapperMgr != null && oldMappedColName != null && oldMappedColName.endsWith("ID")) { IdMapperIFace idMapper = idMapperMgr.get(fromTableName, oldMappedColName); if (idMapper != null) { int showNullOption = SHOW_NULL_FK; int showFkLookUpOption = SHOW_FK_LOOKUP; int oldPrimaryKeyId = rs.getInt(columnIndex); if (oldMappedColName.equalsIgnoreCase(fromTableName + "id")) { showNullOption = SHOW_NULL_PM; showFkLookUpOption = SHOW_PM_LOOKUP; } // if the value was null, getInt() returns 0 // use wasNull() to distinguish real 0 from a null return if (rs.wasNull()) { dataObj = null; if (isOptionOn(showNullOption)) { String msg = "Unable to Map " + (showNullOption == SHOW_NULL_FK ? "Foreign" : "Primary") + " Key Id[NULL] old Name[" + oldMappedColName + "] colInx[" + columnIndex + "] newColName[" + newColName + "]"; log.error(msg); writeErrLog(msg); skipRecord = true; } } else { dataObj = idMapper.get(oldPrimaryKeyId); if (dataObj == null && isOptionOn(showFkLookUpOption)) { String msg = "Unable to Map Primary Id[" + oldPrimaryKeyId + "] old Name[" + oldMappedColName + "] table[" + fromTableName + "]"; log.error(msg); writeErrLog(msg); skipRecord = true; } } } else { if (isOptionOn(SHOW_NAME_MAPPING_ERROR) && (ignoreMappingFieldIDs == null || ignoreMappingFieldIDs.get(oldMappedColName) == null)) { // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! // XXX Temporary fix so it doesn't hide other errors // Josh has promised his first born if he doesn't fix this! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (!oldMappedColName.equals("RankID")) { //idMapperMgr.dumpKeys(); String msg = "No ID Map for [" + fromTableName + "] Old Column Name[" + oldMappedColName + "]"; log.error(msg); writeErrLog(msg); skipRecord = true; } } } } // First check to see if it is null if (dataObj == null) { if (newFldMetaData.getName().equals("TimestampCreated")) { if (timestampCreatedInx != null) { if (isAccessionTable) { Date date = UIHelper .convertIntToDate(rs.getInt(fromHash.get("DateAccessioned"))); str.append(date != null ? getStrValue(date) : getStrValue(timestampCreatedCached, newFldMetaData.getType())); } else { str.append(getStrValue(timestampCreatedCached, newFldMetaData.getType())); } } else { str.append(getStrValue(timestampCreatedCached, newFldMetaData.getType())); } } else if (newFldMetaData.getName().equals("TimestampModified")) { if (timestampModifiedInx != null) { if (isAccessionTable) { Date date = UIHelper .convertIntToDate(rs.getInt(fromHash.get("DateAccessioned"))); str.append(date != null ? getStrValue(date) : getStrValue(timestampCreatedCached, newFldMetaData.getType())); } else { str.append(getStrValue(timestampModifiedCached, newFldMetaData.getType())); } } else { str.append(getStrValue(timestampModifiedCached, newFldMetaData.getType())); } } else { str.append("NULL"); } } else if (dataObj instanceof Integer && (newFldMetaData.getSqlType() == java.sql.Types.DATE || newColName.toLowerCase().endsWith("date") || newColName.toLowerCase().startsWith("date"))) { PartialDateConv datePr = dateMap.get(newColName); if (datePr != null) { str.append(datePr.getDateStr()); } else { str.append("NULL"); } } else if (verbatimDateFieldName != null) { PartialDateConv datePr = dateMap.get(newColName); str.append(datePr != null ? datePr.getVerbatim() : "NULL"); } else if (dataObj instanceof Number) { DBFieldInfo fi = tblInfo.getFieldByColumnName(newColName); String type = newFldMetaData.getType().toLowerCase().startsWith("tiny") ? fi.getType() : newFldMetaData.getType(); str.append(getStrValue(dataObj, type)); } else { if (columnValueMapper != null) { BasicSQLUtilsMapValueIFace valueMapper = columnValueMapper.get(newColName); if (valueMapper != null) { dataObj = valueMapper.mapValue(dataObj); } } if (dataObj instanceof String && newFldMetaData.isString()) { DBFieldInfo fi = tblInfo.getFieldByColumnName(newColName); String s = (String) dataObj; if (s.length() > fi.getLength()) { String msg = String.format( "Truncating Table '%s' Field '%s' with Length %d, db len %d Value[%s]", toTableName, newColName, s.length(), fi.getLength(), s); tblWriter.logError(msg); log.error(msg); dataObj = s.substring(0, fi.getLength()); } } str.append(getStrValue(dataObj, newFldMetaData.getType())); } } else if (hasInstIdCol && newFldMetaData.getName().equals("InstitutionID")) { if (i > 0) str.append(", "); str.append("1"); } else if (newColName.endsWith("Version")) { if (i > 0) str.append(", "); str.append("0"); } else if (newColName.endsWith("DatePrecision")) { if (i > 0) str.append(", "); String cName = newColName.substring(0, newColName.length() - 9); PartialDateConv datePr = dateMap.get(cName); if (datePr != null) { str.append(datePr.getPartial()); } else { str.append("NULL"); } } else if (idMapperMgr != null && newColName.endsWith("ID") && oneToOneIDHash != null && oneToOneIDHash.get(newColName) != null) { IdMapperIFace idMapper = idMapperMgr.get(toTableName, newColName); if (idMapper != null) { idMapper.setShowLogErrors(false); Integer newPrimaryId = idMapper.get(Integer.parseInt(id)); if (newPrimaryId != null) { if (i > 0) str.append(", "); str.append(newPrimaryId); } else { if (i > 0) str.append(", "); str.append("NULL"); if (isOptionOn(SHOW_VAL_MAPPING_ERROR)) { String msg = "For Table[" + fromTableName + "] mapping new Column Name[" + newColName + "] ID[" + id + "] was not mapped"; log.error(msg); writeErrLog(msg); skipRecord = true; } } } } else // there was no old column that maps to this new column { String newColValue = null; if (newColDefValues != null) { newColValue = newColDefValues.get(newColName); } if (newColValue == null) { newColValue = "NULL"; //System.out.println("ignoreMappingFieldNames" + ignoreMappingFieldNames); //System.out.println("ignoreMappingFieldNames.get(colName)" + ignoreMappingFieldNames.get(colName)); if (isOptionOn(SHOW_NAME_MAPPING_ERROR) && (ignoreMappingFieldNames == null || ignoreMappingFieldNames.get(newColName) == null)) { String msg = "For Table[" + fromTableName + "] mapping new Column Name[" + newColName + "] was not mapped"; log.error(msg); writeErrLog(msg); skipRecord = true; } } if (i > 0) str.append(", "); BasicSQLUtilsMapValueIFace valueMapper = columnValueMapper.get(newFldMetaData.getName()); if (valueMapper != null) { newColValue = valueMapper.mapValue(newColValue); } str.append(newColValue); } } str.append(")"); if (frame != null) { if (count % 500 == 0) { frame.setProcess(count); } } else { if (count % 2000 == 0) { log.info(toTableName + " processed: " + count); } } //setQuotedIdentifierOFFForSQLServer(toConn, BasicSQLUtils.myDestinationServerType); //exeUpdateCmd(updateStatement, "SET FOREIGN_KEY_CHECKS = 0"); //if (str.toString().toLowerCase().contains("insert into locality")) //{ //log.debug(str.toString()); //} //String str2 = "SET QUOTED_IDENTIFIER ON"; //log.debug("executing: " + str); //updateStatement.execute(str2); // updateStatement.close(); if (!skipRecord) { if (isOptionOn(SHOW_COPY_TABLE)) { log.debug("executing: " + str); } int retVal = exeUpdateCmd(updateStatement, str.toString()); if (retVal == -1) { rs.close(); stmt.clearBatch(); stmt.close(); return false; } } count++; // if (count == 1) break; } if (frame != null) { frame.setProcess(count); } else { log.info(fromTableName + " processed " + count + " records."); } rs.close(); stmt.clearBatch(); stmt.close(); } catch (SQLException ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BasicSQLUtils.class, ex); //e.printStackTrace(); log.error(sqlStr); log.error(ex); log.error("ID: " + id); } finally { try { updateStatement.clearBatch(); updateStatement.close(); } catch (SQLException ex) { } } BasicSQLUtils.setFieldsToIgnoreWhenMappingNames(null);//meg added return true; }
From source file:com.mimp.hibernate.HiberEtapa.java
public ArrayList<Designacion> getListaAdopciones() { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();//w ww. j a v a2s . c om final ArrayList<Designacion> allDesig = new ArrayList(); Work work = new Work() { @Override public void execute(Connection connection) throws SQLException { ExpedienteNna expnna; String hql = "{call HE_LISTADESIG_ADOPCION(?)}"; CallableStatement statement = connection.prepareCall(hql); statement.registerOutParameter(1, OracleTypes.CURSOR); statement.execute(); ResultSet rs = (ResultSet) statement.getObject(1); while (rs.next()) { Designacion tempDesig = new Designacion(); ExpedienteFamilia tempEF = new ExpedienteFamilia(); Nna tempNna = new Nna(); Personal tempPerso = new Personal(); Unidad tempUA = new Unidad(); tempDesig.setIddesignacion(rs.getLong(1)); tempDesig.setNDesignacion(rs.getString(5)); tempDesig.setPrioridad(rs.getLong(6)); tempDesig.setFechaPropuesta(rs.getDate(7)); tempDesig.setFechaConsejo(rs.getDate(8)); tempDesig.setAceptacionConsejo(rs.getShort(9)); tempDesig.setTipoPropuesta(rs.getString(10)); tempDesig.setObs(rs.getString(11)); tempPerso.setIdpersonal(rs.getLong(4)); tempUA.setIdunidad(rs.getLong("IDUNIDAD")); String hql4 = "{call HE_GET_UNIDAD(?, ?)}"; CallableStatement statement4 = connection.prepareCall(hql4); statement4.setLong(1, tempUA.getIdunidad()); statement4.registerOutParameter(2, OracleTypes.CURSOR); statement4.execute(); ResultSet rs4 = (ResultSet) statement4.getObject(2); if (rs4.next()) { tempUA.setIdunidad(rs4.getLong(1)); tempUA.setDepartamento(rs4.getString("DEPARTAMENTO")); tempEF.setUnidad(tempUA); } statement4.close(); tempEF.setIdexpedienteFamilia(rs.getLong(2)); tempEF.setExpediente(rs.getString("EXPEDIENTE")); tempEF.setHt(rs.getString("HT")); tempEF.setNumeroExpediente(rs.getString("NUMERO_EXPEDIENTE")); tempEF.setFechaIngresoDga(rs.getDate("FECHA_INGRESO_DGA")); tempEF.setEstado(rs.getString("ESTADO")); tempEF.setTupa(rs.getDate("TUPA")); tempEF.setNacionalidad(rs.getString("NACIONALIDAD")); tempEF.setRnsa(rs.getShort("RNSA")); tempEF.setRnaa(rs.getShort("RNAA")); tempEF.setTipoFamilia(rs.getString("TIPO_FAMILIA")); tempEF.setTipoListaEspera(rs.getString("TIPO_LISTA_ESPERA")); tempEF.setHtFicha(rs.getString("HTFICHA")); tempEF.setnFicha(rs.getString("NFICHA")); tempEF.setFechaIngresoFicha(rs.getDate("FECHA_INGRESO_FICHA")); Set<Evaluacion> listaEv = new HashSet<Evaluacion>(); String hql2 = "{call HE_LISTAEVAL_BY_IDEXPFAM(?,?)}"; CallableStatement statement2 = connection.prepareCall(hql2); statement2.setLong(1, tempEF.getIdexpedienteFamilia()); statement2.registerOutParameter(2, OracleTypes.CURSOR); statement2.execute(); ResultSet rs2 = (ResultSet) statement2.getObject(2); while (rs2.next()) { Evaluacion tempEval = new Evaluacion(); tempEval.setIdevaluacion(rs2.getLong("IDEVALUACION")); tempEval.setExpedienteFamilia(tempEF); tempEval.setTipo(rs2.getString("TIPO")); tempEval.setFechaAsignacion(rs2.getDate("FECHA_ASIGNACION")); tempEval.setResultado(rs2.getString("RESULTADO")); tempEval.setFechaResultado(rs2.getDate("FECHA_RESULTADO")); tempEval.setObservacion(rs2.getString("OBSERVACION")); tempEval.setSustento(rs2.getString("SUSTENTO")); tempEval.setNDesignacion(rs2.getString("N_DESIGNACION")); tempEval.setNumEval(rs2.getString("NUM_EVAL")); Set<Resolucion> listaRe = new HashSet<Resolucion>(); if (tempEval.getTipo().equals("empatia") || tempEval.getTipo().equals("informe")) { String hql3 = "{call HE_ULTRESOL_LEGAL(?,?)}"; CallableStatement statement3 = connection.prepareCall(hql3); statement3.setLong(1, tempEval.getIdevaluacion()); statement3.registerOutParameter(2, OracleTypes.CURSOR); statement3.execute(); ResultSet rs3 = (ResultSet) statement3.getObject(2); if (rs3.next()) { Resolucion tempResol = new Resolucion(); tempResol.setIdresolucion(rs3.getLong("IDRESOLUCION")); tempResol.setTipo(rs3.getString("TIPO")); tempResol.setNumero(rs3.getString("NUMERO")); tempResol.setFechaResol(rs3.getDate("FECHA_RESOL")); tempResol.setFechaNotificacion(rs3.getDate("FECHA_NOTIFICACION")); tempResol.setEvaluacion(tempEval); listaRe.add(tempResol); } rs3.close(); statement3.close(); } tempEval.setResolucions(listaRe); listaEv.add(tempEval); } rs2.close(); statement2.close(); tempEF.setEvaluacions(listaEv); tempNna.setIdnna(rs.getLong("IDNNA")); tempNna.setNombre(rs.getString("NOMBRE")); tempNna.setApellidoP(rs.getString("APELLIDO_P")); tempNna.setApellidoM(rs.getString("APELLIDO_M")); tempNna.setSexo(rs.getString("SEXO")); tempNna.setFechaNacimiento(rs.getDate("FECHA_NACIMIENTO")); tempNna.setEdadAnhos(rs.getShort("EDAD_ANHOS")); tempNna.setEdadMeses(rs.getShort("EDAD_MESES")); tempNna.setActaNacimiento(rs.getShort("ACTA_NACIMIENTO")); tempNna.setCondicionSalud(rs.getString("CONDICION_SALUD")); tempNna.setDepartamentoNacimiento(rs.getString("DEPARTAMENTO_NACIMIENTO")); tempNna.setProvinciaNacimiento(rs.getString("PROVINCIA_NACIMIENTO")); tempNna.setDistritoNacimiento(rs.getString("DISTRITO_NACIMIENTO")); tempNna.setPaisNacimiento(rs.getString("PAIS_NACIMIENTO")); tempNna.setLugarNac(rs.getString("LUGAR_NAC")); tempNna.setFechaResolAbandono(rs.getDate("FECHA_RESOL_ABANDONO")); tempNna.setFechaResolConsentida(rs.getDate("FECHA_RESOL_CONSENTIDA")); tempNna.setClasificacion(rs.getString("CLASIFICACION")); tempNna.setIncesto(rs.getShort("INCESTO")); tempNna.setMental(rs.getShort("MENTAL")); tempNna.setEpilepsia(rs.getShort("EPILEPSIA")); tempNna.setAbuso(rs.getShort("ABUSO")); tempNna.setSifilis(rs.getShort("SIFILIS")); tempNna.setSeguiMedico(rs.getShort("SEGUI_MEDICO")); tempNna.setOperacion(rs.getShort("OPERACION")); tempNna.setHiperactivo(rs.getShort("HIPERACTIVO")); tempNna.setEspecial(rs.getShort("ESPECIAL")); tempNna.setEnfermo(rs.getShort("ENFERMO")); tempNna.setMayor(rs.getShort("MAYOR")); tempNna.setAdolescente(rs.getShort("ADOLESCENTE")); tempNna.setHermano(rs.getShort("HERMANO")); tempNna.setNn(rs.getShort("NN")); tempNna.setObservaciones(rs.getString("OBSERVACIONES")); tempNna.setNResolAband(rs.getString("N_RESOL_ABAND")); tempNna.setNResolCons(rs.getString("N_RESOL_CONS")); tempDesig.setExpedienteFamilia(tempEF); tempDesig.setNna(tempNna); tempDesig.setPersonal(tempPerso); allDesig.add(tempDesig); } rs.close(); statement.close(); } }; session.doWork(work); return allDesig; }
From source file:com.mimp.hibernate.HiberEtapa.java
public ArrayList<ExpedienteFamilia> ListaExpedientes(String nacionalidad, String estado) { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();/*from www . ja va 2 s . com*/ final String nac = nacionalidad; final String est = estado; final ArrayList<ExpedienteFamilia> allExpedienteFamilia = new ArrayList(); Work work = new Work() { @Override public void execute(Connection connection) throws SQLException { ExpedienteNna expnna; String hql = "{call HE_LISTA_EXP_FAM_BY_NAC_EST(?,?,?)}"; CallableStatement statement = connection.prepareCall(hql); statement.setString(1, nac); statement.setString(2, est); statement.registerOutParameter(3, OracleTypes.CURSOR); statement.execute(); ResultSet rs = (ResultSet) statement.getObject(3); while (rs.next()) { Set<Evaluacion> listaEv = new HashSet<Evaluacion>(); ExpedienteFamilia tempEF = new ExpedienteFamilia(); Unidad tempUA = new Unidad(); tempUA.setIdunidad(rs.getLong("IDUNIDAD")); tempUA.setDepartamento(rs.getString("DEPARTAMENTO")); tempEF.setIdexpedienteFamilia(rs.getLong("IDEXPEDIENTE_FAMILIA")); tempEF.setExpediente(rs.getString("EXPEDIENTE")); tempEF.setHt(rs.getString("HT")); tempEF.setNumeroExpediente(rs.getString("NUMERO_EXPEDIENTE")); tempEF.setFechaIngresoDga(rs.getDate("FECHA_INGRESO_DGA")); tempEF.setEstado(rs.getString("ESTADO")); tempEF.setTupa(rs.getDate("TUPA")); tempEF.setNacionalidad(rs.getString("NACIONALIDAD")); tempEF.setRnsa(rs.getShort("RNSA")); tempEF.setRnaa(rs.getShort("RNAA")); tempEF.setTipoFamilia(rs.getString("TIPO_FAMILIA")); tempEF.setTipoListaEspera(rs.getString("TIPO_LISTA_ESPERA")); tempEF.setHtFicha(rs.getString("HTFICHA")); tempEF.setnFicha(rs.getString("NFICHA")); tempEF.setFechaIngresoFicha(rs.getDate("FECHA_INGRESO_FICHA")); String hql2 = "{call HE_LISTAEVAL_BY_IDEXPFAM(?,?)}"; CallableStatement statement2 = connection.prepareCall(hql2); statement2.setLong(1, tempEF.getIdexpedienteFamilia()); statement2.registerOutParameter(2, OracleTypes.CURSOR); statement2.execute(); ResultSet rs2 = (ResultSet) statement2.getObject(2); while (rs2.next()) { Evaluacion tempEval = new Evaluacion(); tempEval.setIdevaluacion(rs2.getLong("IDEVALUACION")); tempEval.setExpedienteFamilia(tempEF); tempEval.setTipo(rs2.getString("TIPO")); tempEval.setFechaAsignacion(rs2.getDate("FECHA_ASIGNACION")); tempEval.setResultado(rs2.getString("RESULTADO")); tempEval.setFechaResultado(rs2.getDate("FECHA_RESULTADO")); tempEval.setObservacion(rs2.getString("OBSERVACION")); tempEval.setSustento(rs2.getString("SUSTENTO")); tempEval.setNDesignacion(rs2.getString("N_DESIGNACION")); tempEval.setNumEval(rs2.getString("NUM_EVAL")); Set<Resolucion> listaRe = new HashSet<Resolucion>(); if (tempEval.getTipo().equals("legal")) { String hql3 = "{call HE_ULTRESOL_LEGAL(?,?)}"; CallableStatement statement3 = connection.prepareCall(hql3); statement3.setLong(1, tempEval.getIdevaluacion()); statement3.registerOutParameter(2, OracleTypes.CURSOR); statement3.execute(); ResultSet rs3 = (ResultSet) statement3.getObject(2); if (rs3.next()) { Resolucion tempResol = new Resolucion(); tempResol.setIdresolucion(rs3.getLong("IDRESOLUCION")); tempResol.setTipo(rs3.getString("TIPO")); tempResol.setNumero(rs3.getString("NUMERO")); tempResol.setFechaResol(rs3.getDate("FECHA_RESOL")); tempResol.setFechaNotificacion(rs3.getDate("FECHA_NOTIFICACION")); tempResol.setEvaluacion(tempEval); listaRe.add(tempResol); } rs3.close(); statement3.close(); } tempEval.setResolucions(listaRe); listaEv.add(tempEval); } rs2.close(); statement2.close(); tempEF.setUnidad(tempUA); tempEF.setEvaluacions(listaEv); allExpedienteFamilia.add(tempEF); } rs.close(); statement.close(); } }; session.doWork(work); return allExpedienteFamilia; }
From source file:com.jd.survey.dao.survey.SurveyDAOImpl.java
/** * Reads a single survey page from the survey data table *//*from w w w .jav a 2s. co m*/ @Override public SurveyPage getPage(final Survey survey, final SurveyDefinitionPage surveyDefinitionPage, final String dateFormat) { try { boolean hasDatabaseQuestions = false; StringBuilder stringBuilder = new StringBuilder(); String pageVisibilityColumn = "p" + surveyDefinitionPage.getOrder() + "v"; stringBuilder.append("select survey_id, " + pageVisibilityColumn + ", "); for (Question question : surveyDefinitionPage.getQuestions()) { int optionsCount = question.getOptions().size(); int rowCount = question.getRowLabels().size(); int columnCount = question.getColumnLabels().size(); switch (question.getType()) { case YES_NO_DROPDOWN: //Yes No DropDown stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); hasDatabaseQuestions = true; break; case SHORT_TEXT_INPUT: //Short Text Input stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); hasDatabaseQuestions = true; break; case LONG_TEXT_INPUT: //Long Text Input stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); hasDatabaseQuestions = true; break; case HUGE_TEXT_INPUT: //Huge Text Input stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); hasDatabaseQuestions = true; break; case INTEGER_INPUT: //Integer Input stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); hasDatabaseQuestions = true; break; case CURRENCY_INPUT: //Currency Input stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); hasDatabaseQuestions = true; break; case DECIMAL_INPUT: //Decimal Input stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); hasDatabaseQuestions = true; break; case DATE_INPUT: //Date Input stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); hasDatabaseQuestions = true; break; case SINGLE_CHOICE_DROP_DOWN: //Single choice Drop Down stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); hasDatabaseQuestions = true; break; case MULTIPLE_CHOICE_CHECKBOXES: //Multiple Choice Checkboxes hasDatabaseQuestions = true; for (int o = 1; o <= optionsCount; o++) { stringBuilder.append( " p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "o" + o + ","); } //other support stringBuilder.append( " p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "text" + ","); break; case DATASET_DROP_DOWN: //DataSet Drop Down hasDatabaseQuestions = true; stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); break; case SINGLE_CHOICE_RADIO_BUTTONS: //Single Choice Radio Buttons hasDatabaseQuestions = true; stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); //other support stringBuilder.append( " p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "text" + ","); break; case YES_NO_DROPDOWN_MATRIX://Yes No DropDown Matrix hasDatabaseQuestions = true; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c + ","); } } break; case SHORT_TEXT_INPUT_MATRIX://Short Text Input Matrix hasDatabaseQuestions = true; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c + ","); } } break; case INTEGER_INPUT_MATRIX://Integer Input Matrix hasDatabaseQuestions = true; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c + ","); } } break; case CURRENCY_INPUT_MATRIX://Currency Input Matrix hasDatabaseQuestions = true; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c + ","); } } break; case DECIMAL_INPUT_MATRIX://Decimal Input Matrix hasDatabaseQuestions = true; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c + ","); } } break; case DATE_INPUT_MATRIX://Date Input Matrix hasDatabaseQuestions = true; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c + ","); } } break; case STAR_RATING: //Integer Input hasDatabaseQuestions = true; stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); break; case SMILEY_FACES_RATING: //Integer Input hasDatabaseQuestions = true; stringBuilder.append(" p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + ","); break; } } stringBuilder.setLength(stringBuilder.length() - 1); if (!hasDatabaseQuestions) { stringBuilder.setLength(stringBuilder.length() - 1); } stringBuilder.append(" from survey_data_" + surveyDefinitionPage.getSurveyDefinition().getId()); stringBuilder.append(" where survey_id = ?"); SurveyPage surveyPage = this.jdbcTemplate.queryForObject(stringBuilder.toString(), new Object[] { survey.getId() }, new RowMapper<SurveyPage>() { public SurveyPage mapRow(ResultSet rs, int rowNum) throws SQLException { int optionsCount; int rowCount; int columnCount; Integer[] integerAnswerValuesArray; Long[][] longAnswerValuesMatrix; String[][] stringAnswerValuesMatrix; BigDecimal[][] bigDecimalAnswerValuesMatrix; Boolean[][] booleanAnswerValuesMatrix; Date[][] dateAnswerValuesMatrix; SurveyPage page = new SurveyPage(survey, surveyDefinitionPage); page.setVisible((rs.getBoolean("p" + surveyDefinitionPage.getOrder() + "v"))); QuestionAnswer questionAnswer; List<QuestionAnswer> questionAnswers = new ArrayList<QuestionAnswer>(); for (Question question : surveyDefinitionPage.getQuestions()) { questionAnswer = new QuestionAnswer(question); optionsCount = question.getOptions().size(); rowCount = question.getRowLabels().size(); columnCount = question.getColumnLabels().size(); switch (question.getType()) { case YES_NO_DROPDOWN: //Yes No DropDown questionAnswer.setBooleanAnswerValue((rs.getBoolean( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case SHORT_TEXT_INPUT: //Short Text Input questionAnswer.setStringAnswerValue((rs.getString( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case LONG_TEXT_INPUT: //Long Text Input questionAnswer.setStringAnswerValue((rs.getString( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case HUGE_TEXT_INPUT: //Huge Text Input questionAnswer.setStringAnswerValue((rs.getString( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case INTEGER_INPUT: //Integer Input questionAnswer.setLongAnswerValue((rs.getLong( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); if (rs.wasNull()) questionAnswer.setLongAnswerValue(null); questionAnswer .setStringAnswerValue(questionAnswer.getLongAnswerValue() == null ? "" : questionAnswer.getLongAnswerValue().toString()); break; case CURRENCY_INPUT: //Currency Input questionAnswer.setBigDecimalAnswerValue((rs.getBigDecimal( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); questionAnswer.setStringAnswerValue( questionAnswer.getBigDecimalAnswerValue() == null ? "" : CurrencyValidator.getInstance().format( questionAnswer.getBigDecimalAnswerValue(), LocaleContextHolder.getLocale())); break; case DECIMAL_INPUT: //Decimal Input questionAnswer.setBigDecimalAnswerValue((rs.getBigDecimal( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); questionAnswer.setStringAnswerValue( questionAnswer.getBigDecimalAnswerValue() == null ? "" : BigDecimalValidator.getInstance().format( questionAnswer.getBigDecimalAnswerValue(), LocaleContextHolder.getLocale())); break; case DATE_INPUT: //Date Input questionAnswer.setDateAnswerValue((rs.getDate( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); questionAnswer .setStringAnswerValue(questionAnswer.getDateAnswerValue() == null ? "" : DateValidator.getInstance().format( questionAnswer.getDateAnswerValue(), dateFormat)); break; case SINGLE_CHOICE_DROP_DOWN: //Single choice Drop Down questionAnswer.setStringAnswerValue((rs.getString( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case MULTIPLE_CHOICE_CHECKBOXES: //Multiple Choice Checkboxes integerAnswerValuesArray = new Integer[optionsCount]; int index = 0; for (int o = 1; o <= optionsCount; o++) { if (rs.getBoolean("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "o" + o)) { integerAnswerValuesArray[index] = o; index++; } } questionAnswer.setIntegerAnswerValuesArray(integerAnswerValuesArray); //other text data questionAnswer.setOtherStringAnswerValue( (rs.getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "text"))); break; case DATASET_DROP_DOWN: //DataSet Drop Down questionAnswer.setStringAnswerValue((rs.getString( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case SINGLE_CHOICE_RADIO_BUTTONS: //Single Choice Radio Buttons questionAnswer.setStringAnswerValue((rs.getString( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); //other text data questionAnswer.setOtherStringAnswerValue( (rs.getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "text"))); break; case YES_NO_DROPDOWN_MATRIX://Yes No DropDown Matrix booleanAnswerValuesMatrix = new Boolean[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { booleanAnswerValuesMatrix[r - 1][c - 1] = rs .getBoolean("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); } } questionAnswer.setBooleanAnswerValuesMatrix(booleanAnswerValuesMatrix); break; case SHORT_TEXT_INPUT_MATRIX://Short Text Input Matrix stringAnswerValuesMatrix = new String[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { stringAnswerValuesMatrix[r - 1][c - 1] = rs .getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); } } questionAnswer.setStringAnswerValuesMatrix(stringAnswerValuesMatrix); break; case INTEGER_INPUT_MATRIX://Integer Input Matrix stringAnswerValuesMatrix = new String[rowCount][columnCount]; longAnswerValuesMatrix = new Long[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { longAnswerValuesMatrix[r - 1][c - 1] = rs .getLong("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); if (rs.wasNull()) longAnswerValuesMatrix[r - 1][c - 1] = null; stringAnswerValuesMatrix[r - 1][c - 1] = longAnswerValuesMatrix[r - 1][c - 1] == null ? "" : longAnswerValuesMatrix[r - 1][c - 1].toString(); } } questionAnswer.setStringAnswerValuesMatrix(stringAnswerValuesMatrix); questionAnswer.setLongAnswerValuesMatrix(longAnswerValuesMatrix); break; case CURRENCY_INPUT_MATRIX://Currency Input Matrix stringAnswerValuesMatrix = new String[rowCount][columnCount]; bigDecimalAnswerValuesMatrix = new BigDecimal[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { bigDecimalAnswerValuesMatrix[r - 1][c - 1] = rs .getBigDecimal("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); stringAnswerValuesMatrix[r - 1][c - 1] = bigDecimalAnswerValuesMatrix[r - 1][c - 1] == null ? "" : CurrencyValidator.getInstance().format( bigDecimalAnswerValuesMatrix[r - 1][c - 1], LocaleContextHolder.getLocale()); } } questionAnswer.setStringAnswerValuesMatrix(stringAnswerValuesMatrix); questionAnswer.setBigDecimalAnswerValuesMatrix(bigDecimalAnswerValuesMatrix); break; case DECIMAL_INPUT_MATRIX://Decimal Input Matrix stringAnswerValuesMatrix = new String[rowCount][columnCount]; bigDecimalAnswerValuesMatrix = new BigDecimal[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { bigDecimalAnswerValuesMatrix[r - 1][c - 1] = rs .getBigDecimal("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); stringAnswerValuesMatrix[r - 1][c - 1] = bigDecimalAnswerValuesMatrix[r - 1][c - 1] == null ? "" : BigDecimalValidator.getInstance().format( bigDecimalAnswerValuesMatrix[r - 1][c - 1], LocaleContextHolder.getLocale()); } } questionAnswer.setStringAnswerValuesMatrix(stringAnswerValuesMatrix); questionAnswer.setBigDecimalAnswerValuesMatrix(bigDecimalAnswerValuesMatrix); break; case DATE_INPUT_MATRIX://Date Input Matrix stringAnswerValuesMatrix = new String[rowCount][columnCount]; dateAnswerValuesMatrix = new Date[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { dateAnswerValuesMatrix[r - 1][c - 1] = rs .getDate("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); stringAnswerValuesMatrix[r - 1][c - 1] = dateAnswerValuesMatrix[r - 1][c - 1] == null ? "" : DateValidator.getInstance().format( dateAnswerValuesMatrix[r - 1][c - 1], dateFormat); } } questionAnswer.setStringAnswerValuesMatrix(stringAnswerValuesMatrix); questionAnswer.setDateAnswerValuesMatrix(dateAnswerValuesMatrix); break; case STAR_RATING: //Integer Input questionAnswer.setLongAnswerValue((rs.getLong( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); if (rs.wasNull()) questionAnswer.setLongAnswerValue(null); questionAnswer .setStringAnswerValue(questionAnswer.getLongAnswerValue() == null ? "" : questionAnswer.getLongAnswerValue().toString()); break; case SMILEY_FACES_RATING: //Integer Input questionAnswer.setLongAnswerValue((rs.getLong( "p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); if (rs.wasNull()) questionAnswer.setLongAnswerValue(null); questionAnswer .setStringAnswerValue(questionAnswer.getLongAnswerValue() == null ? "" : questionAnswer.getLongAnswerValue().toString()); break; } questionAnswers.add(questionAnswer); } page.setQuestionAnswers(questionAnswers); return page; } }); return surveyPage; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.github.woonsan.jdbc.jcr.impl.JcrJdbcResultSetTest.java
@SuppressWarnings("deprecation") @Test//w w w. j a v a 2s . c om public void testResultSetWhenClosed() throws Exception { Statement statement = getConnection().createStatement(); ResultSet rs = statement.executeQuery(SQL_EMPS); rs.close(); try { rs.isBeforeFirst(); fail(); } catch (SQLException ignore) { } try { rs.isAfterLast(); fail(); } catch (SQLException ignore) { } try { rs.isFirst(); fail(); } catch (SQLException ignore) { } try { rs.isLast(); fail(); } catch (SQLException ignore) { } try { rs.beforeFirst(); fail(); } catch (SQLException ignore) { } try { rs.afterLast(); fail(); } catch (SQLException ignore) { } try { rs.first(); fail(); } catch (SQLException ignore) { } try { rs.last(); fail(); } catch (SQLException ignore) { } try { rs.next(); fail(); } catch (SQLException ignore) { } try { rs.getRow(); fail(); } catch (SQLException ignore) { } try { rs.getType(); fail(); } catch (SQLException ignore) { } try { rs.getConcurrency(); fail(); } catch (SQLException ignore) { } try { rs.rowUpdated(); fail(); } catch (SQLException ignore) { } try { rs.rowDeleted(); fail(); } catch (SQLException ignore) { } try { rs.rowInserted(); fail(); } catch (SQLException ignore) { } try { rs.getStatement(); fail(); } catch (SQLException ignore) { } try { rs.wasNull(); fail(); } catch (SQLException ignore) { } try { rs.getString(1); fail(); } catch (SQLException ignore) { } try { rs.getString("col1"); fail(); } catch (SQLException ignore) { } try { rs.getBoolean(1); fail(); } catch (SQLException ignore) { } try { rs.getBoolean("col1"); fail(); } catch (SQLException ignore) { } try { rs.getByte(1); fail(); } catch (SQLException ignore) { } try { rs.getByte("col1"); fail(); } catch (SQLException ignore) { } try { rs.getShort(1); fail(); } catch (SQLException ignore) { } try { rs.getShort("col1"); fail(); } catch (SQLException ignore) { } try { rs.getInt(1); fail(); } catch (SQLException ignore) { } try { rs.getInt("col1"); fail(); } catch (SQLException ignore) { } try { rs.getLong(1); fail(); } catch (SQLException ignore) { } try { rs.getLong("col1"); fail(); } catch (SQLException ignore) { } try { rs.getFloat(1); fail(); } catch (SQLException ignore) { } try { rs.getFloat("col1"); fail(); } catch (SQLException ignore) { } try { rs.getDouble(1); fail(); } catch (SQLException ignore) { } try { rs.getDouble("col1"); fail(); } catch (SQLException ignore) { } try { rs.getBigDecimal(1); fail(); } catch (SQLException ignore) { } try { rs.getBigDecimal("col1"); fail(); } catch (SQLException ignore) { } try { rs.getBytes(1); fail(); } catch (SQLException ignore) { } try { rs.getBytes("col1"); fail(); } catch (SQLException ignore) { } try { rs.getDate(1); fail(); } catch (SQLException ignore) { } try { rs.getDate(1, null); fail(); } catch (SQLException ignore) { } try { rs.getDate("col1"); fail(); } catch (SQLException ignore) { } try { rs.getDate("col1", null); fail(); } catch (SQLException ignore) { } try { rs.getTime(1); fail(); } catch (SQLException ignore) { } try { rs.getTime(1, null); fail(); } catch (SQLException ignore) { } try { rs.getTime("col1"); fail(); } catch (SQLException ignore) { } try { rs.getTime("col1", null); fail(); } catch (SQLException ignore) { } try { rs.getTimestamp(1); fail(); } catch (SQLException ignore) { } try { rs.getTimestamp(1, null); fail(); } catch (SQLException ignore) { } try { rs.getTimestamp("col1"); fail(); } catch (SQLException ignore) { } try { rs.getTimestamp("col1", null); fail(); } catch (SQLException ignore) { } try { rs.getAsciiStream(1); fail(); } catch (SQLException ignore) { } try { rs.getAsciiStream("col1"); fail(); } catch (SQLException ignore) { } try { rs.getUnicodeStream(1); fail(); } catch (SQLException ignore) { } try { rs.getUnicodeStream("col1"); fail(); } catch (SQLException ignore) { } try { rs.getBinaryStream(1); fail(); } catch (SQLException ignore) { } try { rs.getBinaryStream("col1"); fail(); } catch (SQLException ignore) { } try { rs.getCharacterStream(1); fail(); } catch (SQLException ignore) { } try { rs.getCharacterStream("col1"); fail(); } catch (SQLException ignore) { } try { rs.getMetaData(); fail(); } catch (SQLException ignore) { } try { rs.setFetchDirection(1); fail(); } catch (SQLException ignore) { } try { rs.getFetchDirection(); fail(); } catch (SQLException ignore) { } try { rs.setFetchSize(100); fail(); } catch (SQLException ignore) { } try { rs.getFetchSize(); fail(); } catch (SQLException ignore) { } try { rs.getHoldability(); fail(); } catch (SQLException ignore) { } statement.close(); }
From source file:com.jd.survey.dao.survey.SurveyDAOImpl.java
/** * Reads a single survey page from the survey data table *///from w w w .j av a2s .c o m @Override public List<SurveyPage> getPages(final Survey survey, final SurveyDefinition surveyDefinition, final String dateFormat) { try { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("select * "); stringBuilder.setLength(stringBuilder.length() - 1); stringBuilder.append(" from survey_data_" + surveyDefinition.getId()); stringBuilder.append(" where survey_id = ?"); List<SurveyPage> surveyPages = this.jdbcTemplate.queryForObject(stringBuilder.toString(), new Object[] { survey.getId() }, new RowMapper<List<SurveyPage>>() { public List<SurveyPage> mapRow(ResultSet rs, int rowNum) throws SQLException { int optionsCount; int rowCount; int columnCount; Integer[] integerAnswerValuesArray; Long[][] longAnswerValuesMatrix; String[][] stringAnswerValuesMatrix; BigDecimal[][] bigDecimalAnswerValuesMatrix; Boolean[][] booleanAnswerValuesMatrix; Date[][] dateAnswerValuesMatrix; List<SurveyPage> pages = new ArrayList<SurveyPage>(); for (SurveyDefinitionPage surveyDefinitionPage : surveyDefinition.getPages()) { SurveyPage page = new SurveyPage(survey, surveyDefinitionPage); page.setVisible((rs.getBoolean("p" + surveyDefinitionPage.getOrder() + "v"))); QuestionAnswer questionAnswer; List<QuestionAnswer> questionAnswers = new ArrayList<QuestionAnswer>(); for (Question question : surveyDefinitionPage.getQuestions()) { questionAnswer = new QuestionAnswer(question); optionsCount = question.getOptions().size(); rowCount = question.getRowLabels().size(); columnCount = question.getColumnLabels().size(); switch (question.getType()) { case YES_NO_DROPDOWN: //Yes No DropDown questionAnswer.setBooleanAnswerValue((rs.getBoolean("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case SHORT_TEXT_INPUT: //Short Text Input questionAnswer.setStringAnswerValue((rs.getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case LONG_TEXT_INPUT: //Long Text Input questionAnswer.setStringAnswerValue((rs.getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case HUGE_TEXT_INPUT: //Huge Text Input questionAnswer.setStringAnswerValue((rs.getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case INTEGER_INPUT: //Integer Input questionAnswer.setLongAnswerValue((rs.getLong("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); questionAnswer.setStringAnswerValue( questionAnswer.getLongAnswerValue() == null ? "" : questionAnswer.getLongAnswerValue().toString()); break; case CURRENCY_INPUT: //Currency Input questionAnswer.setBigDecimalAnswerValue((rs.getBigDecimal("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); questionAnswer.setStringAnswerValue( questionAnswer.getBigDecimalAnswerValue() == null ? "" : CurrencyValidator.getInstance().format( questionAnswer.getBigDecimalAnswerValue(), LocaleContextHolder.getLocale())); break; case DECIMAL_INPUT: //Decimal Input questionAnswer.setBigDecimalAnswerValue((rs.getBigDecimal("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); questionAnswer.setStringAnswerValue( questionAnswer.getBigDecimalAnswerValue() == null ? "" : BigDecimalValidator.getInstance().format( questionAnswer.getBigDecimalAnswerValue(), LocaleContextHolder.getLocale())); break; case DATE_INPUT: //Date Input questionAnswer.setDateAnswerValue((rs.getDate("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); questionAnswer .setStringAnswerValue( questionAnswer.getDateAnswerValue() == null ? "" : DateValidator.getInstance().format( questionAnswer.getDateAnswerValue(), dateFormat)); break; case SINGLE_CHOICE_DROP_DOWN: //Single choice Drop Down questionAnswer.setStringAnswerValue((rs.getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case MULTIPLE_CHOICE_CHECKBOXES: //Multiple Choice Checkboxes integerAnswerValuesArray = new Integer[optionsCount]; int index = 0; for (int o = 1; o <= optionsCount; o++) { if (rs.getBoolean("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "o" + o)) { integerAnswerValuesArray[index] = o; index++; } } questionAnswer.setIntegerAnswerValuesArray(integerAnswerValuesArray); //other text data questionAnswer.setOtherStringAnswerValue( (rs.getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "text"))); break; case DATASET_DROP_DOWN: //DataSet Drop Down questionAnswer.setStringAnswerValue((rs.getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); break; case SINGLE_CHOICE_RADIO_BUTTONS: //Single Choice Radio Buttons questionAnswer.setStringAnswerValue((rs.getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); //other text data questionAnswer.setOtherStringAnswerValue( (rs.getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "text"))); break; case YES_NO_DROPDOWN_MATRIX://Yes No DropDown Matrix booleanAnswerValuesMatrix = new Boolean[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { booleanAnswerValuesMatrix[r - 1][c - 1] = rs .getBoolean("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); } } questionAnswer.setBooleanAnswerValuesMatrix(booleanAnswerValuesMatrix); break; case SHORT_TEXT_INPUT_MATRIX://Short Text Input Matrix stringAnswerValuesMatrix = new String[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { stringAnswerValuesMatrix[r - 1][c - 1] = rs .getString("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); } } questionAnswer.setStringAnswerValuesMatrix(stringAnswerValuesMatrix); break; case INTEGER_INPUT_MATRIX://Integer Input Matrix stringAnswerValuesMatrix = new String[rowCount][columnCount]; longAnswerValuesMatrix = new Long[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { longAnswerValuesMatrix[r - 1][c - 1] = rs .getLong("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); stringAnswerValuesMatrix[r - 1][c - 1] = longAnswerValuesMatrix[r - 1][c - 1] == null ? "" : longAnswerValuesMatrix[r - 1][c - 1].toString(); } } questionAnswer.setStringAnswerValuesMatrix(stringAnswerValuesMatrix); questionAnswer.setLongAnswerValuesMatrix(longAnswerValuesMatrix); break; case CURRENCY_INPUT_MATRIX://Currency Input Matrix stringAnswerValuesMatrix = new String[rowCount][columnCount]; bigDecimalAnswerValuesMatrix = new BigDecimal[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { bigDecimalAnswerValuesMatrix[r - 1][c - 1] = rs .getBigDecimal("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); stringAnswerValuesMatrix[r - 1][c - 1] = bigDecimalAnswerValuesMatrix[r - 1][c - 1] == null ? "" : CurrencyValidator.getInstance().format( bigDecimalAnswerValuesMatrix[r - 1][c - 1], LocaleContextHolder.getLocale()); } } questionAnswer.setStringAnswerValuesMatrix(stringAnswerValuesMatrix); questionAnswer .setBigDecimalAnswerValuesMatrix(bigDecimalAnswerValuesMatrix); break; case DECIMAL_INPUT_MATRIX://Decimal Input Matrix stringAnswerValuesMatrix = new String[rowCount][columnCount]; bigDecimalAnswerValuesMatrix = new BigDecimal[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { bigDecimalAnswerValuesMatrix[r - 1][c - 1] = rs .getBigDecimal("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); stringAnswerValuesMatrix[r - 1][c - 1] = bigDecimalAnswerValuesMatrix[r - 1][c - 1] == null ? "" : BigDecimalValidator.getInstance().format( bigDecimalAnswerValuesMatrix[r - 1][c - 1], LocaleContextHolder.getLocale()); } } questionAnswer.setStringAnswerValuesMatrix(stringAnswerValuesMatrix); questionAnswer .setBigDecimalAnswerValuesMatrix(bigDecimalAnswerValuesMatrix); break; case DATE_INPUT_MATRIX://Date Input Matrix stringAnswerValuesMatrix = new String[rowCount][columnCount]; dateAnswerValuesMatrix = new Date[rowCount][columnCount]; for (int r = 1; r <= rowCount; r++) { for (int c = 1; c <= columnCount; c++) { dateAnswerValuesMatrix[r - 1][c - 1] = rs .getDate("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder() + "r" + r + "c" + c); stringAnswerValuesMatrix[r - 1][c - 1] = dateAnswerValuesMatrix[r - 1][c - 1] == null ? "" : DateValidator.getInstance().format( dateAnswerValuesMatrix[r - 1][c - 1], dateFormat); } } questionAnswer.setStringAnswerValuesMatrix(stringAnswerValuesMatrix); questionAnswer.setDateAnswerValuesMatrix(dateAnswerValuesMatrix); break; case STAR_RATING: //Integer Input questionAnswer.setLongAnswerValue((rs.getLong("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); if (rs.wasNull()) questionAnswer.setLongAnswerValue(null); questionAnswer.setStringAnswerValue( questionAnswer.getLongAnswerValue() == null ? "" : questionAnswer.getLongAnswerValue().toString()); break; case SMILEY_FACES_RATING: //Integer Input questionAnswer.setLongAnswerValue((rs.getLong("p" + surveyDefinitionPage.getOrder() + "q" + question.getOrder()))); if (rs.wasNull()) questionAnswer.setLongAnswerValue(null); questionAnswer.setStringAnswerValue( questionAnswer.getLongAnswerValue() == null ? "" : questionAnswer.getLongAnswerValue().toString()); break; } questionAnswers.add(questionAnswer); } page.setQuestionAnswers(questionAnswers); pages.add(page); } return pages; } }); return surveyPages; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.mimp.hibernate.HiberEtapa.java
public ArrayList<ExpedienteFamilia> listaExpInfoFam() { Session session = sessionFactory.getCurrentSession(); session.beginTransaction();/*ww w . j a v a2s.c o m*/ final ArrayList<ExpedienteFamilia> allInfoFam = new ArrayList(); Work work = new Work() { @Override public void execute(Connection connection) throws SQLException { ExpedienteNna expnna; String hql = "{call HE_LISTA_EXP_POR_ESTADOS(?)}"; CallableStatement statement = connection.prepareCall(hql); statement.registerOutParameter(1, OracleTypes.CURSOR); statement.execute(); ResultSet rs = (ResultSet) statement.getObject(1); while (rs.next()) { ExpedienteFamilia tempEF = new ExpedienteFamilia(); Familia tempFam = new Familia(); Unidad TempUn = new Unidad(); Set<Evaluacion> listaEv = new HashSet<Evaluacion>(); Set<InfoFamilia> listaInf = new HashSet<InfoFamilia>(); tempEF.setIdexpedienteFamilia(rs.getLong("IDEXPEDIENTE_FAMILIA")); tempFam.setIdfamilia(rs.getLong("IDFAMILIA")); TempUn.setIdunidad(rs.getLong("IDUNIDAD")); tempEF.setNumero(rs.getLong("NUMERO")); tempEF.setExpediente(rs.getString("EXPEDIENTE")); tempEF.setHt(rs.getString("HT")); tempEF.setNumeroExpediente(rs.getString("NUMERO_EXPEDIENTE")); tempEF.setFechaIngresoDga(rs.getDate("FECHA_INGRESO_DGA")); tempEF.setEstado(rs.getString("ESTADO")); tempEF.setTupa(rs.getDate("TUPA")); tempEF.setNacionalidad(rs.getString("NACIONALIDAD")); tempEF.setRnsa(rs.getShort("RNSA")); tempEF.setRnaa(rs.getShort("RNAA")); tempEF.setTipoFamilia(rs.getString("TIPO_FAMILIA")); tempEF.setTipoListaEspera(rs.getString("TIPO_LISTA_ESPERA")); tempEF.setHtFicha(rs.getString("HTFICHA")); tempEF.setnFicha(rs.getString("NFICHA")); tempEF.setFechaIngresoFicha(rs.getDate("FECHA_INGRESO_FICHA")); String hql2 = "{call HE_LISTAEVAL_BY_IDEXPFAM(?,?)}"; CallableStatement statement2 = connection.prepareCall(hql2); statement2.setLong(1, tempEF.getIdexpedienteFamilia()); statement2.registerOutParameter(2, OracleTypes.CURSOR); statement2.execute(); ResultSet rs2 = (ResultSet) statement2.getObject(2); while (rs2.next()) { Evaluacion tempEval = new Evaluacion(); tempEval.setIdevaluacion(rs2.getLong("IDEVALUACION")); tempEval.setExpedienteFamilia(tempEF); tempEval.setTipo(rs2.getString("TIPO")); tempEval.setFechaAsignacion(rs2.getDate("FECHA_ASIGNACION")); tempEval.setResultado(rs2.getString("RESULTADO")); tempEval.setFechaResultado(rs2.getDate("FECHA_RESULTADO")); tempEval.setObservacion(rs2.getString("OBSERVACION")); tempEval.setSustento(rs2.getString("SUSTENTO")); tempEval.setNDesignacion(rs2.getString("N_DESIGNACION")); tempEval.setNumEval(rs2.getString("NUM_EVAL")); Set<Resolucion> listaRe = new HashSet<Resolucion>(); if (tempEval.getTipo().equals("legal")) { String hql3 = "{call HE_ULTRESOL_LEGAL(?,?)}"; CallableStatement statement3 = connection.prepareCall(hql3); statement3.setLong(1, tempEval.getIdevaluacion()); statement3.registerOutParameter(2, OracleTypes.CURSOR); statement3.execute(); ResultSet rs3 = (ResultSet) statement3.getObject(2); if (rs3.next()) { Resolucion tempResol = new Resolucion(); tempResol.setIdresolucion(rs3.getLong("IDRESOLUCION")); tempResol.setTipo(rs3.getString("TIPO")); tempResol.setNumero(rs3.getString("NUMERO")); tempResol.setFechaResol(rs3.getDate("FECHA_RESOL")); tempResol.setFechaNotificacion(rs3.getDate("FECHA_NOTIFICACION")); tempResol.setEvaluacion(tempEval); listaRe.add(tempResol); } rs3.close(); statement3.close(); } tempEval.setResolucions(listaRe); listaEv.add(tempEval); } rs2.close(); statement2.close(); String hql4 = "{call HE_GETINFOFAM_POR_IDFAM(?,?)}"; CallableStatement statement4 = connection.prepareCall(hql4); statement4.setLong(1, tempFam.getIdfamilia()); statement4.registerOutParameter(2, OracleTypes.CURSOR); statement4.execute(); ResultSet rs4 = (ResultSet) statement4.getObject(2); if (rs4.next()) { InfoFamilia tempInfo = new InfoFamilia(); tempInfo.setIdinfoFamilia(rs4.getLong("IDINFO_FAMILIA")); tempInfo.setFamilia(tempFam); tempInfo.setDepRes(rs4.getString("DEP_RES")); tempInfo.setPaisRes(rs4.getString("PAIS_RES")); tempInfo.setDomicilio(rs4.getString("DOMICILIO")); tempInfo.setPropiedadVivienda(rs4.getString("PROPIEDAD_VIVIENDA")); tempInfo.setTipoVivienda(rs4.getString("TIPO_VIVIENDA")); tempInfo.setAreaVivTotal(rs4.getLong("AREA_VIV_TOTAL")); tempInfo.setAreaVivConst(rs4.getLong("AREA_VIV_CONST")); tempInfo.setDistVivienda(rs4.getString("DIST_VIVIENDA")); tempInfo.setLuz(rs4.getShort("LUZ")); tempInfo.setAgua(rs4.getShort("AGUA")); tempInfo.setDesague(rs4.getShort("DESAGUE")); tempInfo.setOtrosServ(rs4.getString("OTROS_SERV")); tempInfo.setMaterConst(rs4.getString("MATER_CONST")); tempInfo.setPared(rs4.getString("PARED")); tempInfo.setTecho(rs4.getString("TECHO")); tempInfo.setPiso(rs4.getString("PISO")); String charValueStr = ""; if (rs4.getString("NIVEL_SOCIOECONOMICO") != null) { charValueStr = rs4.getString("NIVEL_SOCIOECONOMICO"); } if (!charValueStr.equals("") && charValueStr != null) { tempInfo.setNivelSocioeconomico(charValueStr.charAt(0)); } tempInfo.setExpectativaEdadMin(rs4.getShort("EXPECTATIVA_EDAD_MIN")); tempInfo.setExpectativaGenero(rs4.getString("EXPECTATIVA_GENERO")); tempInfo.setOrigenHijos(rs4.getString("ORIGEN_HIJOS")); tempInfo.setPuedeViajar(rs4.getShort("PUEDE_VIAJAR")); tempInfo.setPredisposicionAp(rs4.getString("PREDISPOSICION_AP")); tempInfo.setCondicion(rs4.getString("CONDICION")); tempInfo.setAntecedenteFamilia(rs4.getString("ANTECEDENTE_FAMILIA")); tempInfo.setFechaAntecedenteFamilia(rs4.getDate("FECHA_ANTECEDENTE_FAMILIA")); tempInfo.setObservaciones(rs4.getString("OBSERVACIONES")); tempInfo.setNnaIncesto(rs4.getShort("NNA_INCESTO")); tempInfo.setNnaMental(rs4.getShort("NNA_MENTAL")); tempInfo.setNnaEpilepsia(rs4.getShort("NNA_EPILEPSIA")); tempInfo.setNnaAbuso(rs4.getShort("NNA_ABUSO")); tempInfo.setNnaSifilis(rs4.getShort("NNA_SIFILIS")); tempInfo.setNnaSeguiMedico(rs4.getShort("NNA_SEGUI_MEDICO")); tempInfo.setNnaOperacion(rs4.getShort("NNA_OPERACION")); tempInfo.setNnaHiperactivo(rs4.getShort("NNA_HIPERACTIVO")); tempInfo.setNnaEspecial(rs4.getShort("NNA_ESPECIAL")); tempInfo.setNnaEnfermo(rs4.getShort("NNA_ENFERMO")); tempInfo.setNnaMayor(rs4.getShort("NNA_MAYOR")); tempInfo.setNnaAdolescente(rs4.getShort("NNA_ADOLESCENTE")); tempInfo.setNnaHermano(rs4.getShort("NNA_HERMANO")); tempInfo.setEstadoCivil(rs4.getString("ESTADO_CIVIL")); tempInfo.setFechaMatrimonio(rs4.getDate("FECHA_MATRIMONIO")); tempInfo.setTelefono(rs4.getString("TELEFONO")); tempInfo.setExpectativaEdadMax(rs4.getShort("EXPECTATIVA_EDAD_MAX")); tempInfo.setnHijos(rs4.getShort("NHIJOS")); listaInf.add(tempInfo); } rs4.close(); statement4.close(); Set<Designacion> listaDesig = new HashSet<Designacion>(); String hql5 = "{call REPORTE_ULTDESIG(?,?)}"; CallableStatement statement5 = connection.prepareCall(hql5); statement5.setLong(1, tempEF.getIdexpedienteFamilia()); statement5.registerOutParameter(2, OracleTypes.CURSOR); statement5.execute(); ResultSet rs5 = (ResultSet) statement5.getObject(2); if (rs5.next()) { Designacion tempDesig = new Designacion(); tempDesig.setIddesignacion(rs5.getLong("IDDESIGNACION")); tempDesig.setNDesignacion(rs5.getString("N_DESIGNACION")); tempDesig.setPrioridad(rs5.getLong("PRIORIDAD")); tempDesig.setFechaPropuesta(rs5.getDate("FECHA_PROPUESTA")); tempDesig.setFechaConsejo(rs5.getDate("FECHA_CONSEJO")); tempDesig.setAceptacionConsejo(rs5.getShort("ACEPTACION_CONSEJO")); tempDesig.setTipoPropuesta(rs5.getString("TIPO_PROPUESTA")); listaDesig.add(tempDesig); } rs5.close(); statement5.close(); tempFam.setInfoFamilias(listaInf); tempEF.setDesignacions(listaDesig); tempEF.setFamilia(tempFam); tempEF.setUnidad(TempUn); tempEF.setEvaluacions(listaEv); allInfoFam.add(tempEF); } rs.close(); statement.close(); } }; session.doWork(work); return allInfoFam; }