本文整理汇总了Java中org.ofbiz.entity.model.ModelField.getName方法的典型用法代码示例。如果您正苦于以下问题:Java ModelField.getName方法的具体用法?Java ModelField.getName怎么用?Java ModelField.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ofbiz.entity.model.ModelField
的用法示例。
在下文中一共展示了ModelField.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setEntityName
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
public void setEntityName(String name) {
this.entityName = name;
if (UtilValidate.isNotEmpty(this.entityName)) {
ModelEntity modelEntity = modelTree.delegator.getModelEntity(this.entityName);
if (modelEntity.getPksSize() == 1) {
ModelField modelField = modelEntity.getOnlyPk();
this.pkName = modelField.getName();
} else {
List<String> pkFieldsName = modelEntity.getPkFieldNames();
StringBuilder sb = new StringBuilder();
for (String pk: pkFieldsName) {
sb.append(pk);
sb.append("|");
}
this.pkName = sb.toString();
}
}
}
示例2: isPrimaryKey
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
public boolean isPrimaryKey(boolean requireValue) {
TreeSet<String> fieldKeys = new TreeSet<String>(this.fields.keySet());
for (ModelField curPk: this.getModelEntity().getPkFieldsUnmodifiable()) {
String fieldName = curPk.getName();
if (requireValue) {
if (this.fields.get(fieldName) == null) return false;
} else {
if (!this.fields.containsKey(fieldName)) return false;
}
fieldKeys.remove(fieldName);
}
if (!fieldKeys.isEmpty()) return false;
return true;
}
示例3: containsPrimaryKey
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
public boolean containsPrimaryKey(boolean requireValue) {
//TreeSet fieldKeys = new TreeSet(fields.keySet());
for (ModelField curPk: this.getModelEntity().getPkFieldsUnmodifiable()) {
String fieldName = curPk.getName();
if (requireValue) {
if (this.fields.get(fieldName) == null) return false;
} else {
if (!this.fields.containsKey(fieldName)) return false;
}
}
return true;
}
示例4: makeXmlElement
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
/** Makes an XML Element object with an attribute for each field of the entity
*@param document The XML Document that the new Element will be part of
*@param prefix A prefix to put in front of the entity name in the tag name
*@return org.w3c.dom.Element object representing this generic entity
*/
public Element makeXmlElement(Document document, String prefix) {
Element element = null;
if (prefix == null) prefix = "";
if (document != null) element = document.createElement(prefix + this.getEntityName());
// else element = new ElementImpl(null, this.getEntityName());
if (element == null) return null;
Iterator<ModelField> modelFields = this.getModelEntity().getFieldsIterator();
while (modelFields.hasNext()) {
ModelField modelField = modelFields.next();
String name = modelField.getName();
String value = this.getString(name);
if (value != null) {
if (value.indexOf('\n') >= 0 || value.indexOf('\r') >= 0) {
UtilXml.addChildElementCDATAValue(element, name, value, document);
} else {
element.setAttribute(name, value);
}
// } else {
// element.setAttribute(name, GenericEntity.NULL_FIELD.toString());
}
}
return element;
}
示例5: makeTempFieldName
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
private String makeTempFieldName(ModelField field) {
String tempName = "tmp_" + field.getName();
if (tempName.length() > 30) {
tempName = tempName.substring(0, 30);
}
return tempName.toUpperCase();
}
示例6: getDefaultPkName
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
public String getDefaultPkName(Map<String, Object> context) {
ModelEntity modelEntity = WidgetWorker.getDelegator(context).getModelEntity(this.defaultEntityName);
if (modelEntity.getPksSize() == 1) {
ModelField modelField = modelEntity.getOnlyPk();
return modelField.getName();
}
return null;
}
示例7: setDefaultEntityName
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
public void setDefaultEntityName(String name) {
String nm = name;
if (UtilValidate.isEmpty(nm)) {
nm = "Content";
}
this.defaultEntityName = nm;
ModelEntity modelEntity = delegator.getModelEntity(this.defaultEntityName);
if (modelEntity.getPksSize() == 1) {
ModelField modelField = modelEntity.getOnlyPk();
this.defaultPkName = modelField.getName();
}
}
示例8: setAllFields
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
/** Intelligently sets fields on this entity from the Map of fields passed in
* @param fields The fields Map to get the values from
* @param setIfEmpty Used to specify whether empty/null values in the field Map should over-write non-empty values in this entity
* @param namePrefix If not null or empty will be pre-pended to each field name (upper-casing the first letter of the field name first), and that will be used as the fields Map lookup name instead of the field-name
* @param pks If null, get all values, if TRUE just get PKs, if FALSE just get non-PKs
*/
public void setAllFields(Map<? extends Object, ? extends Object> fields, boolean setIfEmpty, String namePrefix, Boolean pks) {
if (fields == null) {
return;
}
Iterator<ModelField> iter = null;
if (pks != null) {
if (pks.booleanValue()) {
iter = this.getModelEntity().getPksIterator();
} else {
iter = this.getModelEntity().getNopksIterator();
}
} else {
iter = this.getModelEntity().getFieldsIterator();
}
while (iter != null && iter.hasNext()) {
ModelField curField = iter.next();
String fieldName = curField.getName();
String sourceFieldName = null;
if (UtilValidate.isNotEmpty(namePrefix)) {
sourceFieldName = namePrefix + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
} else {
sourceFieldName = curField.getName();
}
if (fields.containsKey(sourceFieldName)) {
Object field = fields.get(sourceFieldName);
// if (Debug.verboseOn()) Debug.logVerbose("Setting field " + curField.getName() + ": " + field + ", setIfEmpty = " + setIfEmpty, module);
if (setIfEmpty) {
// if empty string, set to null
if (field != null && field instanceof String && ((String) field).length() == 0) {
this.set(curField.getName(), null);
} else {
this.set(curField.getName(), field);
}
} else {
// okay, only set if not empty...
if (field != null) {
// if it's a String then we need to check length, otherwise set it because it's not null
if (field instanceof String) {
String fieldStr = (String) field;
if (fieldStr.length() > 0) {
this.set(curField.getName(), fieldStr);
}
} else {
this.set(curField.getName(), field);
}
}
}
}
}
}
示例9: makeValue
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
@Override
public GenericValue makeValue(Element element) {
if (element == null) {
return null;
}
String entityName = element.getTagName();
// if a dash or colon is in the tag name, grab what is after it
if (entityName.indexOf('-') > 0) {
entityName = entityName.substring(entityName.indexOf('-') + 1);
}
if (entityName.indexOf(':') > 0) {
entityName = entityName.substring(entityName.indexOf(':') + 1);
}
GenericValue value = this.makeValue(entityName);
ModelEntity modelEntity = value.getModelEntity();
Iterator<ModelField> modelFields = modelEntity.getFieldsIterator();
while (modelFields.hasNext()) {
ModelField modelField = modelFields.next();
String name = modelField.getName();
String attr = element.getAttribute(name);
if (UtilValidate.isNotEmpty(attr)) {
// GenericEntity.makeXmlElement() sets null values to GenericEntity.NULL_FIELD.toString(), so look for
// that and treat it as null
if (GenericEntity.NULL_FIELD.toString().equals(attr)) {
value.set(name, null);
} else {
value.setString(name, attr);
}
} else {
// if no attribute try a subelement
Element subElement = UtilXml.firstChildElement(element, name);
if (subElement != null) {
value.setString(name, UtilXml.elementValue(subElement));
}
}
}
return value;
}
示例10: runFind
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
public static GenericValue runFind(ModelEntity modelEntity, Map<String, Object> context, Delegator delegator, boolean useCache, boolean autoFieldMap,
Map<FlexibleMapAccessor<Object>, Object> fieldMap, List<FlexibleStringExpander> selectFieldExpanderList) throws GeneralException {
// assemble the field map
Map<String, Object> entityContext = new HashMap<String, Object>();
if (autoFieldMap) {
// try a map called "parameters", try it first so values from here are overridden by values in the main context
Object parametersObj = context.get("parameters");
Boolean parametersObjExists = parametersObj != null && parametersObj instanceof Map<?, ?>;
// only need PK fields
Iterator<ModelField> iter = modelEntity.getPksIterator();
while (iter.hasNext()) {
ModelField curField = iter.next();
String fieldName = curField.getName();
Object fieldValue = null;
if (parametersObjExists) {
fieldValue = ((Map<?, ?>) parametersObj).get(fieldName);
}
if (context.containsKey(fieldName)) {
fieldValue = context.get(fieldName);
}
entityContext.put(fieldName, fieldValue);
}
}
EntityFinderUtil.expandFieldMapToContext(fieldMap, context, entityContext);
//Debug.logInfo("PrimaryKeyFinder: entityContext=" + entityContext, module);
// then convert the types...
// need the timeZone and locale for conversion, so add here and remove after
entityContext.put("locale", context.get("locale"));
entityContext.put("timeZone", context.get("timeZone"));
modelEntity.convertFieldMapInPlace(entityContext, delegator);
entityContext.remove("locale");
entityContext.remove("timeZone");
// get the list of fieldsToSelect from selectFieldExpanderList
Set<String> fieldsToSelect = EntityFinderUtil.makeFieldsToSelect(selectFieldExpanderList, context);
//if fieldsToSelect != null and useCacheBool is true, throw an error
if (fieldsToSelect != null && useCache) {
throw new IllegalArgumentException("Error in entity-one definition, cannot specify select-field elements when use-cache is set to true");
}
try {
GenericValue valueOut = null;
GenericPK entityPK = delegator.makePK(modelEntity.getEntityName(), entityContext);
// make sure we have a full primary key, if any field is null then just log a warning and return null instead of blowing up
if (entityPK.containsPrimaryKey(true)) {
if (useCache) {
valueOut = EntityQuery.use(delegator).from(entityPK.getEntityName()).where(entityPK).cache(true).queryOne();
} else {
if (fieldsToSelect != null) {
valueOut = delegator.findByPrimaryKeyPartial(entityPK, fieldsToSelect);
} else {
valueOut = EntityQuery.use(delegator).from(entityPK.getEntityName()).where(entityPK).cache(false).queryOne();
}
}
} else {
if (Debug.infoOn()) Debug.logInfo("Returning null because found incomplete primary key in find: " + entityPK, module);
}
return valueOut;
} catch (GenericEntityException e) {
String errMsg = "Error finding entity value by primary key with entity-one: " + e.toString();
Debug.logError(e, errMsg, module);
throw new GeneralException(errMsg, e);
}
}
示例11: createCondition
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
/**
* createCondition, comparing the normalizedFields with the list of keys, .
*
* This is use to the generic method that expects entity data affixed with special suffixes
* to indicate their purpose in formulating an SQL query statement.
* @param modelEntity the model entity object
* @param normalizedFields list of field the user have populated
* @return a arrayList usable to create an entityCondition
*/
public static List<EntityCondition> createCondition(ModelEntity modelEntity, Map<String, Map<String, Map<String, Object>>> normalizedFields, Map<String, Object> queryStringMap, Map<String, List<Object[]>> origValueMap, Delegator delegator, Map<String, ?> context) {
Map<String, Map<String, Object>> subMap = null;
Map<String, Object> subMap2 = null;
Object fieldValue = null; // If it is a "value" field, it will be the value to be used in the query.
// If it is an "op" field, it will be "equals", "greaterThan", etc.
EntityCondition cond = null;
List<EntityCondition> tmpList = new LinkedList<EntityCondition>();
String opString = null;
boolean ignoreCase = false;
List<ModelField> fields = modelEntity.getFieldsUnmodifiable();
for (ModelField modelField: fields) {
String fieldName = modelField.getName();
subMap = normalizedFields.get(fieldName);
if (subMap == null) {
continue;
}
subMap2 = subMap.get("fld0");
fieldValue = subMap2.get("value");
opString = (String) subMap2.get("op");
// null fieldValue is OK if operator is "empty"
if (fieldValue == null && !"empty".equals(opString)) {
continue;
}
ignoreCase = "Y".equals(subMap2.get("ic"));
cond = createSingleCondition(modelField, opString, fieldValue, ignoreCase, delegator, context);
tmpList.add(cond);
subMap2 = subMap.get("fld1");
if (subMap2 == null) {
continue;
}
fieldValue = subMap2.get("value");
opString = (String) subMap2.get("op");
if (fieldValue == null && !"empty".equals(opString)) {
continue;
}
ignoreCase = "Y".equals(subMap2.get("ic"));
cond = createSingleCondition(modelField, opString, fieldValue, ignoreCase, delegator, context);
tmpList.add(cond);
// add to queryStringMap
List<Object[]> origList = origValueMap.get(fieldName);
if (UtilValidate.isNotEmpty(origList)) {
for (Object[] arr: origList) {
queryStringMap.put((String) arr[0], arr[1]);
}
}
}
return tmpList;
}
示例12: getParametersMap
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Map<String, String> getParametersMap(Map<String, Object> context, String defaultEntityName) {
Map<String, String> autEntityParams = new HashMap<String, String>();
Delegator delegator = (Delegator) context.get("delegator");
if (delegator == null) {
Debug.logError(
"We can not append auto entity Parameters since we could not find delegator in the current context",
module);
return autEntityParams;
}
if (UtilValidate.isEmpty(entityName))
entityName = defaultEntityName;
FlexibleStringExpander toExpand = FlexibleStringExpander.getInstance(entityName);
ModelEntity entity = delegator.getModelEntity(toExpand.expandString(context));
if (entity == null) {
Debug.logError("We can not append auto entity Parameters since we could not find entity with name [" + entityName
+ "]", module);
return autEntityParams;
}
Iterator<ModelField> fieldsIter = entity.getFieldsIterator();
if (fieldsIter != null) {
while (fieldsIter.hasNext()) {
ModelField field = fieldsIter.next();
String fieldName = field.getName();
FlexibleMapAccessor<Object> fma = FlexibleMapAccessor.getInstance(fieldName);
boolean shouldExclude = excludeList.contains(fieldName);
if ((!shouldExclude) && (!field.getIsAutoCreatedInternal())
&& ((field.getIsPk() && includePk) || (!field.getIsPk() && includeNonPk))) {
Object flexibleValue = fma.get(context);
if (UtilValidate.isEmpty(flexibleValue) && context.containsKey("parameters")) {
flexibleValue = fma.get((Map<String, Object>) context.get("parameters"));
}
if (UtilValidate.isNotEmpty(flexibleValue) || sendIfEmpty) {
autEntityParams.put(fieldName, String.valueOf(flexibleValue));
}
}
}
}
return autEntityParams;
}
示例13: makeValue
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
public GenericValue makeValue(Element element) {
if (element == null) {
return null;
}
String entityName = element.getTagName();
// if a dash or colon is in the tag name, grab what is after it
if (entityName.indexOf('-') > 0) {
entityName = entityName.substring(entityName.indexOf('-') + 1);
}
if (entityName.indexOf(':') > 0) {
entityName = entityName.substring(entityName.indexOf(':') + 1);
}
GenericValue value = this.makeValue(entityName);
ModelEntity modelEntity = value.getModelEntity();
Iterator<ModelField> modelFields = modelEntity.getFieldsIterator();
while (modelFields.hasNext()) {
ModelField modelField = modelFields.next();
String name = modelField.getName();
String attr = element.getAttribute(name);
if (UtilValidate.isNotEmpty(attr)) {
// GenericEntity.makeXmlElement() sets null values to GenericEntity.NULL_FIELD.toString(), so look for
// that and treat it as null
if (GenericEntity.NULL_FIELD.toString().equals(attr)) {
value.set(name, null);
} else {
value.setString(name, attr);
}
} else {
// if no attribute try a subelement
Element subElement = UtilXml.firstChildElement(element, name);
if (subElement != null) {
value.setString(name, UtilXml.elementValue(subElement));
}
}
}
return value;
}
示例14: runFind
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
public static GenericValue runFind(ModelEntity modelEntity, Map<String, Object> context, Delegator delegator, boolean useCache, boolean autoFieldMap,
Map<FlexibleMapAccessor<Object>, Object> fieldMap, List<FlexibleStringExpander> selectFieldExpanderList) throws GeneralException {
// assemble the field map
Map<String, Object> entityContext = new HashMap<String, Object>();
if (autoFieldMap) {
// try a map called "parameters", try it first so values from here are overridden by values in the main context
Object parametersObj = context.get("parameters");
Boolean parametersObjExists = parametersObj != null && parametersObj instanceof Map<?, ?>;
// only need PK fields
Iterator<ModelField> iter = modelEntity.getPksIterator();
while (iter.hasNext()) {
ModelField curField = iter.next();
String fieldName = curField.getName();
Object fieldValue = null;
if (parametersObjExists) {
fieldValue = ((Map<?, ?>) parametersObj).get(fieldName);
}
if (context.containsKey(fieldName)) {
fieldValue = context.get(fieldName);
}
entityContext.put(fieldName, fieldValue);
}
}
EntityFinderUtil.expandFieldMapToContext(fieldMap, context, entityContext);
//Debug.logInfo("PrimaryKeyFinder: entityContext=" + entityContext, module);
// then convert the types...
// need the timeZone and locale for conversion, so add here and remove after
entityContext.put("locale", context.get("locale"));
entityContext.put("timeZone", context.get("timeZone"));
modelEntity.convertFieldMapInPlace(entityContext, delegator);
entityContext.remove("locale");
entityContext.remove("timeZone");
// get the list of fieldsToSelect from selectFieldExpanderList
Set<String> fieldsToSelect = EntityFinderUtil.makeFieldsToSelect(selectFieldExpanderList, context);
//if fieldsToSelect != null and useCacheBool is true, throw an error
if (fieldsToSelect != null && useCache) {
throw new IllegalArgumentException("Error in entity-one definition, cannot specify select-field elements when use-cache is set to true");
}
try {
GenericValue valueOut = null;
GenericPK entityPK = delegator.makePK(modelEntity.getEntityName(), entityContext);
// make sure we have a full primary key, if any field is null then just log a warning and return null instead of blowing up
if (entityPK.containsPrimaryKey(true)) {
if (useCache) {
valueOut = delegator.findOne(entityPK.getEntityName(), entityPK, true);
} else {
if (fieldsToSelect != null) {
valueOut = delegator.findByPrimaryKeyPartial(entityPK, fieldsToSelect);
} else {
valueOut = delegator.findOne(entityPK.getEntityName(), entityPK, false);
}
}
} else {
if (Debug.infoOn()) Debug.logInfo("Returning null because found incomplete primary key in find: " + entityPK, module);
}
return valueOut;
} catch (GenericEntityException e) {
String errMsg = "Error finding entity value by primary key with entity-one: " + e.toString();
Debug.logError(e, errMsg, module);
throw new GeneralException(errMsg, e);
}
}
示例15: createCondition
import org.ofbiz.entity.model.ModelField; //导入方法依赖的package包/类
/**
* createCondition, comparing the normalizedFields with the list of keys, .
*
* This is use to the generic method that expects entity data affixed with special suffixes
* to indicate their purpose in formulating an SQL query statement.
* @param modelEntity the model entity object
* @param normalizedFields list of field the user have populated
* @return a arrayList usable to create an entityCondition
*/
public static List<EntityCondition> createCondition(ModelEntity modelEntity, Map<String, Map<String, Map<String, Object>>> normalizedFields, Map<String, Object> queryStringMap, Map<String, List<Object[]>> origValueMap, Delegator delegator, Map<String, ?> context) {
Map<String, Map<String, Object>> subMap = null;
Map<String, Object> subMap2 = null;
Object fieldValue = null; // If it is a "value" field, it will be the value to be used in the query.
// If it is an "op" field, it will be "equals", "greaterThan", etc.
EntityCondition cond = null;
List<EntityCondition> tmpList = FastList.newInstance();
String opString = null;
boolean ignoreCase = false;
List<ModelField> fields = modelEntity.getFieldsUnmodifiable();
for (ModelField modelField: fields) {
String fieldName = modelField.getName();
subMap = normalizedFields.get(fieldName);
if (subMap == null) {
continue;
}
subMap2 = subMap.get("fld0");
fieldValue = subMap2.get("value");
opString = (String) subMap2.get("op");
// null fieldValue is OK if operator is "empty"
if (fieldValue == null && !"empty".equals(opString)) {
continue;
}
ignoreCase = "Y".equals(subMap2.get("ic"));
cond = createSingleCondition(modelField, opString, fieldValue, ignoreCase, delegator, context);
tmpList.add(cond);
subMap2 = subMap.get("fld1");
if (subMap2 == null) {
continue;
}
fieldValue = subMap2.get("value");
opString = (String) subMap2.get("op");
if (fieldValue == null && !"empty".equals(opString)) {
continue;
}
ignoreCase = "Y".equals(subMap2.get("ic"));
cond = createSingleCondition(modelField, opString, fieldValue, ignoreCase, delegator, context);
tmpList.add(cond);
// add to queryStringMap
List<Object[]> origList = origValueMap.get(fieldName);
if (UtilValidate.isNotEmpty(origList)) {
for (Object[] arr: origList) {
queryStringMap.put((String) arr[0], arr[1]);
}
}
}
return tmpList;
}