public String getType() { return objAttribute.getType(); }
/** * Returns Java class of an object property described by this attribute. * Wraps any thrown exceptions into CayenneRuntimeException. */ public Class<?> getJavaClass() { if (this.getType() == null) { return null; } try { return Util.getJavaClass(getType()); } catch (ClassNotFoundException e) { throw new CayenneRuntimeException("Failed to load class for name '" + this.getType() + "': " + e.getMessage(), e); } }
/** * @since 1.2 */ public ColumnDescriptor(ObjAttribute objAttribute, DbAttribute dbAttribute, String columnAlias) { this(dbAttribute, columnAlias); this.dataRowKey = objAttribute.getDbAttributePath(); this.javaClass = objAttribute.getType(); }
/** * @since 1.2 */ public ColumnDescriptor(ObjAttribute objAttribute, DbAttribute dbAttribute, String columnAlias) { this(dbAttribute, columnAlias); this.label = objAttribute.getDbAttributePath(); this.javaClass = objAttribute.getType(); }
/** * Returns Java class of an object property described by this attribute. Wraps any * thrown exceptions into CayenneRuntimeException. */ public Class getJavaClass() { if (this.getType() == null) { return null; } try { // tolerate null class loader return Util.getJavaClass(getType()); } catch (ClassNotFoundException e) { throw new CayenneRuntimeException("Failed to load class for name '" + this.getType() + "': " + e.getMessage(), e); } }
public void setDuplicatedAttributes(List<ObjAttribute> attributes) { if (duplicatedAttributes == null) { duplicatedAttributes = new LinkedList<DuplicatedAttributeInfo>(); } duplicatedAttributes.clear(); for (ObjAttribute attribute : attributes) { DuplicatedAttributeInfo attributeInfo = new DuplicatedAttributeInfo(attribute.getName(), attribute.getType(), superEntity.getAttribute(attribute.getName()).getType(), DELETE_ACTION); duplicatedAttributes.add(attributeInfo); } attributesTable.setModel(new DuplicatedAttributeTableModel(getMediator(), this, duplicatedAttributes)); }
public boolean isChange() { boolean isOverrideTableChange = ((OverrideEmbeddableAttributeTableModel) view.getOverrideAttributeTable() .getModel()).isAttributeOverrideChange(); return isOverrideTableChange || !attribute.getName().equals(view.getAttributeName().getText()) || (attribute.getType() == null && view.getTypeComboBox().getSelectedItem() != null) || !Objects.equals(attribute.getType(), view.getTypeComboBox().getSelectedItem()); }
protected void initConvertersFromMapping() { // assert that we have all the data if (dbAttributes.size() == 0) { throw new IllegalArgumentException("DbAttributes list is empty."); } if (rootEntity == null) { throw new IllegalArgumentException("Root ObjEntity is null."); } int resultWidth = dbAttributes.size(); this.converters = new ExtendedType[resultWidth]; for (int i = 0; i < resultWidth; i++) { String javaType = null; DbAttribute attr = (DbAttribute) dbAttributes.get(i); ObjAttribute objAttr = rootEntity.getAttributeForDbAttribute(attr); // TODO: [See CAY-207 for details] This setup doesn't allow to correctly // determine the Java class of an attribute if it is defined in a sub-entity // of the query root entity... Hence all inherited attributes will be fetched // as generic types, ignoring any possible custom type. if (objAttr != null) { javaType = objAttr.getType(); } else { javaType = TypesMapping.getJavaBySqlType(attr.getType()); } converters[i] = typesMapping.getRegisteredType(javaType); } }
/** * Returns an ObjAttribute stripped of any server-side information, such as * DbAttribute mapping. * * @since 1.2 */ public ObjAttribute getClientAttribute() { ObjAttribute attribute = new ObjAttribute(getName()); attribute.setType(getType()); // TODO: will likely need "userForLocking" property as well. return attribute; } }
private String javaType(DbAttribute attribute) { ObjAttribute objAttribute = entity.getAttributeForDbAttribute(attribute); return (objAttribute != null) ? objAttribute.getType() : TypesMapping.getJavaBySqlType(attribute.getType()); }
public Map<String, String> getCurrentOverrideAttribute() { Map<String, String> currentEmbeddableOverrite = new HashMap<>(); Collection<EmbeddableAttribute> embList = embeddableModel.getEmbeddableList(); Embeddable emb = stringToEmbeddables.get(attributeSaved.getType()); Iterator<EmbeddableAttribute> it = embList.iterator(); while (it.hasNext()) { EmbeddableAttribute e = it.next(); if ((emb.getAttribute(e.getName()).getDbAttributeName() == null && e.getDbAttributeName() != null) || (emb.getAttribute(e.getName()).getDbAttributeName() != null && !emb.getAttribute(e.getName()) .getDbAttributeName().equals(e.getDbAttributeName()))) { currentEmbeddableOverrite.put(e.getName(), e.getDbAttributeName()); } } return currentEmbeddableOverrite; }
private void copyObjAttribute(ObjAttribute attributeSaved, ObjAttribute attribute) { attributeSaved.setDbAttributePath(attribute.getDbAttributePath()); attributeSaved.setName(attribute.getName()); attributeSaved.setEntity(attribute.getEntity()); attributeSaved.setParent(attribute.getParent()); attributeSaved.setType(attribute.getType()); attributeSaved.setUsedForLocking(attribute.isUsedForLocking()); if (attributeSaved instanceof EmbeddedAttribute) { Map<String, String> attrOverrides; if (attribute instanceof EmbeddedAttribute) { attrOverrides = ((EmbeddedAttribute) attribute).getAttributeOverrides(); } else { attrOverrides = new HashMap<>(); } if (attrOverrides.size() > 0) { Iterator it = attrOverrides.entrySet().iterator(); while (it.hasNext()) { Map.Entry attrOv = (Map.Entry) it.next(); ((EmbeddedAttribute) attributeSaved).addAttributeOverride(attrOv.getKey().toString(), attrOv .getValue().toString()); } } } }
public Object toRawValue(Object value) { if (value == null) return null; DataView rootOwner = getOwner().getOwner(); if (isLookup()) { return rootOwner.getLookupCache().getDataObject(lookupField, value); } if (objAttribute == null) return null; String type = objAttribute.getType(); Object v = null; try { Class untypedValueClass = Class.forName(type); v = rootOwner.getDataTypeSpec().fromDataType( untypedValueClass, dataType, value); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } return v; }
private ValidationFailure validateAttribute(ObjAttribute attribute) { String name = attribute.getEntity().getName(); ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(name, "attribute.name", attribute.getName()); if (emptyName != null) { return emptyName; } ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(name, "attribute.name", attribute.getName()); if (badName != null) { return badName; } ValidationFailure emptyType = BeanValidationFailure.validateNotEmpty(name, "attribute.type", attribute.getType()); if (emptyType != null) { return emptyType; } ValidationFailure badType = BeanValidationFailure.validateJavaClassName(name, "attribute.type", attribute.getType()); if (badType != null) { return badType; } return null; }
public boolean visitAttribute(AttributeProperty property) { ObjAttribute oa = property.getAttribute(); Iterator<?> dbPathIterator = oa.getDbPathIterator(); EJBQLJoinAppender joinAppender = null; String marker = null; EJBQLTableId lhsId = new EJBQLTableId(idVar); while (dbPathIterator.hasNext()) { Object pathPart = dbPathIterator.next(); if (pathPart == null) { throw new CayenneRuntimeException("ObjAttribute has no component: %s", oa.getName()); } else if (pathPart instanceof DbRelationship) { if (marker == null) { marker = EJBQLJoinAppender.makeJoinTailMarker(idVar); joinAppender = context.getTranslatorFactory().getJoinAppender(context); } DbRelationship dr = (DbRelationship) pathPart; EJBQLTableId rhsId = new EJBQLTableId(lhsId, dr.getName()); joinAppender.appendOuterJoin(marker, lhsId, rhsId); lhsId = rhsId; } else if (pathPart instanceof DbAttribute) { appendColumn(idVar, oa, (DbAttribute) pathPart, fields, oa.getType()); } } return true; }
void validate(ObjAttribute attribute, ValidationResult validationResult) { validateName(attribute, validationResult); // all attributes must have type if (Util.isEmptyString(attribute.getType())) { addFailure(validationResult, attribute, "ObjAttribute '%s' has no Java type", attribute.getName()); } if (attribute instanceof EmbeddedAttribute) { validateEmbeddable((EmbeddedAttribute)attribute, validationResult); } else { validateDbAttribute(attribute, validationResult); } checkForDuplicates(attribute, validationResult); checkSuperEntityAttributes(attribute, validationResult); }
/** * Creates a clone of an ObjAttribute argument. * * @since 3.0 */ public ObjAttribute(ObjAttribute attribute) { setName(attribute.getName()); setType(attribute.getType()); setEntity(attribute.getEntity()); setDbAttributePath(attribute.getDbAttributePath()); setUsedForLocking(attribute.isUsedForLocking()); }
@Override protected void processTerminatingAttribute(ObjAttribute attribute) { EJBQLAggregateColumnTranslator.this.attributeType = attribute.getType(); DbEntity table = currentEntity.getDbEntity(); String alias = this.lastAlias != null ? lastAlias : context.getTableAlias(idPath, context .getQuotingStrategy().quotedFullyQualifiedName(table)); context.append(alias).append('.') .append(context.getQuotingStrategy().quotedName(attribute.getDbAttribute())); }
@Override public boolean visitIdentifier(EJBQLExpression expression) { Map<String, String> fields = null; if (context.isAppendingResultColumns()) { fields = context.nextEntityResult().getFields(); } String idVar = expression.getText(); ClassDescriptor descriptor = context.getEntityDescriptor(idVar); ObjEntity oe = descriptor.getEntity(); for (ObjAttribute oa : oe.getPrimaryKeys()) { DbAttribute t = oe.getDbEntity().getAttribute(oa.getDbAttributeName()); appendColumn(idVar, oa, t, fields, oa.getType()); } return false; }
/** * Returns an ObjAttribute stripped of any server-side information, such as * DbAttribute mapping. * * @since 1.2 */ public ObjAttribute getClientAttribute() { ClientObjAttribute attribute = new ClientObjAttribute(getName()); attribute.setType(getType()); DbAttribute dbAttribute = getDbAttribute(); if (dbAttribute != null) { // expose PK attribute names - the client may need those to build // ObjectIds if (dbAttribute.isPrimaryKey()) { attribute.setDbAttributePath(dbAttribute.getName()); attribute.setPrimaryKey(true); } attribute.setMandatory(isMandatory()); attribute.setMaxLength(getMaxLength()); } // TODO: will likely need "userForLocking" property as well. return attribute; }