| 1 | |
package org.jtheque.primary.services.impl; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.jtheque.core.managers.persistence.able.DataListener; |
| 20 | |
import org.jtheque.primary.PrimaryUtils; |
| 21 | |
import org.jtheque.primary.dao.able.IDaoTypes; |
| 22 | |
import org.jtheque.primary.od.able.Type; |
| 23 | |
import org.jtheque.primary.services.able.ITypesService; |
| 24 | |
import org.springframework.transaction.annotation.Transactional; |
| 25 | |
|
| 26 | |
import javax.annotation.Resource; |
| 27 | |
import java.util.Collection; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | 0 | public final class TypesService implements ITypesService { |
| 35 | |
@Resource |
| 36 | |
private IDaoTypes daoTypes; |
| 37 | |
|
| 38 | |
private Type defaultType; |
| 39 | |
|
| 40 | |
@Override |
| 41 | |
@Transactional |
| 42 | |
public Type getDefaultType() { |
| 43 | 0 | if (defaultType == null) { |
| 44 | 0 | defaultType = daoTypes.getType("Base"); |
| 45 | |
|
| 46 | 0 | if (defaultType == null) { |
| 47 | 0 | defaultType = getEmptyType(); |
| 48 | 0 | defaultType.setName("Base"); |
| 49 | 0 | defaultType.setPrimaryImpl(PrimaryUtils.getPrimaryImpl()); |
| 50 | |
|
| 51 | 0 | daoTypes.create(defaultType); |
| 52 | |
} |
| 53 | |
} |
| 54 | |
|
| 55 | 0 | return defaultType; |
| 56 | |
} |
| 57 | |
|
| 58 | |
@Override |
| 59 | |
public Collection<Type> getTypes() { |
| 60 | 0 | return daoTypes.getTypes(); |
| 61 | |
} |
| 62 | |
|
| 63 | |
@Override |
| 64 | |
@Transactional |
| 65 | |
public void create(Type type) { |
| 66 | 0 | daoTypes.create(type); |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
@Transactional |
| 71 | |
public boolean delete(Type type) { |
| 72 | 0 | return daoTypes.delete(type); |
| 73 | |
} |
| 74 | |
|
| 75 | |
@Override |
| 76 | |
@Transactional |
| 77 | |
public void save(Type type) { |
| 78 | 0 | daoTypes.save(type); |
| 79 | 0 | } |
| 80 | |
|
| 81 | |
@Override |
| 82 | |
public boolean exists(Type type) { |
| 83 | 0 | return daoTypes.exists(type); |
| 84 | |
} |
| 85 | |
|
| 86 | |
@Override |
| 87 | |
public Type getType(String name) { |
| 88 | 0 | return daoTypes.getType(name); |
| 89 | |
} |
| 90 | |
|
| 91 | |
@Override |
| 92 | |
public boolean hasNoTypes() { |
| 93 | 0 | return daoTypes.getTypes().isEmpty(); |
| 94 | |
} |
| 95 | |
|
| 96 | |
@Override |
| 97 | |
@Transactional |
| 98 | |
public void createAll(Iterable<Type> types) { |
| 99 | 0 | for (Type type : types) { |
| 100 | 0 | daoTypes.create(type); |
| 101 | |
} |
| 102 | 0 | } |
| 103 | |
|
| 104 | |
@Override |
| 105 | |
public Type getEmptyType() { |
| 106 | 0 | return daoTypes.createType(); |
| 107 | |
} |
| 108 | |
|
| 109 | |
@Override |
| 110 | |
public Collection<Type> getDatas() { |
| 111 | 0 | return daoTypes.getTypes(); |
| 112 | |
} |
| 113 | |
|
| 114 | |
@Override |
| 115 | |
public void addDataListener(DataListener listener) { |
| 116 | 0 | daoTypes.addDataListener(listener); |
| 117 | 0 | } |
| 118 | |
|
| 119 | |
@Override |
| 120 | |
@Transactional |
| 121 | |
public void clearAll() { |
| 122 | 0 | daoTypes.clearAll(); |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
@Override |
| 126 | |
public String getDataType() { |
| 127 | 0 | return DATA_TYPE; |
| 128 | |
} |
| 129 | |
} |