@Test public void testGetNoMetaDataColumns() throws SQLException { String channelId = "abc"; DatabaseMetaData metaData = mock(DatabaseMetaData.class); ResultSet metaDataResultSet = mock(ResultSet.class); when(metaData.getColumns(any(), any(), any(), any())).thenReturn(metaDataResultSet); when(metaDataResultSet.next()).thenReturn(true, false); when(metaDataResultSet.getInt(any())).thenReturn(Types.INTEGER); when(connection.getMetaData()).thenReturn(metaData); setLocalChannelId(channelId, 1L); when(metaDataResultSet.getString("COLUMN_NAME")).thenReturn("metadata_id"); assertEquals(0, dao.getMetaDataColumns(channelId).size()); }
@Override public List<MetaDataColumn> getMetaDataColumns(String channelId) { ResultSet columns = null; try { List<MetaDataColumn> metaDataColumns = new ArrayList<MetaDataColumn>(); long localChannelId = getLocalChannelId(channelId); columns = connection.getMetaData().getColumns(connection.getCatalog(), null, "d_mcm" + localChannelId, null); if (!columns.next()) { columns.close(); columns = connection.getMetaData().getColumns(connection.getCatalog(), null, "D_MCM" + localChannelId, null); if (!columns.next()) { return metaDataColumns; } } do { String name = columns.getString("COLUMN_NAME"); if (!name.equalsIgnoreCase("METADATA_ID") && !name.equalsIgnoreCase("MESSAGE_ID")) { MetaDataColumnType columnType = MetaDataColumnType.fromSqlType(columns.getInt("DATA_TYPE")); if (columnType == null) { logger.error("Invalid custom metadata column: " + name + " (type: " + sqlTypeToString(columns.getInt("DATA_TYPE")) + ")."); } else { metaDataColumns.add(new MetaDataColumn(name, columnType, null)); } } } while (columns.next()); return metaDataColumns; } catch (Exception e) { throw new DonkeyDaoException("Failed to retrieve meta data columns", e); } finally { close(columns); } }
JdbcDao implements DonkeyDao { @Override public List<MetaDataColumn> getMetaDataColumns(String channelId) { ResultSet columns = null; try { List<MetaDataColumn> metaDataColumns = new ArrayList<MetaDataColumn>(); long localChannelId = getLocalChannelId(channelId); columns = connection.getMetaData().getColumns(connection.getCatalog(), null, "d_mcm" + localChannelId, null); if (!columns.next()) { columns.close(); columns = connection.getMetaData().getColumns(connection.getCatalog(), null, "D_MCM" + localChannelId, null); if (!columns.next()) { return metaDataColumns; } } do { String name = columns.getString("COLUMN_NAME"); if (!name.equalsIgnoreCase("METADATA_ID") && !name.equalsIgnoreCase("MESSAGE_ID")) { MetaDataColumnType columnType = MetaDataColumnType.fromSqlType(columns.getInt("DATA_TYPE")); if (columnType == null) { logger.error("Invalid custom metadata column: " + name + " (type: " + sqlTypeToString(columns.getInt("DATA_TYPE")) + ")."); } else { metaDataColumns.add(new MetaDataColumn(name, columnType, null)); } } } while (columns.next()); return metaDataColumns; } catch (Exception e) { throw new DonkeyDaoException("Failed to retrieve meta data columns", e); } finally { close(columns); } } }
JdbcDao implements DonkeyDao { @Override public List<MetaDataColumn> getMetaDataColumns(String channelId) { ResultSet columns = null; try { List<MetaDataColumn> metaDataColumns = new ArrayList<MetaDataColumn>(); long localChannelId = getLocalChannelId(channelId); columns = connection.getMetaData().getColumns(connection.getCatalog(), null, "d_mcm" + localChannelId, null); if (!columns.next()) { columns.close(); columns = connection.getMetaData().getColumns(connection.getCatalog(), null, "D_MCM" + localChannelId, null); if (!columns.next()) { return metaDataColumns; } } do { String name = columns.getString("COLUMN_NAME"); if (!name.equalsIgnoreCase("METADATA_ID") && !name.equalsIgnoreCase("MESSAGE_ID")) { MetaDataColumnType columnType = MetaDataColumnType.fromSqlType(columns.getInt("DATA_TYPE")); if (columnType == null) { logger.error("Invalid custom metadata column: " + name + " (type: " + sqlTypeToString(columns.getInt("DATA_TYPE")) + ")."); } else { metaDataColumns.add(new MetaDataColumn(name, columnType, null)); } } } while (columns.next()); return metaDataColumns; } catch (Exception e) { throw new DonkeyDaoException("Failed to retrieve meta data columns", e); } finally { close(columns); } } protected  JdbcDao(Donkey donkey, Connection connection, QuerySource querySource, PreparedStatementSource statementSource, SerializerProvider serializerProvider, boolean encryptData, boolean decryptData, StatisticsUpdater statisticsUpdater, Statistics currentStats, Statistics totalStats, String statsServerId); }
JdbcDao implements DonkeyDao { @Override public List<MetaDataColumn> getMetaDataColumns(String channelId) { ResultSet columns = null; try { List<MetaDataColumn> metaDataColumns = new ArrayList<MetaDataColumn>(); long localChannelId = getLocalChannelId(channelId); columns = connection.getMetaData().getColumns(connection.getCatalog(), null, "d_mcm" + localChannelId, null); if (!columns.next()) { columns.close(); columns = connection.getMetaData().getColumns(connection.getCatalog(), null, "D_MCM" + localChannelId, null); if (!columns.next()) { return metaDataColumns; } } do { String name = columns.getString("COLUMN_NAME"); if (!name.equalsIgnoreCase("METADATA_ID") && !name.equalsIgnoreCase("MESSAGE_ID")) { MetaDataColumnType columnType = MetaDataColumnType.fromSqlType(columns.getInt("DATA_TYPE")); if (columnType == null) { logger.error("Invalid custom metadata column: " + name + " (type: " + sqlTypeToString(columns.getInt("DATA_TYPE")) + ")."); } else { metaDataColumns.add(new MetaDataColumn(name, columnType, null)); } } } while (columns.next()); return metaDataColumns; } catch (Exception e) { throw new DonkeyDaoException("Failed to retrieve meta data columns", e); } finally { close(columns); } } protected  JdbcDao(Donkey donkey, Connection connection, QuerySource querySource, PreparedStatementSource statementSource, SerializerProvider serializerProvider, boolean encryptData, boolean decryptData, StatisticsUpdater statisticsUpdater, Statistics currentStats, Statistics totalStats, String statsServerId); @Override void setEncryptData(boolean encryptData); @Override void setDecryptData(boolean decryptData); @Override void setStatisticsUpdater(StatisticsUpdater statisticsUpdater); char getQuoteChar(); void setQuoteChar(char quoteChar); @Override void insertMessage(Message message); @Override void updateSendAttempts(ConnectorMessage connectorMessage); @Override void insertMessageContent(MessageContent messageContent); @Override void batchInsertMessageContent(MessageContent messageContent); @Override void executeBatchInsertMessageContent(String channelId); @Override void storeMessageContent(MessageContent messageContent); void storeContent(String channelId, long messageId, int metaDataId, ContentType contentType, String content, String dataType, boolean encrypted); @Override void addChannelStatistics(Statistics statistics); @Override void insertMessageAttachment(String channelId, long messageId, Attachment attachment); @Override void updateMessageAttachment(String channelId, long messageId, Attachment attachment); @Override void insertMetaData(ConnectorMessage connectorMessage, List<MetaDataColumn> metaDataColumns); @Override void storeMetaData(ConnectorMessage connectorMessage, List<MetaDataColumn> metaDataColumns); @Override void insertConnectorMessage(ConnectorMessage connectorMessage, boolean storeMaps, boolean updateStats); @Override void deleteMessage(String channelId, long messageId); @Override void deleteConnectorMessages(String channelId, long messageId, Set<Integer> metaDataIds); @Override void deleteMessageStatistics(String channelId, long messageId, Set<Integer> metaDataIds); @Override void updateStatus(ConnectorMessage connectorMessage, Status previousStatus); @Override void updateErrors(ConnectorMessage connectorMessage); @Override void updateMaps(ConnectorMessage connectorMessage); @Override void updateSourceMap(ConnectorMessage connectorMessage); @Override void updateResponseMap(ConnectorMessage connectorMessage); @Override void markAsProcessed(String channelId, long messageId); @Override void resetMessage(String channelId, long messageId); @Override Map<String, Long> getLocalChannelIds(); @Override void removeChannel(String channelId); @Override Long selectMaxLocalChannelId(); @Override void deleteAllMessages(String channelId); @Override void deleteMessageContent(String channelId, long messageId); @Override void deleteMessageContentByMetaDataIds(String channelId, long messageId, Set<Integer> metaDataIds); @Override void deleteMessageAttachments(String channelId, long messageId); @Override List<MetaDataColumn> getMetaDataColumns(String channelId); @Override void removeMetaDataColumn(String channelId, String columnName); @Override long getMaxMessageId(String channelId); @Override long getMinMessageId(String channelId); @Override long getNextMessageId(String channelId); @Override List<Attachment> getMessageAttachment(String channelId, long messageId); @Override Attachment getMessageAttachment(String channelId, String attachmentId, Long messageId); @Override List<Message> getUnfinishedMessages(String channelId, String serverId, int limit, Long minMessageId); @Override List<Message> getPendingConnectorMessages(String channelId, String serverId, int limit, Long minMessageId); @Override List<Message> getMessages(String channelId, List<Long> messageIds); @Override List<ConnectorMessage> getConnectorMessages(String channelId, String serverId, int metaDataId, Status status, int offset, int limit, Long minMessageId, Long maxMessageId); @Override List<ConnectorMessage> getConnectorMessages(String channelId, long messageId, Set<Integer> metaDataIds, boolean includeContent); @Override Map<Integer, ConnectorMessage> getConnectorMessages(String channelId, long messageId, List<Integer> metaDataIds); @Override Map<Integer, Status> getConnectorMessageStatuses(String channelId, long messageId, boolean checkProcessed); @Override int getConnectorMessageCount(String channelId, String serverId, int metaDataId, Status status); @Override long getConnectorMessageMaxMessageId(String channelId, String serverId, int metaDataId, Status status); @Override void addMetaDataColumn(String channelId, MetaDataColumn metaDataColumn); @Override void createChannel(String channelId, long localChannelId); @Override void checkAndCreateChannelTables(); @Override void resetStatistics(String channelId, Integer metaDataId, Set<Status> statuses); @Override void resetAllStatistics(String channelId); @Override Statistics getChannelStatistics(String serverId); @Override Statistics getChannelTotalStatistics(String serverId); @Override void commit(); @Override void commit(boolean durable); @Override void rollback(); @Override void close(); @Override boolean isClosed(); @Override boolean initTableStructure(); Connection getConnection(); String getAsyncCommitCommand(); void setAsyncCommitCommand(String asyncCommitCommand); }
JdbcDao implements DonkeyDao { @Override public List<MetaDataColumn> getMetaDataColumns(String channelId) { ResultSet columns = null; try { List<MetaDataColumn> metaDataColumns = new ArrayList<MetaDataColumn>(); long localChannelId = getLocalChannelId(channelId); columns = connection.getMetaData().getColumns(connection.getCatalog(), null, "d_mcm" + localChannelId, null); if (!columns.next()) { columns.close(); columns = connection.getMetaData().getColumns(connection.getCatalog(), null, "D_MCM" + localChannelId, null); if (!columns.next()) { return metaDataColumns; } } do { String name = columns.getString("COLUMN_NAME"); if (!name.equalsIgnoreCase("METADATA_ID") && !name.equalsIgnoreCase("MESSAGE_ID")) { MetaDataColumnType columnType = MetaDataColumnType.fromSqlType(columns.getInt("DATA_TYPE")); if (columnType == null) { logger.error("Invalid custom metadata column: " + name + " (type: " + sqlTypeToString(columns.getInt("DATA_TYPE")) + ")."); } else { metaDataColumns.add(new MetaDataColumn(name, columnType, null)); } } } while (columns.next()); return metaDataColumns; } catch (Exception e) { throw new DonkeyDaoException("Failed to retrieve meta data columns", e); } finally { close(columns); } } protected  JdbcDao(Donkey donkey, Connection connection, QuerySource querySource, PreparedStatementSource statementSource, SerializerProvider serializerProvider, boolean encryptData, boolean decryptData, StatisticsUpdater statisticsUpdater, Statistics currentStats, Statistics totalStats, String statsServerId); @Override void setEncryptData(boolean encryptData); @Override void setDecryptData(boolean decryptData); @Override void setStatisticsUpdater(StatisticsUpdater statisticsUpdater); char getQuoteChar(); void setQuoteChar(char quoteChar); @Override void insertMessage(Message message); @Override void updateSendAttempts(ConnectorMessage connectorMessage); @Override void insertMessageContent(MessageContent messageContent); @Override void batchInsertMessageContent(MessageContent messageContent); @Override void executeBatchInsertMessageContent(String channelId); @Override void storeMessageContent(MessageContent messageContent); void storeContent(String channelId, long messageId, int metaDataId, ContentType contentType, String content, String dataType, boolean encrypted); @Override void addChannelStatistics(Statistics statistics); @Override void insertMessageAttachment(String channelId, long messageId, Attachment attachment); @Override void updateMessageAttachment(String channelId, long messageId, Attachment attachment); @Override void insertMetaData(ConnectorMessage connectorMessage, List<MetaDataColumn> metaDataColumns); @Override void storeMetaData(ConnectorMessage connectorMessage, List<MetaDataColumn> metaDataColumns); @Override void insertConnectorMessage(ConnectorMessage connectorMessage, boolean storeMaps, boolean updateStats); @Override void deleteMessage(String channelId, long messageId); @Override void deleteConnectorMessages(String channelId, long messageId, Set<Integer> metaDataIds); @Override void deleteMessageStatistics(String channelId, long messageId, Set<Integer> metaDataIds); @Override void updateStatus(ConnectorMessage connectorMessage, Status previousStatus); @Override void updateErrors(ConnectorMessage connectorMessage); @Override void updateMaps(ConnectorMessage connectorMessage); @Override void updateSourceMap(ConnectorMessage connectorMessage); @Override void updateResponseMap(ConnectorMessage connectorMessage); @Override void markAsProcessed(String channelId, long messageId); @Override void resetMessage(String channelId, long messageId); @Override Map<String, Long> getLocalChannelIds(); @Override void removeChannel(String channelId); @Override Long selectMaxLocalChannelId(); @Override void deleteAllMessages(String channelId); @Override void deleteMessageContent(String channelId, long messageId); @Override void deleteMessageContentByMetaDataIds(String channelId, long messageId, Set<Integer> metaDataIds); @Override void deleteMessageAttachments(String channelId, long messageId); @Override List<MetaDataColumn> getMetaDataColumns(String channelId); @Override void removeMetaDataColumn(String channelId, String columnName); @Override long getMaxMessageId(String channelId); @Override long getMinMessageId(String channelId); @Override long getNextMessageId(String channelId); @Override List<Attachment> getMessageAttachment(String channelId, long messageId); @Override Attachment getMessageAttachment(String channelId, String attachmentId, Long messageId); @Override List<Message> getUnfinishedMessages(String channelId, String serverId, int limit, Long minMessageId); @Override List<Message> getPendingConnectorMessages(String channelId, String serverId, int limit, Long minMessageId); @Override List<Message> getMessages(String channelId, List<Long> messageIds); @Override List<ConnectorMessage> getConnectorMessages(String channelId, String serverId, int metaDataId, Status status, int offset, int limit, Long minMessageId, Long maxMessageId); @Override List<ConnectorMessage> getConnectorMessages(String channelId, long messageId, Set<Integer> metaDataIds, boolean includeContent); @Override Map<Integer, ConnectorMessage> getConnectorMessages(String channelId, long messageId, List<Integer> metaDataIds); @Override Map<Integer, Status> getConnectorMessageStatuses(String channelId, long messageId, boolean checkProcessed); @Override int getConnectorMessageCount(String channelId, String serverId, int metaDataId, Status status); @Override long getConnectorMessageMaxMessageId(String channelId, String serverId, int metaDataId, Status status); @Override void addMetaDataColumn(String channelId, MetaDataColumn metaDataColumn); @Override void createChannel(String channelId, long localChannelId); @Override void checkAndCreateChannelTables(); @Override void resetStatistics(String channelId, Integer metaDataId, Set<Status> statuses); @Override void resetAllStatistics(String channelId); @Override Statistics getChannelStatistics(String serverId); @Override Statistics getChannelTotalStatistics(String serverId); @Override void commit(); @Override void commit(boolean durable); @Override void rollback(); @Override void close(); @Override boolean isClosed(); @Override boolean initTableStructure(); Connection getConnection(); String getAsyncCommitCommand(); void setAsyncCommitCommand(String asyncCommitCommand);  }