idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
14,300
private MethodHandle findIdReadMethod ( ) { try { Method readMethod = clazz . getMethod ( READ_METHOD_NAME ) ; Class < ? > dataClass = readMethod . getReturnType ( ) ; DataType dataType = IdentifierMetadata . DataType . forClass ( dataClass ) ; if ( dataType == null ) { String pattern = "Method %s in class %s must have...
Creates and returns the MethodHandle for reading the underlying ID .
14,301
private MethodHandle findConstructor ( ) { try { MethodHandle mh = MethodHandles . publicLookup ( ) . findConstructor ( clazz , MethodType . methodType ( void . class , getIdType ( ) ) ) ; return mh ; } catch ( NoSuchMethodException | IllegalAccessException exp ) { String pattern = "Class %s requires a public construct...
Creates and returns the MethodHandle for the constructor .
14,302
public static Object instantiate ( MetadataBase metadata ) { try { return metadata . getConstructorMetadata ( ) . getConstructorMethodHandle ( ) . invoke ( ) ; } catch ( Throwable t ) { throw new EntityManagerException ( t ) ; } }
Creates and returns a new instance of a persistence class for the given metadata . The returned object will be an instance of the primary persistence class or its Builder .
14,303
public static PropertyMetadata getPropertyMetadata ( Field field ) { Property property = field . getAnnotation ( Property . class ) ; try { PropertyMetadata propertyMetadata = new PropertyMetadata ( field ) ; return propertyMetadata ; } catch ( NoAccessorMethodException | NoMutatorMethodException exp ) { if ( property ...
Returns the metadata for the given field .
14,304
public static Object instantiateObject ( Class < ? > clazz ) { try { Constructor < ? > constructor = clazz . getConstructor ( ) ; return constructor . newInstance ( ) ; } catch ( Exception exp ) { throw new EntityManagerException ( exp ) ; } }
Creates a new object of given class by invoking the class default public constructor .
14,305
public static Object getFieldValue ( FieldMetadata fieldMetadata , Object target ) { MethodHandle readMethod = fieldMetadata . getReadMethod ( ) ; try { return readMethod . invoke ( target ) ; } catch ( Throwable t ) { throw new EntityManagerException ( t . getMessage ( ) , t ) ; } }
Returns the value of the field represented by the given metadata .
14,306
public static MethodHandle findStaticMethod ( Class < ? > clazz , String methodName , Class < ? > expectedReturnType , Class < ? > ... expectedParameterTypes ) { return findMethod ( clazz , methodName , true , expectedReturnType , expectedParameterTypes ) ; }
Finds and returns a MethodHandle for a public static method .
14,307
public static MethodHandle findInstanceMethod ( Class < ? > clazz , String methodName , Class < ? > expectedReturnType , Class < ? > ... expectedParameterTypes ) { return findMethod ( clazz , methodName , false , expectedReturnType , expectedParameterTypes ) ; }
Finds and returns a MethodHandle for a public instance method .
14,308
private static MethodHandle findMethod ( Class < ? > clazz , String methodName , boolean staticMethod , Class < ? > expectedReturnType , Class < ? > ... expectedParameterTypes ) { MethodHandle methodHandle = null ; try { Method method = clazz . getMethod ( methodName , expectedParameterTypes ) ; int modifiers = method ...
Finds and returns a method handle for the given criteria .
14,309
public void setOptional ( boolean optional ) { if ( field . getType ( ) . isPrimitive ( ) || field . isAnnotationPresent ( Version . class ) || field . isAnnotationPresent ( CreatedTimestamp . class ) || field . isAnnotationPresent ( UpdatedTimestamp . class ) ) { this . optional = false ; } else { this . optional = op...
Sets whether or not the field represented by this metadata is optional .
14,310
private void initializeSecondaryIndexer ( ) { SecondaryIndex secondaryIndexAnnotation = field . getAnnotation ( SecondaryIndex . class ) ; if ( secondaryIndexAnnotation == null ) { return ; } String indexName = secondaryIndexAnnotation . name ( ) ; if ( indexName == null || indexName . trim ( ) . length ( ) == 0 ) { in...
Initializes the secondary indexer for this property if any .
14,311
public static EntityListenersMetadata introspect ( Class < ? > entityClass ) { EntityListenersIntrospector introspector = new EntityListenersIntrospector ( entityClass ) ; introspector . introspect ( ) ; return introspector . metadata ; }
Returns the metadata of various registered listeners for the given entity class .
14,312
private List < Class < ? > > getAllExternalListeners ( ) { Class < ? > clazz = entityClass ; List < Class < ? > > allListeners = new ArrayList < > ( ) ; boolean stop = false ; while ( ! stop ) { EntityListeners entityListenersAnnotation = clazz . getAnnotation ( EntityListeners . class ) ; if ( entityListenersAnnotatio...
Inspects the entity hierarchy and returns all external listeners .
14,313
private void processExternalListener ( Class < ? > listenerClass ) { ExternalListenerMetadata listenerMetadata = ExternalListenerIntrospector . introspect ( listenerClass ) ; Map < CallbackType , Method > callbacks = listenerMetadata . getCallbacks ( ) ; if ( callbacks != null ) { for ( Map . Entry < CallbackType , Met...
Introspects the given listener class and finds all methods that should receive callback event notifications .
14,314
private void validateExternalCallback ( Method method , CallbackType callbackType ) { Class < ? > [ ] parameters = method . getParameterTypes ( ) ; if ( ! parameters [ 0 ] . isAssignableFrom ( entityClass ) ) { String message = String . format ( "Method %s in class %s is not valid for entity %s" , method . getName ( ) ...
Validates and registers the given callback method .
14,315
private void processInternalListeners ( ) { List < Class < ? > > internalListeners = getAllInternalListeners ( ) ; for ( Class < ? > internalListener : internalListeners ) { processInternalListener ( internalListener ) ; } }
Introspects the entity class hierarchy for any internal callback methods and updates the metadata .
14,316
private List < Class < ? > > getAllInternalListeners ( ) { Class < ? > clazz = entityClass ; List < Class < ? > > allListeners = new ArrayList < > ( ) ; boolean stop = false ; while ( ! stop ) { allListeners . add ( 0 , clazz ) ; boolean excludeSuperClassListeners = clazz . isAnnotationPresent ( ExcludeSuperclassListen...
Traverses up the entity class hierarchy and returns the list of all classes that may potentially have callback listeners .
14,317
private void processInternalListener ( Class < ? > listenerClass ) { InternalListenerMetadata listenerMetadata = InternalListenerIntrospector . introspect ( listenerClass ) ; Map < CallbackType , Method > callbacks = listenerMetadata . getCallbacks ( ) ; if ( callbacks != null ) { for ( Map . Entry < CallbackType , Met...
Processes the given class and finds any internal callbacks .
14,318
public Object getListener ( Class < ? > listenerClass ) { Object listener = listeners . get ( listenerClass ) ; if ( listener == null ) { listener = loadListener ( listenerClass ) ; } return listener ; }
Returns the listener object for the given class .
14,319
private Object loadListener ( Class < ? > listenerClass ) { synchronized ( listenerClass ) { Object listener = listeners . get ( listenerClass ) ; if ( listener == null ) { listener = IntrospectionUtils . instantiateObject ( listenerClass ) ; listeners . put ( listenerClass , listener ) ; } return listener ; } }
Instantiates the listener of given type and caches it .
14,320
public static EmbeddableMetadata introspect ( Class < ? > embeddableClass ) { EmbeddableIntrospector introspector = new EmbeddableIntrospector ( embeddableClass ) ; introspector . introspect ( ) ; return introspector . metadata ; }
Introspects the given Embeddable class and returns the metadata .
14,321
private void introspect ( ) { if ( ! embeddableClass . isAnnotationPresent ( Embeddable . class ) ) { String message = String . format ( "Class %s must have %s annotation" , embeddableClass . getName ( ) , Embeddable . class . getName ( ) ) ; throw new EntityManagerException ( message ) ; } metadata = new EmbeddableMet...
Introspects the Embeddable .
14,322
private void processFields ( ) { List < Field > fields = IntrospectionUtils . getPersistableFields ( embeddableClass ) ; for ( Field field : fields ) { if ( field . isAnnotationPresent ( Embedded . class ) ) { processEmbeddedField ( field ) ; } else { processSimpleField ( field ) ; } } }
Processes each field in this Embeddable and updates the metadata .
14,323
public static EmbeddedMetadata introspect ( EmbeddedField field , EntityMetadata entityMetadata ) { EmbeddedIntrospector introspector = new EmbeddedIntrospector ( field , entityMetadata ) ; introspector . process ( ) ; return introspector . metadata ; }
Introspects the given embedded field and returns its metadata .
14,324
private void process ( ) { metadata = new EmbeddedMetadata ( field ) ; if ( ! clazz . isAnnotationPresent ( Embeddable . class ) ) { String message = String . format ( "Class %s must have %s annotation" , clazz . getName ( ) , Embeddable . class . getName ( ) ) ; throw new EntityManagerException ( message ) ; } Embedde...
Worker class for introspection .
14,325
private void processFields ( ) { List < Field > children = IntrospectionUtils . getPersistableFields ( clazz ) ; for ( Field child : children ) { if ( child . isAnnotationPresent ( Embedded . class ) ) { processEmbeddedField ( child ) ; } else { processSimpleField ( child ) ; } } }
Processes each field in this embedded object and updates the metadata .
14,326
private void processPropertyOverride ( PropertyMetadata propertyMetadata ) { String qualifiedName = field . getQualifiedName ( ) + "." + propertyMetadata . getField ( ) . getName ( ) ; Property override = entityMetadata . getPropertyOverride ( qualifiedName ) ; if ( override != null ) { String mappedName = override . n...
Processes the override if any for the given property .
14,327
private void validateIntent ( ) { if ( entityMetadata . isProjectedEntity ( ) && ! intent . isValidOnProjectedEntities ( ) ) { String message = String . format ( "Operation %s is not allowed for ProjectedEntity %s" , intent , entity . getClass ( ) . getName ( ) ) ; throw new EntityManagerException ( message ) ; } }
Validates if the Intent is legal for the entity being marshalled .
14,328
private BaseEntity < ? > marshal ( ) { marshalKey ( ) ; if ( key instanceof Key ) { entityBuilder = Entity . newBuilder ( ( Key ) key ) ; } else { entityBuilder = FullEntity . newBuilder ( key ) ; } marshalFields ( ) ; marshalAutoTimestampFields ( ) ; if ( intent == Intent . UPDATE ) { marshalVersionField ( ) ; } marsh...
Marshals the given entity and and returns the equivalent Entity needed for the underlying Cloud Datastore API .
14,329
public static Key marshalKey ( DefaultEntityManager entityManager , Object entity ) { Marshaller marshaller = new Marshaller ( entityManager , entity , Intent . DELETE ) ; marshaller . marshalKey ( ) ; return ( Key ) marshaller . key ; }
Extracts the key from the given object entity and returns it . The entity must have its ID set .
14,330
private void marshalKey ( ) { Key parent = null ; ParentKeyMetadata parentKeyMetadata = entityMetadata . getParentKeyMetadata ( ) ; if ( parentKeyMetadata != null ) { DatastoreKey parentDatastoreKey = ( DatastoreKey ) getFieldValue ( parentKeyMetadata ) ; if ( parentDatastoreKey != null ) { parent = parentDatastoreKey ...
Marshals the key .
14,331
private static boolean isValidId ( Object idValue , DataType identifierType ) { boolean validId = false ; if ( idValue != null ) { switch ( identifierType ) { case LONG : case LONG_OBJECT : validId = ( long ) idValue != 0 ; break ; case STRING : validId = ( ( String ) idValue ) . trim ( ) . length ( ) > 0 ; break ; def...
Checks to see if the given value is a valid identifier for the given ID type .
14,332
private void createCompleteKey ( Key parent , long id ) { String kind = entityMetadata . getKind ( ) ; if ( parent == null ) { key = entityManager . newNativeKeyFactory ( ) . setKind ( kind ) . newKey ( id ) ; } else { key = Key . newBuilder ( parent , kind , id ) . build ( ) ; } }
Creates a complete key using the given parameters .
14,333
private void createIncompleteKey ( Key parent ) { String kind = entityMetadata . getKind ( ) ; if ( parent == null ) { key = entityManager . newNativeKeyFactory ( ) . setKind ( kind ) . newKey ( ) ; } else { key = IncompleteKey . newBuilder ( parent , kind ) . build ( ) ; } }
Creates an IncompleteKey .
14,334
private void marshalFields ( ) { Collection < PropertyMetadata > propertyMetadataCollection = entityMetadata . getPropertyMetadataCollection ( ) ; for ( PropertyMetadata propertyMetadata : propertyMetadataCollection ) { marshalField ( propertyMetadata , entity ) ; } }
Marshals all the fields .
14,335
private static void marshalField ( PropertyMetadata propertyMetadata , Object target , BaseEntity . Builder < ? , ? > entityBuilder ) { Object fieldValue = IntrospectionUtils . getFieldValue ( propertyMetadata , target ) ; if ( fieldValue == null && propertyMetadata . isOptional ( ) ) { return ; } ValueBuilder < ? , ? ...
Marshals the field with the given property metadata .
14,336
private void marshalEmbeddedFields ( ) { for ( EmbeddedMetadata embeddedMetadata : entityMetadata . getEmbeddedMetadataCollection ( ) ) { if ( embeddedMetadata . getStorageStrategy ( ) == StorageStrategy . EXPLODED ) { marshalWithExplodedStrategy ( embeddedMetadata , entity ) ; } else { ValueBuilder < ? , ? , ? > embed...
Marshals the embedded fields .
14,337
private void marshalWithExplodedStrategy ( EmbeddedMetadata embeddedMetadata , Object target ) { try { Object embeddedObject = initializeEmbedded ( embeddedMetadata , target ) ; for ( PropertyMetadata propertyMetadata : embeddedMetadata . getPropertyMetadataCollection ( ) ) { marshalField ( propertyMetadata , embeddedO...
Marshals an embedded field represented by the given metadata .
14,338
private ValueBuilder < ? , ? , ? > marshalWithImplodedStrategy ( EmbeddedMetadata embeddedMetadata , Object target ) { try { Object embeddedObject = embeddedMetadata . getReadMethod ( ) . invoke ( target ) ; if ( embeddedObject == null ) { if ( embeddedMetadata . isOptional ( ) ) { return null ; } NullValue . Builder n...
Marshals the embedded field represented by the given metadata .
14,339
private void marshalUpdatedTimestamp ( ) { PropertyMetadata updatedTimestampMetadata = entityMetadata . getUpdatedTimestampMetadata ( ) ; if ( updatedTimestampMetadata != null ) { applyAutoTimestamp ( updatedTimestampMetadata , System . currentTimeMillis ( ) ) ; } }
Marshals the updated timestamp field .
14,340
private void marshalCreatedAndUpdatedTimestamp ( ) { PropertyMetadata createdTimestampMetadata = entityMetadata . getCreatedTimestampMetadata ( ) ; PropertyMetadata updatedTimestampMetadata = entityMetadata . getUpdatedTimestampMetadata ( ) ; long millis = System . currentTimeMillis ( ) ; if ( createdTimestampMetadata ...
Marshals both created and updated timestamp fields .
14,341
private void marshalVersionField ( ) { PropertyMetadata versionMetadata = entityMetadata . getVersionMetadata ( ) ; if ( versionMetadata != null ) { long version = ( long ) IntrospectionUtils . getFieldValue ( versionMetadata , entity ) ; ValueBuilder < ? , ? , ? > valueBuilder = versionMetadata . getMapper ( ) . toDat...
Marshals the version field if it exists . The version will be set to one more than the previous value .
14,342
private void initializeMapper ( ) { if ( itemClass == null ) { itemMapper = CatchAllMapper . getInstance ( ) ; } else { try { itemMapper = MapperFactory . getInstance ( ) . getMapper ( itemClass ) ; } catch ( NoSuitableMapperException exp ) { itemMapper = CatchAllMapper . getInstance ( ) ; } } }
Initializes the mapper for items in the List .
14,343
public void setJsonCredentialsFile ( String jsonCredentialsPath ) { if ( ! Utility . isNullOrEmpty ( jsonCredentialsPath ) ) { setJsonCredentialsFile ( new File ( jsonCredentialsPath ) ) ; } else { setJsonCredentialsFile ( ( File ) null ) ; } }
Sets the JSON credentials path .
14,344
private void initializeMapper ( ) { if ( valueClass == null ) { valueMapper = CatchAllMapper . getInstance ( ) ; } else { try { valueMapper = MapperFactory . getInstance ( ) . getMapper ( valueClass ) ; } catch ( NoSuitableMapperException exp ) { valueMapper = CatchAllMapper . getInstance ( ) ; } } }
Initializes the mapper for values in the Map .
14,345
public static InternalListenerMetadata introspect ( Class < ? > listenerClass ) { InternalListenerMetadata cachedMetadata = cache . get ( listenerClass ) ; if ( cachedMetadata != null ) { return cachedMetadata ; } synchronized ( listenerClass ) { cachedMetadata = cache . get ( listenerClass ) ; if ( cachedMetadata != n...
Introspects the given class for any defined listeners and returns the metadata .
14,346
private void processMethods ( ) { Method [ ] methods = listenerClass . getDeclaredMethods ( ) ; for ( Method method : methods ) { for ( CallbackType callbackType : CallbackType . values ( ) ) { if ( method . isAnnotationPresent ( callbackType . getAnnotationClass ( ) ) ) { validateMethod ( method , callbackType ) ; met...
Processes the methods in the listener class and updates the metadata for any valid methods found .
14,347
private void validateMethod ( Method method , CallbackType callbackType ) { int modifiers = method . getModifiers ( ) ; if ( ! Modifier . isPublic ( modifiers ) ) { String message = String . format ( "Method %s in class %s must be public" , method . getName ( ) , method . getDeclaringClass ( ) . getName ( ) ) ; throw n...
Validates the given method to ensure if it is a valid callback method for the given event type .
14,348
public < E > E insert ( E entity ) { try { entityManager . executeEntityListeners ( CallbackType . PRE_INSERT , entity ) ; FullEntity < ? > nativeEntity = ( FullEntity < ? > ) Marshaller . marshal ( entityManager , entity , Intent . INSERT ) ; Entity insertedNativeEntity = nativeWriter . add ( nativeEntity ) ; @ Suppre...
Inserts the given entity into the Cloud Datastore .
14,349
@ SuppressWarnings ( "unchecked" ) public < E > List < E > insert ( List < E > entities ) { if ( entities == null || entities . isEmpty ( ) ) { return new ArrayList < > ( ) ; } try { entityManager . executeEntityListeners ( CallbackType . PRE_INSERT , entities ) ; FullEntity < ? > [ ] nativeEntities = toNativeFullEntit...
Inserts the given list of entities into the Cloud Datastore .
14,350
@ SuppressWarnings ( "unchecked" ) public < E > E update ( E entity ) { try { entityManager . executeEntityListeners ( CallbackType . PRE_UPDATE , entity ) ; Intent intent = ( nativeWriter instanceof Batch ) ? Intent . BATCH_UPDATE : Intent . UPDATE ; Entity nativeEntity = ( Entity ) Marshaller . marshal ( entityManage...
Updates the given entity in the Cloud Datastore . The passed in Entity must have its ID set for the update to work .
14,351
@ SuppressWarnings ( "unchecked" ) public < E > List < E > update ( List < E > entities ) { if ( entities == null || entities . isEmpty ( ) ) { return new ArrayList < > ( ) ; } try { Class < E > entityClass = ( Class < E > ) entities . get ( 0 ) . getClass ( ) ; entityManager . executeEntityListeners ( CallbackType . P...
Updates the given list of entities in the Cloud Datastore .
14,352
public < E > E updateWithOptimisticLock ( E entity ) { PropertyMetadata versionMetadata = EntityIntrospector . getVersionMetadata ( entity ) ; if ( versionMetadata == null ) { return update ( entity ) ; } else { return updateWithOptimisticLockingInternal ( entity , versionMetadata ) ; } }
Updates the given entity with optimistic locking if the entity is set up to support optimistic locking . Otherwise a normal update is performed .
14,353
public < E > List < E > updateWithOptimisticLock ( List < E > entities ) { if ( entities == null || entities . isEmpty ( ) ) { return new ArrayList < > ( ) ; } Class < ? > entityClass = entities . get ( 0 ) . getClass ( ) ; PropertyMetadata versionMetadata = EntityIntrospector . getVersionMetadata ( entityClass ) ; if ...
Updates the given list of entities using optimistic locking feature if the entities are set up to support optimistic locking . Otherwise a normal update is performed .
14,354
@ SuppressWarnings ( "unchecked" ) protected < E > E updateWithOptimisticLockingInternal ( E entity , PropertyMetadata versionMetadata ) { Transaction transaction = null ; try { entityManager . executeEntityListeners ( CallbackType . PRE_UPDATE , entity ) ; Entity nativeEntity = ( Entity ) Marshaller . marshal ( entity...
Worker method for updating the given entity with optimistic locking .
14,355
@ SuppressWarnings ( "unchecked" ) protected < E > List < E > updateWithOptimisticLockInternal ( List < E > entities , PropertyMetadata versionMetadata ) { Transaction transaction = null ; try { entityManager . executeEntityListeners ( CallbackType . PRE_UPDATE , entities ) ; Entity [ ] nativeEntities = toNativeEntitie...
Internal worker method for updating the entities using optimistic locking .
14,356
public < E > E upsert ( E entity ) { try { entityManager . executeEntityListeners ( CallbackType . PRE_UPSERT , entity ) ; FullEntity < ? > nativeEntity = ( FullEntity < ? > ) Marshaller . marshal ( entityManager , entity , Intent . UPSERT ) ; Entity upsertedNativeEntity = nativeWriter . put ( nativeEntity ) ; @ Suppre...
Updates or inserts the given entity in the Cloud Datastore . If the entity does not have an ID it may be generated .
14,357
@ SuppressWarnings ( "unchecked" ) public < E > List < E > upsert ( List < E > entities ) { if ( entities == null || entities . isEmpty ( ) ) { return new ArrayList < > ( ) ; } try { entityManager . executeEntityListeners ( CallbackType . PRE_UPSERT , entities ) ; FullEntity < ? > [ ] nativeEntities = toNativeFullEntit...
Updates or inserts the given list of entities in the Cloud Datastore . If the entities do not have a valid ID IDs may be generated .
14,358
public void delete ( Object entity ) { try { entityManager . executeEntityListeners ( CallbackType . PRE_DELETE , entity ) ; Key nativeKey = Marshaller . marshalKey ( entityManager , entity ) ; nativeWriter . delete ( nativeKey ) ; entityManager . executeEntityListeners ( CallbackType . POST_DELETE , entity ) ; } catch...
Deletes the given entity from the Cloud Datastore .
14,359
public void delete ( List < ? > entities ) { try { entityManager . executeEntityListeners ( CallbackType . PRE_DELETE , entities ) ; Key [ ] nativeKeys = new Key [ entities . size ( ) ] ; for ( int i = 0 ; i < entities . size ( ) ; i ++ ) { nativeKeys [ i ] = Marshaller . marshalKey ( entityManager , entities . get ( i...
Deletes the given entities from the Cloud Datastore .
14,360
public < E > void delete ( Class < E > entityClass , DatastoreKey parentKey , long id ) { try { EntityMetadata entityMetadata = EntityIntrospector . introspect ( entityClass ) ; Key nativeKey = Key . newBuilder ( parentKey . nativeKey ( ) , entityMetadata . getKind ( ) , id ) . build ( ) ; nativeWriter . delete ( nativ...
Deletes the entity with the given ID and parent key .
14,361
public void deleteByKey ( DatastoreKey key ) { try { nativeWriter . delete ( key . nativeKey ( ) ) ; } catch ( DatastoreException exp ) { throw DatastoreUtils . wrap ( exp ) ; } }
Deletes an entity given its key .
14,362
public void deleteByKey ( List < DatastoreKey > keys ) { try { Key [ ] nativeKeys = new Key [ keys . size ( ) ] ; for ( int i = 0 ; i < keys . size ( ) ; i ++ ) { nativeKeys [ i ] = keys . get ( i ) . nativeKey ( ) ; } nativeWriter . delete ( nativeKeys ) ; } catch ( DatastoreException exp ) { throw DatastoreUtils . wr...
Deletes the entities having the given keys .
14,363
public void setNamedBindings ( Map < String , Object > namedBindings ) { if ( namedBindings == null ) { throw new IllegalArgumentException ( "namedBindings cannot be null" ) ; } this . namedBindings = namedBindings ; }
Sets the named bindings that are needed for any named parameters in the GQL query .
14,364
public void addPositionalBindings ( Object first , Object ... others ) { positionalBindings . add ( first ) ; positionalBindings . addAll ( Arrays . asList ( others ) ) ; }
Adds the positional bindings that are needed for any positional parameters in the GQL query .
14,365
private void computeQualifiedName ( ) { if ( parent != null ) { qualifiedName = parent . qualifiedName + "." + field . getName ( ) ; } else { qualifiedName = field . getName ( ) ; } }
Computes and sets the qualified name of this field .
14,366
public void put ( CallbackType callbackType , CallbackMetadata callbackMetadata ) { if ( callbacks == null ) { callbacks = new EnumMap < > ( CallbackType . class ) ; } List < CallbackMetadata > callbackMetadataList = callbacks . get ( callbackType ) ; if ( callbackMetadataList == null ) { callbackMetadataList = new Arr...
Adds the given CallbackEventMetadata .
14,367
public List < CallbackMetadata > getCallbacks ( CallbackType callbackType ) { return callbacks == null ? null : callbacks . get ( callbackType ) ; }
Returns the callbacks for the given callback type .
14,368
private static ConstructorMetadata loadMetadata ( Class < ? > clazz ) { synchronized ( clazz ) { ConstructorMetadata metadata = cache . get ( clazz ) ; if ( metadata == null ) { ConstructorIntrospector introspector = new ConstructorIntrospector ( clazz ) ; introspector . process ( ) ; metadata = introspector . metadata...
Loads the metadata if it does not already exist in the cache .
14,369
private void process ( ) { metadataBuilder = ConstructorMetadata . newBuilder ( ) . setClazz ( clazz ) ; MethodHandle mh = IntrospectionUtils . findDefaultConstructor ( clazz ) ; if ( mh != null ) { metadataBuilder . setConstructionStrategy ( ConstructorMetadata . ConstructionStrategy . CLASSIC ) . setConstructorMethod...
Introspects the class and builds the metadata .
14,370
public static MethodHandle findNewBuilderMethod ( Class < ? > clazz ) { MethodHandle mh = null ; for ( String methodName : NEW_BUILDER_METHOD_NAMES ) { mh = IntrospectionUtils . findStaticMethod ( clazz , methodName , Object . class ) ; if ( mh != null ) { break ; } } return mh ; }
Finds and returns a method handle for new instance of a Builder class .
14,371
public static < T > T unmarshal ( Entity nativeEntity , Class < T > entityClass ) { return unmarshalBaseEntity ( nativeEntity , entityClass ) ; }
Unmarshals the given native Entity into an object of given type entityClass .
14,372
public static < T > T unmarshal ( ProjectionEntity nativeEntity , Class < T > entityClass ) { return unmarshalBaseEntity ( nativeEntity , entityClass ) ; }
Unmarshals the given native ProjectionEntity into an object of given type entityClass .
14,373
@ SuppressWarnings ( "unchecked" ) private < T > T unmarshal ( ) { try { instantiateEntity ( ) ; unmarshalIdentifier ( ) ; unmarshalKeyAndParentKey ( ) ; unmarshalProperties ( ) ; unmarshalEmbeddedFields ( ) ; ConstructorMetadata constructorMetadata = entityMetadata . getConstructorMetadata ( ) ; if ( constructorMetada...
Unmarshals the given Datastore Entity and returns the equivalent Entity POJO .
14,374
private static < T > T unmarshalBaseEntity ( BaseEntity < ? > nativeEntity , Class < T > entityClass ) { if ( nativeEntity == null ) { return null ; } Unmarshaller unmarshaller = new Unmarshaller ( nativeEntity , entityClass ) ; return unmarshaller . unmarshal ( ) ; }
Unmarshals the given BaseEntity and returns the equivalent model object .
14,375
private void unmarshalIdentifier ( ) throws Throwable { IdentifierMetadata identifierMetadata = entityMetadata . getIdentifierMetadata ( ) ; Object id = ( ( Key ) nativeEntity . getKey ( ) ) . getNameOrId ( ) ; IdClassMetadata idClassMetadata = identifierMetadata . getIdClassMetadata ( ) ; if ( idClassMetadata != null ...
Unamrshals the identifier .
14,376
private void unmarshalKeyAndParentKey ( ) throws Throwable { KeyMetadata keyMetadata = entityMetadata . getKeyMetadata ( ) ; if ( keyMetadata != null ) { MethodHandle writeMethod = keyMetadata . getWriteMethod ( ) ; Key entityKey = ( Key ) nativeEntity . getKey ( ) ; writeMethod . invoke ( entity , new DefaultDatastore...
Unamrshals the entity s key and parent key .
14,377
private void unmarshalProperties ( ) throws Throwable { Collection < PropertyMetadata > propertyMetadataCollection = entityMetadata . getPropertyMetadataCollection ( ) ; for ( PropertyMetadata propertyMetadata : propertyMetadataCollection ) { unmarshalProperty ( propertyMetadata , entity ) ; } }
Unmarshal all the properties .
14,378
private void unmarshalEmbeddedFields ( ) throws Throwable { for ( EmbeddedMetadata embeddedMetadata : entityMetadata . getEmbeddedMetadataCollection ( ) ) { if ( embeddedMetadata . getStorageStrategy ( ) == StorageStrategy . EXPLODED ) { unmarshalWithExplodedStrategy ( embeddedMetadata , entity ) ; } else { unmarshalWi...
Unmarshals the embedded fields of this entity .
14,379
private void unmarshalWithExplodedStrategy ( EmbeddedMetadata embeddedMetadata , Object target ) throws Throwable { Object embeddedObject = initializeEmbedded ( embeddedMetadata , target ) ; for ( PropertyMetadata propertyMetadata : embeddedMetadata . getPropertyMetadataCollection ( ) ) { unmarshalProperty ( propertyMe...
Unmarshals the embedded field represented by the given embedded metadata .
14,380
private static void unmarshalWithImplodedStrategy ( EmbeddedMetadata embeddedMetadata , Object target , BaseEntity < ? > nativeEntity ) throws Throwable { Object embeddedObject = null ; ConstructorMetadata constructorMetadata = embeddedMetadata . getConstructorMetadata ( ) ; FullEntity < ? > nativeEmbeddedEntity = null...
Unmarshals the embedded field represented by the given metadata .
14,381
private void unmarshalProperty ( PropertyMetadata propertyMetadata , Object target ) throws Throwable { unmarshalProperty ( propertyMetadata , target , nativeEntity ) ; }
Unmarshals the property represented by the given property metadata and updates the target object with the property value .
14,382
public void setIdentifierMetadata ( IdentifierMetadata identifierMetadata ) { if ( this . identifierMetadata != null ) { String format = "Class %s has at least two fields, %s and %s, marked with %s annotation. " + "Only one field can be marked as an identifier. " ; String message = String . format ( format , entityClas...
Sets the metadata of the identifier . An exception will be thrown if there is an IdentifierMetadata already set .
14,383
public void setKeyMetadata ( KeyMetadata keyMetadata ) { if ( this . keyMetadata != null ) { String format = "Class %s has two fields, %s and %s marked with %s annotation. Only one " + "field can be marked as Key. " ; String message = String . format ( format , entityClass . getName ( ) , this . keyMetadata . getName (...
Sets the metadata of the Key field .
14,384
public void setParentKetMetadata ( ParentKeyMetadata parentKeyMetadata ) { if ( this . parentKeyMetadata != null ) { String format = "Class %s has two fields, %s and %s marked with %s annotation. Only one " + "field can be marked as ParentKey. " ; String message = String . format ( format , entityClass . getName ( ) , ...
Sets the metadata about the parent key .
14,385
public void setVersionMetadata ( PropertyMetadata versionMetadata ) { if ( this . versionMetadata != null ) { throwDuplicateAnnotationException ( entityClass , Version . class , this . versionMetadata , versionMetadata ) ; } this . versionMetadata = versionMetadata ; }
Sets the metadata of the field that is used for optimistic locking .
14,386
public void setCreatedTimestampMetadata ( PropertyMetadata createdTimestampMetadata ) { if ( this . createdTimestampMetadata != null ) { throwDuplicateAnnotationException ( entityClass , CreatedTimestamp . class , this . createdTimestampMetadata , createdTimestampMetadata ) ; } this . createdTimestampMetadata = created...
Sets the created timestamp metadata to the given value .
14,387
public void updateMasterPropertyMetadataMap ( String mappedName , String qualifiedName ) { String old = masterPropertyMetadataMap . put ( mappedName , qualifiedName ) ; if ( old != null ) { String message = "Duplicate property %s in entity %s. Check fields %s and %s" ; throw new EntityManagerException ( String . format...
Updates the master property metadata map with the given property metadata .
14,388
private void ensureUniqueProperties ( EmbeddedMetadata embeddedMetadata , StorageStrategy storageStrategy ) { if ( embeddedMetadata . getStorageStrategy ( ) == StorageStrategy . EXPLODED ) { for ( PropertyMetadata propertyMetadata : embeddedMetadata . getPropertyMetadataCollection ( ) ) { updateMasterPropertyMetadataMa...
Validates the embedded field represented by the given metadata to ensure there are no duplicate property names defined across the entity .
14,389
private static void throwDuplicateAnnotationException ( Class < ? > entityClass , Class < ? extends Annotation > annotationClass , PropertyMetadata metadata1 , PropertyMetadata metadata2 ) { String format = "Class %s has at least two fields, %s and %s, with an annotation of %s. " + "A given entity can have at most one ...
Raises an exception with a detailed message reporting that the entity has more than one field that has a specific annotation .
14,390
public static ExternalListenerMetadata introspect ( Class < ? > listenerClass ) { ExternalListenerMetadata cachedMetadata = cache . get ( listenerClass ) ; if ( cachedMetadata != null ) { return cachedMetadata ; } synchronized ( listenerClass ) { cachedMetadata = cache . get ( listenerClass ) ; if ( cachedMetadata != n...
Introspects the given entity listener class and returns its metadata .
14,391
private void introspect ( ) { if ( ! listenerClass . isAnnotationPresent ( EntityListener . class ) ) { String message = String . format ( "Class %s must have %s annotation to be used as an EntityListener" , listenerClass . getName ( ) , EntityListener . class . getName ( ) ) ; throw new EntityManagerException ( messag...
Introspects the listener class and creates the metadata .
14,392
public Mapper getMapper ( Field field ) { PropertyMapper propertyMapperAnnotation = field . getAnnotation ( PropertyMapper . class ) ; if ( propertyMapperAnnotation != null ) { return createCustomMapper ( field , propertyMapperAnnotation ) ; } Class < ? > fieldType = field . getType ( ) ; if ( fieldType . equals ( BigD...
Returns the mapper for the given field . If the field has a custom mapper a new instance of the specified mapper will be created and returned . Otherwise one of the built - in mappers will be returned based on the field type .
14,393
public Mapper getMapper ( Type type ) { Mapper mapper = cache . get ( type ) ; if ( mapper == null ) { mapper = createMapper ( type ) ; } return mapper ; }
Returns a mapper for the given type . If a mapper that can handle given type exists in the cache it will be returned . Otherwise a new mapper will be created .
14,394
public void setDefaultMapper ( Type type , Mapper mapper ) { if ( mapper == null ) { throw new IllegalArgumentException ( "mapper cannot be null" ) ; } lock . lock ( ) ; try { cache . put ( type , mapper ) ; } finally { lock . unlock ( ) ; } }
Sets or registers the given mapper for the given type . This method must be called before performing any persistence operations preferably during application startup . Entities that were introspected before calling this method will NOT use the new mapper .
14,395
private Mapper createMapper ( Type type ) { lock . lock ( ) ; try { Mapper mapper = cache . get ( type ) ; if ( mapper != null ) { return mapper ; } if ( type instanceof Class ) { mapper = createMapper ( ( Class < ? > ) type ) ; } else if ( type instanceof ParameterizedType ) { mapper = createMapper ( ( ParameterizedTy...
Creates a new mapper for the given type .
14,396
private Mapper createMapper ( Class < ? > clazz ) { Mapper mapper ; if ( Enum . class . isAssignableFrom ( clazz ) ) { mapper = new EnumMapper ( clazz ) ; } else if ( Map . class . isAssignableFrom ( clazz ) ) { mapper = new MapMapper ( clazz ) ; } else if ( clazz . isAnnotationPresent ( Embeddable . class ) ) { mapper...
Creates a mapper for the given class .
14,397
private void createDefaultMappers ( ) { BooleanMapper booleanMapper = new BooleanMapper ( ) ; CharMapper charMapper = new CharMapper ( ) ; ShortMapper shortMapper = new ShortMapper ( ) ; IntegerMapper integerMapper = new IntegerMapper ( ) ; LongMapper longMapper = new LongMapper ( ) ; FloatMapper floatMapper = new Floa...
Creates and assigns default Mappers various common types .
14,398
private Mapper createCustomMapper ( Field field , PropertyMapper propertyMapperAnnotation ) { Class < ? extends Mapper > mapperClass = propertyMapperAnnotation . value ( ) ; Constructor < ? extends Mapper > constructor = IntrospectionUtils . getConstructor ( mapperClass , Field . class ) ; if ( constructor != null ) { ...
Creates and returns a custom mapper for the given field .
14,399
public void putListener ( CallbackType callbackType , Method method ) { if ( callbacks == null ) { callbacks = new EnumMap < > ( CallbackType . class ) ; } Method oldMethod = callbacks . put ( callbackType , method ) ; if ( oldMethod != null ) { String format = "Class %s has at least two methods, %s and %s, with annota...
Registers the given method as the callback method for the given event type .