Commit 8ebccdb9 authored by saurabh's avatar saurabh
Browse files

added new code for tag addition in database

parent 2199eefa
......@@ -119,6 +119,8 @@ public interface TagDataLocalService extends BaseLocalService,
@Indexable(type = IndexableType.REINDEX)
public TagData updateTagData(TagData tagData);
public boolean findTagData(java.lang.String tag);
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public ActionableDynamicQuery getActionableDynamicQuery();
......
......@@ -113,6 +113,10 @@ public class TagDataLocalServiceUtil {
return getService().updateTagData(tagData);
}
public static boolean findTagData(java.lang.String tag) {
return getService().findTagData(tag);
}
public static com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery getActionableDynamicQuery() {
return getService().getActionableDynamicQuery();
}
......
......@@ -110,6 +110,11 @@ public class TagDataLocalServiceWrapper implements TagDataLocalService,
return _tagDataLocalService.updateTagData(tagData);
}
@Override
public boolean findTagData(java.lang.String tag) {
return _tagDataLocalService.findTagData(tag);
}
@Override
public com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery getActionableDynamicQuery() {
return _tagDataLocalService.getActionableDynamicQuery();
......
......@@ -42,6 +42,51 @@ public interface TagDataPersistence extends BasePersistence<TagData> {
* Never modify or reference this interface directly. Always use {@link TagDataUtil} to access the tag data persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this interface.
*/
/**
* Returns the tag data where Tag = &#63; or throws a {@link NoSuchTagDataException} if it could not be found.
*
* @param Tag the tag
* @return the matching tag data
* @throws NoSuchTagDataException if a matching tag data could not be found
*/
public TagData findByTagName(java.lang.String Tag)
throws NoSuchTagDataException;
/**
* Returns the tag data where Tag = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
*
* @param Tag the tag
* @return the matching tag data, or <code>null</code> if a matching tag data could not be found
*/
public TagData fetchByTagName(java.lang.String Tag);
/**
* Returns the tag data where Tag = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
*
* @param Tag the tag
* @param retrieveFromCache whether to retrieve from the finder cache
* @return the matching tag data, or <code>null</code> if a matching tag data could not be found
*/
public TagData fetchByTagName(java.lang.String Tag,
boolean retrieveFromCache);
/**
* Removes the tag data where Tag = &#63; from the database.
*
* @param Tag the tag
* @return the tag data that was removed
*/
public TagData removeByTagName(java.lang.String Tag)
throws NoSuchTagDataException;
/**
* Returns the number of tag datas where Tag = &#63;.
*
* @param Tag the tag
* @return the number of matching tag datas
*/
public int countByTagName(java.lang.String Tag);
/**
* Caches the tag data in the entity cache if it is enabled.
*
......
......@@ -109,6 +109,61 @@ public class TagDataUtil {
return getPersistence().update(tagData, serviceContext);
}
/**
* Returns the tag data where Tag = &#63; or throws a {@link NoSuchTagDataException} if it could not be found.
*
* @param Tag the tag
* @return the matching tag data
* @throws NoSuchTagDataException if a matching tag data could not be found
*/
public static TagData findByTagName(java.lang.String Tag)
throws analysisService.exception.NoSuchTagDataException {
return getPersistence().findByTagName(Tag);
}
/**
* Returns the tag data where Tag = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
*
* @param Tag the tag
* @return the matching tag data, or <code>null</code> if a matching tag data could not be found
*/
public static TagData fetchByTagName(java.lang.String Tag) {
return getPersistence().fetchByTagName(Tag);
}
/**
* Returns the tag data where Tag = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
*
* @param Tag the tag
* @param retrieveFromCache whether to retrieve from the finder cache
* @return the matching tag data, or <code>null</code> if a matching tag data could not be found
*/
public static TagData fetchByTagName(java.lang.String Tag,
boolean retrieveFromCache) {
return getPersistence().fetchByTagName(Tag, retrieveFromCache);
}
/**
* Removes the tag data where Tag = &#63; from the database.
*
* @param Tag the tag
* @return the tag data that was removed
*/
public static TagData removeByTagName(java.lang.String Tag)
throws analysisService.exception.NoSuchTagDataException {
return getPersistence().removeByTagName(Tag);
}
/**
* Returns the number of tag datas where Tag = &#63;.
*
* @param Tag the tag
* @return the number of matching tag datas
*/
public static int countByTagName(java.lang.String Tag) {
return getPersistence().countByTagName(Tag);
}
/**
* Caches the tag data in the entity cache if it is enabled.
*
......
......@@ -42,6 +42,9 @@
<entity name="TagData" local-service="true">
<column name="TagID" type="long" primary="true" id-type="increment"></column>
<column name="Tag" type="String"></column>
<finder name="TagName" return-type="String">
<finder-column name="Tag"></finder-column>
</finder>
</entity>
<exceptions>
<exception>NoSuchAlgorithm</exception>
......
......@@ -89,7 +89,11 @@ public class TagDataModelImpl extends BaseModelImpl<TagData>
public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(analysisService.service.util.ServiceProps.get(
"value.object.finder.cache.enabled.analysisService.model.TagData"),
true);
public static final boolean COLUMN_BITMASK_ENABLED = false;
public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(analysisService.service.util.ServiceProps.get(
"value.object.column.bitmask.enabled.analysisService.model.TagData"),
true);
public static final long TAG_COLUMN_BITMASK = 1L;
public static final long TAGID_COLUMN_BITMASK = 2L;
/**
* Converts the soap model instance into a normal model instance.
......@@ -218,9 +222,23 @@ public class TagDataModelImpl extends BaseModelImpl<TagData>
@Override
public void setTag(String Tag) {
_columnBitmask |= TAG_COLUMN_BITMASK;
if (_originalTag == null) {
_originalTag = _Tag;
}
_Tag = Tag;
}
public String getOriginalTag() {
return GetterUtil.getString(_originalTag);
}
public long getColumnBitmask() {
return _columnBitmask;
}
@Override
public ExpandoBridge getExpandoBridge() {
return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
......@@ -310,6 +328,11 @@ public class TagDataModelImpl extends BaseModelImpl<TagData>
@Override
public void resetOriginalValues() {
TagDataModelImpl tagDataModelImpl = this;
tagDataModelImpl._originalTag = tagDataModelImpl._Tag;
tagDataModelImpl._columnBitmask = 0;
}
@Override
......@@ -370,5 +393,7 @@ public class TagDataModelImpl extends BaseModelImpl<TagData>
};
private long _TagID;
private String _Tag;
private String _originalTag;
private long _columnBitmask;
private TagData _escapedModel;
}
\ No newline at end of file
......@@ -14,10 +14,12 @@
package analysisService.service.impl;
import analysisService.exception.NoSuchTagDataException;
import analysisService.model.TagData;
import analysisService.model.impl.TagDataImpl;
import analysisService.service.TagDataLocalServiceUtil;
import analysisService.service.base.TagDataLocalServiceBaseImpl;
import analysisService.service.persistence.TagDataUtil;
/**
* The implementation of the tag data local service.
......@@ -39,13 +41,28 @@ public class TagDataLocalServiceImpl extends TagDataLocalServiceBaseImpl {
*
* Never reference this class directly. Always use {@link analysisService.service.TagDataLocalServiceUtil} to access the tag data local service.
*/
/**
* adds Tag String to the Tag table
* auto increments the Tag ID - PK
*/
public long addNewTag(String tag){
TagData newTagData = new TagDataImpl();
newTagData.setTag(tag);
TagDataLocalServiceUtil.addTagData(newTagData);
return newTagData.getPrimaryKey();
}
/**
* Can be used to check for duplicate strings in the Tag table
* returns true if new tag is already present
*/
public boolean findTagData(String tag){
try{
TagDataUtil.findByTagName(tag);
}catch(NoSuchTagDataException ex){
return false;
}
return true;
}
}
\ No newline at end of file
......@@ -29,6 +29,7 @@ import com.liferay.portal.kernel.dao.orm.EntityCache;
import com.liferay.portal.kernel.dao.orm.FinderCache;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.log.Log;
......@@ -37,6 +38,7 @@ import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.spring.extender.service.ServiceReference;
import java.io.Serializable;
......@@ -47,6 +49,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
......@@ -83,6 +86,249 @@ public class TagDataPersistenceImpl extends BasePersistenceImpl<TagData>
public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TagDataModelImpl.ENTITY_CACHE_ENABLED,
TagDataModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
public static final FinderPath FINDER_PATH_FETCH_BY_TAGNAME = new FinderPath(TagDataModelImpl.ENTITY_CACHE_ENABLED,
TagDataModelImpl.FINDER_CACHE_ENABLED, TagDataImpl.class,
FINDER_CLASS_NAME_ENTITY, "fetchByTagName",
new String[] { String.class.getName() },
TagDataModelImpl.TAG_COLUMN_BITMASK);
public static final FinderPath FINDER_PATH_COUNT_BY_TAGNAME = new FinderPath(TagDataModelImpl.ENTITY_CACHE_ENABLED,
TagDataModelImpl.FINDER_CACHE_ENABLED, Long.class,
FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTagName",
new String[] { String.class.getName() });
/**
* Returns the tag data where Tag = &#63; or throws a {@link NoSuchTagDataException} if it could not be found.
*
* @param Tag the tag
* @return the matching tag data
* @throws NoSuchTagDataException if a matching tag data could not be found
*/
@Override
public TagData findByTagName(String Tag) throws NoSuchTagDataException {
TagData tagData = fetchByTagName(Tag);
if (tagData == null) {
StringBundler msg = new StringBundler(4);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("Tag=");
msg.append(Tag);
msg.append(StringPool.CLOSE_CURLY_BRACE);
if (_log.isDebugEnabled()) {
_log.debug(msg.toString());
}
throw new NoSuchTagDataException(msg.toString());
}
return tagData;
}
/**
* Returns the tag data where Tag = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
*
* @param Tag the tag
* @return the matching tag data, or <code>null</code> if a matching tag data could not be found
*/
@Override
public TagData fetchByTagName(String Tag) {
return fetchByTagName(Tag, true);
}
/**
* Returns the tag data where Tag = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
*
* @param Tag the tag
* @param retrieveFromCache whether to retrieve from the finder cache
* @return the matching tag data, or <code>null</code> if a matching tag data could not be found
*/
@Override
public TagData fetchByTagName(String Tag, boolean retrieveFromCache) {
Object[] finderArgs = new Object[] { Tag };
Object result = null;
if (retrieveFromCache) {
result = finderCache.getResult(FINDER_PATH_FETCH_BY_TAGNAME,
finderArgs, this);
}
if (result instanceof TagData) {
TagData tagData = (TagData)result;
if (!Objects.equals(Tag, tagData.getTag())) {
result = null;
}
}
if (result == null) {
StringBundler query = new StringBundler(3);
query.append(_SQL_SELECT_TAGDATA_WHERE);
boolean bindTag = false;
if (Tag == null) {
query.append(_FINDER_COLUMN_TAGNAME_TAG_1);
}
else if (Tag.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_TAGNAME_TAG_3);
}
else {
bindTag = true;
query.append(_FINDER_COLUMN_TAGNAME_TAG_2);
}
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
if (bindTag) {
qPos.add(Tag);
}
List<TagData> list = q.list();
if (list.isEmpty()) {
finderCache.putResult(FINDER_PATH_FETCH_BY_TAGNAME,
finderArgs, list);
}
else {
if (list.size() > 1) {
Collections.sort(list, Collections.reverseOrder());
if (_log.isWarnEnabled()) {
_log.warn(
"TagDataPersistenceImpl.fetchByTagName(String, boolean) with parameters (" +
StringUtil.merge(finderArgs) +
") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
}
}
TagData tagData = list.get(0);
result = tagData;
cacheResult(tagData);
if ((tagData.getTag() == null) ||
!tagData.getTag().equals(Tag)) {
finderCache.putResult(FINDER_PATH_FETCH_BY_TAGNAME,
finderArgs, tagData);
}
}
}
catch (Exception e) {
finderCache.removeResult(FINDER_PATH_FETCH_BY_TAGNAME,
finderArgs);
throw processException(e);
}
finally {
closeSession(session);
}
}
if (result instanceof List<?>) {
return null;
}
else {
return (TagData)result;
}
}
/**
* Removes the tag data where Tag = &#63; from the database.
*
* @param Tag the tag
* @return the tag data that was removed
*/
@Override
public TagData removeByTagName(String Tag) throws NoSuchTagDataException {
TagData tagData = findByTagName(Tag);
return remove(tagData);
}
/**
* Returns the number of tag datas where Tag = &#63;.
*
* @param Tag the tag
* @return the number of matching tag datas
*/
@Override
public int countByTagName(String Tag) {
FinderPath finderPath = FINDER_PATH_COUNT_BY_TAGNAME;
Object[] finderArgs = new Object[] { Tag };
Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
if (count == null) {
StringBundler query = new StringBundler(2);
query.append(_SQL_COUNT_TAGDATA_WHERE);
boolean bindTag = false;
if (Tag == null) {
query.append(_FINDER_COLUMN_TAGNAME_TAG_1);
}
else if (Tag.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_TAGNAME_TAG_3);
}
else {
bindTag = true;
query.append(_FINDER_COLUMN_TAGNAME_TAG_2);
}
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
if (bindTag) {
qPos.add(Tag);
}
count = (Long)q.uniqueResult();
finderCache.putResult(finderPath, finderArgs, count);
}
catch (Exception e) {
finderCache.removeResult(finderPath, finderArgs);
throw processException(e);
}
finally {
closeSession(session);
}
}
return count.intValue();
}
private static final String _FINDER_COLUMN_TAGNAME_TAG_1 = "tagData.Tag IS NULL";
private static final String _FINDER_COLUMN_TAGNAME_TAG_2 = "tagData.Tag = ?";
private static final String _FINDER_COLUMN_TAGNAME_TAG_3 = "(tagData.Tag IS NULL OR tagData.Tag = '')";
public TagDataPersistenceImpl() {
setModelClass(TagData.class);
......@@ -98,6 +344,9 @@ public class TagDataPersistenceImpl extends BasePersistenceImpl<TagData>
entityCache.putResult(TagDataModelImpl.ENTITY_CACHE_ENABLED,
TagDataImpl.class, tagData.getPrimaryKey(), tagData);
finderCache.putResult(FINDER_PATH_FETCH_BY_TAGNAME,
new Object[] { tagData.getTag() }, tagData);
tagData.resetOriginalValues();
}
......@@ -149,6 +398,8 @@ public class TagDataPersistenceImpl extends BasePersistenceImpl<TagData>
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
clearUniqueFindersCache((TagDataModelImpl)tagData, true);
}
@Override
......@@ -159,6 +410,35 @@ public class TagDataPersistenceImpl extends BasePersistenceImpl<TagData>
for (TagData tagData : tagDatas) {