Package gwlpr.database.entities

Examples of gwlpr.database.entities.Account


    public void edit(Account account) throws IllegalOrphanException, NonexistentEntityException, Exception {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            Account persistentAccount = em.find(Account.class, account.getEMail());
            Usergroup userGroupOld = persistentAccount.getUserGroup();
            Usergroup userGroupNew = account.getUserGroup();
            Inventory materialStorageOld = persistentAccount.getMaterialStorage();
            Inventory materialStorageNew = account.getMaterialStorage();
            Collection<Storagetab> storagetabCollectionOld = persistentAccount.getStoragetabCollection();
            Collection<Storagetab> storagetabCollectionNew = account.getStoragetabCollection();
            Collection<Factionstat> factionstatCollectionOld = persistentAccount.getFactionstatCollection();
            Collection<Factionstat> factionstatCollectionNew = account.getFactionstatCollection();
            Collection<Character> characterCollectionOld = persistentAccount.getCharacterCollection();
            Collection<Character> characterCollectionNew = account.getCharacterCollection();
            List<String> illegalOrphanMessages = null;
            for (Storagetab storagetabCollectionOldStoragetab : storagetabCollectionOld) {
                if (!storagetabCollectionNew.contains(storagetabCollectionOldStoragetab)) {
                    if (illegalOrphanMessages == null) {
                        illegalOrphanMessages = new ArrayList<String>();
                    }
                    illegalOrphanMessages.add("You must retain Storagetab " + storagetabCollectionOldStoragetab + " since its account field is not nullable.");
                }
            }
            for (Factionstat factionstatCollectionOldFactionstat : factionstatCollectionOld) {
                if (!factionstatCollectionNew.contains(factionstatCollectionOldFactionstat)) {
                    if (illegalOrphanMessages == null) {
                        illegalOrphanMessages = new ArrayList<String>();
                    }
                    illegalOrphanMessages.add("You must retain Factionstat " + factionstatCollectionOldFactionstat + " since its account field is not nullable.");
                }
            }
            for (Character characterCollectionOldCharacter : characterCollectionOld) {
                if (!characterCollectionNew.contains(characterCollectionOldCharacter)) {
                    if (illegalOrphanMessages == null) {
                        illegalOrphanMessages = new ArrayList<String>();
                    }
                    illegalOrphanMessages.add("You must retain Character " + characterCollectionOldCharacter + " since its accountID field is not nullable.");
                }
            }
            if (illegalOrphanMessages != null) {
                throw new IllegalOrphanException(illegalOrphanMessages);
            }
            if (userGroupNew != null) {
                userGroupNew = em.getReference(userGroupNew.getClass(), userGroupNew.getId());
                account.setUserGroup(userGroupNew);
            }
            if (materialStorageNew != null) {
                materialStorageNew = em.getReference(materialStorageNew.getClass(), materialStorageNew.getId());
                account.setMaterialStorage(materialStorageNew);
            }
            Collection<Storagetab> attachedStoragetabCollectionNew = new ArrayList<Storagetab>();
            for (Storagetab storagetabCollectionNewStoragetabToAttach : storagetabCollectionNew) {
                storagetabCollectionNewStoragetabToAttach = em.getReference(storagetabCollectionNewStoragetabToAttach.getClass(), storagetabCollectionNewStoragetabToAttach.getStoragetabPK());
                attachedStoragetabCollectionNew.add(storagetabCollectionNewStoragetabToAttach);
            }
            storagetabCollectionNew = attachedStoragetabCollectionNew;
            account.setStoragetabCollection(storagetabCollectionNew);
            Collection<Factionstat> attachedFactionstatCollectionNew = new ArrayList<Factionstat>();
            for (Factionstat factionstatCollectionNewFactionstatToAttach : factionstatCollectionNew) {
                factionstatCollectionNewFactionstatToAttach = em.getReference(factionstatCollectionNewFactionstatToAttach.getClass(), factionstatCollectionNewFactionstatToAttach.getFactionstatPK());
                attachedFactionstatCollectionNew.add(factionstatCollectionNewFactionstatToAttach);
            }
            factionstatCollectionNew = attachedFactionstatCollectionNew;
            account.setFactionstatCollection(factionstatCollectionNew);
            Collection<Character> attachedCharacterCollectionNew = new ArrayList<Character>();
            for (Character characterCollectionNewCharacterToAttach : characterCollectionNew) {
                characterCollectionNewCharacterToAttach = em.getReference(characterCollectionNewCharacterToAttach.getClass(), characterCollectionNewCharacterToAttach.getId());
                attachedCharacterCollectionNew.add(characterCollectionNewCharacterToAttach);
            }
            characterCollectionNew = attachedCharacterCollectionNew;
            account.setCharacterCollection(characterCollectionNew);
            account = em.merge(account);
            if (userGroupOld != null && !userGroupOld.equals(userGroupNew)) {
                userGroupOld.getAccountCollection().remove(account);
                userGroupOld = em.merge(userGroupOld);
            }
            if (userGroupNew != null && !userGroupNew.equals(userGroupOld)) {
                userGroupNew.getAccountCollection().add(account);
                userGroupNew = em.merge(userGroupNew);
            }
            if (materialStorageOld != null && !materialStorageOld.equals(materialStorageNew)) {
                materialStorageOld.getAccountCollection().remove(account);
                materialStorageOld = em.merge(materialStorageOld);
            }
            if (materialStorageNew != null && !materialStorageNew.equals(materialStorageOld)) {
                materialStorageNew.getAccountCollection().add(account);
                materialStorageNew = em.merge(materialStorageNew);
            }
            for (Storagetab storagetabCollectionNewStoragetab : storagetabCollectionNew) {
                if (!storagetabCollectionOld.contains(storagetabCollectionNewStoragetab)) {
                    Account oldAccountOfStoragetabCollectionNewStoragetab = storagetabCollectionNewStoragetab.getAccount();
                    storagetabCollectionNewStoragetab.setAccount(account);
                    storagetabCollectionNewStoragetab = em.merge(storagetabCollectionNewStoragetab);
                    if (oldAccountOfStoragetabCollectionNewStoragetab != null && !oldAccountOfStoragetabCollectionNewStoragetab.equals(account)) {
                        oldAccountOfStoragetabCollectionNewStoragetab.getStoragetabCollection().remove(storagetabCollectionNewStoragetab);
                        oldAccountOfStoragetabCollectionNewStoragetab = em.merge(oldAccountOfStoragetabCollectionNewStoragetab);
                    }
                }
            }
            for (Factionstat factionstatCollectionNewFactionstat : factionstatCollectionNew) {
                if (!factionstatCollectionOld.contains(factionstatCollectionNewFactionstat)) {
                    Account oldAccountOfFactionstatCollectionNewFactionstat = factionstatCollectionNewFactionstat.getAccount();
                    factionstatCollectionNewFactionstat.setAccount(account);
                    factionstatCollectionNewFactionstat = em.merge(factionstatCollectionNewFactionstat);
                    if (oldAccountOfFactionstatCollectionNewFactionstat != null && !oldAccountOfFactionstatCollectionNewFactionstat.equals(account)) {
                        oldAccountOfFactionstatCollectionNewFactionstat.getFactionstatCollection().remove(factionstatCollectionNewFactionstat);
                        oldAccountOfFactionstatCollectionNewFactionstat = em.merge(oldAccountOfFactionstatCollectionNewFactionstat);
                    }
                }
            }
            for (Character characterCollectionNewCharacter : characterCollectionNew) {
                if (!characterCollectionOld.contains(characterCollectionNewCharacter)) {
                    Account oldAccountIDOfCharacterCollectionNewCharacter = characterCollectionNewCharacter.getAccountID();
                    characterCollectionNewCharacter.setAccountID(account);
                    characterCollectionNewCharacter = em.merge(characterCollectionNewCharacter);
                    if (oldAccountIDOfCharacterCollectionNewCharacter != null && !oldAccountIDOfCharacterCollectionNewCharacter.equals(account)) {
                        oldAccountIDOfCharacterCollectionNewCharacter.getCharacterCollection().remove(characterCollectionNewCharacter);
                        oldAccountIDOfCharacterCollectionNewCharacter = em.merge(oldAccountIDOfCharacterCollectionNewCharacter);
                    }
                }
            }
            em.getTransaction().commit();
View Full Code Here


    public void destroy(String id) throws IllegalOrphanException, NonexistentEntityException {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            Account account;
            try {
                account = em.getReference(Account.class, id);
                account.getEMail();
            } catch (EntityNotFoundException enfe) {
                throw new NonexistentEntityException("The account with id " + id + " no longer exists.", enfe);
            }
            List<String> illegalOrphanMessages = null;
            Collection<Storagetab> storagetabCollectionOrphanCheck = account.getStoragetabCollection();
            for (Storagetab storagetabCollectionOrphanCheckStoragetab : storagetabCollectionOrphanCheck) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("This Account (" + account + ") cannot be destroyed since the Storagetab " + storagetabCollectionOrphanCheckStoragetab + " in its storagetabCollection field has a non-nullable account field.");
            }
            Collection<Factionstat> factionstatCollectionOrphanCheck = account.getFactionstatCollection();
            for (Factionstat factionstatCollectionOrphanCheckFactionstat : factionstatCollectionOrphanCheck) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("This Account (" + account + ") cannot be destroyed since the Factionstat " + factionstatCollectionOrphanCheckFactionstat + " in its factionstatCollection field has a non-nullable account field.");
            }
            Collection<Character> characterCollectionOrphanCheck = account.getCharacterCollection();
            for (Character characterCollectionOrphanCheckCharacter : characterCollectionOrphanCheck) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("This Account (" + account + ") cannot be destroyed since the Character " + characterCollectionOrphanCheckCharacter + " in its characterCollection field has a non-nullable accountID field.");
            }
            if (illegalOrphanMessages != null) {
                throw new IllegalOrphanException(illegalOrphanMessages);
            }
            Usergroup userGroup = account.getUserGroup();
            if (userGroup != null) {
                userGroup.getAccountCollection().remove(account);
                userGroup = em.merge(userGroup);
            }
            Inventory materialStorage = account.getMaterialStorage();
            if (materialStorage != null) {
                materialStorage.getAccountCollection().remove(account);
                materialStorage = em.merge(materialStorage);
            }
            em.remove(account);
View Full Code Here

TOP

Related Classes of gwlpr.database.entities.Account

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.