Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug with orderRepository.deleteByShippingAddress spring-projects/spri…
- Loading branch information
Nikita Konev
committed
Apr 6, 2022
1 parent
cdab926
commit 57ec646
Showing
9 changed files
with
6 additions
and
176 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
37 changes: 1 addition & 36 deletions
37
src/main/kotlin/com/example/web/jdbc/web/jdbc/JdbcConfig.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,45 +1,10 @@ | ||
package com.example.web.jdbc.web.jdbc | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.postgresql.util.PGobject | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.core.convert.converter.Converter | ||
import org.springframework.data.convert.ReadingConverter | ||
import org.springframework.data.convert.WritingConverter | ||
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions | ||
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration | ||
|
||
abstract class AbstractJsonWritingConverter<T> ( | ||
private val objectMapper: ObjectMapper | ||
) : Converter<T, PGobject> { | ||
override fun convert(source: T): PGobject { | ||
val jsonObject = PGobject() | ||
jsonObject.type = "json" | ||
jsonObject.value = objectMapper.writeValueAsString(source) | ||
return jsonObject | ||
} | ||
} | ||
|
||
abstract class AbstractJsonReadingConverter<T>( | ||
private val objectMapper: ObjectMapper, | ||
private val valueType: Class<T> | ||
) : Converter<PGobject, T> { | ||
override fun convert(pgObject: PGobject): T? { | ||
val source = pgObject.value | ||
return objectMapper.readValue(source, valueType) | ||
} | ||
} | ||
|
||
@Configuration | ||
class JdbcConfig(private val objectMapper: ObjectMapper) : AbstractJdbcConfiguration() { | ||
class JdbcConfig : AbstractJdbcConfiguration() { | ||
|
||
override fun userConverters() = listOf( | ||
PersonDataWritingConverter(objectMapper), PersonDataReadingConverter(objectMapper), | ||
) | ||
} | ||
|
||
@WritingConverter | ||
class PersonDataWritingConverter(objectMapper: ObjectMapper) : AbstractJsonWritingConverter<BranchData>(objectMapper) | ||
|
||
@ReadingConverter | ||
class PersonDataReadingConverter(objectMapper: ObjectMapper) : AbstractJsonReadingConverter<BranchData>(objectMapper, BranchData::class.java) |
22 changes: 4 additions & 18 deletions
22
src/main/kotlin/com/example/web/jdbc/web/jdbc/Repositories.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,24 +1,10 @@ | ||
package com.example.web.jdbc.web.jdbc | ||
|
||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.jdbc.repository.query.Query | ||
import org.springframework.data.jdbc.repository.query.Modifying | ||
import org.springframework.data.repository.CrudRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
|
||
@Repository | ||
interface SubjectRepository : CrudRepository<Subject, Int> | ||
|
||
@Repository | ||
interface BranchRepository : CrudRepository<Branch, Int> | ||
|
||
@Repository | ||
interface PersonRepository : CrudRepository<Person, Long> { | ||
fun findByLastName(lastname: String, pageable: Pageable) : Page<Person> | ||
} | ||
|
||
interface OrderRepository : CrudRepository<PurchaseOrder, Long> { | ||
@Query("select count(*) from order_item") | ||
fun countItems(): Int | ||
|
||
@Modifying | ||
fun deleteByShippingAddress(shippingAddress: String) | ||
} |
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 was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/main/resources/db/changelog/1648459518__branch_data_jsonb.sql
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.