List of usage examples for java.sql ResultSet getTimestamp
java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Timestamp
object in the Java programming language. From source file:com.silverpeas.gallery.dao.MediaDAO.java
/** * Finds media according to the given criteria. * @param con the database connection.//from www. j av a2 s . c o m * @param criteria the media criteria. * @return the media list corresponding to the given criteria. */ public static List<Media> findByCriteria(final Connection con, final MediaCriteria criteria) throws SQLException { MediaSQLQueryBuilder queryBuilder = new MediaSQLQueryBuilder(); criteria.processWith(queryBuilder); Pair<String, List<Object>> queryBuild = queryBuilder.result(); final Map<String, Photo> photos = new HashMap<String, Photo>(); final Map<String, Video> videos = new HashMap<String, Video>(); final Map<String, Sound> sounds = new HashMap<String, Sound>(); final Map<String, Streaming> streamings = new HashMap<String, Streaming>(); List<Media> media = select(con, queryBuild.getLeft(), queryBuild.getRight(), new SelectResultRowProcessor<Media>(criteria.getResultLimit()) { @Override protected Media currentRow(final int rowIndex, final ResultSet rs) throws SQLException { String mediaId = rs.getString(1); MediaType mediaType = MediaType.from(rs.getString(2)); String instanceId = rs.getString(3); final Media currentMedia; switch (mediaType) { case Photo: currentMedia = new Photo(); photos.put(mediaId, (Photo) currentMedia); break; case Video: currentMedia = new Video(); videos.put(mediaId, (Video) currentMedia); break; case Sound: currentMedia = new Sound(); sounds.put(mediaId, (Sound) currentMedia); break; case Streaming: currentMedia = new Streaming(); streamings.put(mediaId, (Streaming) currentMedia); break; default: currentMedia = null; } if (currentMedia == null) { // Unknown media ... SilverTrace.warn(GalleryComponentSettings.COMPONENT_NAME, "MediaDAO.findByCriteria()", "root.MSG_GEN_PARAM_VALUE", "unknown media type: " + mediaType); return null; } currentMedia.setMediaPK(new MediaPK(mediaId, instanceId)); currentMedia.setTitle(rs.getString(4)); currentMedia.setDescription(rs.getString(5)); currentMedia.setAuthor(rs.getString(6)); currentMedia.setKeyWord(rs.getString(7)); currentMedia.setVisibilityPeriod( Period.check(Period.from(new Date(rs.getLong(8)), new Date(rs.getLong(9))))); currentMedia.setCreationDate(rs.getTimestamp(10)); currentMedia.setCreatorId(rs.getString(11)); currentMedia.setLastUpdateDate(rs.getTimestamp(12)); currentMedia.setLastUpdatedBy(rs.getString(13)); return currentMedia; } }); decoratePhotos(con, media, photos); decorateVideos(con, media, videos); decorateSounds(con, media, sounds); decorateStreamings(con, media, streamings); return queryBuilder.orderingResult(media); }
From source file:com.intuit.it.billing.data.BillingDAOImpl.java
/** * getBillingHistory is to be used to get get the billing history of a given customer. * <p/>//from w w w .j a va2s . c o m * <p/> * <b>DATABASE PROCEDURE:</b> * * @code * FUNCTION fn_get_history( * customer IN VARCHAR2, * start_date IN DATE, * end_date IN DATE, * page IN INTEGER, * records IN INTEGER ) * RETURN ref_cursor; * @endcode * <p/> * <b>DATABASE RESULT SET:</b> * <ul> * <li>ITEM_ID,</li> * <li>BILL_ITEM_NO,</li> * <li>AR_ACCOUNT_NO,</li> * <li>ACCOUNT_NO,</li> * <li>ORDER_NO,</li> * <li>ORDER_LINE_NO,</li> * <li>EVENT_TYPE,</li> * <li>CHARGE_TYPE,</li> * <li> CURRENCY,</li> * <li>CREATED_DATE,</li> * <li>BILL_DATE,</li> * <li>DUE_DATE,</li> * <li>STATUS,</li> * <li>REASON_CODE,</li> * <li>ITEM_TOTAL,</li> * <li>ITEM_DUE,</li> * <li>ITEM_DISPUTED,</li> * <li>ITEM_BASE,</li> * <li>ITEM_TAX,</li> * <li>ITEM_DESCRIPTION,</li> * <li>ITEM_CODE,</li> * <li>LICENSE,</li> * <li>PAY_TYPE,</li> * <li>PAY_DESCR,</li> * <li>PAY_ACCT_TYPE, * <li>PAY_PSON,</li> * <li>QUANTITY </li> * </ul> * * @param customer : The Customer.accountNo of the customer we want history for * @param startDate : The starting date of the allocation - to be merged with a billing history record set * @param endDate : The ending date of the allocation - to be merged with a billing history record set * @param skip : Starting record for server side paging * @param pageSize : How many records to retrieve * * @return A list of LineItem objects in reverse date order sort */ @Override public List<LineItem> getBillingHistory(String cust, Date startDate, Date endDate, Integer startPage, Integer pageSize) throws JSONException { List<LineItem> history = new ArrayList<LineItem>(); java.sql.Date sqlStartDate = new java.sql.Date(startDate.getTime()); java.sql.Date sqlEndDate = new java.sql.Date(endDate.getTime()); String query = "begin ? := billing_inquiry.fn_get_history( ?, ?, ?, ?, ? ); end;"; Connection conn = null; ResultSet rs = null; // DB Connection try { conn = this.getConnection(); } catch (SQLException e) { throw JSONException.sqlError(e); } catch (NamingException e) { throw JSONException.namingError(e.toString()); } try { CallableStatement stmt = conn.prepareCall(query); stmt.registerOutParameter(1, OracleTypes.CURSOR); stmt.setString(2, cust); stmt.setDate(3, sqlStartDate); stmt.setDate(4, sqlEndDate); stmt.setInt(5, startPage); stmt.setInt(6, pageSize); stmt.execute(); rs = (ResultSet) stmt.getObject(1); while (rs.next()) { LineItem l = new LineItem(); l.setRowId(rs.getInt("ROW_ID")); l.setBaseAmount(rs.getBigDecimal("ITEM_BASE")); l.setItemTotal(rs.getBigDecimal("ITEM_TOTAL")); l.setItemDue(rs.getBigDecimal("ITEM_DUE")); l.setItemDisputed(rs.getBigDecimal("ITEM_DISPUTED")); l.setTaxAmount(rs.getBigDecimal("ITEM_TAX")); l.setBillDate(rs.getTimestamp("BILL_DATE")); l.setBillItemNo(rs.getString("BILL_ITEM_NO")); l.setBillTo(rs.getString("AR_ACCOUNT_NO")); l.setChargeType(rs.getString("CHARGE_TYPE")); l.setCreatedDate(rs.getTimestamp("CREATED_DATE")); l.setCurrency(rs.getString("CURRENCY")); l.setDueDate(rs.getTimestamp("DUE_DATE")); l.setEventType(rs.getString("EVENT_TYPE")); l.setItemCode(rs.getString("ITEM_CODE")); l.setItemDescription(rs.getString("ITEM_DESCRIPTION")); l.setLicense(rs.getString("LICENSE")); l.setItemID(rs.getString("ITEM_ID")); l.setOrderLine(rs.getString("ORDER_LINE_NO")); l.setOrderNo(rs.getString("ORDER_NO")); l.setPayAccountType(rs.getString("PAY_ACCT_TYPE")); l.setPayDescription(rs.getString("PAY_DESCR")); l.setPayType(rs.getString("PAY_TYPE")); l.setpSON(rs.getString("PAY_PSON")); l.setQuantity(rs.getInt("QUANTITY")); l.setReasonCode(rs.getString("REASON_CODE")); l.setStatus(rs.getInt("STATUS")); history.add(l); } conn.close(); rs.close(); } catch (SQLException e) { throw JSONException.sqlError(e); } if (history == null || history.isEmpty()) { throw JSONException.noDataFound("Null set returned - no data found"); } return history; }
From source file:com.alfaariss.oa.authentication.remote.saml2.idp.storage.jdbc.IDPJDBCStorage.java
/** * @see com.alfaariss.oa.engine.core.idp.storage.IIDPStorage#getAll() */// w ww.j av a 2 s.co m public List<IIDP> getAll() throws OAException { Connection connection = null; PreparedStatement pSelect = null; ResultSet resultSet = null; List<IIDP> listIDPs = new Vector<IIDP>(); IMetadataProviderManager oMPM = MdMgrManager.getInstance().getMetadataProviderManager(_sId); try { boolean dateLastModifiedExists = true; connection = _dataSource.getConnection(); pSelect = connection.prepareStatement(_sQuerySelectAll); pSelect.setBoolean(1, true); resultSet = pSelect.executeQuery(); while (resultSet.next()) { boolean bACSIndex = resultSet.getBoolean(COLUMN_ACS_INDEX); Boolean boolAllowCreate = null; String sAllowCreate = resultSet.getString(COLUMN_ALLOW_CREATE); if (sAllowCreate != null) { boolean bAllowCreate = resultSet.getBoolean(COLUMN_ALLOW_CREATE); boolAllowCreate = new Boolean(bAllowCreate); } boolean bScoping = resultSet.getBoolean(COLUMN_SCOPING); boolean bNameIDPolicy = resultSet.getBoolean(COLUMN_NAMEIDPOLICY); boolean bAvoidSubjectConfirmation = resultSet.getBoolean(COLUMN_AVOID_SUBJCONF); boolean bDisableSSOForIDP = resultSet.getBoolean(COLUMN_DISABLE_SSO); // Implement date_last_modified column as optional Date dLastModified = null; if (dateLastModifiedExists) { try { dLastModified = resultSet.getTimestamp(COLUMN_DATELASTMODIFIED); } catch (Exception e) { _oLogger.info("No " + COLUMN_DATELASTMODIFIED + " column found; ignoring."); dateLastModifiedExists = false; } } SAML2IDP idp = new SAML2IDP(resultSet.getString(COLUMN_ID), resultSet.getBytes(COLUMN_SOURCEID), resultSet.getString(COLUMN_FRIENDLYNAME), resultSet.getString(COLUMN_METADATA_FILE), resultSet.getString(COLUMN_METADATA_URL), resultSet.getInt(COLUMN_METADATA_TIMEOUT), bACSIndex, boolAllowCreate, bScoping, bNameIDPolicy, resultSet.getString(COLUMN_NAMEIDFORMAT), bAvoidSubjectConfirmation, bDisableSSOForIDP, dLastModified, oMPM.getId()); listIDPs.add(idp); } } catch (Exception e) { _oLogger.fatal("Internal error during retrieval of all IDPs", e); throw new OAException(SystemErrors.ERROR_INTERNAL); } finally { try { if (pSelect != null) pSelect.close(); } catch (Exception e) { _oLogger.error("Could not close select statement", e); } try { if (connection != null) connection.close(); } catch (Exception e) { _oLogger.error("Could not close connection", e); } } return listIDPs; }
From source file:com.sfs.whichdoctor.dao.AssessmentDAOImpl.java
/** * Load assessment bean.//from w w w. j a va 2 s. c o m * * @param rs the rs * @param loadDetails the load details * @return the assessment bean * @throws SQLException the sQL exception */ private AssessmentBean loadAssessmentBean(final ResultSet rs, final BuilderBean loadDetails) throws SQLException { AssessmentBean assessment = new AssessmentBean(); /* Create resource bean and fill with dataset info */ assessment.setId(rs.getInt("AssessmentId")); assessment.setGUID(rs.getInt("GUID")); assessment.setAssessmentType(rs.getString("AssessmentType")); /* Set assessment details */ assessment.setTrainingOrganisation(rs.getString("TrainingOrganisation")); assessment.setTrainingProgram(rs.getString("TrainingProgram")); assessment.setTrainingProgramISBMapping(rs.getString("TrainingProgramISBMapping")); assessment.setCommitteeSpecialty(rs.getString("SpecialtyType")); assessment.setCommitteeSpecialtyAbbreviation(rs.getString("SpecialtyTypeAbbreviation")); assessment.setYearOfTraining(rs.getInt("YearOfTraining")); assessment.setStatus(rs.getString("FeedbackStatus")); assessment.setStatusReason(rs.getString("StatusReason")); assessment.setApproved(rs.getString("Approved")); assessment.setApprovedCondition(rs.getString("ApprovedCondition")); assessment.setApplicationComment(rs.getString("ApplicationComment")); assessment.setAccreditationComment(rs.getString("AccreditationComment")); RotationBean rotation = new RotationBean(); rotation.setGUID(rs.getInt("ReferenceGUID")); assessment.setRotation(rotation); assessment.setActive(rs.getBoolean("Active")); if (loadDetails.getBoolean("HISTORY")) { try { assessment.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error parsing ModifiedDate: " + sqe.getMessage()); } assessment.setCreatedBy(rs.getString("CreatedBy")); try { assessment.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error parsing ModifiedDate: " + sqe.getMessage()); } assessment.setModifiedBy(rs.getString("ModifiedBy")); } /* Load user details */ if (loadDetails.getBoolean("CREATED")) { try { UserBean user = new UserBean(); user.setDN(rs.getString("CreatedBy")); user.setPreferredName(rs.getString("CreatedFirstName")); user.setLastName(rs.getString("CreatedLastName")); assessment.setCreatedUser(user); } catch (SQLException sqe) { dataLogger.debug("Error loading created user details: " + sqe.getMessage()); } } if (loadDetails.getBoolean("MODIFIED")) { try { UserBean user = new UserBean(); user.setDN(rs.getString("ModifiedBy")); user.setPreferredName(rs.getString("ModifiedFirstName")); user.setLastName(rs.getString("ModifiedLastName")); assessment.setModifiedUser(user); } catch (SQLException sqe) { dataLogger.debug("Error loading modified user details: " + sqe.getMessage()); } } return assessment; }
From source file:ResultSetIterator.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * // w w w. ja va 2 s . co m * <p> * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return new Integer(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return new Boolean(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return new Long(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return new Double(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return new Float(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return new Short(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return new Byte(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else { return rs.getObject(index); } }
From source file:CSVWriter.java
private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; switch (colType) { case Types.BIT: case Types.JAVA_OBJECT: value = handleObject(rs.getObject(colIndex)); break;//from w ww . j ava 2 s . c o m case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); value = Boolean.valueOf(b).toString(); break; case NCLOB: // todo : use rs.getNClob case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { value = read(c); } break; case Types.BIGINT: value = handleLong(rs, colIndex); break; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: value = handleBigDecimal(rs.getBigDecimal(colIndex)); break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: value = handleInteger(rs, colIndex); break; case Types.DATE: value = handleDate(rs, colIndex); break; case Types.TIME: value = handleTime(rs.getTime(colIndex)); break; case Types.TIMESTAMP: value = handleTimestamp(rs.getTimestamp(colIndex)); break; case NVARCHAR: // todo : use rs.getNString case NCHAR: // todo : use rs.getNString case LONGNVARCHAR: // todo : use rs.getNString case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:com.commander4j.db.JDBDespatch.java
public LinkedList<JDBDespatch> browseDespatchData(String status, int limit) { String temp = ""; Boolean top = false;//from w ww .j a v a 2s .c om PreparedStatement stmt = null; LinkedList<JDBDespatch> result = new LinkedList<JDBDespatch>(); ResultSet rs; result.clear(); try { temp = Common.hostList.getHost(getHostID()).getSqlstatements().getSQL("JDBDespatch.browse"); if (temp.indexOf("[top]") >= 0) { top = true; temp = temp.replace("[top]", "top " + String.valueOf(limit)); } stmt = Common.hostList.getHost(getHostID()).getConnection(getSessionID()).prepareStatement(temp); stmt.setFetchSize(100); stmt.setString(1, status); if (top == false) { stmt.setInt(2, limit); } rs = stmt.executeQuery(); while (rs.next()) { result.addLast(new JDBDespatch(getHostID(), getSessionID(), rs.getString("despatch_no"), rs.getTimestamp("despatch_date"), rs.getString("location_id_from"), rs.getString("location_id_to"), rs.getString("status"), rs.getInt("total_pallets"), rs.getString("trailer"), rs.getString("haulier"), rs.getString("load_no"), rs.getString("user_id"), rs.getString("journey_ref"))); } rs.close(); stmt.close(); } catch (SQLException e) { setErrorMessage(e.getMessage()); } return result; }
From source file:com.nway.spring.jdbc.bean.AsmBeanProcessor.java
private Object processColumn(ResultSet rs, int index, Class<?> propType, String writer, String processorName, String beanName, MethodVisitor mv) throws SQLException { if (propType.equals(String.class)) { visitMethod(mv, index, beanName, "Ljava/lang/String;", "getString", writer); return rs.getString(index); } else if (propType.equals(Integer.TYPE)) { visitMethod(mv, index, beanName, "I", "getInt", writer); return rs.getInt(index); } else if (propType.equals(Integer.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_INTEGER, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Integer.class); } else if (propType.equals(Long.TYPE)) { visitMethod(mv, index, beanName, "J", "getLong", writer); return rs.getLong(index); } else if (propType.equals(Long.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_LONG, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Long.class); } else if (propType.equals(java.sql.Date.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Date;", "getDate", writer); return rs.getDate(index); } else if (propType.equals(java.util.Date.class)) { visitMethodCast(mv, index, beanName, PROPERTY_TYPE_DATE, "java/util/Date", writer); return rs.getTimestamp(index); } else if (propType.equals(Timestamp.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Timestamp;", "getTimestamp", writer); return rs.getTimestamp(index); } else if (propType.equals(Time.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Time;", "getTime", writer); return rs.getTime(index); } else if (propType.equals(Double.TYPE)) { visitMethod(mv, index, beanName, "D", "getDouble", writer); return rs.getDouble(index); } else if (propType.equals(Double.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_DOUBLE, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Double.class); } else if (propType.equals(Float.TYPE)) { visitMethod(mv, index, beanName, "F", "getFloat", writer); return rs.getFloat(index); } else if (propType.equals(Float.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_FLOAT, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Float.class); } else if (propType.equals(Boolean.TYPE)) { visitMethod(mv, index, beanName, "Z", "getBoolean", writer); return rs.getBoolean(index); } else if (propType.equals(Boolean.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_BOOLEAN, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Boolean.class); } else if (propType.equals(Clob.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Clob;", "getClob", writer); return rs.getClob(index); } else if (propType.equals(Blob.class)) { visitMethod(mv, index, beanName, "Ljava/sql/Blob;", "getBlob", writer); return rs.getBlob(index); } else if (propType.equals(byte[].class)) { visitMethod(mv, index, beanName, "[B", "getBytes", writer); return rs.getBytes(index); } else if (propType.equals(Short.TYPE)) { visitMethod(mv, index, beanName, "S", "getShort", writer); return rs.getShort(index); } else if (propType.equals(Short.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_SHORT, writer, processorName); return JdbcUtils.getResultSetValue(rs, index, Short.class); } else if (propType.equals(Byte.TYPE)) { visitMethod(mv, index, beanName, "B", "getByte", writer); return rs.getByte(index); } else if (propType.equals(Byte.class)) { visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_BYTE, writer, processorName); return rs.getByte(index); } else {//from ww w . j ava 2 s. c om visitMethodCast(mv, index, beanName, PROPERTY_TYPE_OTHER, propType.getName().replace('.', '/'), writer); return rs.getObject(index); } }
From source file:com.flexive.core.search.PropertyEntry.java
/** * Return the result value of this property entry in a given result set. * * @param rs the SQL result set//from w ww . j a va 2 s . c o m * @param languageId id of the requested language * @param xpathAvailable if the XPath was selected as an additional column for content table entries * @param typeId the result row type ID (if available, otherwise -1) * @return the value of this property (column) in the result set * @throws FxSqlSearchException if the database cannot read the value */ public Object getResultValue(ResultSet rs, long languageId, boolean xpathAvailable, long typeId) throws FxSqlSearchException { final FxValue result; final int pos = positionInResultSet; // Handle by type try { switch (overrideDataType == null ? property.getDataType() : overrideDataType) { case DateTime: switch (rs.getMetaData().getColumnType(pos)) { case java.sql.Types.BIGINT: case java.sql.Types.DECIMAL: case java.sql.Types.NUMERIC: case java.sql.Types.INTEGER: result = new FxDateTime(multilanguage, FxLanguage.SYSTEM_ID, new Date(rs.getLong(pos))); break; default: Timestamp dttstp = rs.getTimestamp(pos); Date _dtdate = dttstp != null ? new Date(dttstp.getTime()) : null; result = new FxDateTime(multilanguage, FxLanguage.SYSTEM_ID, _dtdate); if (dttstp == null) result.setEmpty(FxLanguage.SYSTEM_ID); } break; case Date: Timestamp tstp = rs.getTimestamp(pos); result = new FxDate(multilanguage, FxLanguage.SYSTEM_ID, tstp != null ? new Date(tstp.getTime()) : null); if (tstp == null) { result.setEmpty(); } break; case DateRange: final Pair<Date, Date> pair = decodeDateRange(rs, pos, 1); if (pair.getFirst() == null || pair.getSecond() == null) { result = new FxDateRange(multilanguage, FxLanguage.SYSTEM_ID, FxDateRange.EMPTY); result.setEmpty(FxLanguage.SYSTEM_ID); } else { result = new FxDateRange(multilanguage, FxLanguage.SYSTEM_ID, new DateRange(pair.getFirst(), pair.getSecond())); } break; case DateTimeRange: final Pair<Date, Date> pair2 = decodeDateRange(rs, pos, 1); if (pair2.getFirst() == null || pair2.getSecond() == null) { result = new FxDateTimeRange(multilanguage, FxLanguage.SYSTEM_ID, FxDateRange.EMPTY); result.setEmpty(FxLanguage.SYSTEM_ID); } else { result = new FxDateTimeRange(new DateRange(pair2.getFirst(), pair2.getSecond())); } break; case HTML: result = new FxHTML(multilanguage, FxLanguage.SYSTEM_ID, rs.getString(pos)); break; case String1024: case Text: result = new FxString(multilanguage, FxLanguage.SYSTEM_ID, rs.getString(pos)); break; case LargeNumber: result = new FxLargeNumber(multilanguage, FxLanguage.SYSTEM_ID, rs.getLong(pos)); break; case Number: result = new FxNumber(multilanguage, FxLanguage.SYSTEM_ID, rs.getInt(pos)); break; case Float: result = new FxFloat(multilanguage, FxLanguage.SYSTEM_ID, rs.getFloat(pos)); break; case Boolean: result = new FxBoolean(multilanguage, FxLanguage.SYSTEM_ID, rs.getBoolean(pos)); break; case Double: result = new FxDouble(multilanguage, FxLanguage.SYSTEM_ID, rs.getDouble(pos)); break; case Reference: result = new FxReference(new ReferencedContent(new FxPK(rs.getLong(pos), FxPK.MAX))); // TODO!! break; case SelectOne: FxSelectListItem oneItem = getEnvironment().getSelectListItem(rs.getLong(pos)); result = new FxSelectOne(multilanguage, FxLanguage.SYSTEM_ID, oneItem); break; case SelectMany: FxSelectListItem manyItem = getEnvironment().getSelectListItem(rs.getLong(pos)); SelectMany valueMany = new SelectMany(manyItem.getList()); valueMany.selectFromList(rs.getString(pos + 1)); result = new FxSelectMany(multilanguage, FxLanguage.SYSTEM_ID, valueMany); break; case Binary: result = new FxBinary(multilanguage, FxLanguage.SYSTEM_ID, DataSelector.decodeBinary(rs, pos)); break; default: throw new FxSqlSearchException(LOG, "ex.sqlSearch.reader.UnknownColumnType", String.valueOf(getProperty().getDataType())); } if (rs.wasNull()) { result.setEmpty(languageId); } int currentPosition = positionInResultSet + getReadColumns().length; // process XPath if (isProcessXPath()) { if (xpathAvailable && getTableType() == PropertyResolver.Table.T_CONTENT_DATA) { // Get the XPATH if we are reading from the content data table result.setXPath(rebuildXPath(rs.getString(currentPosition++))); } else if (xpathAvailable && getTableType() == PropertyResolver.Table.T_CONTENT && property != null) { // set XPath for system-internal properties result.setXPath("ROOT/" + property.getName()); } else if (getTableType() == PropertyResolver.Table.T_CONTENT_DATA_FLAT) { // fill in XPath from assignment, create XPath with full type information if (typeId != -1) { result.setXPath(getEnvironment().getType(typeId).getName() + "/" + assignment.getAlias()); } } } else { result.setXPath(null); } // process data if (isProcessData() && getTableType() != null) { final Integer valueData; switch (getTableType()) { case T_CONTENT_DATA: final int data = rs.getInt(currentPosition++); valueData = rs.wasNull() ? null : data; break; case T_CONTENT_DATA_FLAT: // comma-separated string with the data entries of all columns final String csvData = rs.getString(currentPosition++); valueData = FxArrayUtils.getHexIntElementAt(csvData, ',', flatColumnIndex); break; default: // no value data in other tables valueData = null; } result.setValueData(languageId, valueData); } return result; } catch (SQLException e) { throw new FxSqlSearchException(e); } }
From source file:edu.indiana.d2i.komadu.query.db.BaseDBQuerier.java
public GetEntityDetailResponseDocument getEntityDetail(Connection connection, EntityIDListType entityIDType) throws QueryException, SQLException { l.debug("Entering getEntityDetail()"); assert (connection != null); assert (entityIDType != null); PreparedStatement entityDetailStmt = null; PreparedStatement membershipDetailStmt = null; ResultSet res = null; ResultSet membershipRes = null; GetEntityDetailResponseDocument getEntityDetailResponseDocument = GetEntityDetailResponseDocument.Factory .newInstance();/* w w w . j a v a 2 s . c om*/ GetEntityDetailResponseType getEntityDetailResponseType = getEntityDetailResponseDocument .addNewGetEntityDetailResponse(); EntityDetailListType entityDetailList = getEntityDetailResponseType.addNewEntityDetailList(); for (String entityID : entityIDType.getEntityIDArray()) { try { if (entityID.startsWith(QueryConstants.FILE_IDENTIFIER)) { entityDetailStmt = connection.prepareStatement(PROVSqlQuery.GET_FILE); entityDetailStmt.setString(1, entityID.replace(QueryConstants.FILE_IDENTIFIER, "")); l.debug("entityDetailStmt: " + entityDetailStmt); res = entityDetailStmt.executeQuery(); if (res.next()) { EntityDetail newEntityDetail = entityDetailList.addNewEntityDetail(); newEntityDetail.setId(entityID); String file_uri = res.getString("file_uri"); String owner_id = res.getString("owner_id"); Timestamp creation_date = res.getTimestamp("creation_date"); long size = res.getLong("size"); String md5 = res.getString("md5_checksum"); String file_name = res.getString("file_name"); newEntityDetail.setFileURI(file_uri); if (owner_id != null) newEntityDetail.setOwner(owner_id); if (creation_date != null) newEntityDetail.setCreationDate(KomaduUtils.getCalendarFromTimeStamp(creation_date)); if (size > 0) newEntityDetail.setSize(size); if (md5 != null) newEntityDetail.setMd5(md5); if (file_name != null) newEntityDetail.setFileName(file_name); } } else if (entityID.startsWith(QueryConstants.BLOCK_IDENTIFIER)) { entityDetailStmt = connection.prepareStatement(PROVSqlQuery.GET_BLOCK); entityDetailStmt.setString(1, entityID.replace(QueryConstants.BLOCK_IDENTIFIER, "")); l.debug("entityDetailStmt: " + entityDetailStmt); res = entityDetailStmt.executeQuery(); if (res.next()) { EntityDetail newEntityDetail = entityDetailList.addNewEntityDetail(); newEntityDetail.setId(entityID); String block_content = res.getString("block_content"); long size = res.getLong("size"); String md5 = res.getString("md5_checksum"); newEntityDetail.setBlockContent(block_content); if (size > 0) newEntityDetail.setSize(size); if (md5 != null) newEntityDetail.setMd5(md5); } } else { entityDetailStmt = connection.prepareStatement(PROVSqlQuery.GET_COLLECTION); entityDetailStmt.setString(1, entityID.replace(QueryConstants.COLLECTION_IDENTIFIER, "")); l.debug("entityDetailStmt: " + entityDetailStmt); res = entityDetailStmt.executeQuery(); if (res.next()) { EntityDetail newEntityDetail = entityDetailList.addNewEntityDetail(); newEntityDetail.setId(entityID); String uri = res.getString("collection_uri"); newEntityDetail.setCollectionURI(uri); membershipDetailStmt = connection.prepareStatement(PROVSqlQuery.GET_MEMBERSHIP); membershipDetailStmt.setString(1, entityID.replace(QueryConstants.COLLECTION_IDENTIFIER, "")); membershipRes = membershipDetailStmt.executeQuery(); while (membershipRes.next()) { MembershipDetail membership = newEntityDetail.addNewMembership(); membership.setId(membershipRes.getString("member_id")); if (membershipRes.getString("entity_type").equals(EntityEnumType.BLOCK.toString())) { membership.setEntityType(EntityEnumType.BLOCK); } else if (membershipRes.getString("entity_type") .equals(EntityEnumType.BLOCK.toString())) { membership.setEntityType(EntityEnumType.FILE); } else if (membershipRes.getString("entity_type") .equals(EntityEnumType.COLLECTION.toString())) { membership.setEntityType(EntityEnumType.COLLECTION); } else { l.error("Unrecognized data object type."); } // String instance_of = membershipRes.getString("instance_of"); // if (instance_of != null) // membership.setInstanceOf(instance_of); } membershipRes.close(); membershipDetailStmt.close(); } } } catch (SQLException e) { l.error("Exiting getEntityDetail() with SQL errors.", e); return null; } finally { if (entityDetailStmt != null) { entityDetailStmt.close(); entityDetailStmt = null; } if (membershipDetailStmt != null) { membershipDetailStmt.close(); membershipDetailStmt = null; } if (res != null) { res.close(); res = null; } if (membershipRes != null) { membershipRes.close(); membershipRes = null; } } } l.debug("Response: " + getEntityDetailResponseDocument); l.debug("Exiting QueryEntityUtil.getEntityDetail() with success."); return getEntityDetailResponseDocument; }