-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
33 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 10 additions & 49 deletions
59
backend/data/src/main/kotlin/io/tolgee/dialects/postgres/CustomPostgreSQLDialect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,19 @@ | ||
package io.tolgee.dialects.postgres | ||
|
||
import com.vladmihalcea.hibernate.type.array.StringArrayType | ||
import com.vladmihalcea.hibernate.type.json.JsonBinaryType | ||
import org.hibernate.NullPrecedence | ||
import org.hibernate.dialect.PostgreSQL10Dialect | ||
import org.hibernate.dialect.function.SQLFunction | ||
import org.hibernate.engine.spi.Mapping | ||
import org.hibernate.engine.spi.SessionFactoryImplementor | ||
import org.hibernate.type.FloatType | ||
import org.hibernate.type.Type | ||
import java.sql.Types | ||
import org.hibernate.boot.model.FunctionContributions | ||
import org.hibernate.dialect.DatabaseVersion | ||
import org.hibernate.dialect.PostgreSQLDialect | ||
import org.hibernate.type.StandardBasicTypes | ||
|
||
@Suppress("unused") | ||
class CustomPostgreSQLDialect : PostgreSQL10Dialect() { | ||
init { | ||
registerHibernateType(2003, StringArrayType::class.java.name) | ||
} | ||
|
||
override fun renderOrderByElement( | ||
expression: String?, | ||
collation: String?, | ||
order: String?, | ||
nulls: NullPrecedence? | ||
): String { | ||
if (nulls == NullPrecedence.NONE) { | ||
if (order == "asc") { | ||
return super.renderOrderByElement(expression, collation, order, NullPrecedence.FIRST) | ||
} | ||
if (order == "desc") { | ||
return super.renderOrderByElement(expression, collation, order, NullPrecedence.LAST) | ||
} | ||
} | ||
return super.renderOrderByElement(expression, collation, order, nulls) | ||
} | ||
class CustomPostgreSQLDialect : PostgreSQLDialect(DatabaseVersion.make(10)) { | ||
|
||
init { | ||
registerFunction( | ||
override fun contributeFunctions(functionContributions: FunctionContributions) { | ||
super.contributeFunctions(functionContributions) | ||
functionContributions.functionRegistry.registerPattern( | ||
"similarity", | ||
object : SQLFunction { | ||
override fun hasArguments(): Boolean = true | ||
|
||
override fun hasParenthesesIfNoArguments() = false | ||
|
||
override fun getReturnType(firstArgumentType: Type?, mapping: Mapping?) = FloatType() | ||
|
||
override fun render( | ||
firstArgumentType: Type, | ||
arguments: MutableList<Any?>, | ||
factory: SessionFactoryImplementor | ||
): String { | ||
return "similarity(${arguments[0]}, ${arguments[1]})" | ||
} | ||
} | ||
"similarity(?1, ?2)", | ||
functionContributions.typeConfiguration.basicTypeRegistry.resolve(StandardBasicTypes.FLOAT) | ||
) | ||
registerHibernateType(Types.OTHER, JsonBinaryType::class.java.name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
backend/data/src/main/kotlin/io/tolgee/model/dataImport/ImportTranslation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
backend/data/src/main/kotlin/io/tolgee/model/key/KeyCodeReference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters