Skip to content
Open
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
2 changes: 1 addition & 1 deletion depmgmt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
<dependency>
<groupId>org.joda</groupId>
<artifactId>joda-money</artifactId>
<version>0.12</version>
<version>1.0.1</version>
<optional>true</optional>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.jadira.usertype.moneyandcurrency.joda;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.jadira.usertype.moneyandcurrency.joda.columnmapper.StringColumnCurrencyUnitMapper;
import org.jadira.usertype.moneyandcurrency.legacyjdk.columnmapper.BigDecimalBigDecimalColumnMapper;
Expand All @@ -29,23 +30,34 @@
*/
public class PersistentMoneyAmountAndCurrency extends AbstractMultiColumnUserType<Money> {

private static final long serialVersionUID = 3735995469031558183L;
private static final long serialVersionUID = 3735995469031558183L;

private static final ColumnMapper<?, ?>[] COLUMN_MAPPERS = new ColumnMapper<?, ?>[] { new StringColumnCurrencyUnitMapper(), new BigDecimalBigDecimalColumnMapper() };
private static final ColumnMapper<?, ?>[] COLUMN_MAPPERS = new ColumnMapper<?, ?>[] { new StringColumnCurrencyUnitMapper(), new BigDecimalBigDecimalColumnMapper() };

private static final String[] PROPERTY_NAMES = new String[]{ "currencyUnit", "amount" };

@Override
protected ColumnMapper<?, ?>[] getColumnMappers() {
return COLUMN_MAPPERS;
}

private RoundingMode roundingMode;

public PersistentMoneyAmountAndCurrency() {
this(RoundingMode.HALF_UP);
}

public PersistentMoneyAmountAndCurrency(RoundingMode roundingMode) {
super();
this.roundingMode = roundingMode;
}

@Override
protected ColumnMapper<?, ?>[] getColumnMappers() {
return COLUMN_MAPPERS;
}

@Override
protected Money fromConvertedColumns(Object[] convertedColumns) {

CurrencyUnit currencyUnitPart = (CurrencyUnit) convertedColumns[0];
BigDecimal amountPart = (BigDecimal) convertedColumns[1];
Money money = Money.of(currencyUnitPart, amountPart);
Money money = Money.of(currencyUnitPart, amountPart, roundingMode);

return money;
}
Expand All @@ -55,9 +67,9 @@ protected Object[] toConvertedColumns(Money value) {

return new Object[] { value.getCurrencyUnit(), value.getAmount() };
}

@Override
public String[] getPropertyNames() {
return PROPERTY_NAMES;
}
public String[] getPropertyNames() {
return PROPERTY_NAMES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.jadira.usertype.moneyandcurrency.joda;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.jadira.usertype.moneyandcurrency.joda.columnmapper.IntegerColumnCurrencyUnitMapper;
import org.jadira.usertype.moneyandcurrency.legacyjdk.columnmapper.BigDecimalBigDecimalColumnMapper;
Expand All @@ -35,6 +36,17 @@ public class PersistentMoneyAmountAndCurrencyAsInteger extends AbstractMultiColu

private static final String[] PROPERTY_NAMES = new String[]{ "currencyUnit", "amount" };

private RoundingMode roundingMode;

public PersistentMoneyAmountAndCurrencyAsInteger() {
this(RoundingMode.HALF_UP);
}

public PersistentMoneyAmountAndCurrencyAsInteger(RoundingMode roundingMode) {
super();
this.roundingMode = roundingMode;
}

@Override
protected ColumnMapper<?, ?>[] getColumnMappers() {
return COLUMN_MAPPERS;
Expand All @@ -45,7 +57,7 @@ protected Money fromConvertedColumns(Object[] convertedColumns) {

CurrencyUnit currencyUnitPart = (CurrencyUnit) convertedColumns[0];
BigDecimal amountPart = (BigDecimal) convertedColumns[1];
Money money = Money.of(currencyUnitPart, amountPart);
Money money = Money.of(currencyUnitPart, amountPart, roundingMode);

return money;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public BigMoney fromNonNullValue(BigDecimal val) {
@Override
public BigDecimal toNonNullValue(BigMoney value) {
if (!currencyUnit.equals(value.getCurrencyUnit())) {
throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit());
throw new IllegalStateException("Expected currency " + currencyUnit.getCode() + " but was " + value.getCurrencyUnit());
}
return BigMoney.of(value).getAmount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Money fromNonNullValue(BigDecimal val) {
@Override
public BigDecimal toNonNullValue(Money value) {
if (!currencyUnit.equals(value.getCurrencyUnit())) {
throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit());
throw new IllegalStateException("Expected currency " + currencyUnit.getCode() + " but was " + value.getCurrencyUnit());
}
return value.getAmount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public CurrencyUnit fromNonNullString(String s) {
public String toNonNullString(CurrencyUnit value) {
String str = value.getNumeric3Code();
if ("".equals(str)) {
return value.getCurrencyCode();
return value.getCode();
} else {
return str;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public BigMoney fromNonNullValue(Long value) {
@Override
public Long toNonNullValue(BigMoney value) {
if (!currencyUnit.equals(value.getCurrencyUnit())) {
throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit());
throw new IllegalStateException("Expected currency " + currencyUnit.getCode() + " but was " + value.getCurrencyUnit());
}
return value.toBigMoney().getAmountMajorLong();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public BigMoney fromNonNullValue(Long val) {
@Override
public Long toNonNullValue(BigMoney value) {
if (!currencyUnit.equals(value.getCurrencyUnit())) {
throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit());
throw new IllegalStateException("Expected currency " + currencyUnit.getCode() + " but was " + value.getCurrencyUnit());
}
return value.toBigMoney().getAmountMinorLong();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Money fromNonNullValue(Long val) {
@Override
public Long toNonNullValue(Money value) {
if (!currencyUnit.equals(value.getCurrencyUnit())) {
throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit());
throw new IllegalStateException("Expected currency " + currencyUnit.getCode() + " but was " + value.getCurrencyUnit());
}
return value.getAmountMajorLong();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Money fromNonNullValue(Long val) {
@Override
public Long toNonNullValue(Money value) {
if (!currencyUnit.equals(value.getCurrencyUnit())) {
throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrencyUnit());
throw new IllegalStateException("Expected currency " + currencyUnit.getCode() + " but was " + value.getCurrencyUnit());
}
return value.getAmountMinorLong();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public CurrencyUnit fromNonNullValue(String s) {

@Override
public String toNonNullValue(CurrencyUnit value) {
return value.getCurrencyCode();
return value.getCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class TestPersistentCurrencyUnit extends AbstractDatabaseTest<CurrencyUnitHolder> {

private static final CurrencyUnit[] currencies = new CurrencyUnit[]{CurrencyUnit.EUR, CurrencyUnit.USD, CurrencyUnit.GBP, CurrencyUnit.getInstance("SAR"), null};
private static final CurrencyUnit[] currencies = new CurrencyUnit[]{CurrencyUnit.EUR, CurrencyUnit.USD, CurrencyUnit.GBP, CurrencyUnit.of("SAR"), null};

public TestPersistentCurrencyUnit() {
super(TestJodaMoneySuite.getFactory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class TestPersistentCurrencyUnitAsInteger extends AbstractDatabaseTest<CurrencyUnitAsIntegerHolder> {

private static final CurrencyUnit[] currencies = new CurrencyUnit[]{CurrencyUnit.EUR, CurrencyUnit.USD, CurrencyUnit.GBP, CurrencyUnit.getInstance("SAR"), null};
private static final CurrencyUnit[] currencies = new CurrencyUnit[]{CurrencyUnit.EUR, CurrencyUnit.USD, CurrencyUnit.GBP, CurrencyUnit.of("SAR"), null};

public TestPersistentCurrencyUnitAsInteger() {
super(TestJodaMoneySuite.getFactory());
Expand Down