List of usage examples for java.sql Connection setReadOnly
void setReadOnly(boolean readOnly) throws SQLException;
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Reset the size field to the value of the size_on_storage field for the * misaligned items i.e. items for which the metadata has been updated but * the updated file has not been uploaded. *//* w w w . j a v a 2 s . c o m*/ public void resetSizeForMisalignedItems() throws DAOException { Connection con = null; PreparedStatement ps = null; try { // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); con.setReadOnly(false); ps = con.prepareStatement(SQL_RESET_EXPIRED_MISALIGNED_FILE_DATA_OBJECTS_BY_USER_ID); ps.setLong(1, getCutOffTime()); ps.setString(2, userId); ps.setString(3, sourceURI); ps.execute(); } catch (Exception e) { throw new DAOException("Error deleting the expired incomplete items.", e); } finally { DBTools.close(con, ps, null); } }
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Retrieves all file data object's properties for the given fdo identifier * specified in the wrapper and set them in the fdo metadata. * * @param fdow the wrapper which on set the properties * @throws DAOException if an error occurs during the getting of properties *//*w w w .j ava 2 s . c o m*/ public void getProperties(FileDataObjectWrapper fdow) throws DAOException { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; Long fdoId = Long.valueOf(fdow.getId()); try { con = getUserDataSource().getRoutedConnection(userId); con.setReadOnly(true); ps = con.prepareStatement(SQL_GET_ALL_FNBL_FILE_DATA_OBJECT_PROPERTY_BY_FDO_ID); ps.setLong(1, fdoId); rs = ps.executeQuery(); setFileDataObjectProperties(fdow.getFileDataObject(), rs); } catch (Exception e) { throw new DAOException("Error retrieving file data object's properties for '" + fdoId + "'", e); } finally { DBTools.close(con, ps, rs); } }
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Removes from the database the expired incomplete items. * Items are incomplete if they don't have a corresponding file on * the file system./*from w w w . jav a 2 s. co m*/ * Incomplete items are considered expired if older than 24h. * @throws DAOException if an error occurs */ public void removeExpiredIncompleteItems() throws DAOException { Connection con = null; PreparedStatement ps = null; try { // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); con.setReadOnly(false); long lastUpdate = getCutOffTime(); ps = con.prepareStatement(SQL_DELETE_EXPIRED_INCOMPLETE_FILE_DATA_OBJECTS_BY_USER_ID); ps.setNull(1, Types.VARCHAR); ps.setLong(2, lastUpdate); ps.setString(3, userId); ps.setString(4, sourceURI); ps.execute(); DBTools.close(con, ps, null); removeAllPropertiesOfExpiredIncompleteItems(lastUpdate); } catch (Exception e) { throw new DAOException("Error deleting the expired incomplete items.", e); } finally { DBTools.close(con, ps, null); } }
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Retrieves the list of the ids of all the twin items of a file data object. * @param fdo//from w ww . j a v a 2s. c o m * @return the list of all the twin items * @throws com.funambol.foundation.exception.DAOException */ public List getTwinItems(FileDataObject fdo) throws DAOException { List twins = new ArrayList(); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); con.setReadOnly(true); // calculate crc Long crc = Long.valueOf(fdo.getCrc()); if (Configuration.getConfiguration().isDebugMode()) { if (log.isTraceEnabled()) { String tdSearch = crc.toString(); StringBuilder sb = new StringBuilder(); sb.append("Looking for items having: ").append("\n> crc: '").append(tdSearch).append('\''); log.trace(sb.toString()); } } ps = con.prepareStatement(SQL_GET_FILE_DATA_OBJECT_TWIN_ID_LIST + SQL_ORDER_BY_ID); ps.setString(1, userId); ps.setString(2, sourceURI); ps.setLong(3, crc); rs = ps.executeQuery(); long twinId; while (rs.next()) { twinId = rs.getLong(1); // The id is the first // and only column if (log.isTraceEnabled()) { log.trace("Twin found for item " + fdo.getName() + " with id: " + twinId); } twins.add(Long.toString(twinId)); } } catch (Exception e) { throw new DAOException("Error retrieving twin.", e); } finally { DBTools.close(con, ps, rs); } return twins; }
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Gets the total size of all the files (except the deleted ones) by * extracting that information from their metadata. * * @return the storage space filled by the user's files (in bytes) * @throws DAOException if an error occurs *//* w w w. ja v a 2 s.c om*/ public long getReservedStorageSpace() throws DAOException { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; long totalSize; try { // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); con.setReadOnly(true); ps = con.prepareStatement(SQL_GET_TOTAL_RESERVED_SIZE_BY_USER); ps.setString(1, userId); ps.setString(2, sourceURI); rs = ps.executeQuery(); rs.next(); totalSize = rs.getLong(1); DBTools.close(null, ps, rs); } catch (Exception e) { throw new DAOException("Error calculating used and reserved " + "storage space.", e); } finally { DBTools.close(con, ps, rs); } return totalSize; }
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Gets the total storage size for all files (except the deleted ones). * * @return the storage space filled by the user's files * @throws DAOException if an error occurs */// w w w . ja v a2 s.c om public long getStorageSpaceUsage() throws DAOException { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; long totalSize; try { // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); con.setReadOnly(true); ps = con.prepareStatement(SQL_GET_TOTAL_SIZE_ON_STORAGE_BY_USER); ps.setString(1, userId); ps.setString(2, sourceURI); rs = ps.executeQuery(); rs.next(); totalSize = rs.getLong(1); DBTools.close(null, ps, rs); } catch (Exception e) { throw new DAOException("Error calculating used storage space.", e); } finally { DBTools.close(con, ps, rs); } return totalSize; }
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Retrieves the file name of the file data object content file. * @param uid file data object unique identifier * @return the filename of the content file * @throws com.funambol.foundation.exception.DAOException *//*from w w w. j ava 2 s . c o m*/ public String getLocalName(String uid) throws DAOException { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; String fileName; try { // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); con.setReadOnly(true); ps = con.prepareStatement(SQL_GET_FILENAME_BY_ID); ps.setLong(1, Long.parseLong(uid)); ps.setString(2, userId); ps.setString(3, sourceURI); rs = ps.executeQuery(); if (rs.next()) { fileName = rs.getString(1); } else { throw new DAOException("No local name found, item with uid '" + uid + "' doesn't exist."); } } catch (DAOException e) { throw e; } catch (Exception e) { throw new DAOException("Error retrieving local file name.", e); } finally { DBTools.close(con, ps, rs); } return fileName; }
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Gets just the size of a file by extracting that information from its * metadata./*w ww . j a v a 2s . co m*/ * * @param uid the unique locator of the file data object in the DB * @return the file size or 0 if the item cannot be found * @throws com.funambol.foundation.exception.DAOException */ public long getItemSize(String uid) throws DAOException { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; long size = 0L; try { Long id = Long.parseLong(uid); // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); con.setReadOnly(true); ps = con.prepareStatement(SQL_GET_SIZE_BY_ID); ps.setLong(1, id); ps.setString(2, userId); ps.setString(3, sourceURI); rs = ps.executeQuery(); if (rs.isBeforeFirst()) { rs.next(); size = rs.getLong(SQL_FIELD_SIZE); } // If the result set is empty, nothing happens and size remains 0 DBTools.close(null, ps, rs); } catch (Exception e) { throw new DAOException("Error seeking file data object.", e); } finally { DBTools.close(con, ps, rs); } return size; }
From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java
/** * Retrieves file data object metadata and all its properties. * * @param uid the file data object identifier to search * @return <code>FileDataObjectWrapper</code> instance. <code>content</code> * is null.// w w w . j av a 2s . c om * @throws DAOException if an error occurs during searching */ public FileDataObjectWrapper getItem(String uid) throws DAOException { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; FileDataObjectWrapper fdow; try { Long id = Long.parseLong(uid); // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); con.setReadOnly(true); ps = con.prepareStatement(SQL_GET_FDO_AND_PROPERTY_BY_USER_ID); ps.setLong(1, id); ps.setString(2, userId); ps.setString(3, sourceURI); rs = ps.executeQuery(); fdow = createFileDataObjectWrapper(uid, rs); DBTools.close(con, ps, rs); } catch (Exception e) { throw new DAOException("Error seeking file data object and its properties.", e); } finally { DBTools.close(con, ps, rs); } return fdow; }
From source file:edu.arizona.rice.kew.docsearch.dao.impl.DocumentSearchDAOJdbcImpl.java
/** * //from w w w.ja va 2 s .c om * @param criteria * @param criteriaModified * @param searchFields * @return */ protected DocumentSearchResults.Builder doInternalSearch(DocumentSearchCriteria criteria, boolean criteriaModified, final List<RemotableAttributeField> searchFields) { Connection conn = null; Statement stmt = null; ResultSet res = null; DocumentSearchResults.Builder retval = DocumentSearchResults.Builder .create(DocumentSearchCriteria.Builder.create(criteria)); retval.setCriteriaModified(criteriaModified); retval.setSearchResults(new ArrayList<DocumentSearchResult.Builder>()); try { conn = dataSource.getConnection(); conn.setReadOnly(true); stmt = conn.createStatement(); int maxRows = getMaxResultCap(criteria) + 1; stmt.setMaxRows(maxRows); int fetchSize = stmt.getFetchSize(); // use default fetch size if document id is included // otherwize use custom fetch size if (StringUtils.isBlank(criteria.getDocumentId())) { fetchSize = customFetchSize; } String sql = getSearchSql(criteria, searchFields); res = stmt.executeQuery(sql); // run up to the starting row if required if (criteria.getStartAtIndex() != null) { for (int i = 0; (i < criteria.getStartAtIndex()) && res.next(); ++i) { } ; } List<DocumentInformation> results = new ArrayList<DocumentInformation>(); // load up document information from the query while (res.next() && (results.size() < maxRows)) { results.add(new DocumentInformation(res)); } // if we have threshold+1 results, then we have more results than we are going to display retval.setOverThreshold(res.next()); if (isUsingAtLeastOneSearchAttribute(criteria)) { // now that we have a list of documents, load the attributes loadDocumentAttributes(results, fetchSize); } // generate the DocumentSearchResults.Builder to return for (DocumentInformation docinfo : results) { retval.getSearchResults().add(docinfo.getSearchResult()); } if (LOG.isDebugEnabled()) { LOG.debug("document search result rows processed: " + retval.getSearchResults().size()); } } catch (Exception ex) { throw new RuntimeException(ex.toString(), ex); } finally { DocumentSearchUtils.closeDbObjects(conn, stmt, res); } return retval; }