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.portal.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.model.Shard;
021    import com.liferay.portal.service.base.ShardLocalServiceBaseImpl;
022    import com.liferay.portal.util.PortalUtil;
023    import com.liferay.portal.util.PropsValues;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class ShardLocalServiceImpl extends ShardLocalServiceBaseImpl {
029    
030            @Override
031            public Shard addShard(String className, long classPK, String name)
032                    throws SystemException {
033    
034                    long classNameId = PortalUtil.getClassNameId(className);
035    
036                    if (Validator.isNull(name)) {
037                            name = PropsValues.SHARD_DEFAULT_NAME;
038                    }
039    
040                    long shardId = counterLocalService.increment();
041    
042                    Shard shard = shardPersistence.create(shardId);
043    
044                    shard.setClassNameId(classNameId);
045                    shard.setClassPK(classPK);
046                    shard.setName(name);
047    
048                    shardPersistence.update(shard, false);
049    
050                    return shard;
051            }
052    
053            @Override
054            public Shard getShard(String className, long classPK)
055                    throws PortalException, SystemException {
056    
057                    long classNameId = PortalUtil.getClassNameId(className);
058    
059                    return shardPersistence.findByC_C(classNameId, classPK);
060            }
061    
062    }