List of usage examples for java.sql ResultSet getByte
byte getByte(String columnLabel) throws SQLException;
ResultSet
object as a byte
in the Java programming language. From source file:com.zimbra.cs.db.DbMailItem.java
static UnderlyingData constructItem(ResultSet rs, int offset, boolean fromDumpster) throws SQLException, ServiceException { UnderlyingData data = new UnderlyingData(); data.id = rs.getInt(CI_ID + offset); data.type = rs.getByte(CI_TYPE + offset); data.parentId = rs.getInt(CI_PARENT_ID + offset); data.folderId = rs.getInt(CI_FOLDER_ID + offset); data.setPrevFolders(rs.getString(CI_PREV_FOLDERS + offset)); data.indexId = rs.getInt(CI_INDEX_ID + offset); if (rs.wasNull()) { data.indexId = MailItem.IndexStatus.NO.id(); }/*from ww w . ja va2s .c o m*/ data.imapId = rs.getInt(CI_IMAP_ID + offset); if (rs.wasNull()) { data.imapId = -1; } data.date = rs.getInt(CI_DATE + offset); data.size = rs.getLong(CI_SIZE + offset); data.locator = rs.getString(CI_LOCATOR + offset); data.setBlobDigest(rs.getString(CI_BLOB_DIGEST + offset)); data.unreadCount = rs.getInt(CI_UNREAD + offset); int flags = rs.getInt(CI_FLAGS + offset); if (!fromDumpster) { data.setFlags(flags); } else { data.setFlags(flags | Flag.BITMASK_UNCACHED | Flag.BITMASK_IN_DUMPSTER); } data.setTags(new Tag.NormalizedTags(DbTag.deserializeTags(rs.getString(CI_TAGS + offset)))); data.setSubject(rs.getString(CI_SUBJECT + offset)); data.name = rs.getString(CI_NAME + offset); data.metadata = decodeMetadata(rs.getString(CI_METADATA + offset)); data.modMetadata = rs.getInt(CI_MODIFIED + offset); data.modContent = rs.getInt(CI_SAVED + offset); data.dateChanged = rs.getInt(CI_MODIFY_DATE + offset); // make sure to handle NULL column values if (data.parentId == 0) { data.parentId = -1; } if (data.dateChanged == 0) { data.dateChanged = -1; } data.uuid = rs.getString(CI_UUID + offset); return data; }
From source file:com.zimbra.cs.db.DbMailItem.java
/** * @param start start time of range, in milliseconds. {@code -1} means to leave the start time unconstrained. * @param end end time of range, in milliseconds. {@code -1} means to leave the end time unconstrained. *///from w w w. j a v a 2 s . c om public static TypedIdList listCalendarItems(Mailbox mbox, MailItem.Type type, long start, long end, int folderId, int[] excludeFolderIds) throws ServiceException { DbConnection conn = mbox.getOperationConnection(); PreparedStatement stmt = null; ResultSet rs = null; try { stmt = calendarItemStatement(conn, "mi.id, mi.type, mi.uuid", mbox, type, start, end, folderId, excludeFolderIds); rs = stmt.executeQuery(); TypedIdList result = new TypedIdList(); while (rs.next()) { result.add(MailItem.Type.of(rs.getByte(2)), rs.getInt(1), rs.getString(3)); } return result; } catch (SQLException e) { throw ServiceException.FAILURE("listing calendar items for mailbox " + mbox.getId(), e); } finally { DbPool.closeResults(rs); DbPool.closeStatement(stmt); } }
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 w ww . j a v a 2 s . c o m*/ visitMethodCast(mv, index, beanName, PROPERTY_TYPE_OTHER, propType.getName().replace('.', '/'), writer); return rs.getObject(index); } }
From source file:com.zimbra.cs.db.DbMailItem.java
/** * @param visible/*from w w w . ja va 2 s. c om*/ * @param modified * @param missed * @param stmt * @return * @throws SQLException * @throws ServiceException */ private static Pair<List<Integer>, TypedIdList> populateWithResultSetData(Set<Integer> visible, PreparedStatement stmt, int lastDeleteSync) throws SQLException, ServiceException { List<Integer> modified = new ArrayList<Integer>(); TypedIdList missed = new TypedIdList(); ResultSet rs = null; try { rs = stmt.executeQuery(); while (rs.next()) { if (visible == null || visible.contains(rs.getInt(3))) { modified.add(rs.getInt(1)); } else { int modSeq = rs.getInt(5); if (modSeq > lastDeleteSync) { missed.add(MailItem.Type.of(rs.getByte(2)), rs.getInt(1), rs.getString(4), modSeq, rs.getString(6)); } } } } finally { DbPool.closeResults(rs); } return new Pair<List<Integer>, TypedIdList>(modified, missed); }
From source file:com.zimbra.cs.db.DbMailItem.java
public static SetMultimap<MailItem.Type, Integer> getIndexDeferredIds(DbConnection conn, Mailbox mbox) throws ServiceException { SetMultimap<MailItem.Type, Integer> result = Multimaps.newSetMultimap( new EnumMap<MailItem.Type, Collection<Integer>>(MailItem.Type.class), new Supplier<Set<Integer>>() { @Override//from w ww .j av a 2s. co m public Set<Integer> get() { return new HashSet<Integer>(); } }); PreparedStatement stmt = null; ResultSet rs = null; try { // from MAIL_ITEM table stmt = conn.prepareStatement("SELECT type, id FROM " + getMailItemTableName(mbox, false) + " WHERE " + IN_THIS_MAILBOX_AND + "index_id <= 1"); // 0: deferred, 1: stale setMailboxId(stmt, mbox, 1); rs = stmt.executeQuery(); while (rs.next()) { result.put(MailItem.Type.of(rs.getByte(1)), rs.getInt(2)); } } catch (SQLException e) { throw ServiceException.FAILURE("Failed to query index deferred IDs", e); } finally { conn.closeQuietly(rs); conn.closeQuietly(stmt); } if (mbox.dumpsterEnabled()) { try { // also from MAIL_ITEM_DUMPSTER table stmt = conn.prepareStatement("SELECT type, id FROM " + getMailItemTableName(mbox, true) + " WHERE " + IN_THIS_MAILBOX_AND + "index_id <= 1"); setMailboxId(stmt, mbox, 1); rs = stmt.executeQuery(); while (rs.next()) { result.put(MailItem.Type.of(rs.getByte(1)), rs.getInt(2)); } } catch (SQLException e) { throw ServiceException.FAILURE("Failed to query index deferred IDs from dumpster", e); } finally { conn.closeQuietly(rs); conn.closeQuietly(stmt); } } return result; }
From source file:com.zimbra.cs.db.DbMailItem.java
public static TypedIdList listByFolder(Folder folder, boolean descending) throws ServiceException { Mailbox mbox = folder.getMailbox();/*from w ww. j ava 2 s . c o m*/ TypedIdList result = new TypedIdList(); DbConnection conn = mbox.getOperationConnection(); PreparedStatement stmt = null; ResultSet rs = null; try { stmt = conn.prepareStatement("SELECT id, type, uuid FROM " + getMailItemTableName(folder) + " WHERE " + IN_THIS_MAILBOX_AND + "folder_id = ?" + " ORDER BY date" + (descending ? " DESC" : "")); int pos = 1; pos = setMailboxId(stmt, mbox, pos); stmt.setInt(pos++, folder.getId()); rs = stmt.executeQuery(); while (rs.next()) { result.add(MailItem.Type.of(rs.getByte(2)), rs.getInt(1), rs.getString(3)); } return result; } catch (SQLException e) { throw ServiceException.FAILURE("fetching item list for folder " + folder.getId(), e); } finally { DbPool.closeResults(rs); DbPool.closeStatement(stmt); } }
From source file:com.funambol.foundation.items.dao.PIMContactDAO.java
/** * Read data from twin query and put it inside a Map. * First map has the contact id as Key and a map of contact items as their values. * Second map has the item type as Key and the item value as Value. * * @param rs the ResultSet to check/*from w w w .ja v a2s. c om*/ * @return the map of potential twins */ private Map<Long, Map<Integer, String>> getTwinsItemsFromRecordset(ResultSet rs) throws Exception { long oldTwinId = -1; long twinId; int itemType; String itemValue; Map<Integer, String> twinValues = null; Map<Long, Map<Integer, String>> values = new HashMap<Long, Map<Integer, String>>(); while (rs.next()) { twinId = rs.getLong(1); // The id is the first if (twinId != oldTwinId) { //new contact id oldTwinId = twinId; twinValues = new HashMap<Integer, String>(); //add new contact record values.put(twinId, twinValues); } //add new item type and value to the map of contact items itemType = rs.getByte(2); itemValue = rs.getString(3); twinValues.put(itemType, itemValue); } return values; }
From source file:com.github.woonsan.jdbc.jcr.impl.JcrJdbcResultSetTest.java
@SuppressWarnings("deprecation") @Test//from www .j av a 2s . c o m 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.zimbra.cs.db.DbMailItem.java
static void accumulateComments(PendingDelete info, Mailbox mbox) throws ServiceException { List<Integer> documents = info.itemIds.getIds(MailItem.Type.DOCUMENT); if (documents == null || documents.size() == 0) { return;/*from ww w.j a v a2 s . co m*/ } DbConnection conn = mbox.getOperationConnection(); PreparedStatement stmt = null; ResultSet rs = null; try { stmt = conn.prepareStatement("SELECT type, id, uuid " + " FROM " + getMailItemTableName(mbox) + " WHERE " + DbUtil.whereIn("parent_id", documents.size()) + (DebugConfig.disableMailboxGroups ? "" : " AND mailbox_id = ?")); int pos = 1; for (int id : documents) { stmt.setInt(pos++, id); } pos = setMailboxId(stmt, mbox, pos); rs = stmt.executeQuery(); while (rs.next()) { info.itemIds.add(MailItem.Type.of(rs.getByte(1)), rs.getInt(2), rs.getString(3)); } } catch (SQLException e) { throw ServiceException.FAILURE("getting Comment deletion info for items: " + documents, e); } finally { DbPool.closeResults(rs); DbPool.closeStatement(stmt); } }
From source file:com.zimbra.cs.db.DbMailItem.java
public static List<ImapMessage> loadImapFolder(Folder folder) throws ServiceException { Mailbox mbox = folder.getMailbox();/* w w w .j a va 2s . c o m*/ List<ImapMessage> result = new ArrayList<ImapMessage>(); DbConnection conn = mbox.getOperationConnection(); PreparedStatement stmt = null; ResultSet rs = null; try { stmt = conn.prepareStatement( "SELECT " + IMAP_FIELDS + " FROM " + getMailItemTableName(folder.getMailbox(), " mi") + " WHERE " + IN_THIS_MAILBOX_AND + "folder_id = ? AND type IN " + IMAP_TYPES); if (folder.getSize() > RESULTS_STREAMING_MIN_ROWS) { Db.getInstance().enableStreaming(stmt); } int pos = 1; pos = setMailboxId(stmt, mbox, pos); stmt.setInt(pos++, folder.getId()); rs = stmt.executeQuery(); while (rs.next()) { int flags = rs.getBoolean(4) ? Flag.BITMASK_UNREAD | rs.getInt(5) : rs.getInt(5); result.add(new ImapMessage(rs.getInt(1), MailItem.Type.of(rs.getByte(2)), rs.getInt(3), flags, DbTag.deserializeTags(rs.getString(6)))); } return result; } catch (SQLException e) { throw ServiceException.FAILURE("loading IMAP folder data: " + folder.getPath(), e); } finally { DbPool.closeResults(rs); DbPool.closeStatement(stmt); } }