Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ insert_final_newline = unset
trim_trailing_whitespace = unset
indent_style = unset
indent_size = unset

[.flattened-pom.xml]
insert_final_newline = false
39 changes: 39 additions & 0 deletions deparser/api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<!--
/*********************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.daanse</groupId>
<artifactId>org.eclipse.daanse.sql.deparser</artifactId>
<version>${revision}</version>
</parent>
<artifactId>org.eclipse.daanse.sql.deparser.api</artifactId>
<name>Daanse SQL Deparser API</name>
<description>API interfaces for SQL deparser factory and dialect-aware SQL
generation.</description>

<dependencies>
<dependency>
<groupId>org.eclipse.daanse</groupId>
<artifactId>org.eclipse.daanse.jdbc.db.dialect.api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>5.4-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SmartCity Jena - initial
* Stefan Bischof (bipolis.org) - initial
*/
package org.eclipse.daanse.sql.deparser.api;

import org.eclipse.daanse.jdbc.db.dialect.api.Dialect;

/**
* Dialect-aware SQL deparsers.
*/
public interface DialectDeparser {

/**
* Deparses a SQL statement using the given dialect.
*
* @param statement the JSqlParser statement to deparse
* @param dialect the database dialect to use for SQL generation
* @return the generated SQL string
*/
String deparse(net.sf.jsqlparser.statement.Statement statement, Dialect dialect);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SmartCity Jena - initial
* Stefan Bischof (bipolis.org) - initial
*/

/**
* API interfaces for SQL deparser factory and dialect-aware SQL generation.
* <p>
* This package provides the factory interface for creating dialect-aware SQL deparsers
* that generate proper SQL syntax according to the target database dialect.
*/
@org.osgi.annotation.bundle.Export
@org.osgi.annotation.versioning.Version("0.0.1")
package org.eclipse.daanse.sql.deparser.api;
49 changes: 49 additions & 0 deletions deparser/jsqlparser/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0"?>
<!--
/*********************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.daanse</groupId>
<artifactId>org.eclipse.daanse.sql.deparser</artifactId>
<version>${revision}</version>
</parent>
<artifactId>org.eclipse.daanse.sql.deparser.jsqlparser</artifactId>
<name>Daanse SQL Deparser JSqlParser Implementation</name>
<description>JSqlParser-based implementation of SQL deparser with
comprehensive dialect support.</description>

<dependencies>
<dependency>
<groupId>org.eclipse.daanse</groupId>
<artifactId>org.eclipse.daanse.sql.deparser.api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.daanse</groupId>
<artifactId>org.eclipse.daanse.jdbc.db.dialect.api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.daanse</groupId>
<artifactId>org.eclipse.daanse.jdbc.db.dialect.db.common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>5.4-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SmartCity Jena - initial
* Stefan Bischof (bipolis.org) - initial
*/
package org.eclipse.daanse.sql.deparser.jsqlparser;

import org.eclipse.daanse.jdbc.db.dialect.api.Dialect;
import org.eclipse.daanse.sql.deparser.api.DialectDeparser;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ServiceScope;

import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.util.deparser.StatementDeParser;

/**
* Factory implementation for creating dialect-aware SQL deparsers.
*/
@Component(service = DialectDeparser.class,scope = ServiceScope.SINGLETON)
public class BasicDialectDeparser implements DialectDeparser {

@Override
public String deparse(Statement statement, Dialect dialect) {
StringBuilder buffer = new StringBuilder();
StatementDeParser deparser = new BasicDialectStatementDeParser(buffer, dialect);
statement.accept(deparser);
return buffer.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SmartCity Jena - initial
* Stefan Bischof (bipolis.org) - initial
*/
package org.eclipse.daanse.sql.deparser.jsqlparser;

import org.eclipse.daanse.jdbc.db.dialect.api.Dialect;

import net.sf.jsqlparser.expression.DateValue;
import net.sf.jsqlparser.expression.DoubleValue;
import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.expression.TimeValue;
import net.sf.jsqlparser.expression.TimestampValue;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.select.SelectVisitor;
import net.sf.jsqlparser.util.deparser.ExpressionDeParser;

public class BasicDialectExpressionDeParser extends ExpressionDeParser {

private final Dialect dialect;

public BasicDialectExpressionDeParser(Dialect dialect) {
super();
this.builder = new StringBuilder();
this.dialect = dialect;
}

public BasicDialectExpressionDeParser(SelectVisitor<StringBuilder> selectVisitor, StringBuilder buffer,
Dialect dialect) {
super(selectVisitor, buffer);
this.dialect = dialect;
}

// Identifier Quoting

@Override
public <S> StringBuilder visit(Column tableColumn, S context) {
final Table table = tableColumn.getTable();
String tableName = null;

if (table != null) {
if (table.getAlias() != null) {
tableName = table.getAlias().getName();
} else {
tableName = table.getFullyQualifiedName();
}
}

if (tableName != null && !tableName.isEmpty()) {
dialect.quoteIdentifier(builder, tableName, tableColumn.getColumnName());
} else {
dialect.quoteIdentifier(builder, tableColumn.getColumnName());
}

if (tableColumn.getArrayConstructor() != null) {
tableColumn.getArrayConstructor().accept(this, context);
}

if (tableColumn.getCommentText() != null) {
builder.append(" /* ").append(tableColumn.getCommentText()).append(" */");
}

return builder;
}

// String Literal Quoting

@Override
public <S> StringBuilder visit(StringValue stringValue, S context) {
if (stringValue.getPrefix() != null) {
builder.append(stringValue.getPrefix());
}
dialect.quoteStringLiteral(builder, stringValue.getValue());
return builder;
}

// Date/Time/Timestamp Literal Quoting

@Override
public <S> StringBuilder visit(DateValue dateValue, S context) {
dialect.quoteDateLiteral(builder, dateValue.getValue().toString());
return builder;
}

@Override
public <S> StringBuilder visit(TimeValue timeValue, S context) {
dialect.quoteTimeLiteral(builder, timeValue.getValue().toString());
return builder;
}

@Override
public <S> StringBuilder visit(TimestampValue timestampValue, S context) {
dialect.quoteTimestampLiteral(builder, timestampValue.getValue().toString());
return builder;
}

// Numeric Literal Formatting

@Override
public <S> StringBuilder visit(LongValue longValue, S context) {
dialect.quoteNumericLiteral(builder, longValue.getStringValue());
return builder;
}

@Override
public <S> StringBuilder visit(DoubleValue doubleValue, S context) {
String valueString = doubleValue.toString();
if (dialect.needsExponent(doubleValue.getValue(), valueString)) {
valueString += "E0";
}
dialect.quoteNumericLiteral(builder, valueString);
return builder;
}
}
Loading
Loading