/** * Copyright (c) 2009 Juwi MacMillan Group GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // license-header java merge-point // // Attention: Generated code! Do not modify by hand! // Generated by: SpringHibernateDaoImpl.vsl in andromda-spring-cartridge. // package de.juwimm.cms.components.model; import java.util.Date; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.tizzit.util.XercesHelper; import de.juwimm.cms.model.SequenceHbmDao; /** * @see de.juwimm.cms.components.model.AddressHbm * @author <a href="mailto:carsten.schalm@juwimm.com">Carsten Schalm</a> , * Juwi|MacMillan Group Gmbh, Walsrode, Germany * @version $Id$ */ public class AddressHbmDaoImpl extends AddressHbmDaoBase { private static Logger log = Logger.getLogger(AddressHbmDaoImpl.class); @Autowired private SequenceHbmDao sequenceHbmDao; /* * (non-Javadoc) * * @see de.juwimm.cms.components.model.AddressHbmDaoBase#create(de.juwimm.cms.components.model.AddressHbm) */ @Override public AddressHbm create(AddressHbm addressHbm) { if (addressHbm.getAddressId() == null) { try { Integer id = sequenceHbmDao.getNextSequenceNumber("address.address_id"); addressHbm.setAddressId(new Long(id.longValue())); } catch (Exception e) { log.error("Error creating Address: " + e.getMessage(), e); } } addressHbm.setLastModifiedDate(new Date().getTime()); return super.create(addressHbm); } /** * @see de.juwimm.cms.components.model.AddressHbm#create() */ @Override public java.lang.Long handleCreate() { Long id = null; AddressHbm address = AddressHbm.Factory.newInstance(); try { id = new Long(sequenceHbmDao.getNextSequenceNumber("address.address_id").longValue()); address.setAddressId(id); } catch (Exception e) { log.error("Error creating new primary key", e); } address.setLastModifiedDate(new Date().getTime()); getHibernateTemplate().save(address); return address.getAddressId(); } /** * @see de.juwimm.cms.components.model.AddressHbm#create(org.w3c.dom.Element, * boolean, java.util.Map) */ @Override public java.lang.Long handleCreate(org.w3c.dom.Element ael, boolean useNewID, java.util.Map mappingAddresses) { Long id = null; AddressHbm address = AddressHbm.Factory.newInstance(); if (useNewID == true) { try { id = new Long(sequenceHbmDao.getNextSequenceNumber("address.address_id").longValue()); address.setAddressId(id); mappingAddresses.put(new Long(ael.getAttribute("id")), address.getAddressId()); } catch (Exception e) { log.error("Error creating new primary key: ", e); } } else { address.setAddressId(new Long(ael.getAttribute("id"))); } address.setAddressType(getNVal(ael, "addressType")); address.setBuildingLevel(getNVal(ael, "buildingLevel")); address.setBuildingNr(getNVal(ael, "buildingNr")); address.setCity(getNVal(ael, "city")); address.setCountry(getNVal(ael, "country")); address.setCountryCode(getNVal(ael, "countryCode")); address.setEmail(getNVal(ael, "email")); address.setFax(getNVal(ael, "fax")); address.setHomepage(getNVal(ael, "homepage")); address.setMisc(getNVal(ael, "misc")); address.setMobilePhone(getNVal(ael, "mobilePhone")); address.setPhone1(getNVal(ael, "phone1")); address.setPhone2(getNVal(ael, "phone2")); address.setPostOfficeBox(getNVal(ael, "postOfficeBox")); address.setRoomNr(getNVal(ael, "roomNr")); address.setStreet(getNVal(ael, "street")); address.setStreetNr(getNVal(ael, "streetNr")); address.setZipCode(getNVal(ael, "zipCode")); address.setExternalId(getNVal(ael, "externalId")); address.setLastModifiedDate(new Date().getTime()); getHibernateTemplate().save(address); return address.getAddressId(); } private String getNVal(org.w3c.dom.Element ael, String nodeName) { String tmp = XercesHelper.getNodeValue(ael, "./" + nodeName); if (tmp.equals("null") || tmp.equals("")) { return null; } return tmp; } /** * @see de.juwimm.cms.components.model.AddressHbm#create(de.juwimm.cms.components.vo.AddressValue) */ @Override public java.lang.Long handleCreate(de.juwimm.cms.components.vo.AddressValue value) { Long id = null; AddressHbm address = AddressHbm.Factory.newInstance(); try { id = new Long(sequenceHbmDao.getNextSequenceNumber("address.address_id").longValue()); address.setAddressId(id); } catch (Exception e) { log.error("Error creating new primary key: ", e); } address.setRoomNr(value.getRoomNr()); address.setBuildingLevel(value.getBuildingLevel()); address.setBuildingNr(value.getBuildingNr()); address.setStreet(value.getStreet()); address.setStreetNr(value.getStreetNr()); address.setPostOfficeBox(value.getPostOfficeBox()); address.setCountryCode(value.getCountryCode()); address.setCountry(value.getCountry()); address.setCity(value.getCity()); address.setZipCode(value.getZipCode()); address.setPhone1(value.getPhone1()); address.setPhone2(value.getPhone2()); address.setFax(value.getFax()); address.setMobilePhone(value.getMobilePhone()); address.setEmail(value.getEmail()); address.setHomepage(value.getHomepage()); address.setMisc(value.getMisc()); address.setAddressType(value.getAddressType()); address.setExternalId(value.getExternalId()); address.setLastModifiedDate(new Date().getTime()); getHibernateTemplate().save(address); return address.getAddressId(); } /* * (non-Javadoc) * * @see de.juwimm.cms.components.model.AddressHbmDaoBase#update(de.juwimm.cms.components.model.AddressHbm) */ @Override public void update(AddressHbm addressHbm) { addressHbm.setLastModifiedDate(new Date().getTime()); super.update(addressHbm); } @Override protected void handleGetTheMostOfNow() throws Exception { // just a hack to prevent AndroMDA from generating this file again // happens if no method is modeled } @Override protected AddressHbm handleCloneAddress(AddressHbm oldAddress) throws Exception { AddressHbm address = AddressHbm.Factory.newInstance(); Long id = new Long(sequenceHbmDao.getNextSequenceNumber("address.address_id").longValue()); address.setAddressId(id); address.setRoomNr(oldAddress.getRoomNr()); address.setBuildingLevel(oldAddress.getBuildingLevel()); address.setBuildingNr(oldAddress.getBuildingNr()); address.setStreet(oldAddress.getStreet()); address.setStreetNr(oldAddress.getStreetNr()); address.setPostOfficeBox(oldAddress.getPostOfficeBox()); address.setCountryCode(oldAddress.getCountryCode()); address.setCountry(oldAddress.getCountry()); address.setCity(oldAddress.getCity()); address.setZipCode(oldAddress.getZipCode()); address.setPhone1(oldAddress.getPhone1()); address.setPhone2(oldAddress.getPhone2()); address.setFax(oldAddress.getFax()); address.setMobilePhone(oldAddress.getMobilePhone()); address.setEmail(oldAddress.getEmail()); address.setHomepage(oldAddress.getHomepage()); address.setMisc(oldAddress.getMisc()); address.setAddressType(oldAddress.getAddressType()); address.setExternalId(oldAddress.getExternalId()); address.setLastModifiedDate(new Date().getTime()); address = create(address); return address; } }