Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Data
- @Entity
- @Table(name = "transaction_line_item_value")
- @Builder
- @AllArgsConstructor
- @NoArgsConstructor
- @TypeDefs({
- @TypeDef(name = "rupee-custom", defaultForType = Rupee.class, typeClass = RupeeType.class)
- })
- public class TransactionLineItemValue {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @PodamExclude
- private int id;
- //@Column(name = "amount", nullable = false) Works! But makes amount immutable.
- @Column(name = "amount")
- private Rupee amount;
- }
- public class RupeeType extends AbstractSingleColumnStandardBasicType<BigDecimal> {
- public RupeeType() {
- super(new RupeeTypeDescriptor(), BigDecimalTypeDescriptor.INSTANCE);
- }
- @Override
- public String getName() {
- return "rupee-custom";
- }
- public static class RupeeTypeDescriptor implements SqlTypeDescriptor {
- @Override
- public int getSqlType() {
- return Types.DOUBLE;
- }
- @Override
- public boolean canBeRemapped() {
- return false;
- }
- @Override
- public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
- return new BasicBinder<X>(javaTypeDescriptor, (SqlTypeDescriptor) this) {
- @Override
- protected void doBind(PreparedStatement preparedStatement, X x, int i, WrapperOptions wrapperOptions) throws SQLException {
- preparedStatement.setBigDecimal(i, ((Rupee) x).getAmount());
- }
- @Override
- protected void doBind(CallableStatement callableStatement, X x, String s, WrapperOptions wrapperOptions) throws SQLException {
- callableStatement.setBigDecimal(s, ((Rupee) x).getAmount());
- }
- };
- }
- @Override
- public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) {
- return new BasicExtractor<X>(javaTypeDescriptor, (SqlTypeDescriptor) this) {
- @Override
- protected X doExtract(ResultSet resultSet, String s, WrapperOptions wrapperOptions) throws SQLException {
- return (X) Rupee.builder().amount(resultSet.getBigDecimal(s)).build();
- }
- @Override
- protected X doExtract(CallableStatement callableStatement, int i, WrapperOptions wrapperOptions) throws SQLException {
- return (X) Rupee.builder().amount(callableStatement.getBigDecimal(i)).build();
- }
- @Override
- protected X doExtract(CallableStatement callableStatement, String s, WrapperOptions wrapperOptions) throws SQLException {
- return (X) Rupee.builder().amount(callableStatement.getBigDecimal(s)).build();
- }
- };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement