public void init(final Configuration config) throws PwmException { final Map<FileValue.FileInformation, FileValue.FileContent> fileValue = config.readSettingAsFile(PwmSetting.DATABASE_JDBC_DRIVER); final byte[] jdbcDriverBytes; if (fileValue != null && !fileValue.isEmpty()) { final FileValue.FileInformation fileInformation1 = fileValue.keySet().iterator().next(); final FileValue.FileContent fileContent = fileValue.get(fileInformation1); jdbcDriverBytes = fileContent.getContents(); } else { jdbcDriverBytes = null; } this.dbConfiguration = new DBConfiguration( config.readSettingAsString(PwmSetting.DATABASE_CLASS), config.readSettingAsString(PwmSetting.DATABASE_URL), config.readSettingAsString(PwmSetting.DATABASE_USERNAME), config.readSettingAsPassword(PwmSetting.DATABASE_PASSWORD), config.readSettingAsString(PwmSetting.DATABASE_COLUMN_TYPE_KEY), config.readSettingAsString(PwmSetting.DATABASE_COLUMN_TYPE_VALUE), jdbcDriverBytes); this.instanceID = pwmApplication == null ? null : pwmApplication.getInstanceID(); this.traceLogging = config.readSettingAsBoolean(PwmSetting.DATABASE_DEBUG_TRACE); if (this.dbConfiguration.isEmpty()) { status = PwmService.STATUS.CLOSED; LOGGER.debug("skipping database connection open, no connection parameters configured"); } }
public boolean getBoolean() throws SQLException { int type = JSONTypes.jsonTypes.get(field.getType()); switch (type) { case JSONTypes.JSON_BOOLEAN: return (boolean) jsonObject; case JSONTypes.JSON_NUMBER: Number number = (Number) jsonObject; return !number.equals((Number) 0); case JSONTypes.JSON_STRING: String string = (String) jsonObject; return !string.isEmpty(); case JSONTypes.JSON_MAP: case JSONTypes.JSON_OBJECT: Map map = (Map) jsonObject; return !map.isEmpty(); case JSONTypes.JSON_ARRAY: List list = (List) jsonObject; return !list.isEmpty(); default: return false; } }
protected ReportParameterValue[] getParamValuesFromDataSource( ReportParameter param, Map<String, Object> parameters) throws ProviderException { Connection conn = null; PreparedStatement pStmt = null; ResultSet rs = null; try { ReportDataSource dataSource = param.getDataSource(); conn = dataSourceProvider.getConnection(dataSource.getId()); if (parameters == null || parameters.isEmpty()) { pStmt = conn.prepareStatement(param.getData()); } else { } rs = pStmt.executeQuery(); ResultSetMetaData rsMetaData = rs.getMetaData(); boolean multipleColumns = false; if (rsMetaData.getColumnCount() > 1) multipleColumns = true; ArrayList<ReportParameterValue> v = new ArrayList<ReportParameterValue>(); while (rs.next()) { ReportParameterValue value = new ReportParameterValue(); if (param.getClassName().equals("java.lang.String")) { value.setId(rs.getString(1)); } else if (param.getClassName().equals("java.lang.Double")) { value.setId(new Double(rs.getDouble(1))); } else if (param.getClassName().equals("java.lang.Integer")) { value.setId(new Integer(rs.getInt(1))); } else if (param.getClassName().equals("java.lang.Long")) { value.setId(new Long(rs.getLong(1))); } else if (param.getClassName().equals("java.math.BigDecimal")) { value.setId(rs.getBigDecimal(1)); } else if (param.getClassName().equals("java.util.Date")) { value.setId(rs.getDate(1)); } else if (param.getClassName().equals("java.sql.Date")) { value.setId(rs.getDate(1)); } else if (param.getClassName().equals("java.sql.Timestamp")) { value.setId(rs.getTimestamp(1)); } if (multipleColumns) { value.setDescription(rs.getString(2)); } v.add(value); } rs.close(); ReportParameterValue[] values = new ReportParameterValue[v.size()]; v.toArray(values); return values; } catch (Exception e) { throw new ProviderException("Error retreiving param values from database: " + e.getMessage()); } finally { try { if (pStmt != null) pStmt.close(); if (conn != null) conn.close(); } catch (Exception c) { log.error("Error closing"); } } }