/** * examines all {@link Type types} for this class and stores pointers to those fields which * represent {@link IObject} instances. These fields may need to be locked when an object of * this type is created or updated. */ Locks(ClassMetadata classMetadata) { this.cm = classMetadata; String[] name = cm.getPropertyNames(); Type[] type = cm.getPropertyTypes(); List<String[]> checks = new ArrayList<String[]>(); List<String[]> groupChecks = new ArrayList<String[]>(); this.size = type.length; this.include = new boolean[size]; this.subnames = new String[size][]; this.subtypes = new Type[size][]; for (int i = 0; i < type.length; i++) { if (type[i].isComponentType() && ((ComponentType) type[i]).isEmbedded()) { EmbeddedComponentType embedded = (EmbeddedComponentType) type[i]; String[] sub_name = embedded.getPropertyNames(); Type[] sub_type = embedded.getSubtypes(); List<String> name_list = new ArrayList<String>(); List<Type> type_list = new ArrayList<Type>(); for (int j = 0; j < sub_type.length; j++) { if (IObject.class.isAssignableFrom(sub_type[j].getReturnedClass())) { String path = name[i] + "." + sub_name[j]; name_list.add(path); type_list.add(sub_type[j]); addCheck(checks, groupChecks, sub_type[j].getReturnedClass(), path); } } add( i, name_list.toArray(new String[name_list.size()]), type_list.toArray(new Type[type_list.size()])); } else if (IObject.class.isAssignableFrom(type[i].getReturnedClass())) { add(i); addCheck(checks, groupChecks, type[i].getReturnedClass(), name[i]); // Create checks for } } this.checks = checks.toArray(new String[checks.size()][]); this.groupChecks = groupChecks.toArray(new String[groupChecks.size()][]); }
Immutables(ClassMetadata metadata) { if (metadata instanceof EntityPersister) { this.ep = (EntityPersister) metadata; } else { throw new IllegalArgumentException( "Metadata passed to Immutables" + " must be an instanceof EntityPersister, not " + (metadata == null ? null : metadata.getClass())); } List<String> retVal = new ArrayList<String>(); Type[] type = this.ep.getPropertyTypes(); String[] name = this.ep.getPropertyNames(); boolean[] up = this.ep.getPropertyUpdateability(); for (int i = 0; i < type.length; i++) { // not updateable, so our work (for this type) is done. if (!up[i]) { retVal.add(name[i]); } // updateable, but maybe a component subtype is NOT. else if (type[i].isComponentType() && ((ComponentType) type[i]).isEmbedded()) { EmbeddedComponentType embedded = (EmbeddedComponentType) type[i]; String[] sub_name = embedded.getPropertyNames(); Type[] sub_type = embedded.getSubtypes(); List<String> name_list = new ArrayList<String>(); List<Type> type_list = new ArrayList<Type>(); for (int j = 0; j < sub_type.length; j++) { // INCOMPLETE !!! } } } immutableFields = retVal.toArray(new String[retVal.size()]); }