congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
PersistentEntity.getPropertyByName
Code IndexAdd Tabnine to your IDE (free)

How to use
getPropertyByName
method
in
org.grails.datastore.mapping.model.PersistentEntity

Best Java code snippets using org.grails.datastore.mapping.model.PersistentEntity.getPropertyByName (Showing top 20 results out of 315)

origin: org.grails/grails-datastore-core

@Override
public Class getPropertyType(String name) {
  PersistentProperty property = persistentEntity.getPropertyByName(name);
  if(property != null) {
    return property.getType();
  }
  return null;
}
origin: org.grails/grails-datastore-core

Object resolvePropertyValue(PersistentEntity entity, String property, Object value) {
  PersistentProperty persistentProperty = entity.getPropertyByName(property);
  Object resolved;
  if(persistentProperty instanceof Embedded) {
    resolved = value;
  }
  else {
    resolved = resolveIdIfEntity(value);
  }
  return resolved;
}
origin: org.grails/grails-datastore-core

private void buildUpdateStatement(StringBuilder queryString, Map<String, Object> propertiesToUpdate, List parameters, boolean hibernateCompatible) {
  queryString.append(SPACE).append("SET");
  // keys need to be sorted before query is built
  Set<String> keys = new TreeSet<String>(propertiesToUpdate.keySet());
  Iterator<String> iterator = keys.iterator();
  while (iterator.hasNext()) {
    String propertyName = iterator.next();
    PersistentProperty prop = entity.getPropertyByName(propertyName);
    if (prop == null) throw new InvalidDataAccessResourceUsageException("Property '"+propertyName+"' of class '"+entity.getName()+"' specified in update does not exist");
    parameters.add(propertiesToUpdate.get(propertyName));
    queryString.append(SPACE).append(logicalName).append(DOT).append(propertyName).append('=');
    queryString.append(PARAMETER_PREFIX).append(parameters.size());
    if (iterator.hasNext()) {
      queryString.append(COMMA);
    }
  }
}
origin: org.grails/grails-datastore-gorm

  @Override
  public void convertArguments(PersistentEntity persistentEntity) {
    ConversionService conversionService = persistentEntity
        .getMappingContext().getConversionService();
    String propertyName = this.propertyName;
    PersistentProperty<?> prop = persistentEntity
        .getPropertyByName(propertyName);
    Object[] arguments = this.arguments;
    convertArgumentsForProp(persistentEntity, prop, propertyName, arguments, conversionService);
  }
}
origin: org.grails/grails-datastore-gorm

@Override
public void convertArguments(PersistentEntity persistentEntity) {
  ConversionService conversionService = persistentEntity
      .getMappingContext().getConversionService();
  PersistentProperty<?> prop = persistentEntity
      .getPropertyByName(propertyName);
  convertArgumentsForProp(persistentEntity, prop, propertyName, arguments, conversionService);
}
origin: org.grails/grails-datastore-gorm

protected void validatePropertyName(String propertyName, String methodName) {
  if (persistentEntity == null) return;
  if (propertyName == null) {
    throw new IllegalArgumentException("Cannot use [" + methodName +
        "] restriction with null property name");
  }
  PersistentProperty property = persistentEntity.getPropertyByName(propertyName);
  if (property == null && persistentEntity.getIdentity().getName().equals(propertyName)) {
    property = persistentEntity.getIdentity();
  }
  if (property == null && !queryCreator.isSchemaless()) {
    throw new IllegalArgumentException("Property [" + propertyName +
        "] is not a valid property of class [" + persistentEntity + "]");
  }
}
origin: org.grails/grails-datastore-gorm-hibernate-core

protected void createKeyForProps(PersistentProperty grailsProp, String path, Table table,
    String columnName, List<?> propertyNames, String sessionFactoryBeanName) {
  List<Column> keyList = new ArrayList<Column>();
  keyList.add(new Column(columnName));
  for (Object po : propertyNames) {
    String propertyName = (String) po;
    PersistentProperty otherProp = grailsProp.getOwner().getPropertyByName(propertyName);
    String otherColumnName = getColumnNameForPropertyAndPath(otherProp, path, null, sessionFactoryBeanName);
    keyList.add(new Column(otherColumnName));
  }
  createUniqueKeyForColumns(table, columnName, keyList);
}
origin: org.grails/grails-datastore-gorm-hibernate-core

private int calculateForeignKeyColumnCount(PersistentEntity refDomainClass, String[] propertyNames) {
  int expectedForeignKeyColumnLength = 0;
  for (String propertyName : propertyNames) {
    PersistentProperty referencedProperty = refDomainClass.getPropertyByName(propertyName);
    if(referencedProperty instanceof ToOne) {
      ToOne toOne = (ToOne) referencedProperty;
      PersistentProperty[] compositeIdentity = toOne.getAssociatedEntity().getCompositeIdentity();
      if(compositeIdentity != null) {
        expectedForeignKeyColumnLength += compositeIdentity.length;
      }
      else {
        expectedForeignKeyColumnLength++;
      }
    }
    else {
      expectedForeignKeyColumnLength++;
    }
  }
  return expectedForeignKeyColumnLength;
}
origin: org.grails/grails-datastore-gorm-hibernate-core

@SuppressWarnings("unchecked")
static void doTypeConversionIfNeccessary(PersistentEntity entity, PropertyCriterion pc) {
  if (pc.getClass().getSimpleName().startsWith(SIZE_CONSTRAINT_PREFIX)) {
    return;
  }
  String property = pc.getProperty();
  Object value = pc.getValue();
  PersistentProperty p = entity.getPropertyByName(property);
  if (p != null && !p.getType().isInstance(value)) {
    pc.setValue(conversionService.convert(value, p.getType()));
  }
}
origin: org.grails/grails-hibernate

static void doTypeConversionIfNeccessary(PersistentEntity entity, PropertyCriterion pc) {
  if(!pc.getClass().getSimpleName().startsWith(SIZE_CONSTRAINT_PREFIX)) {
    String property = pc.getProperty();
    Object value = pc.getValue();
    PersistentProperty p = entity.getPropertyByName(property);
    if(p != null && !p.getType().isInstance(value)) {
      pc.setValue( conversionService.convert(value, p.getType()));
    }
  }
}
origin: org.grails/grails-datastore-core

@Override
public PersistentProperty getPropertyByName(String name) {
  if(name != null && name.contains(".")) {
    String[] props = name.split("\\.");
    // Get the embedded property type
    PersistentProperty embeddedProp = super.getPropertyByName(props[0]);
    if( embeddedProp instanceof Embedded) {
      PersistentEntity embeddedEntity = ((Embedded) embeddedProp).getAssociatedEntity();
      return embeddedEntity.getPropertyByName(props[1]);
    }
    return super.getPropertyByName(name);
  }
  else {
    return super.getPropertyByName(name);
  }
}
origin: org.grails/grails-datastore-gorm

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());
  }
}
origin: org.grails/grails-datastore-core

/**
 * Obtain the fetch strategy for the given property
 *
 * @param property The fetch strategy
 * @return A specific strategy or lazy by default
 */
protected FetchType fetchStrategy(String property) {
  final FetchType fetchType = fetchStrategies.get(property);
  if(fetchType != null) {
    return fetchType;
  }
  else {
    final PersistentProperty prop = entity.getPropertyByName(property);
    if(prop != null) {
      return prop.getMapping().getMappedForm().getFetchStrategy();
    }
  }
  return FetchType.LAZY;
}
origin: org.grails/grails-datastore-core

private static PersistentProperty validateProperty(PersistentEntity entity, String name, Class criterionType) {
  PersistentProperty identity = entity.getIdentity();
  if (identity != null && identity.getName().equals(name)) {
    return identity;
  }
  PersistentProperty[] compositeIdentity = ((AbstractPersistentEntity) entity).getCompositeIdentity();
  if(compositeIdentity != null) {
    for (PersistentProperty property : compositeIdentity) {
      if(property.getName().equals(name)) {
        return property;
      }
    }
  }
  PersistentProperty prop = entity.getPropertyByName(name);
  if (prop == null) {
    throw new InvalidDataAccessResourceUsageException("Cannot use [" +
       criterionType.getSimpleName() + "] criterion on non-existent property: " + name);
  }
  return prop;
}
origin: org.grails/grails-datastore-core

/**
 * Creates an association query
 *
 * @param associationName The assocation name
 * @return The Query instance
 */
public AssociationQuery createQuery(String associationName) {
  final PersistentProperty property = entity.getPropertyByName(associationName);
  if (property == null || !(property instanceof Association)) {
    throw new InvalidDataAccessResourceUsageException("Cannot query association [" +
       associationName + "] of class [" + entity +
       "]. The specified property is not an association.");
  }
  Association association = (Association) property;
  final PersistentEntity associatedEntity = association.getAssociatedEntity();
  return new AssociationQuery(session, associatedEntity, association);
}
origin: org.grails/grails-datastore-core

@Override
public boolean isInherited() {
  if (inherited == null) {
    if (owner.isRoot()) {
      inherited = false;
    } else {
      PersistentEntity parentEntity = owner.getParentEntity();
      boolean foundInParent = false;
      while (parentEntity != null) {
        final PersistentProperty p = parentEntity.getPropertyByName(name);
        if (p != null) {
          foundInParent = true;
          break;
        }
        parentEntity = parentEntity.getParentEntity();
      }
      inherited = foundInParent;
    }
  }
  return inherited;
}
origin: org.grails/grails-datastore-gorm-hibernate-core

/**
 * Add order to criteria, creating necessary subCriteria if nested sort property (ie. sort:'nested.property').
 */
private static void addOrderPossiblyNested(Criteria c, PersistentEntity entity, String sort, String order, boolean ignoreCase) {
  int firstDotPos = sort.indexOf(".");
  if (firstDotPos == -1) {
    addOrder(c, sort, order, ignoreCase);
  } else { // nested property
    String sortHead = sort.substring(0,firstDotPos);
    String sortTail = sort.substring(firstDotPos+1);
    PersistentProperty property = entity.getPropertyByName(sortHead);
    if (property instanceof Embedded) {
      // embedded objects cannot reference entities (at time of writing), so no more recursion needed
      addOrder(c, sort, order, ignoreCase);
    } else if(property instanceof Association) {
      Association a = (Association) property;
      Criteria subCriteria = c.createCriteria(sortHead);
      PersistentEntity associatedEntity = a.getAssociatedEntity();
      Class<?> propertyTargetClass = associatedEntity.getJavaClass();
      cacheCriteriaByMapping(propertyTargetClass, subCriteria);
      addOrderPossiblyNested( subCriteria, associatedEntity, sortTail, order, ignoreCase); // Recurse on nested sort
    }
  }
}
origin: org.grails/grails-datastore-core

/**
 * @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.");
}
origin: org.grails/grails-hibernate

@Override
public AssociationQuery createQuery(String associationName) {
  final PersistentProperty property = entity.getPropertyByName(calculatePropertyName(associationName));
  if (property != null && (property instanceof Association)) {
    @SuppressWarnings("hiding") String alias = generateAlias(associationName);
    CriteriaAndAlias subCriteria = getOrCreateAlias(associationName, alias);
    Association association = (Association) property;
    return new HibernateAssociationQuery(subCriteria.criteria, (HibernateSession) getSession(), association.getAssociatedEntity(), association, alias);
  }
  throw new InvalidDataAccessApiUsageException("Cannot query association [" + calculatePropertyName(associationName) + "] of entity [" + entity + "]. Property is not an association!");
}
origin: org.grails/grails-datastore-gorm-hibernate-core

@Override
public AssociationQuery createQuery(String associationName) {
  final PersistentProperty property = entity.getPropertyByName(calculatePropertyName(associationName));
  if (property != null && (property instanceof Association)) {
    String alias = generateAlias(associationName);
    CriteriaAndAlias subCriteria = getOrCreateAlias(associationName, alias);
    Association association = (Association) property;
    if(subCriteria.criteria != null) {
      return new HibernateAssociationQuery(subCriteria.criteria, (AbstractHibernateSession) getSession(), association.getAssociatedEntity(), association, alias);
    }
    else if(subCriteria.detachedCriteria != null) {
      return new HibernateAssociationQuery(subCriteria.detachedCriteria, (AbstractHibernateSession) getSession(), association.getAssociatedEntity(), association, alias);
    }
  }
  throw new InvalidDataAccessApiUsageException("Cannot query association [" + calculatePropertyName(associationName) + "] of entity [" + entity + "]. Property is not an association!");
}
org.grails.datastore.mapping.modelPersistentEntitygetPropertyByName

Javadoc

Obtains a PersistentProperty instance by name

Popular methods of PersistentEntity

  • getJavaClass
  • getIdentity
    Returns the identity of the instance
  • getMapping
    Defines the mapping between this persistent entity and an external form
  • getName
    The entity name including any package prefix
  • getPersistentProperties
    A list of properties to be persisted
  • getVersion
    Returns the version property.
  • isMultiTenant
  • getAssociations
    A list of the associations for this entity. This is typically a subset of the list returned by #getP
  • getCompositeIdentity
    The composite id
  • getMappingContext
    Obtains the MappingContext where this PersistentEntity is defined
  • getReflector
  • getTenantId
  • getReflector,
  • getTenantId,
  • isInitialized,
  • isOwningEntity,
  • isRoot,
  • isVersioned,
  • addOwner,
  • getDecapitalizedName,
  • getDiscriminator

Popular in Java

  • Making http requests using okhttp
  • getSupportFragmentManager (FragmentActivity)
  • startActivity (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • Option (scala)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now