001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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            public Shard addShard(String className, long classPK, String name)
031                    throws SystemException {
032    
033                    long classNameId = PortalUtil.getClassNameId(className);
034    
035                    if (Validator.isNull(name)) {
036                            name = PropsValues.SHARD_DEFAULT_NAME;
037                    }
038    
039                    long shardId = counterLocalService.increment();
040    
041                    Shard shard = shardPersistence.create(shardId);
042    
043                    shard.setClassNameId(classNameId);
044                    shard.setClassPK(classPK);
045                    shard.setName(name);
046    
047                    shardPersistence.update(shard, false);
048    
049                    return shard;
050            }
051    
052            public Shard getShard(String className, long classPK)
053                    throws PortalException, SystemException {
054    
055                    long classNameId = PortalUtil.getClassNameId(className);
056    
057                    return shardPersistence.findByC_C(classNameId, classPK);
058            }
059    
060    }