org.xaloon.wicket.plugin.blog.dao.JpaBlogDao Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xaloon-wicket-plugin-blog Show documentation
Show all versions of xaloon-wicket-plugin-blog Show documentation
blog plugin for apache wicket
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.xaloon.wicket.plugin.blog.dao;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.commons.lang.StringUtils;
import org.xaloon.core.api.image.model.ImageComposition;
import org.xaloon.core.api.persistence.PersistenceServices;
import org.xaloon.core.api.persistence.QueryBuilder;
import org.xaloon.core.api.storage.FileDescriptorDao;
import org.xaloon.core.api.user.UserFacade;
import org.xaloon.core.api.user.model.User;
import org.xaloon.wicket.plugin.blog.model.BlogEntry;
import org.xaloon.wicket.plugin.blog.model.BlogEntrySearchRequest;
import org.xaloon.wicket.plugin.blog.model.JpaBlogEntry;
import org.xaloon.wicket.plugin.blog.model.JpaBlogEntryImageComposition;
import org.xaloon.wicket.plugin.blog.path.BlogEntryPathTypeEnum;
/**
* @author vytautas r.
*/
@Named
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@TransactionManagement(TransactionManagementType.CONTAINER)
public class JpaBlogDao implements BlogDao {
/**
*
*/
private static final long serialVersionUID = 1L;
@Inject
private FileDescriptorDao fileDescriptorDao;
@Inject
private UserFacade userFacade;
@Inject
@Named("persistenceServices")
private PersistenceServices persistenceServices;
public BlogEntry save(BlogEntry blogEntry) {
blogEntry = persistenceServices.edit(blogEntry);
return blogEntry;
}
public boolean deleteBlogEntry(BlogEntry blogEntry) {
if (blogEntry == null) {
throw new IllegalArgumentException("Blog entry was not provided!");
}
persistenceServices.remove(JpaBlogEntry.class, blogEntry.getId());
return true;
}
@Override
public Long getCount() {
return persistenceServices.getCount(JpaBlogEntry.class);
}
@Override
public Long getCount(BlogEntrySearchRequest blogEntrySearchRequest) {
QueryBuilder queryBuilder = createQueryBuilder("select count(be) ", blogEntrySearchRequest);
return persistenceServices.executeQuerySingle(queryBuilder);
}
@Override
public JpaBlogEntry findEntryByPath(String username, String blogEntryPath) {
BlogEntrySearchRequest blogEntrySearchRequest = new BlogEntrySearchRequest();
blogEntrySearchRequest.setUsername(username);
blogEntrySearchRequest.setBlogEntryPath(blogEntryPath);
QueryBuilder queryBuilder = createQueryBuilder("select be ", blogEntrySearchRequest);
return persistenceServices.executeQuerySingle(queryBuilder);
}
@Override
public List findAvailableBlogEntryList(BlogEntrySearchRequest blogEntrySearchRequest, int first, int count) {
QueryBuilder queryBuilder = createQueryBuilder("select be.id, be.customPath, be.path, cat.id, be.blogEntryPathType, o.username, be.description, th.id, be.createDate, be.title, count(img) ", blogEntrySearchRequest);
queryBuilder.setFirstRow(first);
queryBuilder.setCount(count);
queryBuilder.addGroup("be.id, be.customPath, be.path, cat.id, be.blogEntryPathType, o.username, be.description, th.id, be.createDate, be.title, be.sticky, be.updateDate");
queryBuilder.addOrderBy("be.sticky desc, be.updateDate desc");
List