@Override public SQLDirectory newDirectory() { return new SQLDirectory(this); }
@Override public SQLSession getSession() { SQLSession session = new SQLSession(this, getDescriptor()); addSession(session); return session; }
public SQLDirectory(SQLDirectoryDescriptor descriptor) { super(descriptor, TableReference.class); nativeCase = Boolean.TRUE.equals(descriptor.nativeCase); // Cache fallback fallbackOnDefaultCache(); }
@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); } }
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); } }
@Override public void initialize() { super.initialize(); SQLDirectoryDescriptor descriptor = getDescriptor(); try (Connection sqlConnection = getConnection()) { dialect = Dialect.createDialect(sqlConnection, null); table = SQLHelper.addTable(tableName, dialect, useNativeCase()); SchemaManager schemaManager = Framework.getService(SchemaManager.class); schema = schemaManager.getSchema(getSchema()); if (schema == null) { throw new DirectoryException("schema not found: " + getSchema()); if (!isReference(fieldName)) { boolean isId = fieldName.equals(getIdField()); ColumnType type = ColumnType.fromField(f); if (isId && descriptor.isAutoincrementIdField()) { type = ColumnType.AUTOINC; Column column = SQLHelper.addColumn(table, fieldName, type, useNativeCase()); if (isId) { if (descriptor.isAutoincrementIdField()) { if (!hasPrimary) { throw new DirectoryException(String.format("Directory '%s' id field '%s' is not present in schema '%s'", getName(), getIdField(), getSchema())); loadData();
protected void initialize(Connection connection) { SQLDirectory directory = (SQLDirectory) getSourceDirectory(); Dialect dialect = directory.getDialect(); boolean nativeCase = directory.useNativeCase(); table = SQLHelper.addTable(tableName, dialect, nativeCase); SQLHelper.addColumn(table, sourceColumn, ColumnType.STRING, nativeCase); SQLHelper helper = new SQLHelper(connection, table, directory.getDescriptor().getCreateTablePolicy()); boolean loadData = helper.setupTable(); if (loadData && dataFileName != null) {
public SQLSession(SQLDirectory directory, SQLDirectoryDescriptor config) { super(directory, TableReference.class); table = directory.getTable(); dialect = directory.getDialect(); sid = String.valueOf(SIDGenerator.next()); staticFilters = config.getStaticFilters(); acquireConnection(); }
for (String columnName : filterMap.keySet()) { if (getDirectory().isReference(columnName)) { log.warn(columnName + " is a reference and will be ignored" + " as a query criterion"); continue; int queryLimitSize = getDirectory().getDescriptor().getQuerySizeLimit(); boolean trucatedResults = false; if (queryLimitSize != 0 && (limit <= 0 || limit > queryLimitSize)) {
protected void addLikeEscaping() { String escape = directory.getDialect().getLikeEscaping(); if (escape != null) { clause.append(escape); } }
@Override protected void addReferences() { super.addReferences(); // add backward compat tableReferences TableReferenceDescriptor[] descs = getDescriptor().getTableReferences(); if (descs != null) { Arrays.stream(descs).map(TableReference::new).forEach(this::addReference); } }
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); } }
protected void visitExpressionILike(Column column, Operator op, Operand rvalue) { if (directory.getDialect().supportsIlike()) { visitExpression(column, op, rvalue); } else { clause.append("LOWER("); visitColumn(column); clause.append(") "); if (op == Operator.NOTILIKE) { clause.append("NOT "); } clause.append("LIKE"); clause.append(" LOWER("); rvalue.accept(this); clause.append(")"); addLikeEscaping(); } }
protected void visitExpression(Column column, Operator op, Operand rvalue) { visitColumn(column); if (op == Operator.EQ || op == Operator.NOTEQ) { if (column.getType().spec == ColumnSpec.BOOLEAN) { rvalue = getBooleanLiteral(rvalue); } if (directory.getDialect().hasNullEmptyString() && rvalue instanceof StringLiteral && ((StringLiteral) rvalue).value.isEmpty()) { // see NXP-6172, empty values are Null in Oracle op = op == Operator.EQ ? Operator.ISNULL : Operator.ISNOTNULL; rvalue = null; } } op.accept(this); if (rvalue != null) { rvalue.accept(this); } }