Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.3 #80

Closed
wants to merge 3 commits into from
Closed

5.3 #80

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
1 change: 1 addition & 0 deletions axelor-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
testImplementation libs.jdbc_hsqldb
implementation libs.jdbc_postgres
implementation libs.jdbc_mysql
implementation libs.jdbc_mssql
api libs.hibernate
implementation libs.hibernate_search

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public interface AvailableAppSettings {
"hibernate.search.default.directory_provider";
String HIBERNATE_SEARCH_DEFAULT_INDEX_BASE = "hibernate.search.default.indexBase";


String HIBERNATE_CONNECTION_ISOLATION = "hibernate.connection.isolation";

String HIBERNATE_HIKARI_MINIMUN_IDLE = "hibernate.hikari.minimumIdle";
String HIBERNATE_HIKARI_MAXIMUN_POOL_SIZE = "hibernate.hikari.maximumPoolSize";
String HIBERNATE_HIKARI_IDLE_TIMEOUT = "hibernate.hikari.idleTimeout";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public Dialect resolveDialect(DialectResolutionInfo info) {
}
log.error("MySQL 5.7 or later is required.");
}

if ("Microsoft SQL Server".equals(databaseName)) {
//if (majorVersion >= 11 ) {
return new SqlServer12Dialect();
//}
//log.error("Microsoft SQL Server 12 or later is required.");
}


log.error("{} {}.{} is not suppported.", databaseName, majorVersion, minorVersion);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2005-2020 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.axelor.db.hibernate.dialect;

import com.axelor.db.hibernate.dialect.unique.SqlServer2008UniqueDelegate;
import com.axelor.db.hibernate.type.EncryptedTextType;
import com.axelor.db.hibernate.type.JsonTextSqlTypeDescriptor;
import com.axelor.db.hibernate.type.JsonType;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.SQLServer2012Dialect;
import org.hibernate.dialect.unique.InformixUniqueDelegate;
import org.hibernate.dialect.unique.UniqueDelegate;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;

import java.util.List;
import java.util.stream.Collectors;

public class SqlServer12Dialect extends SQLServer2012Dialect {

private final UniqueDelegate uniqueDelegate;

static class JsonValueFunction extends AbstractJsonExtractFunction {

public JsonValueFunction(Type type, String cast) {
super("JSON_VALUE", type, cast);
}

@Override
protected String transformPath(List<String> path) {
return path.stream()
.map(item -> item.substring(1, item.length() - 1))
.collect(Collectors.joining(".", "'$.", "'"));
}
}

@Override
public UniqueDelegate getUniqueDelegate() {
return uniqueDelegate;
}

public SqlServer12Dialect() {
super();

registerFunction("json_extract", new JsonValueFunction(StandardBasicTypes.STRING, null));
registerFunction("json_extract_text", new JsonValueFunction(StandardBasicTypes.STRING, null));
registerFunction(
"json_extract_boolean", new JsonValueFunction(StandardBasicTypes.BOOLEAN, "bit"));
registerFunction(
"json_extract_integer", new JsonValueFunction(StandardBasicTypes.INTEGER, "bigint"));
registerFunction(
"json_extract_decimal", new JsonValueFunction(StandardBasicTypes.BIG_DECIMAL, "numeric(28,12)"));
uniqueDelegate = new SqlServer2008UniqueDelegate( this );
}

@Override
public void contributeTypes(
TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(typeContributions, serviceRegistry);
typeContributions.contributeType(new JsonType(JsonTextSqlTypeDescriptor.INSTANCE));
typeContributions.contributeType(EncryptedTextType.INSTANCE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package com.axelor.db.hibernate.dialect.unique;

import org.hibernate.boot.Metadata;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.unique.DefaultUniqueDelegate;
import org.hibernate.dialect.unique.UniqueDelegate;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.mapping.UniqueKey;

import java.util.Iterator;

/**

*/
public class SqlServer2008UniqueDelegate extends DefaultUniqueDelegate {


public SqlServer2008UniqueDelegate( Dialect dialect ) {
super( dialect );
}

// legacy model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

protected String uniqueConstraintSql1(UniqueKey uniqueKey) {
final StringBuilder sb = new StringBuilder();
sb.append( "unique (" );
final Iterator<org.hibernate.mapping.Column> columnIterator = uniqueKey.columnIterator();
while ( columnIterator.hasNext() ) {
final org.hibernate.mapping.Column column = columnIterator.next();
sb.append( column.getQuotedName( dialect ) );
if ( uniqueKey.getColumnOrderMap().containsKey( column ) ) {
sb.append( " " ).append( uniqueKey.getColumnOrderMap().get( column ) );
}
if ( columnIterator.hasNext() ) {
sb.append( ", " );
}
}

return sb.append( ')' ).toString();
}

protected String uniqueConstraintSql(UniqueKey uniqueKey) {
final StringBuilder sb = new StringBuilder();
final StringBuilder whereIsNotNull = new StringBuilder();
boolean firstColumn = true;

sb.append( "unique (" );
final Iterator<org.hibernate.mapping.Column> columnIterator = uniqueKey.columnIterator();
while ( columnIterator.hasNext() ) {
final org.hibernate.mapping.Column column = columnIterator.next();
if (column.isNullable()){
if (!firstColumn){
whereIsNotNull.append( " AND " );
}else{
whereIsNotNull.append( " WHERE " );
firstColumn = false;
}

whereIsNotNull.append( column.getQuotedName( dialect ) ).append( " IS NOT NULL " );
}
sb.append( column.getQuotedName( dialect ) );
if ( uniqueKey.getColumnOrderMap().containsKey( column ) ) {
sb.append( " " ).append( uniqueKey.getColumnOrderMap().get( column ) );
}
if ( columnIterator.hasNext() ) {
sb.append( ", " );
}
}
sb.append( ')' );

if (whereIsNotNull.length() > 0){
sb.append( whereIsNotNull.toString() );
}



return sb.toString();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ public static boolean isMySQL() {
return jdbcDriver != null && jdbcDriver.contains("mysql");
}

/** Whether using ms sql server database. */
public static boolean isMsSQL() {
return jdbcDriver != null && jdbcDriver.contains("SQLServer");
}

/**
* Get the jdbc batch size configured with <code>hibernate.jdbc.batch_size</code> property.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ private Query<MetaView> findForCompute(String module, boolean update, Collection
+ "WHERE computedView.name = self.name AND self.computed = TRUE))) "
+ "AND COALESCE(self.extension, FALSE) = FALSE "
+ "AND COALESCE(self.computed, FALSE) = FALSE "
+ "AND (self.name, self.priority) "
+ "IN (SELECT other.name, MAX(other.priority) FROM MetaView other "
+ "AND CONCAT(self.name, CAST(self.priority as string)) "
+ "IN (SELECT CONCAT(other.name, CAST(MAX(other.priority) as string)) FROM MetaView other "
+ "WHERE COALESCE(other.extension, FALSE) = FALSE AND COALESCE(other.computed, FALSE) = FALSE "
+ "GROUP BY name) "
+ "AND EXISTS (SELECT extensionView FROM MetaView extensionView "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.axelor.db.JPA;
import com.axelor.db.Model;
import com.axelor.db.internal.DBHelper;
import com.axelor.i18n.I18n;
import com.axelor.meta.ActionHandler;
import com.axelor.rpc.ActionResponse;
Expand Down Expand Up @@ -220,6 +221,11 @@ public Object evaluate(ActionHandler handler) {
&& (domain.contains("$") || (domain.startsWith("#{") && domain.endsWith("}")))) {
domain = handler.evaluate(toExpression(domain, true)).toString();
}
if (domain != null
&& DBHelper.isMsSQL()){
domain = domain.replace("current_date", "CONVERT(DATE, GETDATE())");
domain = domain.replace("CURRENT_DATE", "CONVERT(DATE, GETDATE())");
}

String title = this.getLocalizedTitle();
if (title != null && (title.contains("$") || (title.startsWith("#{") && title.endsWith("}")))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.axelor.auth.AuthUtils;
import com.axelor.auth.db.User;
import com.axelor.db.JpaSupport;
import com.axelor.db.internal.DBHelper;
import com.axelor.rpc.ActionRequest;
import com.axelor.rpc.ActionResponse;
import com.axelor.rpc.Response;
Expand Down Expand Up @@ -61,9 +62,15 @@ private Long countTasks(String queryString) {
return 0L;
}

final String countString =
String countString =
queryString.replace("SELECT tt FROM TeamTask tt", "SELECT COUNT(tt.id) FROM TeamTask tt");

if (DBHelper.isMsSQL()){
countString =
countString.replace("current_date", "CONVERT(DATE, GETDATE())");
}


final TypedQuery<Long> query = getEntityManager().createQuery(countString, Long.class);

query.setParameter("uid", user.getId());
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ libs.greenmail = "com.icegreen:greenmail:1.5.3"
libs.jdbc_hsqldb = "org.hsqldb:hsqldb:2.3.4"
libs.jdbc_postgres = "org.postgresql:postgresql:42.0.0"
libs.jdbc_mysql = "mysql:mysql-connector-java:5.1.41"
libs.jdbc_mssql = "com.microsoft.sqlserver:mssql-jdbc:8.4.1.jre8"


// Hibernate
libs.hibernate = [
Expand Down