From 86c237803c419e9077f10451f6d42694a49b58f2 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 14 Oct 2015 10:17:13 +0200 Subject: [PATCH] =?utf8?q?Continued:=20-=20added=20remote=20session=20bean?= =?utf8?q?=20for=20sharing=20address=20books=20-=20updated=20jar(s)=20Sign?= =?utf8?q?ed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- lib/jcoreee.jar | Bin 18511 -> 18714 bytes .../shared/SharedAddressbooksSessionBean.java | 111 ++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/java/org/mxchange/addressbook/model/shared/SharedAddressbooksSessionBean.java diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar index c2e022d69fedac84439d9796883f1931d015a012..4cdb134dfe55c2381d746baac342af402e2a4f80 100644 GIT binary patch delta 3118 zcma);X-r(#703T~2DrnUH^8vl;11Z}0fPavcm^=bFu;JpfEybdyanSicmbR761zWeR{kbJa+wVChIh zL8HeC$D$J#qbIg^U2Q4ZQ4^@CJGL{hwCs0k(?9ym@==9elwZ`DbzC%?_3NU=tZ$1B zv;NRgr-s9M?vDjm_jvF1aJu@Y!?mij$E^1pA+xqQBYKTrbKXw#Qi!~NZ}eY<%v_&A z^{&{gt_O3}%T{LKkcBj~Tj)Tig%G+V!Y*`6^jPRc#6k-CT&B+o-IUAkjzoK8jajNV_-Whd%=T_C@iRI98SYm{(CAKh( z#9s9qPi@ACjnCr|{%2z!_N&D}rK-!QaF5zJfP*%2F{UOnPKt3g8w{vND>uitWd2Tw zm(=~Nzsx@k54K_lN>Bp+-5}EYJ(sfQ?+W6g`oe}|w zphUBfXpv~;(kvLS{X?YsGO>vUDU5IN+(p@ewj{hFuMS?A8nyv_wzFV<_2-_AYN0HB zURksr(U-lJ-Z)F|n#8CJ2P6(!7{j>4p>!sC*y80#I@3RD@p4S!Q41NE&}PS7sC8o! zCnTb700ah2nr%%|O) zM2wl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ya&sEf9`!^tez2. + */ +package org.mxchange.addressbook.model.shared; + +import java.text.MessageFormat; +import java.util.List; +import javax.ejb.Stateless; +import javax.persistence.NoResultException; +import javax.persistence.Query; +import org.mxchange.addressbook.model.addressbook.shared.AddressbookShare; +import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook; +import org.mxchange.jcoreee.database.BaseDatabaseBean; +import org.mxchange.jusercore.model.user.User; + +/** + * A stateless bean for handling address book sharing + *

+ * @author Roland Haeder + */ +@Stateless (name = "share", mappedName = "ejb/stateless-share", description = "A stateless bean for handling shared addressbooks") +public class SharedAddressbooksSessionBean extends BaseDatabaseBean implements SharedAddressbooksSessionBeanRemote { + + /** + * Serial number + */ + private static final long serialVersionUID = 136_984_697_285_694_710L; + + /** + * Shared address books. If you add another share to the database, please + * also update this list as some methods may prefer this over asking the JPA + * all over again. + */ + private List shares; + + /** + * Default constructor + */ + public SharedAddressbooksSessionBean () { + // Init shares list + this.shares = null; + } + + @Override + @SuppressWarnings ("unchecked") + public boolean isUserSharingAddressbooks (final User user) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserSharingAddressbooks: user={0} - CALLED!", user)); //NOI18N + + // Is user null? + if (null == user) { + // Throw NPE + throw new NullPointerException("user is null"); //NOI18N + } else if (user.getUserId() == null) { + // Null userId is not allowed + throw new NullPointerException("user.userId is null"); //NOI18N + } else if (user.getUserId() < 1) { + // Not allowed value + throw new IllegalArgumentException(MessageFormat.format("user.UserId={0} is an invalid value", user.getUserId())); //NOI18N + } else if (this.shares instanceof List) { + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserSharingAddressbooks: this.shares.isEmpty()={0} - EXIT!", this.shares.isEmpty())); + + // Is already initialized + return (!this.shares.isEmpty()); + } + + // Get named query + Query query = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", AddressbookShare.class); //NOI18N + + // Set parameter + query.setParameter("user", user); //NOI18N + + // Default is not sharing + boolean isSharing = false; + + // Try it as an exception may be thrown + try { + // Get results + this.shares = query.getResultList(); + + // Debug message + this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserSharingAddressbooks: shares.size()={0}", this.shares.size())); + + // Is it not empty? + isSharing = (!this.shares.isEmpty()); + } catch (final NoResultException ex) { + // Not sharing anything + this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserSharingAddressbooks: User {0} is not sharing address books: {1}", user, ex)); //NOI18N + } + + // Trace message + this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserSharingAddressbooks: iSharing={0} - EXIT!", isSharing)); //NOI18N + + // Return it + return isSharing; + } +} -- 2.39.5