1 package com.dotmarketing.portlets.structure.factories; 2 3 import java.util.List ; 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 public static Field getFieldByInode(long inode) 14 { 15 return (Field) InodeFactory.getInode(inode,Field.class); 16 } 17 18 @SuppressWarnings ("unchecked") 19 public static List <Field> getFieldByStructureType(long structureInode) 20 { 21 String condition = "structure_inode = '" + structureInode + "'"; 22 String order = "sort_order asc, field_name asc"; 23 return InodeFactory.getInodesOfClassByConditionAndOrderBy(Field.class,condition,order); 24 } 25 26 public static List <Field> getFieldByStructureTypeNoLock(long structureInode) 27 { 28 DotHibernate dh = new DotHibernate(Field.class); 29 StringBuffer querie = new StringBuffer (); 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 getFieldsByContentletField(String dataType, long fieldInode, long structureInode) 40 { 41 String condition = "structure_inode = '" + structureInode + "' and field_contentlet like '" + dataType + "%' and inode <> " + fieldInode; 42 String order = "field_contentlet"; 43 return InodeFactory.getInodesOfClassByConditionAndOrderBy(Field.class,condition,order); 44 } 45 46 public static Field getFieldByName(long structureInode, String fieldName) 47 { 48 String condition = "structure_inode = '" + structureInode + "' and field_name = '" + fieldName + "'"; 49 return (Field) InodeFactory.getInodeOfClassByCondition(Field.class,condition); 50 } 51 52 public static Field getFieldByName(String structureType, String fieldName) 53 { 54 Structure st = StructureFactory.getStructureByType(structureType); 55 String condition = "structure_inode = '" + st.getInode() + "' and field_name = '" + fieldName + "'"; 56 return (Field) InodeFactory.getInodeOfClassByCondition(Field.class,condition); 57 } 58 59 public static void saveField(Field field) 61 { 62 InodeFactory.saveInode(field); 63 } 64 65 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 |