org.springframework.data.relational.core.dialect.PostgresDialect Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-data-relational Show documentation
Show all versions of spring-data-relational Show documentation
Spring Data Relational support
/*
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.relational.core.dialect;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.IdentifierProcessing.LetterCasing;
import org.springframework.data.relational.core.sql.IdentifierProcessing.Quoting;
import org.springframework.data.relational.core.sql.LockOptions;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.core.sql.TableLike;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* An SQL dialect for Postgres.
*
* @author Mark Paluch
* @author Myeonghyeon Lee
* @author Jens Schauder
* @author Nikita Konev
* @since 1.1
*/
public class PostgresDialect extends AbstractDialect {
/**
* Singleton instance.
*/
public static final PostgresDialect INSTANCE = new PostgresDialect();
protected PostgresDialect() {}
private static final LimitClause LIMIT_CLAUSE = new LimitClause() {
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.dialect.LimitClause#getLimit(long)
*/
@Override
public String getLimit(long limit) {
return "LIMIT " + limit;
}
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.dialect.LimitClause#getOffset(long)
*/
@Override
public String getOffset(long offset) {
return "OFFSET " + offset;
}
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.dialect.LimitClause#getClause(long, long)
*/
@Override
public String getLimitOffset(long limit, long offset) {
return String.format("LIMIT %d OFFSET %d", limit, offset);
}
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.dialect.LimitClause#getClausePosition()
*/
@Override
public Position getClausePosition() {
return Position.AFTER_ORDER_BY;
}
};
private final PostgresArrayColumns ARRAY_COLUMNS = new PostgresArrayColumns();
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.dialect.Dialect#limit()
*/
@Override
public LimitClause limit() {
return LIMIT_CLAUSE;
}
private final PostgresLockClause LOCK_CLAUSE = new PostgresLockClause(this.getIdentifierProcessing());
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.dialect.Dialect#lock()
*/
@Override
public LockClause lock() {
return LOCK_CLAUSE;
}
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.dialect.Dialect#getArraySupport()
*/
@Override
public ArrayColumns getArraySupport() {
return ARRAY_COLUMNS;
}
@Override
public Collection