/** * Enable connection status checking on SQL directory connections * * @since 5.7.2 */ public boolean isLive() { try { return !sqlConnection.isClosed(); } catch (SQLException e) { throw new DirectoryException("Cannot check connection status of " + this, e); } }
public String getCreateTablePolicy() { if (StringUtils.isBlank(createTablePolicy)) { return CREATE_TABLE_POLICY_DEFAULT; } String ctp = createTablePolicy.toLowerCase(); if (!CREATE_TABLE_POLICIES.contains(ctp)) { throw new DirectoryException("Invalid createTablePolicy: " + createTablePolicy + ", it should be one of: " + CREATE_TABLE_POLICIES); } return ctp; }
public DirectoryDeleteConstraint getDeleteConstraint() { try { DirectoryDeleteConstraint instance = klass.newInstance(); if (properties != null) { instance.setProperties(properties); } return instance; } catch (InstantiationException e) { throw new DirectoryException(e); } catch (IllegalAccessException e) { throw new DirectoryException(e); } }
@Override public void accept(Map<String, Object> map) { try { ps.setString(1, (String) map.get(sourceColumn)); ps.setString(2, (String) map.get(targetColumn)); ps.execute(); } catch (SQLException e) { throw new DirectoryException(e); } } };
@Override public Directory getSourceDirectory() { Directory sourceDir = super.getSourceDirectory(); if (sourceDir instanceof LDAPDirectory) { return sourceDir; } else { throw new DirectoryException(sourceDirectoryName + " is not a LDAPDirectory and thus cannot be used in a reference for " + fieldName); } }
@Override public Directory getTargetDirectory() { Directory targetDir = super.getTargetDirectory(); if (targetDir instanceof LDAPDirectory) { return targetDir; } else { throw new DirectoryException(targetDirectoryName + " is not a LDAPDirectory and thus cannot be referenced as target by " + fieldName); } }
@Override public Directory getSourceDirectory() { Directory sourceDir = super.getSourceDirectory(); if (sourceDir instanceof LDAPDirectory) { return sourceDir; } else { throw new DirectoryException(sourceDirectoryName + " is not a LDAPDirectory and thus cannot be used in a reference for " + fieldName); } }
@Override public void close() { try { if (!sqlConnection.isClosed()) { sqlConnection.close(); } } catch (SQLException e) { throw new DirectoryException("close failed", e); } finally { getDirectory().removeSession(this); } }
@Override public void addLinks(List<String> sourceIds, String targetId) { if (sourceIds == null || sourceIds.isEmpty()) { return; } try (MongoDBSession session = getMongoDBSession()) { addLinks(sourceIds, targetId, session); } catch (MongoWriteException e) { throw new DirectoryException(e); } }
private Object getFieldValue(ResultSet rs, Column column) { try { int index = rs.findColumn(column.getPhysicalName()); return column.getFromResultSet(rs, index); } catch (SQLException e) { throw new DirectoryException("getFieldValue failed", e); } }
public Connection getConnection() { SQLDirectoryDescriptor descriptor = getDescriptor(); if (StringUtils.isBlank(descriptor.dataSourceName)) { throw new DirectoryException("Missing dataSource for SQL directory: " + getName()); } try { return ConnectionHelper.getConnection(descriptor.dataSourceName); } catch (SQLException e) { throw new DirectoryException("Cannot connect to SQL directory '" + getName() + "': " + e.getMessage(), e); } }
protected void setIdFieldInMap(ResultSet rs, Column column, String idFieldName, Map<String, Object> fieldMap) throws SQLException { if (!rs.next()) { throw new DirectoryException("Cannot get generated key"); } if (logger.isLogEnabled()) { logger.logResultSet(rs, Collections.singletonList(column)); } Serializable rawId = column.getFromResultSet(rs, 1); fieldMap.put(idFieldName, rawId); }
private void acquireConnection() { try { if (sqlConnection == null || sqlConnection.isClosed()) { sqlConnection = getDirectory().getConnection(); } } catch (SQLException e) { throw new DirectoryException( "Cannot connect to SQL directory '" + directory.getName() + "': " + e.getMessage(), e); } }
private void setFieldValue(PreparedStatement ps, int index, Column column, Object value) { try { column.setToPreparedStatement(ps, index, fieldValueForWrite(value, column)); } catch (SQLException e) { throw new DirectoryException("setFieldValue failed", e); } }
private void removeLinksFor(String field, String value, MongoDBSession session) { try { DeleteResult result = getCollection(session) .deleteMany(MongoDBSerializationHelper.fieldMapToBson(field, value)); if (!result.wasAcknowledged()) { throw new DirectoryException( "Error while deleting the entry, the request has not been acknowledged by the server"); } } catch (MongoWriteException e) { throw new DirectoryException(e); } }
private void addMissingColumns() { try (Statement stmt = connection.createStatement()) { for (Column column : getMissingColumns(false)) { String alter = table.getAddColumnSql(column); if (logger.isLogEnabled()) { logger.log(alter); } stmt.execute(alter); } } catch (SQLException e) { throw new DirectoryException(String.format("Table '%s' alteration failed: %s", table, e.getMessage()), e); } }
public void removeLinksFor(String column, String entryId, SQLSession session) { String sql = String.format("DELETE FROM %s WHERE %s = ?", table.getQuotedName(), table.getColumn(column) .getQuotedName()); if (session.logger.isLogEnabled()) { session.logger.logSQL(sql, Collections.<Serializable> singleton(entryId)); } try (PreparedStatement ps = session.sqlConnection.prepareStatement(sql)) { ps.setString(1, entryId); ps.execute(); } catch (SQLException e) { throw new DirectoryException("error remove links to " + entryId, e); } }
public LDAPDirectory(LDAPDirectoryDescriptor descriptor) { super(descriptor, LDAPReference.class); if (StringUtils.isEmpty(descriptor.getSearchBaseDn())) { throw new DirectoryException("searchBaseDn configuration is missing for directory " + getName()); } factory = Framework.getService(LDAPDirectoryFactory.class); }
@Override public void initializeReferences() { try (Connection connection = getConnection()) { for (Reference reference : getReferences()) { if (reference instanceof TableReference) { ((TableReference) reference).initialize(connection); } } } catch (SQLException e) { throw new DirectoryException(e); } }
protected void handleException(Exception e, String message) { LdapExceptionProcessor processor = getDirectory().getDescriptor().getExceptionProcessor(); RecoverableClientException userException = processor.extractRecoverableException(e); if (userException != null) { throw userException; } throw new DirectoryException(message + " " + e.getMessage(), e); }