001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.model.impl;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.xml.Document;
021    import com.liferay.portal.kernel.xml.DocumentException;
022    import com.liferay.portal.kernel.xml.Element;
023    import com.liferay.portal.kernel.xml.SAXReaderUtil;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class ServiceComponentImpl extends ServiceComponentBaseImpl {
029    
030            public ServiceComponentImpl() {
031            }
032    
033            public String getIndexesSQL() {
034                    return _getData("indexes-sql");
035            }
036    
037            public String getSequencesSQL() {
038                    return _getData("sequences-sql");
039            }
040    
041            public String getTablesSQL() {
042                    return _getData("tables-sql");
043            }
044    
045            @Override
046            public void setData(String data) {
047                    super.setData(data);
048    
049                    _dataEl = null;
050            }
051    
052            private String _getData(String name) {
053                    try {
054                            return _getDataEl().elementText(name);
055                    }
056                    catch (Exception e) {
057                            _log.error(e, e);
058    
059                            return StringPool.BLANK;
060                    }
061            }
062    
063            private Element _getDataEl() throws DocumentException {
064                    if (_dataEl == null) {
065                            Document doc = SAXReaderUtil.read(getData());
066    
067                            _dataEl = doc.getRootElement();
068                    }
069    
070                    return _dataEl;
071            }
072    
073            private static Log _log = LogFactoryUtil.getLog(ServiceComponentImpl.class);
074    
075            private Element _dataEl;
076    
077    }