Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a TypeContributor that registers all supported types #166
- Loading branch information
1 parent
059fd07
commit a5130b4
Showing
6 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...nate-types-5/src/main/java/com/vladmihalcea/hibernate/type/HibernateTypesContributor.java
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.vladmihalcea.hibernate.type; | ||
|
||
import com.vladmihalcea.hibernate.type.array.*; | ||
import com.vladmihalcea.hibernate.type.basic.NullableCharacterType; | ||
import com.vladmihalcea.hibernate.type.basic.PostgreSQLEnumType; | ||
import com.vladmihalcea.hibernate.type.basic.PostgreSQLHStoreType; | ||
import com.vladmihalcea.hibernate.type.basic.PostgreSQLInetType; | ||
import com.vladmihalcea.hibernate.type.json.*; | ||
import com.vladmihalcea.hibernate.type.range.PostgreSQLRangeType; | ||
import com.vladmihalcea.hibernate.type.range.guava.PostgreSQLGuavaRangeType; | ||
import org.hibernate.boot.model.TypeContributions; | ||
import org.hibernate.boot.model.TypeContributor; | ||
import org.hibernate.dialect.*; | ||
import org.hibernate.engine.jdbc.spi.JdbcServices; | ||
import org.hibernate.service.ServiceRegistry; | ||
|
||
/** | ||
* The {@link HibernateTypesContributor} registers various types automatically. | ||
* | ||
* @author Vlad Mihalcea | ||
* @since 2.15.0 | ||
*/ | ||
public class HibernateTypesContributor implements TypeContributor { | ||
|
||
@Override | ||
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { | ||
JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class); | ||
Dialect dialect = jdbcServices.getDialect(); | ||
|
||
if(dialect instanceof PostgreSQLDialect) { | ||
/* Arrays */ | ||
typeContributions.contributeType(BooleanArrayType.INSTANCE); | ||
typeContributions.contributeType(DateArrayType.INSTANCE); | ||
typeContributions.contributeType(DecimalArrayType.INSTANCE); | ||
typeContributions.contributeType(DoubleArrayType.INSTANCE); | ||
typeContributions.contributeType(EnumArrayType.INSTANCE); | ||
typeContributions.contributeType(IntArrayType.INSTANCE); | ||
typeContributions.contributeType(DoubleArrayType.INSTANCE); | ||
typeContributions.contributeType(ListArrayType.INSTANCE); | ||
typeContributions.contributeType(LongArrayType.INSTANCE); | ||
typeContributions.contributeType(StringArrayType.INSTANCE); | ||
typeContributions.contributeType(TimestampArrayType.INSTANCE); | ||
typeContributions.contributeType(UUIDArrayType.INSTANCE); | ||
|
||
/* JSON */ | ||
typeContributions.contributeType(JsonBinaryType.INSTANCE); | ||
|
||
/* Specific-types */ | ||
typeContributions.contributeType(PostgreSQLEnumType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLHStoreType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLInetType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLRangeType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLGuavaRangeType.INSTANCE); | ||
} else if(dialect instanceof MySQLDialect) { | ||
/* JSON */ | ||
typeContributions.contributeType(JsonStringType.INSTANCE); | ||
typeContributions.contributeType(JsonNodeStringType.INSTANCE); | ||
} else if(dialect instanceof SQLServerDialect) { | ||
/* JSON */ | ||
typeContributions.contributeType(JsonStringType.INSTANCE); | ||
} else if(dialect instanceof OracleDialect) { | ||
/* JSON */ | ||
typeContributions.contributeType(JsonStringType.INSTANCE); | ||
typeContributions.contributeType(JsonBlobType.INSTANCE); | ||
} | ||
|
||
/* Basic */ | ||
typeContributions.contributeType(NullableCharacterType.INSTANCE); | ||
/* JSON */ | ||
typeContributions.contributeType(JsonType.INSTANCE); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ate-types-5/src/main/resources/META-INF/services/org.hibernate.boot.model.TypeContributor
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
com.vladmihalcea.hibernate.type.HibernateTypesContributor |
90 changes: 90 additions & 0 deletions
90
...ate-types-52/src/main/java/com/vladmihalcea/hibernate/type/HibernateTypesContributor.java
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.vladmihalcea.hibernate.type; | ||
|
||
import com.vladmihalcea.hibernate.type.array.*; | ||
import com.vladmihalcea.hibernate.type.basic.*; | ||
import com.vladmihalcea.hibernate.type.interval.OracleIntervalDayToSecondType; | ||
import com.vladmihalcea.hibernate.type.interval.PostgreSQLIntervalType; | ||
import com.vladmihalcea.hibernate.type.interval.PostgreSQLPeriodType; | ||
import com.vladmihalcea.hibernate.type.json.*; | ||
import com.vladmihalcea.hibernate.type.range.PostgreSQLRangeType; | ||
import com.vladmihalcea.hibernate.type.range.guava.PostgreSQLGuavaRangeType; | ||
import com.vladmihalcea.hibernate.type.search.PostgreSQLTSVectorType; | ||
import org.hibernate.boot.model.TypeContributions; | ||
import org.hibernate.boot.model.TypeContributor; | ||
import org.hibernate.dialect.*; | ||
import org.hibernate.engine.jdbc.spi.JdbcServices; | ||
import org.hibernate.service.ServiceRegistry; | ||
|
||
/** | ||
* The {@link HibernateTypesContributor} registers various types automatically. | ||
* | ||
* @author Vlad Mihalcea | ||
* @since 2.15.0 | ||
*/ | ||
public class HibernateTypesContributor implements TypeContributor { | ||
|
||
@Override | ||
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { | ||
JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class); | ||
Dialect dialect = jdbcServices.getDialect(); | ||
|
||
if(dialect instanceof PostgreSQLDialect) { | ||
/* Arrays */ | ||
typeContributions.contributeType(BooleanArrayType.INSTANCE); | ||
typeContributions.contributeType(DateArrayType.INSTANCE); | ||
typeContributions.contributeType(DecimalArrayType.INSTANCE); | ||
typeContributions.contributeType(DoubleArrayType.INSTANCE); | ||
typeContributions.contributeType(EnumArrayType.INSTANCE); | ||
typeContributions.contributeType(IntArrayType.INSTANCE); | ||
typeContributions.contributeType(DoubleArrayType.INSTANCE); | ||
typeContributions.contributeType(ListArrayType.INSTANCE); | ||
typeContributions.contributeType(LocalDateArrayType.INSTANCE); | ||
typeContributions.contributeType(LocalDateTimeArrayType.INSTANCE); | ||
typeContributions.contributeType(LongArrayType.INSTANCE); | ||
typeContributions.contributeType(StringArrayType.INSTANCE); | ||
typeContributions.contributeType(TimestampArrayType.INSTANCE); | ||
typeContributions.contributeType(UUIDArrayType.INSTANCE); | ||
|
||
/* Date/Time */ | ||
typeContributions.contributeType(PostgreSQLIntervalType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLPeriodType.INSTANCE); | ||
|
||
/* JSON */ | ||
typeContributions.contributeType(JsonBinaryType.INSTANCE); | ||
|
||
/* Specific-types */ | ||
typeContributions.contributeType(PostgreSQLTSVectorType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLEnumType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLHStoreType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLInetType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLRangeType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLGuavaRangeType.INSTANCE); | ||
} else if(dialect instanceof MySQLDialect) { | ||
/* JSON */ | ||
typeContributions.contributeType(JsonStringType.INSTANCE); | ||
typeContributions.contributeType(JsonNodeStringType.INSTANCE); | ||
} else if(dialect instanceof SQLServerDialect) { | ||
/* JSON */ | ||
typeContributions.contributeType(JsonStringType.INSTANCE); | ||
} else if(dialect instanceof OracleDialect) { | ||
/* Date/Time */ | ||
typeContributions.contributeType(OracleIntervalDayToSecondType.INSTANCE); | ||
/* JSON */ | ||
typeContributions.contributeType(JsonStringType.INSTANCE); | ||
typeContributions.contributeType(JsonBlobType.INSTANCE); | ||
} | ||
|
||
/* Basic */ | ||
typeContributions.contributeType(NullableCharacterType.INSTANCE); | ||
/* Date/Time */ | ||
typeContributions.contributeType(Iso8601MonthType.INSTANCE); | ||
typeContributions.contributeType(MonthDayDateType.INSTANCE); | ||
typeContributions.contributeType(MonthDayIntegerType.INSTANCE); | ||
typeContributions.contributeType(YearMonthDateType.INSTANCE); | ||
typeContributions.contributeType(YearMonthEpochType.INSTANCE); | ||
typeContributions.contributeType(YearMonthIntegerType.INSTANCE); | ||
typeContributions.contributeType(YearMonthTimestampType.INSTANCE); | ||
/* JSON */ | ||
typeContributions.contributeType(JsonType.INSTANCE); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...te-types-52/src/main/resources/META-INF/services/org.hibernate.boot.model.TypeContributor
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
com.vladmihalcea.hibernate.type.HibernateTypesContributor |
90 changes: 90 additions & 0 deletions
90
...ate-types-55/src/main/java/com/vladmihalcea/hibernate/type/HibernateTypesContributor.java
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.vladmihalcea.hibernate.type; | ||
|
||
import com.vladmihalcea.hibernate.type.array.*; | ||
import com.vladmihalcea.hibernate.type.basic.*; | ||
import com.vladmihalcea.hibernate.type.interval.OracleIntervalDayToSecondType; | ||
import com.vladmihalcea.hibernate.type.interval.PostgreSQLIntervalType; | ||
import com.vladmihalcea.hibernate.type.interval.PostgreSQLPeriodType; | ||
import com.vladmihalcea.hibernate.type.json.*; | ||
import com.vladmihalcea.hibernate.type.range.PostgreSQLRangeType; | ||
import com.vladmihalcea.hibernate.type.range.guava.PostgreSQLGuavaRangeType; | ||
import com.vladmihalcea.hibernate.type.search.PostgreSQLTSVectorType; | ||
import org.hibernate.boot.model.TypeContributions; | ||
import org.hibernate.boot.model.TypeContributor; | ||
import org.hibernate.dialect.*; | ||
import org.hibernate.engine.jdbc.spi.JdbcServices; | ||
import org.hibernate.service.ServiceRegistry; | ||
|
||
/** | ||
* The {@link HibernateTypesContributor} registers various types automatically. | ||
* | ||
* @author Vlad Mihalcea | ||
* @since 2.15.0 | ||
*/ | ||
public class HibernateTypesContributor implements TypeContributor { | ||
|
||
@Override | ||
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { | ||
JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class); | ||
Dialect dialect = jdbcServices.getDialect(); | ||
|
||
if(dialect instanceof PostgreSQLDialect) { | ||
/* Arrays */ | ||
typeContributions.contributeType(BooleanArrayType.INSTANCE); | ||
typeContributions.contributeType(DateArrayType.INSTANCE); | ||
typeContributions.contributeType(DecimalArrayType.INSTANCE); | ||
typeContributions.contributeType(DoubleArrayType.INSTANCE); | ||
typeContributions.contributeType(EnumArrayType.INSTANCE); | ||
typeContributions.contributeType(IntArrayType.INSTANCE); | ||
typeContributions.contributeType(DoubleArrayType.INSTANCE); | ||
typeContributions.contributeType(ListArrayType.INSTANCE); | ||
typeContributions.contributeType(LocalDateArrayType.INSTANCE); | ||
typeContributions.contributeType(LocalDateTimeArrayType.INSTANCE); | ||
typeContributions.contributeType(LongArrayType.INSTANCE); | ||
typeContributions.contributeType(StringArrayType.INSTANCE); | ||
typeContributions.contributeType(TimestampArrayType.INSTANCE); | ||
typeContributions.contributeType(UUIDArrayType.INSTANCE); | ||
|
||
/* Date/Time */ | ||
typeContributions.contributeType(PostgreSQLIntervalType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLPeriodType.INSTANCE); | ||
|
||
/* JSON */ | ||
typeContributions.contributeType(JsonBinaryType.INSTANCE); | ||
|
||
/* Specific-types */ | ||
typeContributions.contributeType(PostgreSQLTSVectorType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLEnumType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLHStoreType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLInetType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLRangeType.INSTANCE); | ||
typeContributions.contributeType(PostgreSQLGuavaRangeType.INSTANCE); | ||
} else if(dialect instanceof MySQLDialect) { | ||
/* JSON */ | ||
typeContributions.contributeType(JsonStringType.INSTANCE); | ||
typeContributions.contributeType(JsonNodeStringType.INSTANCE); | ||
} else if(dialect instanceof SQLServerDialect) { | ||
/* JSON */ | ||
typeContributions.contributeType(JsonStringType.INSTANCE); | ||
} else if(dialect instanceof OracleDialect) { | ||
/* Date/Time */ | ||
typeContributions.contributeType(OracleIntervalDayToSecondType.INSTANCE); | ||
/* JSON */ | ||
typeContributions.contributeType(JsonStringType.INSTANCE); | ||
typeContributions.contributeType(JsonBlobType.INSTANCE); | ||
} | ||
|
||
/* Basic */ | ||
typeContributions.contributeType(NullableCharacterType.INSTANCE); | ||
/* Date/Time */ | ||
typeContributions.contributeType(Iso8601MonthType.INSTANCE); | ||
typeContributions.contributeType(MonthDayDateType.INSTANCE); | ||
typeContributions.contributeType(MonthDayIntegerType.INSTANCE); | ||
typeContributions.contributeType(YearMonthDateType.INSTANCE); | ||
typeContributions.contributeType(YearMonthEpochType.INSTANCE); | ||
typeContributions.contributeType(YearMonthIntegerType.INSTANCE); | ||
typeContributions.contributeType(YearMonthTimestampType.INSTANCE); | ||
/* JSON */ | ||
typeContributions.contributeType(JsonType.INSTANCE); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...te-types-55/src/main/resources/META-INF/services/org.hibernate.boot.model.TypeContributor
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
com.vladmihalcea.hibernate.type.HibernateTypesContributor |