public Object convertSetId(Object idValue, Object bean) { // allow Map or String for concatenated id Map<?, ?> mapVal = null; if (idValue instanceof Map<?, ?>) { mapVal = (Map<?, ?>) idValue; } else { mapVal = MapFromString.parse(idValue.toString()); } // Use a new LinkedHashMap to control the order LinkedHashMap<String, Object> newMap = new LinkedHashMap<String, Object>(); for (int i = 0; i < props.length; i++) { BeanProperty prop = props[i]; Object value = mapVal.get(prop.getName()); // Convert the property type if required value = props[i].getScalarType().toBeanType(value); newMap.put(prop.getName(), value); if (bean != null) { // support PropertyChangeSupport prop.setValueIntercept(bean, value); } } return newMap; }
/** * Build a map of logical to physical names for use in Orm Updates for a given descriptor. * * <p>This includes the dbWrite scalar properties and imported foreign key properties. */ public static Map<String, String> build(BeanDescriptor<?> descriptor) { Map<String, String> deployMap = new HashMap<String, String>(); String shortName = descriptor.getName(); String beanName = shortName.toLowerCase(); deployMap.put(beanName, descriptor.getBaseTable()); BeanProperty[] baseScalar = descriptor.propertiesBaseScalar(); for (BeanProperty baseProp : baseScalar) { // excluding formula, secondary table properties if (baseProp.isDbInsertable() || baseProp.isDbUpdatable()) { deployMap.put(baseProp.getName().toLowerCase(), baseProp.getDbColumn()); } } BeanPropertyAssocOne<?>[] oneImported = descriptor.propertiesOneImported(); for (BeanPropertyAssocOne<?> assocOne : oneImported) { ImportedId importedId = assocOne.getImportedId(); if (importedId == null) { String m = descriptor.getFullName() + " importedId is null for associated: " + assocOne.getFullBeanName(); logger.log(Level.SEVERE, m); } else if (importedId.isScalar()) { deployMap.put(importedId.getLogicalName(), importedId.getDbColumn()); } } return deployMap; }
/** Return true if this property is loaded (full bean or included in partial bean). */ public boolean isLoadedProperty(BeanProperty prop) { if (loadedProps == null) { return true; } else { return loadedProps.contains(prop.getName()); } }
/** * Determine the concurrency mode depending on fully/partially populated bean. * * <p>Specifically with version concurrency we want to check that the version property was one of * the loaded properties. */ public ConcurrencyMode determineConcurrencyMode() { if (loadedProps != null) { // 'partial bean' update/delete... if (concurrencyMode.equals(ConcurrencyMode.VERSION)) { // check the version property was loaded BeanProperty prop = beanDescriptor.firstVersionProperty(); if (prop != null && loadedProps.contains(prop.getName())) { // OK to use version property } else { concurrencyMode = ConcurrencyMode.NONE; } } } return concurrencyMode; }
public void add(ElPropertyDeploy elProp) { String join = elProp.getElPrefix(); BeanProperty p = elProp.getBeanProperty(); if ((p instanceof BeanPropertyAssocMany)) { join = addManyToJoin(join, p.getName()); } if (join != null) { this.joins.add(join); String secondaryTableJoinPrefix = p.getSecondaryTableJoinPrefix(); if (secondaryTableJoinPrefix != null) { this.joins.add(join + "." + secondaryTableJoinPrefix); } addParentJoins(join); } }
@SuppressWarnings({"unchecked", "rawtypes"}) public DeployBeanPropertyLists( BeanDescriptorMap owner, BeanDescriptor<?> desc, DeployBeanDescriptor<?> deploy) { this.desc = desc; setImportedPrimaryKeys(deploy); DeployBeanPropertyAssocOne<?> deployUnidirectional = deploy.getUnidirectional(); if (deployUnidirectional == null) { unidirectional = null; } else { unidirectional = new BeanPropertyAssocOne(owner, desc, deployUnidirectional); } this.propertyMap = new LinkedHashMap<String, BeanProperty>(); // see if there is a discriminator property we should add String discriminatorColumn = null; BeanProperty discProperty = null; InheritInfo inheritInfo = deploy.getInheritInfo(); if (inheritInfo != null) { // Create a BeanProperty for the discriminator column to support // using RawSql queries with inheritance discriminatorColumn = inheritInfo.getDiscriminatorColumn(); DeployBeanProperty discDeployProp = new DeployBeanProperty(deploy, String.class, new ScalarTypeString(), null); discDeployProp.setDiscriminator(); discDeployProp.setName(discriminatorColumn); discDeployProp.setDbColumn(discriminatorColumn); // only register it in the propertyMap. This might not be used if // an explicit property is mapped to the discriminator on the bean discProperty = new BeanProperty(desc, discDeployProp); } for (DeployBeanProperty prop : deploy.propertiesAll()) { if (discriminatorColumn != null && discriminatorColumn.equals(prop.getDbColumn())) { // we have an explicit property mapped to the discriminator column prop.setDiscriminator(); discProperty = null; } BeanProperty beanProp = createBeanProperty(owner, prop); propertyMap.put(beanProp.getName(), beanProp); } int order = 0; for (BeanProperty prop : propertyMap.values()) { prop.setDeployOrder(order++); allocateToList(prop); } if (discProperty != null) { // put the discriminator property into the property map only // (after the real properties have been organised into their lists) propertyMap.put(discProperty.getName(), discProperty); } List<DeployTableJoin> deployTableJoins = deploy.getTableJoins(); tableJoins = new TableJoin[deployTableJoins.size()]; for (int i = 0; i < deployTableJoins.size(); i++) { tableJoins[i] = new TableJoin(deployTableJoins.get(i)); } }
/** Return true if this property should be included in the where clause. */ public boolean isIncludedWhere(BeanProperty prop) { return (includeWhereProps == null || includeWhereProps.contains(prop.getName())); }
/** Test if the property value has changed and if so include it in the update. */ public boolean hasChanged(BeanProperty prop) { return changedProps.contains(prop.getName()); }
/** * Create a Matching BeanProperty with some attributes overridden. * * <p>Primarily for supporting Embedded beans with overridden dbColumn mappings. */ public BeanProperty(BeanProperty source, BeanPropertyOverride override) { this.descriptor = source.descriptor; this.name = InternString.intern(source.getName()); this.propertyIndex = source.propertyIndex; this.dbColumn = InternString.intern(override.getDbColumn()); // override with sqlFormula not currently supported this.sqlFormulaJoin = null; this.sqlFormulaSelect = null; this.formula = false; this.excludedFromHistory = source.excludedFromHistory; this.draft = source.draft; this.draftDirty = source.draftDirty; this.draftOnly = source.draftOnly; this.draftReset = source.draftReset; this.softDelete = source.softDelete; this.softDeleteDbSet = source.softDeleteDbSet; this.softDeleteDbPredicate = source.softDeleteDbPredicate; this.fetchEager = source.fetchEager; this.unidirectionalShadow = source.unidirectionalShadow; this.discriminator = source.discriminator; this.localEncrypted = source.isLocalEncrypted(); this.isTransient = source.isTransient(); this.secondaryTable = source.isSecondaryTable(); this.secondaryTableJoin = source.secondaryTableJoin; this.secondaryTableJoinPrefix = source.secondaryTableJoinPrefix; this.dbComment = source.dbComment; this.dbBind = source.getDbBind(); this.dbEncrypted = source.isDbEncrypted(); this.dbEncryptedType = source.getDbEncryptedType(); this.dbEncryptFunction = source.dbEncryptFunction; this.dbRead = source.isDbRead(); this.dbInsertable = source.isDbInsertable(); this.dbUpdatable = source.isDbUpdatable(); this.nullable = source.isNullable(); this.unique = source.isUnique(); this.naturalKey = source.isNaturalKey(); this.dbLength = source.getDbLength(); this.dbScale = source.getDbScale(); this.dbColumnDefn = InternString.intern(source.getDbColumnDefn()); this.dbColumnDefault = source.dbColumnDefault; this.inherited = source.isInherited(); this.owningType = source.owningType; this.local = owningType.equals(descriptor.getBeanType()); this.version = source.isVersion(); this.embedded = source.isEmbedded(); this.id = source.isId(); this.generatedProperty = source.getGeneratedProperty(); this.getter = source.getter; this.setter = source.setter; this.dbType = source.getDbType(true); this.scalarType = source.scalarType; this.lob = isLobType(dbType); this.propertyType = source.getPropertyType(); this.field = source.getField(); this.docOptions = source.docOptions; this.elPlaceHolder = override.replace(source.elPlaceHolder, source.dbColumn); this.elPlaceHolderEncrypted = override.replace(source.elPlaceHolderEncrypted, source.dbColumn); this.jsonSerialize = source.jsonSerialize; this.jsonDeserialize = source.jsonDeserialize; }