मेरे पास निम्न परिदृश्य है और मैं इसे प्राप्त करने के लिए slick डीबीआईओ कार्यों का उपयोग करने की कोशिश कर रहा हूं।स्लिक डीबीओ क्रियाओं में क्लीनअप एक्शन त्रुटि को संभालें
Execute a batch Insert operation. On success, return the inserted result On failure,
-> if the failure is due to duplicate value in a particular column, then remove the duplicates from the list, and try batch insert again. If the second batch insert is successful, return a successful future with the second inserted list, else the failed future of the 2nd batch insert.
-> if the failure is due to something else, then throw that exception
उपरोक्त परिदृश्य के लिए, मैंने क्लीनअप कार्रवाई का उपयोग करने का प्रयास किया। लेकिन, मुझे नहीं पता कि मुख्य कार्य विफल होने पर क्लीनअप क्रिया परिणाम कैसे वापस आना है।
डीबीआईओ क्रियाओं का उपयोग कर मेरी आवश्यकता को कैसे प्राप्त कर सकता हूं त्रुटि प्रबंधन?
def insertBatchAndReturnQuery(rowList: List[E]): FixedSqlAction[Seq[E], NoStream, Write] = {
query returning query ++= rowList
}
def insert(entities: List[E]): Future[Seq[E]] = {
val q = insertBatchAndReturnQuery(entities).cleanUp {
case Some(ex) => ex match {
case b: PSQLException => {
if (b.getSQLState.equals("23505")) {
//unique key exception, handle this by removing the duplicate entries from the list
???
} else {
throw new Exception("some database exception")
}
}
}
case None => insertBatchAndReturnQuery(Nil)
}
db.run(q)
}
यहाँ, क्वेरी TableQuery [टी] है।
स्लिक संस्करण: 3.2.0-M2