Skip to content

Commit

Permalink
[#1295] Add Cockroach DBMS detection and a DbmsDialect implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Apr 22, 2021
1 parent 11dde29 commit 176f62d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ None yet
* Improve dialect detection for MariaDB dialects
* Workaround Hibernate proxy field access bug for non-pk relations
* Fix issues with de-serializing of singular entity view attributes that use a collection type
* Add Cockroach DBMS detection and a `DbmsDialect` implementation

### Backwards-incompatible changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.blazebit.persistence.ConfigurationProperties;
import com.blazebit.persistence.CriteriaBuilderFactory;
import com.blazebit.persistence.impl.dialect.CockroachSQLDbmsDialect;
import com.blazebit.persistence.impl.dialect.DB2DbmsDialect;
import com.blazebit.persistence.impl.dialect.DefaultDbmsDialect;
import com.blazebit.persistence.impl.dialect.H2DbmsDialect;
Expand Down Expand Up @@ -1840,6 +1841,7 @@ private void loadDbmsDialects() {
registerDialect("postgresql", new PostgreSQLDbmsDialect());
registerDialect("oracle", new OracleDbmsDialect());
registerDialect("microsoft", new MSSQLDbmsDialect());
registerDialect("cockroach", new CockroachSQLDbmsDialect());
}

private void loadDefaultProperties() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2014 - 2021 Blazebit.
*
* 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
*
* http://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 com.blazebit.persistence.impl.dialect;

import com.blazebit.persistence.spi.OrderByElement;

import java.util.Map;

/**
* @author Christian Beikov
* @since 1.6.0
*/
public class CockroachSQLDbmsDialect extends PostgreSQLDbmsDialect {

public CockroachSQLDbmsDialect() {
}

public CockroachSQLDbmsDialect(Map<Class<?>, String> childSqlTypes) {
super(childSqlTypes);
}

@Override
public void appendOrderByElement(StringBuilder sqlSb, OrderByElement element, String[] aliases) {
if (!element.isNullable()) {
super.appendOrderByElement(sqlSb, element, aliases);
} else {
appendEmulatedOrderByElementWithNulls(sqlSb, element, aliases);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ protected String getDbmsName(EntityManagerFactory emf, EntityManager em, Dialect
} else if (dialect instanceof InterbaseDialect) {
return "interbase";
} else {
try {
Class<?> cockroachDialect = dialect.getClass().getClassLoader().loadClass("org.hibernate.dialect.CockroachDB192Dialect");
if (cockroachDialect.isInstance(dialect)) {
return "cockroach";
}
} catch (ClassNotFoundException e) {
// Ignore
}
return null;
}
}
Expand Down

0 comments on commit 176f62d

Please sign in to comment.