PageRenderTime 793ms CodeModel.GetById 659ms app.highlight 3ms RepoModel.GetById 129ms app.codeStats 0ms

/src/main/java/com/google/ie/business/dao/impl/BaseDaoImpl.java

http://thoughtsite.googlecode.com/
Java | 62 lines | 20 code | 9 blank | 33 comment | 4 complexity | 82aa294b7467a4869f3267fe3b0da918 MD5 | raw file
 1/* Copyright 2010 Google Inc.
 2 * 
 3 * Licensed under the Apache License, Version 2.0 (the "License");
 4 * you may not use this file except in compliance with the License.
 5 * You may obtain a copy of the License at
 6 * 
 7 *      http://www.apache.org/licenses/LICENSE-2.0
 8 * 
 9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS.
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License
14 */
15
16package com.google.ie.business.dao.impl;
17
18import com.google.ie.business.dao.BaseDao;
19
20import org.springframework.orm.jdo.support.JdoDaoSupport;
21import org.springframework.transaction.annotation.Transactional;
22
23/**
24 * A data access object specification base class for all data access objects
25 * that use JDO to interact with the datastore.
26 * 
27 * @author Charanjeet singh
28 */
29@Transactional(readOnly = true)
30public abstract class BaseDaoImpl extends JdoDaoSupport implements BaseDao {
31
32    /**
33     * Finds an entity by primary key.
34     * 
35     * @param clazz the class type of the entity to be fetched
36     * @param key the key of the entity to be fetched
37     * @return the fetched entity
38     */
39    @Override
40    public <T> T findEntityByPrimaryKey(java.lang.Class<T> clazz, String key) {
41        return key == null ? null : getJdoTemplate().getObjectById(clazz, key);
42    }
43
44    /**
45     * Persist entity after checking persist manager availability.
46     * 
47     * @param object the object to be persisted
48     * @return the persisted object
49     */
50    public <T> T persist(T object) {
51        if (javax.jdo.JDOHelper.getPersistenceManager(object) == null) {
52            getJdoTemplate().makePersistent(object);
53        } else {
54            javax.jdo.JDOHelper.getPersistenceManager(object)
55                            .makePersistent(object);
56        }
57        return object;
58
59    }
60
61}
62