congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
ErraiSingularAttribute
Code IndexAdd Tabnine to your IDE (free)

How to use
ErraiSingularAttribute
in
org.jboss.errai.jpa.client.local

Best Java code snippets using org.jboss.errai.jpa.client.local.ErraiSingularAttribute (Showing top 12 results out of 315)

origin: errai/errai

/**
 * Generates a new ID value for the given entity instance that is guaranteed
 * to be unique <i>on this client</i>. If the entity instance with this ID is
 * ever synchronized to the server, this client-local ID will be replaced by a
 * permanent server-generated ID.
 * <p>
 * This method only works for attributes that are configured as
 * {@code @GeneratedValue}s. The GenerationType has no effect locally, but of
 * course it will come into play on the server side when and if the entity is
 * synchronized to the server.
 *
 * @param entityInstance
 *          the entity instance to receive the generated ID. This attribute of
 *          that entity instance will be set to the newly generated ID value.
 * @return the generated ID value, which has already been set on the entity
 *         instance.
 */
private <X, T> T generateAndSetLocalId(final X entityInstance, final ErraiSingularAttribute<X, T> attr) {
 final T nextId = attr.getValueGenerator().next(this);
 attr.set(entityInstance, nextId);
 return nextId;
}
origin: errai/errai

@Override
public BigInteger next(ErraiEntityManager entityManager) {
 BigInteger nextAvailableId = nextCandidateId;
 while (entityManager.isKeyInUse(new Key<X, BigInteger>((ErraiIdentifiableType<X>) attr.getDeclaringType(), nextAvailableId))) {
  nextAvailableId = nextAvailableId.add(new BigInteger(String.valueOf(Math.random() * probeJumpSize)));
 }
 nextCandidateId = nextAvailableId.add(BigInteger.ONE);
 return nextAvailableId;
}
origin: errai/errai

ErraiIdentifiableType<E> entityType = desiredStateEm.getMetamodel().entity((Class<E>) newEntity.getClass());
ErraiSingularAttribute<? super E, Object> idAttr = entityType.getId(Object.class);
changeId(entityType, icr.getOldId(), idAttr.get(newEntity));
desiredStateEm.merge(newEntity);
 ErraiIdentifiableType<E> entityType = desiredStateEm.getMetamodel().entity(entityClass);
 ErraiSingularAttribute<? super E, Object> idAttr = entityType.getId(Object.class);
 ErraiIdGenerator<Object> idGenerator = idAttr.getValueGenerator();
 if (idGenerator != null && idGenerator.hasNext(desiredStateEm)) {
  Object newLocalId = idGenerator.next(desiredStateEm);
origin: errai/errai

Class<Y> attributeType = attr.getJavaType();
Y entityToReference = attr.get(targetEntity);
if (entityToReference == null) {
 return JSONNull.getInstance();
Object idToReference = attrEntityType.getId(Object.class).get(entityToReference);
JSONValue ref;
if (idToReference == null) {
origin: errai/errai

/**
 * Creates the key that describes the given entity, <b>generating and setting
 * it if it is presently unset and the given entity type's ID is configured to
 * be generated on demand</b>.
 *
 * @param entityType
 *          The entity type of the entity
 * @param entity
 *          The entity instance. <b>Side effect: this instance may have its ID
 *          value initialized as a result of this call</b>.
 * @return The key for the given entity, which--for generated values--may have
 *         just been set on the entity.
 */
public <X> Key<X, ?> keyFor(final ErraiIdentifiableType<X> entityType, final X entity) {
 ErraiSingularAttribute<? super X, ?> idAttr;
 switch (entityType.getIdType().getPersistenceType()) {
 case BASIC:
  idAttr = entityType.getId(entityType.getIdType().getJavaType());
  break;
 default:
  throw new RuntimeException(entityType.getIdType().getPersistenceType() + " ids are not yet supported");
 }
 Object id = idAttr.get(entity);
 if ( idAttr.isGeneratedValue() && (id == null || (id instanceof Number && ((Number) id).doubleValue() == 0.0)) ) {
  id = generateAndSetLocalId(entity, idAttr);
  // TODO track this generated ID for later reconciliation with the server
 }
 return new Key<>(entityType, id);
}
origin: errai/errai

protected <Y> void parseSingularJsonReference(
    X targetEntity, ErraiSingularAttribute<? super X, Y> attr, JSONValue attrJsonValue, ErraiEntityManager eem) {
 if (attrJsonValue == null || attrJsonValue.isNull() != null) return;
 Key<Y, ?> key = (Key<Y, ?>) Key.fromJsonObject(eem, attrJsonValue.isObject(), true);
 logger.trace("   looking for " + key);
 Y value = eem.find(key, Collections.<String,Object>emptyMap());
 attr.set(targetEntity, value);
}
origin: errai/errai

final ErraiIdentifiableType<X> entityType = getMetamodel().entity(getNarrowedClass(entity));
if (backend.isModified(key, entity)) {
 final Object currentId = entityType.getId(Object.class).get(entity);
 if (!key.getId().equals(currentId)) {
  throw new PersistenceException(
origin: errai/errai

 /**
  * Returns a Key instance based on the given JSON object.
  *
  * @param em
  *          The entity manager that can be used to look up the entity type
  *          corresponding with the key.
  * @param key
  *          The properties of the key to create.
  * @param failIfNotFound
  *          If true, and the entity type given in {@code key} is not known to
  *          {@code em}, an IllegalArgumentException will be thrown.
  * @return An instance of Key that corresponds with the entity type and ID of
  *         the given JSON object.
  */
 public static Key<?, ?> fromJsonObject(ErraiEntityManager em, JSONObject key, boolean failIfNotFound) {
  String entityClassName = key.get("entityType").isString().stringValue();
  ErraiIdentifiableType<Object> et = em.getMetamodel().entity(entityClassName, failIfNotFound);
  if (et == null) {
   return null;
  }
  ErraiSingularAttribute<?, Object> idAttr = et.getId(Object.class);
  Object id = JsonUtil.basicValueFromJson(key.get("id"), idAttr.getJavaType());

  return new Key<Object, Object>(et, id);
 }
}
origin: errai/errai

/**
 * Changes the ID of an existing entity in desiredStateEm.
 *
 * @param entityType The metamodel type for the entity whose ID is to be changed
 * @param oldId The ID that the entity currently has.
 * @param newId The ID that the entity will have when this method returns.
 */
private <E> void changeId(ErraiIdentifiableType<E> entityType, Object oldId, Object newId) {
 // XXX this routine is probably better handled internally by the ErraiEntityManager
 // TODO what about related entities that refer to this one? (needs tests)
 E entity = desiredStateEm.find(entityType.getJavaType(), oldId);
 desiredStateEm.remove(entity);
 desiredStateEm.flush();
 desiredStateEm.detach(entity);
 entityType.getId(Object.class).set(entity, newId);
 desiredStateEm.persist(entity);
}
origin: errai/errai

int index = 0;
for (E element : (Iterable<E>) attrValue) {
 Object idToReference = attrEntityType.getId(Object.class).get(element);
 JSONValue ref;
 if (idToReference == null) {
origin: errai/errai

 @Override
 public Long next(ErraiEntityManager entityManager) {
  while (entityManager.isKeyInUse(new Key<X, Long>((ErraiIdentifiableType<X>) attr.getDeclaringType(), nextCandidateId))) {
   nextCandidateId += (long) (Math.random() * probeJumpSize);

   // control rollover in case we run out of values
   if (nextCandidateId >= Long.MAX_VALUE - probeJumpSize) {
    nextCandidateId = 0;
   }
  }

  return nextCandidateId++;
 }
}
origin: errai/errai

@Override
public Integer next(ErraiEntityManager entityManager) {
 while (entityManager.isKeyInUse(new Key<X, Integer>((ErraiIdentifiableType<X>) attr.getDeclaringType(), nextCandidateId))) {
  nextCandidateId += (int) (Math.random() * probeJumpSize);
  // control rollover in case we run out of values
  if (nextCandidateId >= Integer.MAX_VALUE - probeJumpSize) {
   nextCandidateId = 1;
  }
 }
 return nextCandidateId++;
}
org.jboss.errai.jpa.client.localErraiSingularAttribute

Javadoc

Extends the JPA SingularAttribute interface with methods required by Errai persistence but missing from the JPA metamodel.

Most used methods

  • get
  • getValueGenerator
    Returns a generator for the values of this attribute. Only works for attributes that are annotated w
  • set
  • getDeclaringType
  • getJavaType
  • isGeneratedValue
    Can the attribute's value be generated (usually for ID attributes).

Popular in Java

  • Start an intent from android
  • setScale (BigDecimal)
  • getContentResolver (Context)
  • findViewById (Activity)
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Collectors (java.util.stream)
  • BoxLayout (javax.swing)
  • Runner (org.openjdk.jmh.runner)
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • 14 Best Plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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