001    /**
002     * Copyright (c) 2000-2013 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.portlet.dynamicdatamapping.storage;
016    
017    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
018    import com.liferay.portal.kernel.util.OrderByComparator;
019    import com.liferay.portal.service.ServiceContext;
020    import com.liferay.portlet.dynamicdatamapping.StorageException;
021    import com.liferay.portlet.dynamicdatamapping.storage.query.Condition;
022    
023    import java.util.List;
024    import java.util.Map;
025    
026    /**
027     * @author Eduardo Lundgren
028     */
029    public class StorageEngineUtil {
030    
031            public static long create(
032                            long companyId, long ddmStructureId, Fields fields,
033                            ServiceContext serviceContext)
034                    throws StorageException {
035    
036                    return getStorageEngine().create(
037                            companyId, ddmStructureId, fields, serviceContext);
038            }
039    
040            public static void deleteByClass(long classPK) throws StorageException {
041                    getStorageEngine().deleteByClass(classPK);
042            }
043    
044            public static void deleteByDDMStructure(long ddmStructureId)
045                    throws StorageException {
046    
047                    getStorageEngine().deleteByDDMStructure(ddmStructureId);
048            }
049    
050            public static Fields getFields(long classPK) throws StorageException {
051                    return getStorageEngine().getFields(classPK);
052            }
053    
054            public static Fields getFields(long classPK, List<String> fieldNames)
055                    throws StorageException {
056    
057                    return getStorageEngine().getFields(classPK, fieldNames);
058            }
059    
060            public static List<Fields> getFieldsList(
061                            long ddmStructureId, List<String> fieldNames)
062                    throws StorageException {
063    
064                    return getStorageEngine().getFieldsList(ddmStructureId, fieldNames);
065            }
066    
067            public static List<Fields> getFieldsList(
068                            long ddmStructureId, List<String> fieldNames,
069                            OrderByComparator orderByComparator)
070                    throws StorageException {
071    
072                    return getStorageEngine().getFieldsList(
073                            ddmStructureId, fieldNames, orderByComparator);
074            }
075    
076            public static List<Fields> getFieldsList(
077                            long ddmStructureId, long[] classPKs, List<String> fieldNames,
078                            OrderByComparator orderByComparator)
079                    throws StorageException {
080    
081                    return getStorageEngine().getFieldsList(
082                            ddmStructureId, classPKs, fieldNames, orderByComparator);
083            }
084    
085            public static List<Fields> getFieldsList(
086                            long ddmStructureId, long[] classPKs,
087                            OrderByComparator orderByComparator)
088                    throws StorageException {
089    
090                    return getStorageEngine().getFieldsList(
091                            ddmStructureId, classPKs, orderByComparator);
092            }
093    
094            public static Map<Long, Fields> getFieldsMap(
095                            long ddmStructureId, long[] classPKs)
096                    throws StorageException {
097    
098                    return getStorageEngine().getFieldsMap(ddmStructureId, classPKs);
099            }
100    
101            public static Map<Long, Fields> getFieldsMap(
102                            long ddmStructureId, long[] classPKs, List<String> fieldNames)
103                    throws StorageException {
104    
105                    return getStorageEngine().getFieldsMap(
106                            ddmStructureId, classPKs, fieldNames);
107            }
108    
109            public static StorageEngine getStorageEngine() {
110                    PortalRuntimePermission.checkGetBeanProperty(StorageEngineUtil.class);
111    
112                    return _storageEngine;
113            }
114    
115            public static List<Fields> query(
116                            long ddmStructureId, List<String> fieldNames, Condition condition,
117                            OrderByComparator orderByComparator)
118                    throws StorageException {
119    
120                    return getStorageEngine().query(
121                            ddmStructureId, fieldNames, condition, orderByComparator);
122            }
123    
124            public static int queryCount(long ddmStructureId, Condition condition)
125                    throws StorageException {
126    
127                    return getStorageEngine().queryCount(ddmStructureId, condition);
128            }
129    
130            public static void update(
131                            long classPK, Fields fields, boolean mergeFields,
132                            ServiceContext serviceContext)
133                    throws StorageException {
134    
135                    getStorageEngine().update(classPK, fields, mergeFields, serviceContext);
136            }
137    
138            public static void update(
139                            long classPK, Fields fields, ServiceContext serviceContext)
140                    throws StorageException {
141    
142                    getStorageEngine().update(classPK, fields, serviceContext);
143            }
144    
145            public void setStorageEngine(StorageEngine storageEngine) {
146                    PortalRuntimePermission.checkSetBeanProperty(getClass());
147    
148                    _storageEngine = storageEngine;
149            }
150    
151            private static StorageEngine _storageEngine;
152    
153    }