private List obtainPropertiesNamesUsedToCalculate() throws XavaException { Set result = new HashSet(); Iterator itProperties = getMetaPropertiesCalculated().iterator(); while (itProperties.hasNext()) { MetaProperty metaProperty = (MetaProperty) itProperties.next(); if (!metaProperty.hasCalculator()) continue; MetaSetsContainer metaCalculator = metaProperty.getMetaCalculator(); if (!metaCalculator.containsMetaSets()) continue; Iterator itSets = metaCalculator.getMetaSets().iterator(); while (itSets.hasNext()) { MetaSet set = (MetaSet) itSets.next(); String propertyNameFrom = set.getPropertyNameFrom(); if (!Is.emptyString(propertyNameFrom)) { String qualifiedName = metaProperty.getQualifiedName(); int idx = qualifiedName.indexOf('.'); String ref = idx < 0 ? "" : qualifiedName.substring(0, idx + 1); String qualifiedPropertyNameFrom = ref + propertyNameFrom; if (!getPropertiesNames().contains(qualifiedPropertyNameFrom)) { result.add(qualifiedPropertyNameFrom); } } } } return new ArrayList(result); }
public Collection getCmpFieldsColumnsInMultipleProperties() throws XavaException { Collection cmpFieldsColumnsInMultipleProperties = new ArrayList(); Iterator it = getMetaProperties().iterator(); String table = getMapping().getTableToQualifyColumn(); while (it.hasNext()) { MetaProperty p = (MetaProperty) it.next(); PropertyMapping mapping = p.getMapping(); if (mapping != null) { if (mapping.hasMultipleConverter()) { Iterator itFields = mapping.getCmpFields().iterator(); while (itFields.hasNext()) { CmpField field = (CmpField) itFields.next(); cmpFieldsColumnsInMultipleProperties.add(table + "." + field.getColumn()); } } } } return cmpFieldsColumnsInMultipleProperties; }
private List createAllPropertiesNames() throws XavaException { List result = new ArrayList(); // First the properties from a possible @EmbeddedId for (Iterator itRef = getMetaModel().getMetaReferencesKey().iterator(); itRef.hasNext(); ) { MetaReference ref = (MetaReference) itRef.next(); if (ref.isAggregate()) { for (Iterator itKey = ref.getMetaModelReferenced() .getPropertiesNamesWithoutHiddenNorTransient() .iterator(); itKey.hasNext(); ) { result.add(ref.getName() + "." + itKey.next()); } } } // Now the plain properties result.addAll(getMetaModel().getPropertiesNamesWithoutHiddenNorTransient()); return result; }
private Collection getTableColumns(Collection propertyNames) throws XavaException { Collection tableColumns = new ArrayList(); Iterator it = propertyNames.iterator(); while (it.hasNext()) { String name = (String) it.next(); try { tableColumns.add(getMapping().getQualifiedColumn(name)); } catch (ElementNotFoundException ex) { tableColumns.add("0"); // It will be replaced } } return tableColumns; }
/** @return Not null, read only and of type <tt>MetaProperty</tt>. */ public Collection getMetaPropertiesHiddenCalculated() throws XavaException { if (metaPropertiesHiddenCalculated == null) { metaPropertiesHiddenCalculated = new ArrayList(); Iterator it = getMetaPropertiesHidden().iterator(); while (it.hasNext()) { MetaProperty metaProperty = (MetaProperty) it.next(); if (metaProperty.isCalculated()) { metaPropertiesHiddenCalculated.add(metaProperty); } } } return metaPropertiesHiddenCalculated; }
private String createSelect() throws XavaException { if (hasBaseCondition()) { String baseCondition = getBaseCondition(); if (baseCondition.trim().toUpperCase().startsWith("SELECT ")) { return baseCondition; } } // basic select StringBuffer select = new StringBuffer("select "); Iterator itProperties = getPropertiesNames().iterator(); while (itProperties.hasNext()) { String property = (String) itProperties.next(); if (Strings.isModelName(property)) select.append("0"); // the property is a table name not column name else { select.append("${"); select.append(property); select.append('}'); } if (itProperties.hasNext()) select.append(", "); } Iterator itHiddenProperties = getHiddenPropertiesNames().iterator(); while (itHiddenProperties.hasNext()) { select.append(", "); select.append("${"); select.append(itHiddenProperties.next()); select.append('}'); } select.append(" from ${"); select.append(getModelName()); select.append('}'); select.append(' '); if (hasBaseCondition()) { select.append(" where "); select.append(getBaseCondition()); } return select.toString(); }
public List namesToMetaProperties(Collection names) throws XavaException { List metaProperties = new ArrayList(); Iterator it = names.iterator(); int i = -1; while (it.hasNext()) { i++; String name = (String) it.next(); MetaProperty metaPropertyTab = null; try { MetaProperty metaProperty = getMetaModel().getMetaProperty(name).cloneMetaProperty(); metaProperty.setQualifiedName(name); String labelId = null; if (representCollection()) { labelId = getId() + "." + name; // If there is no specific translation for the collection, // we take the translation from the default tab. if (!Labels.existsExact(labelId)) { labelId = getIdForDefaultTab() + ".properties." + name; } } else { labelId = getId() + ".properties." + name; } if (Labels.exists(labelId)) { metaProperty.setLabelId(labelId); } else if (metaPropertiesTab != null) { // By now only the label overwritten from the property of tab metaPropertyTab = (MetaProperty) metaPropertiesTab.get(name); if (metaPropertyTab != null) { metaProperty = metaProperty.cloneMetaProperty(); metaProperty.setLabel(metaPropertyTab.getLabel()); } } metaProperties.add(metaProperty); } catch (ElementNotFoundException ex) { MetaProperty notInEntity = new MetaProperty(); notInEntity.setName(name); notInEntity.setTypeName("java.lang.Object"); if (metaPropertyTab != null) { notInEntity.setLabel(metaPropertyTab.getLabel()); } metaProperties.add(notInEntity); } } return metaProperties; }
/** This method generates the output given a context and output stream */ public boolean generate(XPathContext context, ProgramWriter out) { try { String collectionName = Strings.firstUpper(collection.getName()); if (ejb) { out.print(" \n\t/**\n\t * @ejb:interface-method\n\t */"); } out.print(" \n\tpublic java.util.Collection get"); out.print(collectionName); out.print("() {"); if (ejb) { out.print( " \n\t\tboolean cmtActivated = false;\n\t\tif (!org.openxava.hibernate.XHibernate.isCmt()) {\n\t\t\torg.openxava.hibernate.XHibernate.setCmt(true);\n\t\t\tcmtActivated = true;\n\t\t}"); } out.print(" \n\t\ttry {"); MetaCalculator calculator = collection.getMetaCalculator(); String calculatorClass = calculator.getClassName(); out.print(" \t\t\n\t\t\t"); out.print(calculatorClass); out.print(" "); out.print(collection.getName()); out.print("Calculator= ("); out.print(calculatorClass); out.print(")\n\t\t\t\tgetMetaModel().getMetaCollection(\""); out.print(collection.getName()); out.print("\").getMetaCalculator().createCalculator();"); Iterator itSets = calculator.getMetaSetsWithoutValue().iterator(); while (itSets.hasNext()) { MetaSet set = (MetaSet) itSets.next(); String propertyNameInCalculator = Strings.firstUpper(set.getPropertyName()); String propertyNameFrom = set.getPropertyNameFrom(); MetaProperty p = metaModel.getMetaProperty(propertyNameFrom); if (propertyNameFrom.indexOf('.') >= 0) { if (p.isKey() || p.getMetaModel() instanceof MetaAggregate) { propertyNameFrom = Strings.firstUpper(Strings.change(propertyNameFrom, ".", "_")); } else { StringTokenizer st = new StringTokenizer(propertyNameFrom, "."); String ref = st.nextToken(); String pro = st.nextToken(); propertyNameFrom = Strings.firstUpper(ref) + "().get" + Strings.firstUpper(pro); } } else { propertyNameFrom = Strings.firstUpper(propertyNameFrom); } String getPropertyFrom = "boolean".equals(p.getTypeName()) ? "is" : "get"; String value = set.getValue(); if (set.hasValue()) { out.print(" \n\t\t\t"); out.print(collection.getName()); out.print("Calculator.set"); out.print(propertyNameInCalculator); out.print("(\""); out.print(value); out.print("\");"); } else { out.print(" \t\n\t\t\t"); out.print(collection.getName()); out.print("Calculator.set"); out.print(propertyNameInCalculator); out.print("("); out.print(getPropertyFrom); out.print(propertyNameFrom); out.print("());"); } } // else/sets if (IModelCalculator.class.isAssignableFrom(Class.forName(calculatorClass))) { out.print(" \n\t\t\t\t"); out.print(collection.getName()); out.print("Calculator.setModel(this);"); } if (IEntityCalculator.class.isAssignableFrom(Class.forName(calculatorClass))) { out.print(" \n\t\t\t\t"); out.print(collection.getName()); out.print("Calculator.setEntity(this);"); } if (IJDBCCalculator.class.isAssignableFrom(Class.forName(calculatorClass))) { out.print(" \n\t\t\t\t"); out.print(collection.getName()); out.print("Calculator.setConnectionProvider(getPortableContext());"); } String calculateValueSentence = collection.getName() + "Calculator.calculate()"; out.print(" \n\t\t\treturn "); out.print(Generators.generateCast("java.util.Collection", calculateValueSentence)); out.print( ";\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tex.printStackTrace();\n\t\t\tthrow new "); out.print(getException()); out.print("(XavaResources.getString(\"generator.calculate_value_error\", \""); out.print(collection.getName()); out.print("\", \""); out.print(metaModel.getName()); out.print("\", ex.getLocalizedMessage()));\n\t\t}"); if (ejb) { out.print( " \n\t\tfinally {\n\t\t\tif (cmtActivated) {\n\t\t\t\torg.openxava.hibernate.XHibernate.setCmt(false);\n\t\t\t}\n\t\t}"); } out.print(" \t\t\t\t\n\t}"); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); e.printStackTrace(); return false; } return true; }