idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
200
public void attachInfo ( Context context , ProviderInfo info ) { super . attachInfo ( context , info ) ; if ( info . exported ) { throw new SecurityException ( "Provider must not be exported" ) ; } if ( ! info . grantUriPermissions ) { throw new SecurityException ( "Provider must grant uri permissions" ) ; } mStrategy = getPathStrategy ( context , info . authority ) ; }
After the FileProvider is instantiated this method is called to provide the system with information about the provider .
201
public static void cleanUp ( Context context ) { File path = getScreenshotFolder ( context ) ; if ( ! path . exists ( ) ) { return ; } delete ( path ) ; }
Delete the screenshot folder for this app . Be careful not to call this before any intents have finished using a screenshot reference .
202
private static void delete ( File file ) { if ( file . isDirectory ( ) ) { File [ ] files = file . listFiles ( ) ; if ( files != null ) { for ( File child : files ) { delete ( child ) ; } } } file . delete ( ) ; }
Recursive delete of a file or directory .
203
public static Drawable getCompatDrawable ( Context c , int drawableRes ) { Drawable d = null ; try { if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . LOLLIPOP ) { d = c . getResources ( ) . getDrawable ( drawableRes ) ; } else { d = c . getResources ( ) . getDrawable ( drawableRes , c . getTheme ( ) ) ; } } catch ( Exception ex ) { } return d ; }
helper method to get the drawable by its resource . specific to the correct android version
204
public static int getThemeAttributeDimensionSize ( Context context , int attr ) { TypedArray a = null ; try { a = context . getTheme ( ) . obtainStyledAttributes ( new int [ ] { attr } ) ; return a . getDimensionPixelSize ( 0 , 0 ) ; } finally { if ( a != null ) { a . recycle ( ) ; } } }
Returns the size in pixels of an attribute dimension
205
private boolean isMobileNetworkEnabled ( ConnectivityManager connectivityManager ) { final NetworkInfo info = connectivityManager . getNetworkInfo ( ConnectivityManager . TYPE_MOBILE ) ; return ( info != null && info . isConnected ( ) ) ; }
True if mobile network enabled
206
public void closeDrawer ( ) { if ( drawerLayout != null ) { if ( drawerGravity != 0 ) { drawerLayout . closeDrawer ( drawerGravity ) ; } else { drawerLayout . closeDrawer ( sliderLayout ) ; } } }
close the drawer
207
public void save ( OnSaveLogListener listener ) { File dir = getLogDir ( ) ; if ( dir == null ) { listener . onError ( "Can't save logs. External storage is not mounted. " + "Check android.permission.WRITE_EXTERNAL_STORAGE permission" ) ; return ; } FileWriter fileWriter = null ; try { File output = new File ( dir , getLogFileName ( ) ) ; fileWriter = new FileWriter ( output , true ) ; List < LogEntry > entries = bufferedLogs ( ) ; for ( LogEntry entry : entries ) { fileWriter . write ( entry . prettyPrint ( ) + "\n" ) ; } listener . onSave ( output ) ; } catch ( IOException e ) { listener . onError ( e . getMessage ( ) ) ; e . printStackTrace ( ) ; } finally { if ( fileWriter != null ) { try { fileWriter . close ( ) ; } catch ( IOException e ) { listener . onError ( e . getMessage ( ) ) ; e . printStackTrace ( ) ; } } } }
Save the current logs to disk .
208
void unregisterReceiver ( ) { try { final Context context = contextRef . get ( ) ; if ( context != null ) { context . unregisterReceiver ( receiver ) ; } } catch ( IllegalArgumentException e ) { } }
Unregister network state broadcast receiver
209
void registerReceiver ( ) { if ( receiver == null ) { receiver = new NetworkReceiver ( new Listener ( ) { public void post ( NetworkChangeEvent event ) { if ( onNetworkChangedListener != null ) { onNetworkChangedListener . onChanged ( event ) ; } } } ) ; } final Context context = contextRef . get ( ) ; if ( context != null ) { IntentFilter filter = new IntentFilter ( ) ; filter . addAction ( ConnectivityManager . CONNECTIVITY_ACTION ) ; filter . addAction ( BluetoothAdapter . ACTION_STATE_CHANGED ) ; context . registerReceiver ( receiver , filter ) ; } }
Register network state broadcast receiver
210
void setIsoEntry ( final Iso9660FileEntry entry ) { if ( null != this . entry ) { throw new RuntimeException ( "Cannot change the underlying entry once it has been set" ) ; } if ( null == entry ) { throw new IllegalArgumentException ( "'entry' cannot be null" ) ; } this . entry = entry ; this . type = ( entry . isDirectory ( ) ) ? FileType . FOLDER : FileType . FILE ; }
Sets the Iso9660FileEntry that backs this FileObject . This method is package - private because IsoFileSystem pre - creates some directory entries when building the file index and it needs to set the backing entry after the fact .
211
protected void doCloseCommunicationLink ( ) { if ( null != this . fileSystem && ! this . fileSystem . isClosed ( ) ) { try { this . fileSystem . close ( ) ; } catch ( IOException ex ) { VfsLog . warn ( getLogger ( ) , log , "vfs.provider.iso/close-iso-file.error :" + this . fileSystem , ex ) ; } } }
Closes the underlying . iso file .
212
public Iterator < ISO9660Directory > unsortedIterator ( ) { if ( unsortedIterator == null ) { unsortedIterator = new ISO9660DirectoryIterator ( this , false ) ; } unsortedIterator . reset ( ) ; return unsortedIterator ; }
Returns a directory iterator to traverse the directory hierarchy using a recursive method
213
protected final boolean readBlock ( final long block , final byte [ ] buffer ) throws IOException { final int bytesRead = readData ( block * this . blockSize , buffer , 0 , this . blockSize ) ; if ( bytesRead <= 0 ) { return false ; } if ( this . blockSize != bytesRead ) { throw new IOException ( "Could not deserialize a complete block" ) ; } return true ; }
Read the data for the specified block into the specified buffer .
214
protected final synchronized int readData ( final long startPos , final byte [ ] buffer , final int offset , final int len ) throws IOException { seek ( startPos ) ; return read ( buffer , offset , len ) ; }
Read file data starting at the specified position .
215
public void setVersion ( int version ) throws HandlerException { if ( version < 1 || version > ISO9660Constants . MAX_FILE_VERSION ) { throw new HandlerException ( "Invalid file version: " + version ) ; } this . version = version ; if ( parent != null ) { parent . forceSort ( ) ; } }
Set file version
216
public static long getUInt32 ( byte [ ] src , int offset ) { final long v0 = src [ offset ] & 0xFF ; final long v1 = src [ offset + 1 ] & 0xFF ; final long v2 = src [ offset + 2 ] & 0xFF ; final long v3 = src [ offset + 3 ] & 0xFF ; return ( ( v3 << 24 ) | ( v2 << 16 ) | ( v1 << 8 ) | v0 ) ; }
Gets a 32 - bit unsigned integer from the given byte array at the given offset .
217
public void addModeForPattern ( String pattern , Integer mode ) { System . out . println ( String . format ( "*** Recording pattern \"%s\" with mode %o" , pattern , mode ) ) ; patternToModeMap . put ( pattern , mode ) ; }
Add a new mode for a specific file pattern .
218
public static String getDChars ( byte [ ] block , int pos , int length ) { return new String ( block , pos - 1 , length ) . trim ( ) ; }
Gets a string of d - characters . See section 7 . 4 . 1 .
219
public void setMovedDirectoryStore ( ) { if ( movedDirectoriesStore == null ) { movedDirectoriesStore = new ISO9660Directory ( MOVED_DIRECTORIES_STORE_NAME ) ; addDirectory ( movedDirectoriesStore ) ; sortedIterator = null ; } }
Create and Add Moved Directories Store to Directory Hierarchy
220
public void setUCS2Level ( int level ) throws ConfigException { if ( level != 1 && level != 2 && level != 3 ) { throw new ConfigException ( this , "Invalid UCS-2 level: " + level ) ; } this . ucs2_level = level ; }
Set UCS - 2 Level
221
public void allowASCII ( boolean allow ) { this . allowASCII = allow ; ISO9660NamingConventions . FORCE_ISO9660_CHARSET = ! allow ; if ( allow ) { System . out . println ( "Warning: Allowing the full ASCII character set breaks ISO 9660 conformance." ) ; } }
Allow ASCII for filenames and other strings
222
private void deserializePrimary ( byte [ ] descriptor ) throws IOException { if ( this . hasPrimary ) { return ; } validateBlockSize ( descriptor ) ; if ( ! this . hasSupplementary ) { deserializeCommon ( descriptor ) ; } this . standardIdentifier = Util . getDChars ( descriptor , 2 , 5 ) ; this . volumeSetSize = Util . getUInt16Both ( descriptor , 121 ) ; this . volumeSequenceNumber = Util . getUInt16Both ( descriptor , 125 ) ; this . totalBlocks = Util . getUInt32Both ( descriptor , 81 ) ; this . publisher = Util . getDChars ( descriptor , 319 , 128 ) ; this . preparer = Util . getDChars ( descriptor , 447 , 128 ) ; this . application = Util . getDChars ( descriptor , 575 , 128 ) ; this . creationTime = Util . getStringDate ( descriptor , 814 ) ; this . mostRecentModificationTime = Util . getStringDate ( descriptor , 831 ) ; this . expirationTime = Util . getStringDate ( descriptor , 848 ) ; this . effectiveTime = Util . getStringDate ( descriptor , 865 ) ; this . pathTableSize = Util . getUInt32Both ( descriptor , 133 ) ; this . locationOfLittleEndianPathTable = Util . getUInt32LE ( descriptor , 141 ) ; this . locationOfOptionalLittleEndianPathTable = Util . getUInt32LE ( descriptor , 145 ) ; this . locationOfBigEndianPathTable = Util . getUInt32BE ( descriptor , 149 ) ; this . locationOfOptionalBigEndianPathTable = Util . getUInt32BE ( descriptor , 153 ) ; this . hasPrimary = true ; }
Read the fields of a primary volume descriptor .
223
private void deserializeSupplementary ( byte [ ] descriptor ) throws IOException { if ( this . hasSupplementary ) { return ; } validateBlockSize ( descriptor ) ; String escapeSequences = Util . getDChars ( descriptor , 89 , 32 ) ; String enc = getEncoding ( escapeSequences ) ; if ( null != enc ) { this . encoding = enc ; this . escapeSequences = escapeSequences ; deserializeCommon ( descriptor ) ; this . hasSupplementary = true ; } else { log . warn ( "Unsupported encoding, escapeSequences: '" + this . escapeSequences + "'" ) ; } }
The supplementary descriptor sets the character encoding and may override the common descriptor information .
224
private void deserializeCommon ( byte [ ] descriptor ) throws IOException { this . systemIdentifier = Util . getAChars ( descriptor , 9 , 32 , this . encoding ) ; this . volumeIdentifier = Util . getDChars ( descriptor , 41 , 32 , this . encoding ) ; this . volumeSetIdentifier = Util . getDChars ( descriptor , 191 , 128 , this . encoding ) ; this . rootDirectoryEntry = new Iso9660FileEntry ( this . isoFile , descriptor , 157 ) ; }
Read the information common to primary and secondary volume descriptors .
225
private void validateBlockSize ( byte [ ] descriptor ) throws IOException { int blockSize = Util . getUInt16Both ( descriptor , 129 ) ; if ( blockSize != Constants . DEFAULT_BLOCK_SIZE ) { throw new LoopFileSystemException ( "Invalid block size: " + blockSize ) ; } }
Check that the block size is what we expect .
226
private String getEncoding ( String escapeSequences ) { String encoding = null ; if ( escapeSequences . equals ( "%/@" ) ) { encoding = "UTF-16BE" ; } else if ( escapeSequences . equals ( "%/C" ) ) { encoding = "UTF-16BE" ; } else if ( escapeSequences . equals ( "%/E" ) ) { encoding = "UTF-16BE" ; } return encoding ; }
Derive an encoding name from the given escape sequences .
227
public void finalizeDisc ( File isoPath ) { ISOImageFileHandler handler = null ; try { handler = new ISOImageFileHandler ( isoPath ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } try { CreateISO iso = new CreateISO ( handler , root ) ; try { iso . process ( iso9660config , rockConfig , jolietConfig , elToritoConfig ) ; } catch ( HandlerException e ) { e . printStackTrace ( ) ; } } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } }
Close out the disc .
228
public List < FileItemStream > items ( String fieldName ) { List < FileItemStream > filteredItems = new ArrayList < FileItemStream > ( ) ; for ( FileItemStream fis : _items ) { if ( fis . getFieldName ( ) . equals ( fieldName ) ) filteredItems . add ( fis ) ; } return filteredItems ; }
find items with given form field name
229
public static FsItemFilter createMimeFilter ( final String [ ] mimeFilters ) { if ( mimeFilters == null || mimeFilters . length == 0 ) return FILTER_ALL ; return new FsItemFilter ( ) { public boolean accepts ( FsItemEx item ) { String mimeType = item . getMimeType ( ) . toUpperCase ( ) ; for ( String mf : mimeFilters ) { mf = mf . toUpperCase ( ) ; if ( mimeType . startsWith ( mf + "/" ) || mimeType . equals ( mf ) ) return true ; } return false ; } } ; }
returns a FsItemFilter according to given mimeFilters
230
protected CommandExecutorFactory createCommandExecutorFactory ( ServletConfig config ) { DefaultCommandExecutorFactory defaultCommandExecutorFactory = new DefaultCommandExecutorFactory ( ) ; defaultCommandExecutorFactory . setClassNamePattern ( "cn.bluejoe.elfinder.controller.executors.%sCommandExecutor" ) ; defaultCommandExecutorFactory . setFallbackCommand ( new MissingCommandExecutor ( ) ) ; return defaultCommandExecutorFactory ; }
create a command executor factory
231
protected ConnectorController createConnectorController ( ServletConfig config ) { ConnectorController connectorController = new ConnectorController ( ) ; connectorController . setCommandExecutorFactory ( createCommandExecutorFactory ( config ) ) ; connectorController . setFsServiceFactory ( createServiceFactory ( config ) ) ; return connectorController ; }
create a connector controller
232
protected StaticFsServiceFactory createServiceFactory ( ServletConfig config ) { StaticFsServiceFactory staticFsServiceFactory = new StaticFsServiceFactory ( ) ; DefaultFsService fsService = createFsService ( ) ; staticFsServiceFactory . setFsService ( fsService ) ; return staticFsServiceFactory ; }
create a service factory
233
private Collection < FsItemEx > findRecursively ( FsItemFilter filter , FsItem root ) { List < FsItemEx > results = new ArrayList < FsItemEx > ( ) ; FsVolume vol = root . getVolume ( ) ; for ( FsItem child : vol . listChildren ( root ) ) { if ( vol . isFolder ( child ) ) { results . addAll ( findRecursively ( filter , child ) ) ; } else { FsItemEx item = new FsItemEx ( child , this ) ; if ( filter . accepts ( item ) ) results . add ( item ) ; } } return results ; }
find files recursively in specific folder
234
static void removeEntityGraphs ( Map < String , Object > queryHints ) { if ( queryHints == null ) { return ; } queryHints . remove ( EntityGraph . EntityGraphType . FETCH . getKey ( ) ) ; queryHints . remove ( EntityGraph . EntityGraphType . LOAD . getKey ( ) ) ; }
Remove all EntityGraph pre existing in the QueryHints
235
static EntityManager proxy ( EntityManager entityManager ) { ProxyFactory proxyFactory = new ProxyFactory ( entityManager ) ; proxyFactory . addAdvice ( new RepositoryEntityManagerEntityGraphInjector ( ) ) ; return ( EntityManager ) proxyFactory . getProxy ( ) ; }
Builds a proxy on entity manager which is aware of methods that can make use of query hints .
236
private void addEntityGraphToFindMethodQueryHints ( EntityGraphBean entityGraphCandidate , MethodInvocation invocation ) { LOG . trace ( "Trying to push the EntityGraph candidate to the query hints find method" ) ; Map < String , Object > queryProperties = null ; int index = 0 ; for ( Object argument : invocation . getArguments ( ) ) { if ( argument instanceof Map ) { queryProperties = ( Map ) argument ; break ; } index ++ ; } if ( queryProperties == null ) { LOG . trace ( "No query hints passed to the find method." ) ; return ; } if ( ! entityGraphCandidate . isPrimary ( ) && QueryHintsUtils . containsEntityGraph ( queryProperties ) ) { LOG . trace ( "The query hints passed with the find method already hold an entity graph. Overriding aborted because the candidate EntityGraph is optional." ) ; return ; } queryProperties = new HashMap < String , Object > ( queryProperties ) ; QueryHintsUtils . removeEntityGraphs ( queryProperties ) ; queryProperties . putAll ( QueryHintsUtils . buildQueryHints ( ( EntityManager ) invocation . getThis ( ) , entityGraphCandidate ) ) ; invocation . getArguments ( ) [ index ] = queryProperties ; }
Push the current entity graph to the find method query hints .
237
public void execute ( ) throws MojoExecutionException { super . execute ( ) ; try { lambdaFunctions . forEach ( context -> { try { deleteTriggers . andThen ( deleteFunction ) . apply ( context . withFunctionArn ( lambdaClient . getFunction ( new GetFunctionRequest ( ) . withFunctionName ( context . getFunctionName ( ) ) ) . getConfiguration ( ) . getFunctionArn ( ) ) ) ; } catch ( Exception e ) { getLog ( ) . error ( e . getMessage ( ) ) ; } } ) ; } catch ( Exception e ) { getLog ( ) . error ( e . getMessage ( ) , e ) ; } }
The entry point into the AWS lambda function .
238
public void storeAs ( String queryName ) { QueryRecorder . queryCompleted ( this . query ) ; QueryMemento qm = this . createMemento ( ) ; IDBAccess dbAccess = ( ( IIntDomainAccess ) this . domainAccess ) . getInternalDomainAccess ( ) . getDBAccess ( ) ; String qLabel = ( ( IIntDomainAccess ) this . domainAccess ) . getInternalDomainAccess ( ) . getDomainLabel ( ) . concat ( Q_LABEL_POSTFIX ) ; JcNode n = new JcNode ( "n" ) ; IClause [ ] clauses = new IClause [ ] { MERGE . node ( n ) . label ( qLabel ) . property ( PROP_NAME ) . value ( queryName ) , DO . SET ( n . property ( PROP_Q_JAVA ) ) . to ( qm . getQueryJava ( ) ) , DO . SET ( n . property ( PROP_Q_JSON ) ) . to ( qm . getQueryJSON ( ) ) } ; JcQuery q = new JcQuery ( ) ; q . setClauses ( clauses ) ; JcQueryResult result = dbAccess . execute ( q ) ; if ( result . hasErrors ( ) ) { StringBuilder sb = new StringBuilder ( ) ; Util . appendErrorList ( Util . collectErrors ( result ) , sb ) ; throw new RuntimeException ( sb . toString ( ) ) ; } return ; }
Store the query with the domain model under the given name .
239
public QueryPersistor augment ( DomainObjectMatch < ? > domainObjectMatch , String as ) { if ( this . augmentations == null ) this . augmentations = new HashMap < DomainObjectMatch < ? > , String > ( ) ; this . augmentations . put ( domainObjectMatch , as ) ; return this ; }
Give a name to a DomainObjectMatch for better readability in a Java - DSL like string representation
240
@ SuppressWarnings ( "unchecked" ) public < T > DomainObjectMatch < T > createMatchFrom ( DomainObjectMatch < T > domainObjectMatch ) { DomainObjectMatch < T > ret ; FromPreviousQueryExpression pqe ; DomainObjectMatch < ? > match ; DomainObjectMatch < ? > delegate = APIAccess . getDelegate ( domainObjectMatch ) ; if ( delegate != null ) { DomainObjectMatch < ? > newDelegate = APIAccess . createDomainObjectMatch ( delegate , this . queryExecutor . getDomainObjectMatches ( ) . size ( ) , this . queryExecutor . getMappingInfo ( ) ) ; this . queryExecutor . getDomainObjectMatches ( ) . add ( newDelegate ) ; pqe = new FromPreviousQueryExpression ( newDelegate , delegate ) ; ret = ( DomainObjectMatch < T > ) APIAccess . createDomainObjectMatch ( DomainObject . class , newDelegate ) ; match = newDelegate ; } else { ret = APIAccess . createDomainObjectMatch ( domainObjectMatch , this . queryExecutor . getDomainObjectMatches ( ) . size ( ) , this . queryExecutor . getMappingInfo ( ) ) ; this . queryExecutor . getDomainObjectMatches ( ) . add ( ret ) ; pqe = new FromPreviousQueryExpression ( ret , domainObjectMatch ) ; match = ret ; } this . queryExecutor . addAstObject ( pqe ) ; QueryRecorder . recordAssignment ( this , "createMatchFrom" , match , QueryRecorder . reference ( domainObjectMatch ) ) ; return ret ; }
Create a match from a DomainObjectMatch specified in the context of another query
241
@ SuppressWarnings ( "unchecked" ) public < T > DomainObjectMatch < T > createMatchFor ( T domainObject ) { DomainObjectMatch < T > ret ; if ( domainObject . getClass ( ) . equals ( DomainObject . class ) ) { List < DomainObject > source = new ArrayList < DomainObject > ( ) ; source . add ( ( DomainObject ) domainObject ) ; String typeName = ( ( DomainObject ) domainObject ) . getDomainObjectType ( ) . getName ( ) ; ret = ( DomainObjectMatch < T > ) createGenMatchForInternal ( source , typeName ) ; } else { List < T > source = new ArrayList < T > ( ) ; source . add ( domainObject ) ; ret = this . createMatchForInternal ( source , ( Class < T > ) domainObject . getClass ( ) ) ; } DomainObjectMatch < ? > delegate = APIAccess . getDelegate ( ret ) ; DomainObjectMatch < ? > match = delegate != null ? delegate : ret ; QueryRecorder . recordAssignment ( this , "createMatchFor" , match , QueryRecorder . reference ( domainObject ) ) ; return ret ; }
Create a match for a domain object which was retrieved by another query
242
public TerminalResult BR_OPEN ( ) { ConcatenateExpression ce = new ConcatenateExpression ( Concatenator . BR_OPEN ) ; this . astObjectsContainer . addAstObject ( ce ) ; TerminalResult ret = APIAccess . createTerminalResult ( ce ) ; QueryRecorder . recordInvocation ( this , "BR_OPEN" , ret ) ; return ret ; }
Open a block encapsulating predicate expressions
243
public Order ORDER ( DomainObjectMatch < ? > toOrder ) { DomainObjectMatch < ? > delegate = APIAccess . getDelegate ( toOrder ) ; DomainObjectMatch < ? > match = delegate != null ? delegate : toOrder ; OrderExpression oe = this . queryExecutor . getOrderFor ( match ) ; Order ret = APIAccess . createOrder ( oe ) ; QueryRecorder . recordInvocation ( this , "ORDER" , ret , QueryRecorder . placeHolder ( match ) ) ; return ret ; }
Define an order on a set of domain objects which are specified by a DomainObjectMatch in the context of the domain query .
244
public Traverse TRAVERSE_FROM ( DomainObjectMatch < ? > start ) { DomainObjectMatch < ? > delegate = APIAccess . getDelegate ( start ) ; DomainObjectMatch < ? > match = delegate != null ? delegate : start ; TraversalExpression te = new TraversalExpression ( match , this . queryExecutor ) ; this . queryExecutor . addAstObject ( te ) ; Traverse ret = APIAccess . createTraverse ( te ) ; QueryRecorder . recordInvocation ( this , "TRAVERSE_FROM" , ret , QueryRecorder . placeHolder ( match ) ) ; return ret ; }
Start traversing the graph of domain objects .
245
public < T > Select < T > SELECT_FROM ( DomainObjectMatch < T > start ) { DomainObjectMatch < ? > delegate = APIAccess . getDelegate ( start ) ; DomainObjectMatch < ? > match = delegate != null ? delegate : start ; SelectExpression < T > se = new SelectExpression < T > ( APIAccess . getDomainObjectType ( start ) , match , this . getIntAccess ( ) ) ; this . queryExecutor . addAstObject ( se ) ; this . astObjectsContainer = se ; Select < T > ret = APIAccess . createSelect ( se , getIntAccess ( ) ) ; QueryRecorder . recordInvocation ( this , "SELECT_FROM" , ret , QueryRecorder . placeHolder ( match ) ) ; return ret ; }
Select domain objects out of a set of other domain objects .
246
public Collect COLLECT ( JcProperty attribute ) { CollectExpression ce = new CollectExpression ( attribute , this . getIntAccess ( ) ) ; Collect coll = APIAccess . createCollect ( ce ) ; this . queryExecutor . addAstObject ( ce ) ; QueryRecorder . recordInvocation ( this , "COLLECT" , coll , QueryRecorder . placeHolder ( attribute ) ) ; return coll ; }
Collect the specified attribute from all objects in a DomainObjectMatch
247
@ SuppressWarnings ( "unchecked" ) public < T > DomainObjectMatch < T > INTERSECTION ( DomainObjectMatch < T > ... set ) { DomainObjectMatch < T > ret = this . union_Intersection ( false , set ) ; Object [ ] placeHolders = new Object [ set . length ] ; DomainObjectMatch < ? > delegate ; DomainObjectMatch < ? > match ; for ( int i = 0 ; i < set . length ; i ++ ) { delegate = APIAccess . getDelegate ( set [ i ] ) ; match = delegate != null ? delegate : set [ i ] ; placeHolders [ i ] = QueryRecorder . placeHolder ( match ) ; } delegate = APIAccess . getDelegate ( ret ) ; match = delegate != null ? delegate : ret ; QueryRecorder . recordAssignment ( this , "INTERSECTION" , match , placeHolders ) ; return ret ; }
Build the intersection of the specified sets
248
public DomainQueryResult execute ( ) { DomainQueryResult ret = new DomainQueryResult ( this ) ; Object so = this . queryExecutor . getMappingInfo ( ) . getInternalDomainAccess ( ) . getSyncObject ( ) ; if ( so != null ) { synchronized ( so ) { this . queryExecutor . execute ( ) ; } } else this . queryExecutor . execute ( ) ; return ret ; }
Execute the domain query
249
public CountQueryResult executeCount ( ) { CountQueryResult ret = new CountQueryResult ( this ) ; Object so = this . queryExecutor . getMappingInfo ( ) . getInternalDomainAccess ( ) . getSyncObject ( ) ; if ( so != null ) { synchronized ( so ) { this . queryExecutor . executeCount ( ) ; } } else this . queryExecutor . executeCount ( ) ; return ret ; }
Retrieve the count for every DomainObjectMatch of the query in order to support pagination
250
public String toJSON ( RecordedQuery query ) { StringWriter sw = new StringWriter ( ) ; JsonGenerator generator ; if ( this . prettyFormat != Format . NONE ) { JsonGeneratorFactory gf = JSONWriter . getPrettyGeneratorFactory ( ) ; generator = gf . createGenerator ( sw ) ; } else generator = Json . createGenerator ( sw ) ; generator . writeStartObject ( ) ; writeQuery ( query , generator ) ; generator . writeEnd ( ) ; generator . flush ( ) ; return sw . toString ( ) ; }
Answer a JSON representation of a recorded query
251
public RecordedQuery fromJSON ( String json ) { RecordedQuery ret = new RecordedQuery ( false ) ; StringReader sr = new StringReader ( json ) ; JsonReader reader = Json . createReader ( sr ) ; JsonObject jsonResult = reader . readObject ( ) ; ret . setGeneric ( jsonResult . getBoolean ( GENERIC ) ) ; JsonArray augmentations = jsonResult . getJsonArray ( AUGMENTATIONS ) ; if ( augmentations != null ) { Map < String , String > augs = new HashMap < String , String > ( ) ; Iterator < JsonValue > ait = augmentations . iterator ( ) ; while ( ait . hasNext ( ) ) { JsonObject a = ( JsonObject ) ait . next ( ) ; augs . put ( a . getString ( KEY ) , a . getString ( VALUE ) ) ; } ret . setAugmentations ( augs ) ; } JsonArray statements = jsonResult . getJsonArray ( STATEMENTS ) ; Iterator < JsonValue > it = statements . iterator ( ) ; while ( it . hasNext ( ) ) { JsonValue s = it . next ( ) ; readStatement ( s , ret . getStatements ( ) , ret ) ; } return ret ; }
Build a recorded query from it s JSON representation
252
public GrProperty getProperty ( String propertyName ) { for ( GrProperty prop : getProperties ( ) ) { if ( prop . getName ( ) . equals ( propertyName ) ) return prop ; } return null ; }
return a property
253
public GrProperty addProperty ( String name , Object value ) { GrProperty prop = GrAccess . createProperty ( name ) ; prop . setValue ( value ) ; return getPropertiesContainer ( ) . addElement ( prop ) ; }
add a new property throw a RuntimeException if the property already exists
254
public long countOf ( DomainObjectMatch < ? > match ) { long ret ; Object so = InternalAccess . getQueryExecutor ( this . domainQuery ) . getMappingInfo ( ) . getInternalDomainAccess ( ) . getSyncObject ( ) ; if ( so != null ) { synchronized ( so ) { ret = intCountOf ( match ) ; } } else ret = intCountOf ( match ) ; return ret ; }
Answer the number of domain objects
255
public static String writePretty ( JsonObject jsonObject ) { JsonWriterFactory factory = createPrettyWriterFactory ( ) ; StringWriter sw = new StringWriter ( ) ; JsonWriter writer = factory . createWriter ( sw ) ; writer . writeObject ( jsonObject ) ; String ret = sw . toString ( ) ; writer . close ( ) ; return ret ; }
write a JsonObject formatted in a pretty way into a String
256
public static void printQuery ( JcQuery query , QueryToObserve toObserve , Format format ) { boolean titlePrinted = false ; ContentToObserve tob = QueriesPrintObserver . contentToObserve ( toObserve ) ; if ( tob == ContentToObserve . CYPHER || tob == ContentToObserve . CYPHER_JSON ) { titlePrinted = true ; QueriesPrintObserver . printStream . println ( "#QUERY: " + toObserve . getTitle ( ) + " --------------------" ) ; QueriesPrintObserver . printStream . println ( "#CYPHER --------------------" ) ; String cypher = iot . jcypher . util . Util . toCypher ( query , format ) ; QueriesPrintObserver . printStream . println ( "#--------------------" ) ; QueriesPrintObserver . printStream . println ( cypher ) ; QueriesPrintObserver . printStream . println ( "" ) ; } if ( tob == ContentToObserve . JSON || tob == ContentToObserve . CYPHER_JSON ) { if ( ! titlePrinted ) QueriesPrintObserver . printStream . println ( "#QUERY: " + toObserve . getTitle ( ) + " --------------------" ) ; String json = iot . jcypher . util . Util . toJSON ( query , format ) ; QueriesPrintObserver . printStream . println ( "#JSON --------------------" ) ; QueriesPrintObserver . printStream . println ( json ) ; QueriesPrintObserver . printStream . println ( "" ) ; } }
map to CYPHER statements and map to JSON print the mapping results to System . out
257
public static void printQueries ( List < JcQuery > queries , QueryToObserve toObserve , Format format ) { boolean titlePrinted = false ; ContentToObserve tob = QueriesPrintObserver . contentToObserve ( toObserve ) ; if ( tob == ContentToObserve . CYPHER || tob == ContentToObserve . CYPHER_JSON ) { titlePrinted = true ; QueriesPrintObserver . printStream . println ( "#QUERIES: " + toObserve . getTitle ( ) + " --------------------" ) ; QueriesPrintObserver . printStream . println ( "#CYPHER --------------------" ) ; for ( int i = 0 ; i < queries . size ( ) ; i ++ ) { String cypher = iot . jcypher . util . Util . toCypher ( queries . get ( i ) , format ) ; QueriesPrintObserver . printStream . println ( "#--------------------" ) ; QueriesPrintObserver . printStream . println ( cypher ) ; } QueriesPrintObserver . printStream . println ( "" ) ; } if ( tob == ContentToObserve . JSON || tob == ContentToObserve . CYPHER_JSON ) { if ( ! titlePrinted ) QueriesPrintObserver . printStream . println ( "#QUERIES: " + toObserve . getTitle ( ) + " --------------------" ) ; String json = iot . jcypher . util . Util . toJSON ( queries , format ) ; QueriesPrintObserver . printStream . println ( "#JSON --------------------" ) ; QueriesPrintObserver . printStream . println ( json ) ; QueriesPrintObserver . printStream . println ( "" ) ; } }
map to CYPHER statements and map to JSON print the mapping results to the output streams configured in QueriesPrintObserver
258
public static List < String > availableDomains ( IDBAccess dbAccess ) { List < GrNode > resultList = loadAllDomainInfoNodes ( dbAccess ) ; List < String > domains = new ArrayList < String > ( ) ; for ( GrNode rNode : resultList ) { domains . add ( rNode . getProperty ( DomainInfoNameProperty ) . getValue ( ) . toString ( ) ) ; } return domains ; }
answer the names of available domains .
259
public List < DomainObjectType > getDomainObjectTypes ( ) { List < DomainObjectType > resultList = new ArrayList < DomainObjectType > ( ) ; GrNode infoNode = loadDomainInfoNode ( ) ; GrProperty prop = infoNode . getProperty ( DomainInfoLabel2ClassProperty ) ; if ( prop != null ) { @ SuppressWarnings ( "unchecked" ) List < String > val = ( List < String > ) prop . getValue ( ) ; for ( String str : val ) { String [ ] c2l = str . split ( "=" ) ; resultList . add ( new DomainObjectType ( c2l [ 1 ] , c2l [ 0 ] ) ) ; } } return resultList ; }
answer a list of DomainObjectTypes stored in the domain graph
260
public List < String > getDomainObjectTypeNames ( ) { List < DomainObjectType > types = getDomainObjectTypes ( ) ; List < String > typeNames = new ArrayList < String > ( types . size ( ) ) ; for ( DomainObjectType typ : types ) { typeNames . add ( typ . getTypeName ( ) ) ; } return typeNames ; }
answer a list of names of DomainObjectTypes stored in the domain graph
261
public T addElement ( T element ) { getElements ( ) ; if ( ! containsElement ( this . elements , element ) ) { this . elements . add ( element ) ; element . addChangeListener ( this . elementChangeListener ) ; element . notifyState ( ) ; return element ; } throw new RuntimeException ( element . toString ( ) + " already exists" ) ; }
add a new element throw a RuntimeException if the element already exists
262
private SyncState checkForElementStates ( SyncState ... states ) { if ( this . elements != null ) { for ( T elem : this . elements ) { for ( SyncState state : states ) { if ( elem . getSyncState ( ) != state ) return elem . getSyncState ( ) ; } } } return null ; }
check all elements if their state is one of the given states
263
public void addListFieldValue ( String fieldName , Object value ) { Object val = value ; if ( value instanceof DomainObject ) val = ( ( DomainObject ) value ) . getRawObject ( ) ; Object lst = getFieldValue ( fieldName , true ) ; DOField fld = getDomainObjectType ( ) . getFieldByName ( fieldName ) ; String ctn = fld . getComponentTypeName ( ) ; Class < ? > clazz ; try { clazz = getDomainObjectType ( ) . getDomainModel ( ) . getClassForName ( ctn ) ; if ( ! clazz . isAssignableFrom ( val . getClass ( ) ) ) throw new RuntimeException ( "value must be of type or subtype of: [" + clazz . getName ( ) + "]" ) ; lst = tryInitListOrArray ( lst , fld , clazz ) ; } catch ( ClassNotFoundException e ) { throw new RuntimeException ( e ) ; } if ( lst instanceof List < ? > ) { @ SuppressWarnings ( "unchecked" ) List < Object > list = ( List < Object > ) lst ; list . add ( val ) ; } else if ( lst != null && lst . getClass ( ) . isArray ( ) ) { int len = Array . getLength ( lst ) ; Object array = Array . newInstance ( clazz , len + 1 ) ; for ( int i = 0 ; i < len ; i ++ ) { Array . set ( array , i , Array . get ( lst , i ) ) ; } Array . set ( array , len , val ) ; } else { if ( ! getDomainObjectType ( ) . getFieldByName ( fieldName ) . isListOrArray ( ) ) throw new RuntimeException ( "field: [" + fieldName + "] is neither list nor array" ) ; if ( lst == null ) throw new RuntimeException ( "field: [" + fieldName + "] has not been initialized as list or array" ) ; } }
Add a value to a list or array field
264
public Object getListFieldValue ( String fieldName , int index ) { Object ret = null ; Object val = getFieldValue ( fieldName , true ) ; if ( val instanceof List < ? > ) { List < ? > list = ( List < ? > ) val ; Object cval = list . get ( index ) ; DomainObject gdo = getForRawObject ( cval ) ; if ( gdo != null ) ret = gdo ; else ret = cval ; } else if ( val != null && val . getClass ( ) . isArray ( ) ) { Object aval = Array . get ( val , index ) ; DomainObject gdo = getForRawObject ( aval ) ; if ( gdo != null ) ret = gdo ; else ret = aval ; } else { if ( ! getDomainObjectType ( ) . getFieldByName ( fieldName ) . isListOrArray ( ) ) throw new RuntimeException ( "field: [" + fieldName + "] is neither list nor array" ) ; if ( val == null ) throw new RuntimeException ( "list or array field: [" + fieldName + "] is null" ) ; } return ret ; }
if the field is a list or array answer the value at the given index .
265
public int getIndexOfValue ( String fieldName , Object value ) { int ret = - 1 ; Object val = value ; if ( value instanceof DomainObject ) val = ( ( DomainObject ) value ) . getRawObject ( ) ; Object lst = getFieldValue ( fieldName , true ) ; if ( lst instanceof List < ? > ) { List < ? > list = ( List < ? > ) lst ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { Object obj = list . get ( i ) ; if ( obj . equals ( val ) ) { ret = i ; break ; } } } else if ( lst != null && lst . getClass ( ) . isArray ( ) ) { int len = Array . getLength ( lst ) ; for ( int i = 0 ; i < len ; i ++ ) { Object obj = Array . get ( lst , i ) ; if ( obj . equals ( val ) ) { ret = i ; break ; } } } else { if ( ! getDomainObjectType ( ) . getFieldByName ( fieldName ) . isListOrArray ( ) ) throw new RuntimeException ( "field: [" + fieldName + "] is neither list nor array" ) ; if ( lst == null ) throw new RuntimeException ( "list or array field: [" + fieldName + "] is null" ) ; } return ret ; }
Returns the index of the first occurrence of the specified value in the list field or - 1 if the list field does not contain the value .
266
public void clearListField ( String fieldName ) { Object val = getFieldValue ( fieldName , true ) ; if ( val instanceof List < ? > ) ( ( List < ? > ) val ) . clear ( ) ; else if ( val != null && val . getClass ( ) . isArray ( ) ) { DOField fld = getDomainObjectType ( ) . getFieldByName ( fieldName ) ; String ctn = fld . getComponentTypeName ( ) ; Class < ? > clazz ; try { clazz = getDomainObjectType ( ) . getDomainModel ( ) . getClassForName ( ctn ) ; tryInitListOrArray ( null , fld , clazz ) ; } catch ( ClassNotFoundException e ) { throw new RuntimeException ( e ) ; } } else { if ( ! getDomainObjectType ( ) . getFieldByName ( fieldName ) . isListOrArray ( ) ) throw new RuntimeException ( "field: [" + fieldName + "] is neither list nor array" ) ; if ( val == null ) throw new RuntimeException ( "list or array field: [" + fieldName + "] is null" ) ; } }
Removes all of the elements from the list field .
267
public int getListFieldLength ( String fieldName ) { int ret = - 1 ; Object val = getFieldValue ( fieldName , true ) ; if ( val instanceof List < ? > ) ret = ( ( List < ? > ) val ) . size ( ) ; else if ( val != null && val . getClass ( ) . isArray ( ) ) { ret = Array . getLength ( val ) ; } else { if ( ! getDomainObjectType ( ) . getFieldByName ( fieldName ) . isListOrArray ( ) ) throw new RuntimeException ( "field: [" + fieldName + "] is neither list nor array" ) ; if ( val == null ) throw new RuntimeException ( "list or array field: [" + fieldName + "] is null" ) ; } return ret ; }
Answer the length of a list field
268
@ SuppressWarnings ( "unchecked" ) public DomainObjectMatch < T > ELEMENTS ( TerminalResult ... where ) { DomainObjectMatch < T > ret ; SelectExpression < T > se = this . getSelectExpression ( ) ; DomainObjectMatch < ? > selDom = APIAccess . createDomainObjectMatch ( se . getStart ( ) . getDomainObjectType ( ) , se . getQueryExecutor ( ) . getDomainObjectMatches ( ) . size ( ) , se . getQueryExecutor ( ) . getMappingInfo ( ) ) ; handleUnionExpressions ( se ) ; se . getQueryExecutor ( ) . getDomainObjectMatches ( ) . add ( selDom ) ; se . resetAstObjectsContainer ( ) ; se . setEnd ( selDom ) ; if ( se . isReject ( ) ) { Boolean br_old = QueryRecorder . blockRecording . get ( ) ; try { QueryRecorder . blockRecording . set ( Boolean . TRUE ) ; APIAccess . setPartOfReturn ( selDom , false ) ; AbstractDomainQuery q = se . getDomainQuery ( ) ; DomainObjectMatch < ? > rejectDom = InternalAccess . createMatch ( q , se . getStart ( ) . getDomainObjectType ( ) ) ; q . WHERE ( rejectDom ) . IN ( se . getStart ( ) ) ; q . WHERE ( rejectDom ) . NOT ( ) . IN ( selDom ) ; selDom = rejectDom ; } finally { QueryRecorder . blockRecording . set ( br_old ) ; } } if ( se . getStartType ( ) . equals ( DomainObject . class ) ) ret = APIAccess . createDomainObjectMatch ( se . getStartType ( ) , selDom ) ; else ret = ( DomainObjectMatch < T > ) selDom ; Object [ ] placeHolders = null ; if ( where != null ) { placeHolders = new QueryRecorder . PlaceHolder [ where . length ] ; for ( int i = 0 ; i < where . length ; i ++ ) { placeHolders [ i ] = QueryRecorder . placeHolder ( where [ i ] ) ; } } DomainObjectMatch < ? > delegate = APIAccess . getDelegate ( ret ) ; DomainObjectMatch < ? > match = delegate != null ? delegate : ret ; if ( placeHolders != null ) QueryRecorder . recordStackedAssignment ( this , "ELEMENTS" , match , placeHolders ) ; else QueryRecorder . recordStackedAssignment ( this , "ELEMENTS" , match ) ; return ret ; }
Specify one or more predicate expressions to constrain the set of domain objects
269
private JcError checkLockingError ( List < JcQueryResult > results , boolean hasCreateQuery , List < ElemId2Query > elemIds2Query ) { JcError error = null ; if ( this . lockingStrategy == Locking . OPTIMISTIC ) { JcNumber lockV = new JcNumber ( "lockV" ) ; JcNumber nSum = new JcNumber ( "sum" ) ; int to = hasCreateQuery ? results . size ( ) - 1 : results . size ( ) ; for ( int i = 0 ; i < to ; i ++ ) { ElemId2Query elemId2Query = elemIds2Query . get ( i ) ; if ( elemId2Query . versionSum >= 0 && elemId2Query . elemId < 0 ) { List < BigDecimal > ires = results . get ( i ) . resultOf ( nSum ) ; if ( ires . size ( ) > 0 ) { if ( ( ( Number ) ires . get ( 0 ) ) . intValue ( ) != elemId2Query . versionSum ) { error = new JcError ( "JCypher.Locking" , "Optimistic locking failed (an element was changed by another client)" , null ) ; break ; } } else { error = new JcError ( "JCypher.Locking" , "Optimistic locking failed (an element was deleted by another client)" , null ) ; break ; } } else { List < BigDecimal > ires = results . get ( i ) . resultOf ( lockV ) ; if ( ires . size ( ) > 0 ) { int res = ires . get ( 0 ) . intValue ( ) ; if ( res == - 2 ) { error = new JcError ( "JCypher.Locking" , "Optimistic locking failed (an element was changed by another client)" , "element id: " + elemId2Query . elemId ) ; break ; } } else { error = new JcError ( "JCypher.Locking" , "Optimistic locking failed (an element was deleted by another client)" , "element id: " + elemId2Query . elemId ) ; break ; } } } } return error ; }
in case of error return the element s id or if not available return - 2 in case of change or - 3 in case of delete in case of ok return - 1
270
Parameter getCreateParameter ( String name ) { if ( this . parameters == null ) this . parameters = new HashMap < String , Parameter > ( ) ; Parameter param = this . parameters . get ( name ) ; if ( param == null ) { param = new Parameter ( name ) ; this . parameters . put ( name , param ) ; } return param ; }
Get or create if not exists a query parameter .
271
public String getDomains ( ) { StringWriter sw = new StringWriter ( ) ; JsonGenerator generator ; if ( this . prettyFormat != Format . NONE ) { JsonGeneratorFactory gf = JSONWriter . getPrettyGeneratorFactory ( ) ; generator = gf . createGenerator ( sw ) ; } else generator = Json . createGenerator ( sw ) ; generator . writeStartArray ( ) ; List < String > doms = DomainInformation . availableDomains ( dbAccess ) ; for ( String dom : doms ) { generator . write ( dom ) ; } generator . writeEnd ( ) ; generator . flush ( ) ; return sw . toString ( ) ; }
Answer a JSON representation of the available domains in the database
272
public List < Class < ? > > getTypes ( boolean noAbstractTypes ) { List < Class < ? > > typeList = new ArrayList < Class < ? > > ( ) ; this . addType ( typeList , noAbstractTypes ) ; return typeList ; }
Answer a list of types of this CompoundObjectType .
273
public LiteralMapList resultMapListOf ( JcPrimitive ... key ) { List < List < ? > > results = new ArrayList < List < ? > > ( ) ; LiteralMapList ret = new LiteralMapList ( ) ; int size = - 1 ; ResultHandler . includeNullValues . set ( Boolean . TRUE ) ; try { for ( JcPrimitive k : key ) { List < ? > r = this . resultOf ( k ) ; if ( size == - 1 ) size = r . size ( ) ; results . add ( r ) ; for ( int i = 0 ; i < r . size ( ) ; i ++ ) { LiteralMap map ; if ( i > ret . size ( ) - 1 ) { map = new LiteralMap ( ) ; ret . add ( map ) ; } else map = ret . get ( i ) ; map . put ( k , r . get ( i ) ) ; } } } finally { ResultHandler . includeNullValues . remove ( ) ; } return ret ; }
answer a list of literal maps containing result values for the given keys
274
protected Class < ? > getComponentType ( GrNode rNode ) { Class < ? > compType ; if ( this . getFieldType ( ) . isArray ( ) && ( compType = this . getFieldType ( ) . getComponentType ( ) ) . isPrimitive ( ) ) { return compType ; } return null ; }
only called when to check for a concrete simple component type
275
public GrLabel getLabel ( String labelName ) { for ( GrLabel lab : getLabels ( ) ) { if ( lab . getName ( ) . equals ( labelName ) ) return lab ; } return null ; }
return a label
276
public GrLabel addLabel ( String name ) { GrLabel lab = GrAccess . createLabel ( name ) ; return getLabelsContainer ( ) . addElement ( lab ) ; }
add a new label throw a RuntimeException if the label already exists
277
public TraversalStep FORTH ( String attributeName ) { TraversalExpression te = ( TraversalExpression ) this . astObject ; te . step ( attributeName , 0 ) ; TraversalStep ret = new TraversalStep ( te ) ; QueryRecorder . recordInvocation ( this , "FORTH" , ret , QueryRecorder . literal ( attributeName ) ) ; return ret ; }
Traverse forward via an attribute
278
public < T > DomainObjectMatch < T > TO ( Class < T > domainObjectType ) { TraversalExpression te = ( TraversalExpression ) this . astObject ; DomainObjectMatch < T > ret = APIAccess . createDomainObjectMatch ( domainObjectType , te . getQueryExecutor ( ) . getDomainObjectMatches ( ) . size ( ) , te . getQueryExecutor ( ) . getMappingInfo ( ) ) ; te . getQueryExecutor ( ) . getDomainObjectMatches ( ) . add ( ret ) ; te . setEnd ( ret ) ; QueryRecorder . recordAssignment ( this , "TO" , ret , QueryRecorder . literal ( domainObjectType . getName ( ) ) ) ; return ret ; }
End the traversal of the domain object graph matching a specific type of domain objects
279
public void remove ( ) { SyncState oldState = this . syncState ; if ( this . syncState == SyncState . NEW || this . syncState == SyncState . NEW_REMOVED ) this . syncState = SyncState . NEW_REMOVED ; else this . syncState = SyncState . REMOVED ; if ( oldState != this . syncState ) fireChanged ( oldState , this . syncState ) ; }
removes this item
280
public JcProperty atttribute ( String name ) { if ( this . delegate != null ) return this . delegate . atttribute ( name ) ; JcProperty ret = checkField_getJcVal ( name , JcProperty . class ) ; QueryRecorder . recordInvocationReplace ( this , ret , "atttribute" ) ; return ret ; }
Access an attribute don t rely on a specific attribute type
281
public JcString stringAtttribute ( String name ) { if ( this . delegate != null ) return this . delegate . stringAtttribute ( name ) ; JcString ret = checkField_getJcVal ( name , JcString . class ) ; QueryRecorder . recordInvocationReplace ( this , ret , "stringAtttribute" ) ; return ret ; }
Access a string attribute
282
public JcNumber numberAtttribute ( String name ) { if ( this . delegate != null ) return this . delegate . numberAtttribute ( name ) ; JcNumber ret = checkField_getJcVal ( name , JcNumber . class ) ; QueryRecorder . recordInvocationReplace ( this , ret , "numberAtttribute" ) ; return ret ; }
Access a number attribute
283
public JcBoolean booleanAtttribute ( String name ) { if ( this . delegate != null ) return this . delegate . booleanAtttribute ( name ) ; JcBoolean ret = checkField_getJcVal ( name , JcBoolean . class ) ; QueryRecorder . recordInvocationReplace ( this , ret , "booleanAtttribute" ) ; return ret ; }
Access a boolean attribute
284
public JcCollection collectionAtttribute ( String name ) { if ( this . delegate != null ) return this . delegate . collectionAtttribute ( name ) ; JcCollection ret = checkField_getJcVal ( name , JcCollection . class ) ; QueryRecorder . recordInvocationReplace ( this , ret , "collectionAtttribute" ) ; return ret ; }
Access a collection attribute
285
public static IDomainAccess createDomainAccess ( IDBAccess dbAccess , String domainName ) { return IDomainAccessFactory . INSTANCE . createDomainAccess ( dbAccess , domainName ) ; }
Create a domain accessor .
286
public static IGenericDomainAccess createGenericDomainAccess ( IDBAccess dbAccess , String domainName , DomainLabelUse domainLabelUse ) { return IDomainAccessFactory . INSTANCE . createGenericDomainAccess ( dbAccess , domainName , domainLabelUse ) ; }
Create a domain accessor which works with a generic domain model .
287
public OrderDirection BY ( String attributeName ) { OrderBy ob = this . orderExpression . getCreateOrderCriteriaFor ( attributeName ) ; OrderDirection ret = new OrderDirection ( ob ) ; QueryRecorder . recordInvocation ( this , "BY" , ret , QueryRecorder . literal ( attributeName ) ) ; return ret ; }
Specify the attribute to be used for sorting
288
public String getDomainName ( ) { DomainModel model = ( ( IIntDomainAccess ) this . domainAccess ) . getInternalDomainAccess ( ) . getDomainModel ( ) ; StringWriter sw = new StringWriter ( ) ; JsonGenerator generator ; if ( this . prettyFormat != Format . NONE ) { JsonGeneratorFactory gf = JSONWriter . getPrettyGeneratorFactory ( ) ; generator = gf . createGenerator ( sw ) ; } else generator = Json . createGenerator ( sw ) ; generator . writeStartObject ( ) ; generator . write ( "domainName" , model . getDomainName ( ) ) ; generator . writeEnd ( ) ; generator . flush ( ) ; return sw . toString ( ) ; }
Answer a JSON object containing the domain name
289
public static Graph create ( IDBAccess dbAccess ) { ResultHandler rh = new ResultHandler ( dbAccess ) ; Graph ret = rh . getGraph ( ) ; ret . setSyncState ( SyncState . NEW ) ; return ret ; }
create an empty graph
290
public GrRelation createRelation ( String type , GrNode startNode , GrNode endNode ) { return this . resultHandler . getLocalElements ( ) . createRelation ( type , startNode , endNode ) ; }
create a relation in the graph
291
public DomainQuery replayQuery ( RecordedQuery recordedQuery , IDomainAccess domainAccess ) { Boolean br_old = null ; DomainQuery query ; try { if ( ! Settings . TEST_MODE ) { br_old = QueryRecorder . blockRecording . get ( ) ; if ( this . createNew ) QueryRecorder . blockRecording . set ( Boolean . FALSE ) ; else QueryRecorder . blockRecording . set ( Boolean . TRUE ) ; } this . generic = false ; this . replayedQueryContext = new ReplayedQueryContext ( recordedQuery ) ; query = ( ( IIntDomainAccess ) domainAccess ) . getInternalDomainAccess ( ) . createRecordedQuery ( this . replayedQueryContext , this . createNew ) ; this . id2ObjectMap . put ( QueryRecorder . QUERY_ID , query ) ; for ( Statement stmt : recordedQuery . getStatements ( ) ) { replayStatement ( stmt ) ; } Map < String , Parameter > params = recordedQuery . getParameters ( ) ; if ( params != null ) { QueryExecutor qe = InternalAccess . getQueryExecutor ( query ) ; Iterator < Parameter > pit = params . values ( ) . iterator ( ) ; while ( pit . hasNext ( ) ) { Parameter param = pit . next ( ) ; qe . addParameter ( param ) ; } } } finally { if ( ! Settings . TEST_MODE ) QueryRecorder . blockRecording . set ( br_old ) ; } return query ; }
Create a domain query from a recorded query .
292
public GDomainQuery replayGenericQuery ( RecordedQuery recordedQuery , IGenericDomainAccess domainAccess ) { Boolean br_old = null ; GDomainQuery query ; try { if ( ! Settings . TEST_MODE ) { br_old = QueryRecorder . blockRecording . get ( ) ; if ( this . createNew ) QueryRecorder . blockRecording . set ( Boolean . FALSE ) ; else QueryRecorder . blockRecording . set ( Boolean . TRUE ) ; } this . generic = true ; this . replayedQueryContext = new ReplayedQueryContext ( recordedQuery ) ; query = ( ( IIntDomainAccess ) domainAccess ) . getInternalDomainAccess ( ) . createRecordedGenQuery ( this . replayedQueryContext , this . createNew ) ; this . id2ObjectMap . put ( QueryRecorder . QUERY_ID , query ) ; for ( Statement stmt : recordedQuery . getStatements ( ) ) { replayStatement ( stmt ) ; } } finally { if ( ! Settings . TEST_MODE ) QueryRecorder . blockRecording . set ( br_old ) ; } return query ; }
Create a generic domain query from a recorded query .
293
public static JcPrimitive fromType ( Class < ? > type , String name ) { if ( type . equals ( String . class ) ) return new JcString ( name ) ; else if ( type . equals ( Number . class ) ) return new JcNumber ( name ) ; else if ( type . equals ( Boolean . class ) ) return new JcBoolean ( name ) ; return null ; }
Answer an appropriate instance of a JcPrimitive for the given simple - type and name . E . g . given a type java . lang . String a JcString instance will be returned .
294
public static Object [ ] getEnumValues ( Class < ? extends Enum < ? > > clazz ) { Object [ ] enums = clazz . getEnumConstants ( ) ; if ( enums == null ) { Method [ ] mthds = clazz . getDeclaredMethods ( ) ; Method mthd = null ; for ( Method mth : mthds ) { if ( mth . getName ( ) . equals ( "values" ) ) { mthd = mth ; break ; } } if ( mthd != null ) try { enums = ( Object [ ] ) mthd . invoke ( null ) ; } catch ( Throwable e ) { throw new RuntimeException ( e ) ; } } return enums ; }
finds enum values in normal enum classes and in dynamically created ones .
295
public List < String > getDeclaredFieldNames ( ) { if ( this . declaredFieldNames == null ) { this . declaredFieldNames = new ArrayList < String > ( this . declaredFields . size ( ) ) ; for ( DOField f : this . declaredFields ) { this . declaredFieldNames . add ( f . getName ( ) ) ; } } return this . declaredFieldNames ; }
Answer a list of all field names declared by this type .
296
public List < String > getFieldNames ( ) { List < String > ret = new ArrayList < String > ( ) ; DOType typ = this ; while ( typ != null ) { ret . addAll ( typ . getDeclaredFieldNames ( ) ) ; typ = typ . getSuperType ( ) ; } return ret ; }
Answer a list of all field names declared by this type and all it s super types .
297
public Object getEnumValue ( String name ) { if ( this . kind != Kind . ENUM ) throw new RuntimeException ( "getEnumValue(..) can only be called on an enum" ) ; Object [ ] vals = getEnumValues ( ) ; if ( vals != null ) { for ( Object val : vals ) { if ( ( ( Enum < ? > ) val ) . name ( ) . equals ( name ) ) return val ; } } return null ; }
Answer an enum value with the given name .
298
@ SuppressWarnings ( "unchecked" ) public Object [ ] getEnumValues ( ) { if ( this . kind != Kind . ENUM ) throw new RuntimeException ( "getEnumValues() can only be called on an enum" ) ; try { return MappingUtil . getEnumValues ( ( Class < ? extends Enum < ? > > ) getRawType ( ) ) ; } catch ( ClassNotFoundException e ) { throw new RuntimeException ( e ) ; } }
Answer the list of enum values of this enum .
299
public static InputStream findInputStreamForResource ( final ZipFile zipFile , final String resourcePath ) throws IOException { final ZipEntry entry = zipFile . getEntry ( resourcePath ) ; InputStream result = null ; if ( entry != null && ! entry . isDirectory ( ) ) { result = zipFile . getInputStream ( entry ) ; } return result ; }
Get input stream for resource in zip file .