001    /**
002     * Copyright (c) 2000-2011 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            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    }