001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.orm.hibernate.tuplizer.accessors;
020
021import java.lang.reflect.Method;
022
023import lucee.runtime.Component;
024import lucee.runtime.exp.PageException;
025import lucee.runtime.orm.hibernate.CommonUtil;
026import lucee.runtime.orm.hibernate.HibernatePageException;
027import lucee.runtime.type.Collection;
028import lucee.runtime.type.Collection.Key;
029
030import org.hibernate.HibernateException;
031import org.hibernate.engine.SessionFactoryImplementor;
032import org.hibernate.property.Setter;
033
034public final class CFCSetter implements Setter {
035        
036        private Key key;
037
038        /**
039         * Constructor of the class
040         * @param key
041         */
042        public CFCSetter(String key){
043                this(CommonUtil.createKey(key));
044        }
045        
046        /**
047         * Constructor of the class
048         * @param key
049         */
050        public CFCSetter(Collection.Key key){
051                this.key=key;
052        }
053
054        @Override
055        public String getMethodName() {
056                return null;
057        }
058
059        @Override
060        public Method getMethod() {
061                return null;
062        }
063
064        /**
065         * {@inheritDoc}
066         */
067        public void set(Object trg, Object value, SessionFactoryImplementor factory) throws HibernateException {
068                try {
069                        Component cfc = CommonUtil.toComponent(trg);
070                        cfc.getComponentScope().set(key,value);
071                } 
072                catch (PageException pe) {
073                        throw new HibernatePageException(pe);
074                }
075        }
076
077}