KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > portlets > structure > factories > FieldFactory


1 package com.dotmarketing.portlets.structure.factories;
2
3 import java.util.List JavaDoc;
4
5 import com.dotmarketing.db.DotHibernate;
6 import com.dotmarketing.factories.InodeFactory;
7 import com.dotmarketing.portlets.structure.model.Field;
8 import com.dotmarketing.portlets.structure.model.Structure;
9
10 public class FieldFactory {
11     
12     //### READ ###
13
public static Field getFieldByInode(long inode)
14     {
15         return (Field) InodeFactory.getInode(inode,Field.class);
16     }
17     
18     @SuppressWarnings JavaDoc("unchecked")
19     public static List JavaDoc<Field> getFieldByStructureType(long structureInode)
20     {
21         String JavaDoc condition = "structure_inode = '" + structureInode + "'";
22         String JavaDoc order = "sort_order asc, field_name asc";
23         return InodeFactory.getInodesOfClassByConditionAndOrderBy(Field.class,condition,order);
24     }
25     
26     public static List JavaDoc<Field> getFieldByStructureTypeNoLock(long structureInode)
27     {
28         DotHibernate dh = new DotHibernate(Field.class);
29         StringBuffer JavaDoc querie = new StringBuffer JavaDoc();
30         querie.append("select {field.*} from field with (nolock), inode field_1_ with (nolock) ");
31         querie.append("where field.inode = field_1_.inode and field.structure_inode = "+structureInode);
32         querie.append(" order by sort_order asc, field_name asc");
33         
34         dh.setSQLQuery(querie.toString());
35         
36         return dh.list();
37     }
38     
39     public static List JavaDoc getFieldsByContentletField(String JavaDoc dataType, long fieldInode, long structureInode)
40     {
41         String JavaDoc condition = "structure_inode = '" + structureInode + "' and field_contentlet like '" + dataType + "%' and inode <> " + fieldInode;
42         String JavaDoc order = "field_contentlet";
43         return InodeFactory.getInodesOfClassByConditionAndOrderBy(Field.class,condition,order);
44     }
45
46     public static Field getFieldByName(long structureInode, String JavaDoc fieldName)
47     {
48         String JavaDoc condition = "structure_inode = '" + structureInode + "' and field_name = '" + fieldName + "'";
49         return (Field) InodeFactory.getInodeOfClassByCondition(Field.class,condition);
50     }
51
52     public static Field getFieldByName(String JavaDoc structureType, String JavaDoc fieldName)
53     {
54         Structure st = StructureFactory.getStructureByType(structureType);
55         String JavaDoc condition = "structure_inode = '" + st.getInode() + "' and field_name = '" + fieldName + "'";
56         return (Field) InodeFactory.getInodeOfClassByCondition(Field.class,condition);
57     }
58
59     //### CREATE AND UPDATE ###
60
public static void saveField(Field field)
61     {
62         InodeFactory.saveInode(field);
63     }
64     
65     //### DELETE ###
66
public static void deleteField(long inode)
67     {
68         Field field = getFieldByInode(inode);
69         deleteField(field);
70     }
71     
72     public static void deleteField(Field field)
73     {
74         InodeFactory.deleteInode(field);
75     }
76 }
77
Popular Tags