private void registerEntityWithContext(PersistentEntity entity) { persistentEntities.remove(entity); persistentEntities.add(entity); persistentEntitiesByName.put(entity.getName(), entity); }
@Override public Validator getValidator(PersistentEntity entity) { String validatorName = entity.getName() + "Validator"; if (beanFactory.containsBean(validatorName)) { return beanFactory.getBean(validatorName, Validator.class); } return null; }
/** * Here for binary compatibility. Deprecated. * * @deprecated Use {@link #hasDateCreated(String)} instead */ protected boolean hasDateCreated(PersistentEntity entity) { return hasDateCreated(entity.getName()); }
public static EntityReflector getOrIntializeReflector(PersistentEntity persistentEntity) { String entityName = persistentEntity.getName(); EntityReflector entityReflector = REFLECTORS.get(entityName); if(entityReflector == null) { entityReflector = new FieldEntityReflector(persistentEntity); REFLECTORS.put(entityName, entityReflector); } return entityReflector; }
@Override public void setPropertyNoConversion(String name, Object value) { try { reflector.setProperty(entity, name, value); } catch (Exception e) { String valueType = value != null ? value.getClass().getName() : null; throw new IllegalArgumentException("Cannot assign value ["+value+"] with type ["+valueType+"] to property ["+name+"] of class ["+persistentEntity.getName()+"]. The value is not an acceptable type: " + e.getMessage(), e); } }
@Override public Family createMappedForm(PersistentEntity entity) { return new Family(keyspace, entity.getName()); }
/** * Here for binary compatibility. Deprecated. * * @deprecated Use {@link #hasLastUpdated(String)} instead */ protected boolean hasLastUpdated(PersistentEntity entity) { return hasLastUpdated(entity.getName()); }
/** * Builds a DELETE statement * * @return The JpaQueryInfo */ public JpaQueryInfo buildDelete() { StringBuilder queryString = new StringBuilder(DELETE_CLAUSE).append(entity.getName()).append(SPACE).append(logicalName); StringBuilder whereClause = new StringBuilder(); List parameters = buildWhereClause(entity, criteria, queryString, whereClause, logicalName, false); return new JpaQueryInfo(queryString.toString(), parameters); }
private void buildSelectClause(StringBuilder queryString) { Query.ProjectionList projectionList = this.projectionList; String logicalName = this.logicalName; PersistentEntity entity = this.entity; buildSelect(queryString, projectionList.getProjectionList(), logicalName, entity); queryString.append(FROM_CLAUSE) .append(entity.getName()) .append(AS_CLAUSE ) .append(logicalName); }
protected void initializeJoinStatus() { Boolean cachedStatus = JOIN_STATUS_CACHE.get(entity.getName()); if(cachedStatus != null) hasJoins = cachedStatus; else { for(Association a : entity.getAssociations()) { if( a.getFetchStrategy() == FetchType.EAGER ) hasJoins = true; } } }
@Override public void setIdentifierNoConversion(Object id) { try { reflector.setIdentifier(entity, id); } catch (Exception e) { throw new IllegalArgumentException("Cannot assign identifier ["+id+"] to property ["+reflector.getIdentifierName()+"] of type ["+reflector.identifierType().getName()+"] of class ["+persistentEntity.getName()+"]. The identifier is not an compatible type: " + e.getMessage(), e); } }
@Override public String toString() { return getOwner().getName() + "->" + getName(); }
protected void logCascadeMapping(Association grailsProperty, String cascadeStrategy, PersistentEntity referenced) { if (LOG.isDebugEnabled() & referenced != null) { String assType = getAssociationDescription(grailsProperty); LOG.debug("Mapping cascade strategy for " + assType + " property " + grailsProperty.getOwner().getName() + "." + grailsProperty.getName() + " referencing type [" + referenced.getJavaClass().getName() + "] -> [CASCADE: " + cascadeStrategy + "]"); } }
@Override public void setProperty(String name, Object value) { FieldEntityReflector.PropertyWriter writer = reflector.getPropertyWriter(name); Object converted; try { converted = conversionService.convert(value, writer.propertyType()); } catch (ConversionException e) { throw new IllegalArgumentException("Cannot assign value ["+value+"] to property ["+name+"] of type ["+writer.propertyType().getName()+"] of class ["+persistentEntity.getName()+"]. The value could not be converted to the appropriate type: " + e.getMessage(), e); } catch (Exception e) { throw new IllegalArgumentException("Cannot assign value ["+value+"] to property ["+name+"] of type ["+writer.propertyType().getName()+"] of class ["+persistentEntity.getName()+"]. The value is not an acceptable type: " + e.getMessage(), e); } writer.write(entity, converted); }
@Override public void setIdentifier(Object id) { Object converted; try { converted = conversionService.convert(id, reflector.identifierType()); } catch (ConversionException e) { throw new IllegalArgumentException("Cannot assign identifier ["+id+"] to property ["+reflector.getIdentifierName()+"] of type ["+reflector.identifierType().getName()+"] of class ["+persistentEntity.getName()+"]. The value could not be converted to the appropriate type: " + e.getMessage(), e); } catch (Exception e) { throw new IllegalArgumentException("Cannot assign identifier ["+id+"] to property ["+reflector.getIdentifierName()+"] of type ["+reflector.identifierType().getName()+"] of class ["+persistentEntity.getName()+"]. The identifier is not an compatible type: " + e.getMessage(), e); } reflector.setIdentifier(entity, converted); }
/** * @return The inverse side or null if the association is not bidirectional */ public Association getInverseSide() { final PersistentProperty associatedProperty = associatedEntity.getPropertyByName(referencedPropertyName); if (associatedProperty == null) return null; if (associatedProperty instanceof Association) { return (Association) associatedProperty; } throw new IllegalMappingException("The inverse side [" + associatedEntity.getName() + "." + associatedProperty.getName() + "] of the association [" + getOwner().getName() + "." + getName() + "] is not valid. Associations can only map to other entities and collection types."); }
protected String getForeignKeyForPropertyDomainClass(PersistentProperty property, String sessionFactoryBeanName) { final String propertyName = NameUtils.decapitalize( property.getOwner().getName() ); NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName); return namingStrategy.propertyToColumnName(propertyName) + FOREIGN_KEY_SUFFIX; }
public boolean beforeUpdate(PersistentEntity entity, EntityAccess ea) { if (hasLastUpdated(entity.getName())) { Class<?> lastUpdateType = ea.getPropertyType(LAST_UPDATED_PROPERTY); Object timestamp = timestampProvider.createTimestamp(lastUpdateType); ea.setProperty(LAST_UPDATED_PROPERTY, timestamp); } return true; }
@Override public Family createMappedForm(PersistentEntity entity) { Family family = super.createMappedForm(entity); if (family.getKeyspace() == null) { family.setKeyspace(keyspace); } if (family.getFamily() == null) { family.setFamily(entity.getName()); } return family; }
protected void storeDateCreatedAndLastUpdatedInfo(PersistentEntity persistentEntity) { if(persistentEntity.isInitialized()) { ClassMapping<?> classMapping = persistentEntity.getMapping(); Entity mappedForm = classMapping.getMappedForm(); if(mappedForm == null || mappedForm.isAutoTimestamp()) { storeTimestampAvailability(entitiesWithDateCreated, persistentEntity, persistentEntity.getPropertyByName(DATE_CREATED_PROPERTY)); storeTimestampAvailability(entitiesWithLastUpdated, persistentEntity, persistentEntity.getPropertyByName(LAST_UPDATED_PROPERTY)); } } else { uninitializedEntities.add(persistentEntity.getName()); } }