From: Roland Haeder Date: Sun, 17 Apr 2016 10:35:24 +0000 (+0200) Subject: Continued a bit: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7635c613760bcc7c0cf3d3f7c563fc026d9b9ce6;p=jphone-core.git Continued a bit: - added named queries for finding cell phone, fax and land-line entries by id number - added Exception thrown when the corresponding entity was not found --- diff --git a/src/org/mxchange/jphone/exceptions/PhoneEntityNotFoundException.java b/src/org/mxchange/jphone/exceptions/PhoneEntityNotFoundException.java new file mode 100644 index 0000000..5623c56 --- /dev/null +++ b/src/org/mxchange/jphone/exceptions/PhoneEntityNotFoundException.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jphone.exceptions; + +import java.text.MessageFormat; + +/** + * An exception thrown when a phone entity is not found. + *

+ * @author Roland Haeder + */ +public class PhoneEntityNotFoundException extends Exception { + + /** + * Serial number + */ + private static final long serialVersionUID = 18_964_581_681_985_597L; + + /** + * Counstructor with id number and causing exception + *

+ * @param cellphoneId Id number that has no corresponding entity + * @param cause Causing exception + */ + public PhoneEntityNotFoundException (final Long cellphoneId, final Throwable cause) { + // Construct message and call super constructor + super(MessageFormat.format("Cell phone entity with id {0} not found.", cellphoneId), cause); //NOI18N + } + +} diff --git a/src/org/mxchange/jphone/phonenumbers/cellphone/CellphoneNumber.java b/src/org/mxchange/jphone/phonenumbers/cellphone/CellphoneNumber.java index ce74ed5..75856e5 100644 --- a/src/org/mxchange/jphone/phonenumbers/cellphone/CellphoneNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/cellphone/CellphoneNumber.java @@ -26,6 +26,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Temporal; @@ -41,6 +43,9 @@ import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider; */ @Entity (name = "cellphone_numbers") @Table (name = "cellphone_numbers") +@NamedQueries ( + @NamedQuery (name = "SearchCellphoneId", query = "SELECT c FROM cellphone_numbers AS c WHERE c.phoneId = :cellphoneId") +) public class CellphoneNumber implements DialableCellphoneNumber { /** diff --git a/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java b/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java index 18db59d..45022e1 100644 --- a/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/fax/FaxNumber.java @@ -26,6 +26,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Temporal; @@ -40,6 +42,9 @@ import org.mxchange.jcountry.data.CountryData; */ @Entity (name = "fax_numbers") @Table (name = "fax_numbers") +@NamedQueries ( + @NamedQuery (name = "SearchFaxId", query = "SELECT f FROM fax_numbers AS f WHERE f.phoneId = :faxId") +) public class FaxNumber implements DialableFaxNumber { /** diff --git a/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java b/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java index 52d8932..17ab3f0 100644 --- a/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java +++ b/src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java @@ -26,6 +26,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Temporal; @@ -40,6 +42,9 @@ import org.mxchange.jcountry.data.CountryData; */ @Entity (name = "phone_numbers") @Table (name = "phone_numbers") +@NamedQueries ( + @NamedQuery (name = "SearchLandLineId", query = "SELECT p FROM phone_numbers AS p WHERE p.phoneId = :phoneId") +) public class LandLineNumber implements DialableLandLineNumber { /**