-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store BigDecimal and BigInteger as Numbers like the Java SDK does. (#…
…1933) Also be able to read BigDecimal and BigInteger that were written as String. Also does not lose precision by converting BigDecimal to double in the transcoder. Closes #1611.
- Loading branch information
1 parent
0857a77
commit 7251e1c
Showing
9 changed files
with
142 additions
and
58 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
51 changes: 51 additions & 0 deletions
51
src/test/java/org/springframework/data/couchbase/domain/BigAirline.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,51 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.couchbase.domain; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
|
||
import org.springframework.data.annotation.PersistenceConstructor; | ||
import org.springframework.data.couchbase.core.mapping.Document; | ||
|
||
@Document | ||
/** | ||
* @author Michael Reiche | ||
*/ | ||
public class BigAirline extends Airline { | ||
BigInteger airlineNumber = new BigInteger("88881234567890123456"); // less than 63 bits, otherwise query truncates | ||
BigDecimal airlineDecimal = new BigDecimal("888812345678901.23"); // less than 53 bits in mantissa | ||
|
||
@PersistenceConstructor | ||
public BigAirline(String id, String name, String hqCountry, Number airlineNumber, Number airlineDecimal) { | ||
super(id, name, hqCountry); | ||
this.airlineNumber = airlineNumber != null && !airlineNumber.equals("") | ||
? new BigInteger(airlineNumber.toString()) | ||
: this.airlineNumber; | ||
this.airlineDecimal = airlineDecimal != null && !airlineDecimal.equals("") | ||
? new BigDecimal(airlineDecimal.toString()) | ||
: this.airlineDecimal; | ||
} | ||
|
||
public BigInteger getAirlineNumber() { | ||
return airlineNumber; | ||
} | ||
|
||
public BigDecimal getAirlineDecimal() { | ||
return airlineDecimal; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/test/java/org/springframework/data/couchbase/domain/BigAirlineRepository.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,38 @@ | ||
/* | ||
* Copyright 2017-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.data.couchbase.domain; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.couchbase.repository.CouchbaseRepository; | ||
import org.springframework.data.couchbase.repository.DynamicProxyable; | ||
import org.springframework.data.couchbase.repository.Query; | ||
import org.springframework.data.querydsl.QuerydslPredicateExecutor; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* @author Michael Reiche | ||
*/ | ||
@Repository | ||
public interface BigAirlineRepository extends CouchbaseRepository<BigAirline, String>, | ||
QuerydslPredicateExecutor<BigAirline>, DynamicProxyable<BigAirlineRepository> { | ||
|
||
@Query("#{#n1ql.selectEntity} where #{#n1ql.filter} and (name = $1)") | ||
List<Airline> getByName(@Param("airline_name") String airlineName); | ||
|
||
} |
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
Oops, something went wrong.