idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
15,000
public DistributedWorkManager resolveDistributedWorkManager ( Address address ) { if ( trace ) { log . tracef ( "resolveDistributedWorkManager(%s)" , address ) ; log . tracef ( " ActiveWorkManagers: %s" , activeWorkmanagers ) ; } WorkManager wm = activeWorkmanagers . get ( address . getWorkManagerId ( ) ) ; if ( wm != ...
Resolve a distributed work manager
367
6
15,001
public synchronized WorkManager createWorkManager ( String id , String name ) { if ( id == null || id . trim ( ) . equals ( "" ) ) throw new IllegalArgumentException ( "The id of WorkManager is invalid: " + id ) ; // Check for an active work manager if ( activeWorkmanagers . keySet ( ) . contains ( id ) ) { if ( trace ...
Create a work manager
634
4
15,002
public synchronized void removeWorkManager ( String id ) { if ( id == null || id . trim ( ) . equals ( "" ) ) throw new IllegalArgumentException ( "The id of WorkManager is invalid: " + id ) ; Integer i = refCountWorkmanagers . get ( id ) ; if ( i != null ) { int newValue = i . intValue ( ) - 1 ; if ( newValue == 0 ) {...
Remove a work manager
287
4
15,003
public synchronized void forceAdminObjects ( List < AdminObject > newContent ) { if ( newContent != null ) { this . adminobjects = new ArrayList < AdminObject > ( newContent ) ; } else { this . adminobjects = new ArrayList < AdminObject > ( 0 ) ; } }
Force adminobjects with new content . This method is thread safe
63
12
15,004
public void deltaTotalBlockingTime ( long delta ) { if ( enabled . get ( ) && delta > 0 ) { totalBlockingTime . addAndGet ( delta ) ; totalBlockingTimeInvocations . incrementAndGet ( ) ; if ( delta > maxWaitTime . get ( ) ) maxWaitTime . set ( delta ) ; } }
Add delta to total blocking timeout
74
6
15,005
public void deltaTotalCreationTime ( long delta ) { if ( enabled . get ( ) && delta > 0 ) { totalCreationTime . addAndGet ( delta ) ; if ( delta > maxCreationTime . get ( ) ) maxCreationTime . set ( delta ) ; } }
Add delta to total creation time
62
6
15,006
public void deltaTotalGetTime ( long delta ) { if ( enabled . get ( ) && delta > 0 ) { totalGetTime . addAndGet ( delta ) ; totalGetTimeInvocations . incrementAndGet ( ) ; if ( delta > maxGetTime . get ( ) ) maxGetTime . set ( delta ) ; } }
Add delta to total get time
71
6
15,007
public void deltaTotalPoolTime ( long delta ) { if ( enabled . get ( ) && delta > 0 ) { totalPoolTime . addAndGet ( delta ) ; totalPoolTimeInvocations . incrementAndGet ( ) ; if ( delta > maxPoolTime . get ( ) ) maxPoolTime . set ( delta ) ; } }
Add delta to total pool time
71
6
15,008
public void deltaTotalUsageTime ( long delta ) { if ( enabled . get ( ) && delta > 0 ) { totalUsageTime . addAndGet ( delta ) ; totalUsageTimeInvocations . incrementAndGet ( ) ; if ( delta > maxUsageTime . get ( ) ) maxUsageTime . set ( delta ) ; } }
Add delta to total usage time
71
6
15,009
@ SuppressWarnings ( "unchecked" ) private void verifyBeanValidation ( Object as ) throws Exception { if ( beanValidation != null ) { ValidatorFactory vf = null ; try { vf = beanValidation . getValidatorFactory ( ) ; Validator v = vf . getValidator ( ) ; Collection < String > l = bvGroups ; if ( l == null || l . isEmpt...
Verify activation spec against bean validation
260
7
15,010
private static void generateToCManagedConnection ( Map < String , TraceEvent > events , FileWriter fw ) throws Exception { writeString ( fw , "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"" ) ; writeEOL ( fw ) ; writeString ( fw , " \"http://www.w3.org/TR/html4/loose.dtd\">" ) ; writeEOL ( fw ) ; wri...
Write toc - mc . html for managed connections
861
10
15,011
private static void generateToCConnectionListener ( Map < String , List < TraceEvent > > events , FileWriter fw ) throws Exception { writeString ( fw , "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"" ) ; writeEOL ( fw ) ; writeString ( fw , " \"http://www.w3.org/TR/html4/loose.dtd\">" ) ; writeEOL ( ...
Write toc - cl . html for connection listeners
776
10
15,012
public void store ( Activation metadata , XMLStreamWriter writer ) throws Exception { if ( metadata != null && writer != null ) { writer . writeStartElement ( XML . ELEMENT_IRONJACAMAR ) ; storeCommon ( metadata , writer ) ; writer . writeEndElement ( ) ; } }
Store an ironjacamar . xml file
64
8
15,013
private static File extract ( File file , File directory ) throws IOException { if ( file == null ) throw new IllegalArgumentException ( "File is null" ) ; if ( directory == null ) throw new IllegalArgumentException ( "Directory is null" ) ; File target = new File ( directory , file . getName ( ) ) ; if ( target . exis...
Extract a JAR type file
528
7
15,014
private void parse ( ) { template = text ; if ( StringUtils . isEmptyTrimmed ( template ) ) return ; int index = 0 ; while ( template . indexOf ( "${" ) != - 1 ) { int from = template . lastIndexOf ( "${" ) ; int to = template . indexOf ( "}" , from + 2 ) ; if ( to == - 1 ) { template = text ; complex = false ; entitie...
Parse a text and get a template and expression entities
404
11
15,015
private void updateComplex ( String string ) { if ( string != null && StringUtils . getExpressionKey ( string ) != null && ! string . equals ( StringUtils . getExpressionKey ( string ) ) ) { complex = true ; } }
Updates the complexness of the expression based on a String value
55
13
15,016
private String resolveTemplate ( boolean toValue ) { String result = template ; if ( StringUtils . isEmptyTrimmed ( result ) ) return result ; String key ; while ( ( key = StringUtils . getExpressionKey ( result ) ) != null ) { String subs ; Expression ex = entities . get ( key ) ; String nKey = StringUtils . getExpres...
Resolves the template to the String value depending on boolean switch
201
12
15,017
public Connector merge ( Connector connector , AnnotationRepository annotationRepository , ClassLoader classLoader ) throws Exception { // Process annotations if ( connector == null || ( connector . getVersion ( ) == Version . V_16 || connector . getVersion ( ) == Version . V_17 ) ) { boolean isMetadataComplete = false...
Scan for annotations in the URLs specified
193
7
15,018
private boolean hasAnnotation ( Class c , Class targetClass , AnnotationRepository annotationRepository ) { Collection < Annotation > values = annotationRepository . getAnnotation ( targetClass ) ; if ( values == null ) return false ; for ( Annotation annotation : values ) { if ( annotation . getClassName ( ) != null &...
hasAnnotation if class c contains annotation targetClass
97
10
15,019
private String getConfigPropertyName ( Annotation annotation ) throws ClassNotFoundException , NoSuchFieldException , NoSuchMethodException { if ( annotation . isOnField ( ) ) { return annotation . getMemberName ( ) ; } else if ( annotation . isOnMethod ( ) ) { String name = annotation . getMemberName ( ) ; if ( name ....
Get the config - property - name for an annotation
225
10
15,020
@ SuppressWarnings ( "unchecked" ) private String getConfigPropertyType ( Annotation annotation , Class < ? > type , ClassLoader classLoader ) throws ClassNotFoundException , ValidateException { if ( annotation . isOnField ( ) ) { Class clz = Class . forName ( annotation . getClassName ( ) , true , classLoader ) ; whil...
Get the config - property - type for an annotation
584
10
15,021
private Set < String > getClasses ( String name , ClassLoader cl ) { Set < String > result = new HashSet < String > ( ) ; try { Class < ? > clz = Class . forName ( name , true , cl ) ; while ( ! Object . class . equals ( clz ) ) { result . add ( clz . getName ( ) ) ; clz = clz . getSuperclass ( ) ; } } catch ( Throwabl...
Get the class names for a class and all of its super classes
124
13
15,022
private boolean hasNotNull ( AnnotationRepository annotationRepository , Annotation annotation ) { Collection < Annotation > values = annotationRepository . getAnnotation ( javax . validation . constraints . NotNull . class ) ; if ( values == null || values . isEmpty ( ) ) return false ; for ( Annotation notNullAnnotat...
Has a NotNull annotation attached
130
6
15,023
protected ConnectionListener validateConnectionListener ( Collection < ConnectionListener > listeners , ConnectionListener cl , int newState ) { ManagedConnectionFactory mcf = pool . getConnectionManager ( ) . getManagedConnectionFactory ( ) ; if ( mcf instanceof ValidatingManagedConnectionFactory ) { ValidatingManaged...
Validate a connection listener
558
5
15,024
protected void destroyAndRemoveConnectionListener ( ConnectionListener cl , Collection < ConnectionListener > listeners ) { try { pool . destroyConnectionListener ( cl ) ; } catch ( ResourceException e ) { // TODO: cl . setState ( ZOMBIE ) ; } finally { listeners . remove ( cl ) ; } }
Destroy and remove a connection listener
66
6
15,025
protected ConnectionListener findConnectionListener ( ManagedConnection mc , Object c , Collection < ConnectionListener > listeners ) { for ( ConnectionListener cl : listeners ) { if ( cl . getManagedConnection ( ) . equals ( mc ) && ( c == null || cl . getConnections ( ) . contains ( c ) ) ) return cl ; } return null ...
Find a ConnectionListener instance
75
5
15,026
protected ConnectionListener removeConnectionListener ( boolean free , Collection < ConnectionListener > listeners ) { if ( free ) { for ( ConnectionListener cl : listeners ) { if ( cl . changeState ( FREE , IN_USE ) ) return cl ; } } else { for ( ConnectionListener cl : listeners ) { if ( cl . getState ( ) == IN_USE )...
Remove a free ConnectionListener instance
84
6
15,027
public Connector getStandardMetaData ( File root ) throws Exception { Connector result = null ; File metadataFile = new File ( root , "/META-INF/ra.xml" ) ; if ( metadataFile . exists ( ) ) { InputStream input = null ; String url = metadataFile . getAbsolutePath ( ) ; try { long start = System . currentTimeMillis ( ) ;...
Get the JCA standard metadata
240
6
15,028
public Activation getIronJacamarMetaData ( File root ) throws Exception { Activation result = null ; File metadataFile = new File ( root , "/META-INF/ironjacamar.xml" ) ; if ( metadataFile . exists ( ) ) { InputStream input = null ; String url = metadataFile . getAbsolutePath ( ) ; try { long start = System . currentTi...
Get the IronJacamar specific metadata
221
7
15,029
public synchronized void forceConnectionDefinitions ( List < ConnectionDefinition > newContent ) { if ( newContent != null ) { this . connectionDefinition = new ArrayList < ConnectionDefinition > ( newContent ) ; } else { this . connectionDefinition = new ArrayList < ConnectionDefinition > ( 0 ) ; } }
Force connectionDefinition with new content . This method is thread safe
63
12
15,030
static InputStream getResourceAsStream ( final String name ) { if ( System . getSecurityManager ( ) == null ) return Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( name ) ; return AccessController . doPrivileged ( new PrivilegedAction < InputStream > ( ) { public InputStream run ( ) { re...
Get the input stream for a resource in the context class loader
102
12
15,031
static WorkClassLoader createWorkClassLoader ( final ClassBundle cb ) { return AccessController . doPrivileged ( new PrivilegedAction < WorkClassLoader > ( ) { public WorkClassLoader run ( ) { return new WorkClassLoader ( cb ) ; } } ) ; }
Create a WorkClassLoader
60
5
15,032
public static TraceEvent parse ( String data ) { String [ ] raw = data . split ( "-" ) ; String header = raw [ 0 ] ; String p = raw [ 1 ] ; String m = raw [ 2 ] ; long tid = Long . parseLong ( raw [ 3 ] ) ; int t = Integer . parseInt ( raw [ 4 ] ) ; long ts = Long . parseLong ( raw [ 5 ] ) ; String c = raw [ 6 ] ; Stri...
Parse a trace event
166
5
15,033
private void writeEIS ( Definition def , Writer out , int indent ) throws IOException { writeWithIndent ( out , indent , "/**\n" ) ; writeWithIndent ( out , indent , " * Returns product name of the underlying EIS instance connected\n" ) ; writeWithIndent ( out , indent , " *\n" ) ; writeWithIndent ( out , indent , " * ...
Output eis info method
456
5
15,034
static ValidatorFactory createValidatorFactory ( ) { Configuration configuration = Validation . byDefaultProvider ( ) . configure ( ) ; Configuration < ? > conf = configuration . traversableResolver ( new IronJacamarTraversableResolver ( ) ) ; return conf . buildValidatorFactory ( ) ; }
Create a validator factory
64
5
15,035
Builder prepareNextPage ( ) { int offset = this . offset + pageSize ; validateOffset ( offset ) ; this . offset = offset ; return builder ; }
Updates offset to point at next data page by adding pageSize .
33
14
15,036
Builder preparePreviousPage ( ) { int offset = this . offset - pageSize ; validateOffset ( offset ) ; this . offset = offset ; return builder ; }
Updates offset to point at previous data page by subtracting pageSize .
33
15
15,037
@ Override public void handleFault ( BackendlessFault fault ) { progressDialog . cancel ( ) ; Toast . makeText ( context , fault . getMessage ( ) , Toast . LENGTH_SHORT ) . show ( ) ; }
This override is optional
52
4
15,038
public static Map < String , Object > serializeToMap ( Object entity ) { IObjectSerializer serializer = getSerializer ( entity . getClass ( ) ) ; return ( Map < String , Object > ) serializer . serializeToMap ( entity , new HashMap < Object , Map < String , Object > > ( ) ) ; }
Serializes Object to Map using WebOrb s serializer .
73
13
15,039
public static String getSimpleName ( Class clazz ) { IObjectSerializer serializer = getSerializer ( clazz ) ; return serializer . getClassName ( clazz ) ; }
Uses pluggable serializers to locate one for the class and get the name which should be used for serialization . The name must match the table name where instance of clazz are persisted
40
39
15,040
private Object getOrMakeSerializedObject ( Object entityEntryValue , Map < Object , Map < String , Object > > serializedCache ) { if ( serializedCache . containsKey ( entityEntryValue ) ) //cyclic relation { //take from cache and substitute return serializedCache . get ( entityEntryValue ) ; } else //not cyclic relatio...
Returns serialized object from cache or serializes object if it s not present in cache .
99
18
15,041
public static void serializeUserProperties ( BackendlessUser user ) { Map < String , Object > serializedProperties = user . getProperties ( ) ; Set < Map . Entry < String , Object > > properties = serializedProperties . entrySet ( ) ; for ( Map . Entry < String , Object > property : properties ) { Object propertyValue ...
Serializes entities inside BackendlessUser properties .
167
10
15,042
private static IObjectSerializer getSerializer ( Class clazz ) { Iterator < Map . Entry < Class , IObjectSerializer > > iterator = serializers . entrySet ( ) . iterator ( ) ; IObjectSerializer serializer = DEFAULT_SERIALIZER ; while ( iterator . hasNext ( ) ) { Map . Entry < Class , IObjectSerializer > entry = iterator...
Returns a serializer for the class
127
7
15,043
public void setCurrentUser ( BackendlessUser user ) { if ( currentUser == null ) currentUser = user ; else currentUser . setProperties ( user . getProperties ( ) ) ; }
Sets the properties of the given user to current one .
43
12
15,044
public MessageStatus publish ( String channelName , Object message ) { return publish ( channelName , message , new PublishOptions ( ) ) ; }
Publishes message to specified channel . The message is not a push notification it does not have any headers and does not go into any subtopics .
30
30
15,045
public static Object getFieldValue ( Object object , String lowerKey , String upperKey ) //throws NoSuchFieldException { if ( object == null ) return null ; Method getMethod = getMethod ( object , "get" + lowerKey ) ; if ( getMethod == null ) getMethod = getMethod ( object , "get" + upperKey ) ; if ( getMethod == null ...
Retrieves the value of the field with given name from the given object .
328
16
15,046
public static boolean hasField ( Class clazz , String fieldName ) { try { clazz . getDeclaredField ( fieldName ) ; return true ; } catch ( NoSuchFieldException nfe ) { if ( clazz . getSuperclass ( ) != null ) { return hasField ( clazz . getSuperclass ( ) , fieldName ) ; } else { return false ; } } }
Checks whether given class contains a field with given name . Recursively checks superclasses .
83
19
15,047
@ Deprecated public void afterMoveToRepository ( RunnerContext context , String fileUrlLocation , ExecutionResult < String > result ) throws Exception { }
Use afterUpload method
31
4
15,048
@ Nonnull public ImmutableList < T > toList ( ) { return this . foldAbelian ( ( v , acc ) -> acc . cons ( v ) , ImmutableList . empty ( ) ) ; }
Does not guarantee ordering of elements in resulting list .
46
10
15,049
protected void setArrayValue ( final PreparedStatement statement , final int i , Connection connection , Object [ ] array ) throws SQLException { if ( array == null || ( isEmptyStoredAsNull ( ) && array . length == 0 ) ) { statement . setNull ( i , Types . ARRAY ) ; } else { statement . setArray ( i , connection . crea...
Stores the array conforming to the EMPTY_IS_NULL directive .
98
16
15,050
@ Nonnull public final ArrayList < A > toArrayList ( ) { ArrayList < A > list = new ArrayList <> ( this . length ) ; ImmutableList < A > l = this ; for ( int i = 0 ; i < length ; i ++ ) { list . add ( ( ( NonEmptyImmutableList < A > ) l ) . head ) ; l = ( ( NonEmptyImmutableList < A > ) l ) . tail ; } return list ; }
Converts this list into a java . util . ArrayList .
103
13
15,051
@ Nonnull public final LinkedList < A > toLinkedList ( ) { LinkedList < A > list = new LinkedList <> ( ) ; ImmutableList < A > l = this ; for ( int i = 0 ; i < length ; i ++ ) { list . add ( ( ( NonEmptyImmutableList < A > ) l ) . head ) ; l = ( ( NonEmptyImmutableList < A > ) l ) . tail ; } return list ; }
Converts this list into a java . util . LinkedList .
104
14
15,052
public < T > Get < T > read ( Class < T > cls ) throws APIException { return new Get < T > ( this , getDF ( cls ) ) ; }
Returns a Get Object ... same as get
39
8
15,053
public < T > Get < T > get ( Class < T > cls ) throws APIException { return new Get < T > ( this , getDF ( cls ) ) ; }
Returns a Get Object ... same as read
39
8
15,054
public < T > Post < T > post ( Class < T > cls ) throws APIException { return new Post < T > ( this , getDF ( cls ) ) ; }
Returns a Post Object ... same as create
39
8
15,055
public < T > Post < T > create ( Class < T > cls ) throws APIException { return new Post < T > ( this , getDF ( cls ) ) ; }
Returns a Post Object ... same as post
39
8
15,056
public < T > Put < T > put ( Class < T > cls ) throws APIException { return new Put < T > ( this , getDF ( cls ) ) ; }
Returns a Put Object ... same as update
39
8
15,057
public < T > Put < T > update ( Class < T > cls ) throws APIException { return new Put < T > ( this , getDF ( cls ) ) ; }
Returns a Put Object ... same as put
39
8
15,058
public < T > Delete < T > delete ( Class < T > cls ) throws APIException { return new Delete < T > ( this , getDF ( cls ) ) ; }
Returns a Delete Object
39
4
15,059
public void set ( TafResp tafResp , Lur lur ) { principal = tafResp . getPrincipal ( ) ; access = tafResp . getAccess ( ) ; this . lur = lur ; }
Allow setting of tafResp and lur after construction
45
10
15,060
public void invalidate ( String id ) { if ( lur instanceof EpiLur ) { ( ( EpiLur ) lur ) . remove ( id ) ; } else if ( lur instanceof CachingLur ) { ( ( CachingLur < ? > ) lur ) . remove ( id ) ; } }
Add a feature
68
3
15,061
public < RET > RET same ( SecuritySetter < HttpURLConnection > ss , Retryable < RET > retryable ) throws APIException , CadiException , LocatorException { RET ret = null ; boolean retry = true ; int retries = 0 ; Rcli < HttpURLConnection > client = retryable . lastClient ( ) ; try { do { // if no previous state, get th...
Reuse the same service . This is helpful for multiple calls that change service side cached data so that there is not a speed issue .
626
27
15,062
protected int seg ( Cached < ? , ? > cache , Object ... fields ) { return cache == null ? 0 : cache . invalidate ( CachedDAO . keyFromObjs ( fields ) ) ; }
be treated by system as fields expected in Tables
46
9
15,063
public Result < DATA > create ( TRANS trans , DATA data ) { if ( createPS == null ) { Result . err ( Result . ERR_NotImplemented , "Create is disabled for %s" , getClass ( ) . getSimpleName ( ) ) ; } if ( async ) /*ResultSetFuture */ { Result < ResultSetFuture > rs = createPS . execAsync ( trans , C_TEXT , data ) ; if ...
Given a DATA object extract the individual elements from the Data into an Object Array for the execute element .
177
20
15,064
public Result < List < DATA > > read ( TRANS trans , DATA data ) { if ( readPS == null ) { Result . err ( Result . ERR_NotImplemented , "Read is disabled for %s" , getClass ( ) . getSimpleName ( ) ) ; } return readPS . read ( trans , R_TEXT , data ) ; }
Read the Unique Row associated with Full Keys
77
8
15,065
public Result < Void > delete ( TRANS trans , DATA data , boolean reread ) { if ( deletePS == null ) { Result . err ( Result . ERR_NotImplemented , "Delete is disabled for %s" , getClass ( ) . getSimpleName ( ) ) ; } // Since Deleting will be stored off, for possible re-constitution, need the whole thing if ( reread ) ...
This method Sig for Cached ...
396
7
15,066
private String update ( ) { // If this has been done before, there is no change in checkSum and the last time notified is within GracePeriod if ( checksum != 0 && checksum ( ) == checksum && now < last . getTime ( ) + graceEnds && now > last . getTime ( ) + lastdays ) { return null ; } else { return "UPDATE authz.notif...
Returns an Update String for CQL if there is data .
136
12
15,067
protected void addUser ( String key , User < PERM > user ) { userMap . put ( key , user ) ; }
Useful for looking up by WebToken etc .
27
10
15,068
protected boolean addMiss ( String key , byte [ ] bs ) { Miss miss = missMap . get ( key ) ; if ( miss == null ) { synchronized ( missMap ) { missMap . put ( key , new Miss ( bs , clean == null ? MIN_INTERVAL : clean . timeInterval ) ) ; } return true ; } return miss . add ( bs ) ; }
Add miss to missMap . If Miss exists or too many tries returns false .
84
16
15,069
public void remove ( String user ) { Object o = userMap . remove ( user ) ; if ( o != null ) { access . log ( Level . INFO , user , "removed from Client Cache by Request" ) ; } }
Removes user from the Cache
49
6
15,070
public Result < List < DATA > > read ( final String key , final TRANS trans , final Object ... objs ) { DAOGetter getter = new DAOGetter ( trans , dao , objs ) ; return get ( trans , key , getter ) ; // if(ld!=null) { // return Result.ok(ld);//.emptyList(ld.isEmpty()); // } // // Result Result if exists // if(getter.re...
Slight Improved performance available when String and Obj versions are known .
146
13
15,071
public String get ( String key ) { if ( key == null ) return null ; int idx = 0 , equal = 0 , amp = 0 ; while ( idx >= 0 && ( equal = tresp . indexOf ( ' ' , idx ) ) >= 0 ) { amp = tresp . indexOf ( ' ' , equal ) ; if ( key . regionMatches ( 0 , tresp , idx , equal - idx ) ) { return amp >= 0 ? tresp . substring ( equa...
Get a value from a named TGuard Property
140
9
15,072
public static void timeSensitiveInit ( Env env , AuthAPI authzAPI , AuthzFacade facade , final DirectAAFUserPass directAAFUserPass ) throws Exception { /** * Basic Auth, quick Validation * * Responds OK or NotAuthorized */ authzAPI . route ( env , HttpMethods . GET , "/authn/basicAuth" , new Code ( facade , "Is given B...
TIME SENSITIVE APIs
833
6
15,073
public Result < Void > addDescription ( AuthzTrans trans , String ns , String name , String description ) { try { getSession ( trans ) . execute ( UPDATE_SP + TABLE + " SET description = '" + description + "' WHERE ns = '" + ns + "' AND name = '" + name + "';" ) ; } catch ( DriverException | APIException | IOException ...
Add description to role
185
4
15,074
public void setPathInfo ( String pathinfo ) { int qp = pathinfo . indexOf ( ' ' ) ; if ( qp < 0 ) { client . setContext ( isProxy ? ( "/proxy" + pathinfo ) : pathinfo ) ; } else { client . setContext ( isProxy ? ( "/proxy" + pathinfo . substring ( 0 , qp ) ) : pathinfo . substring ( 0 , qp ) ) ; client . setQueryParams...
DME2 can t handle having QueryParams on the URL line but it is the most natural way so ...
118
23
15,075
public void cleanupParams ( int size , long interval ) { timer . cancel ( ) ; timer . schedule ( new Cleanup ( content , size ) , interval , interval ) ; }
Reset the Cleanup size and interval
38
8
15,076
public Content load ( LogTarget logTarget , String dataRoot , String key , String mediaType , long _timeCheck ) throws IOException { long timeCheck = _timeCheck ; if ( timeCheck < 0 ) { timeCheck = checkInterval ; // if time < 0, then use default } String fileName = dataRoot + ' ' + key ; Content c = content . get ( ke...
Load a file first checking cache
483
6
15,077
public < T > Future < Void > update ( String pathinfo ) throws APIException , CadiException { final int idx = pathinfo . indexOf ( ' ' ) ; final String qp ; if ( idx >= 0 ) { qp = pathinfo . substring ( idx + 1 ) ; pathinfo = pathinfo . substring ( 0 , idx ) ; } else { qp = queryParams ; } EClient < CT > client = clien...
A method to update with a VOID
220
8
15,078
private static JaxInfo [ ] buildFields ( Class < ? > clazz , String defaultNS ) throws SecurityException , NoSuchFieldException , ClassNotFoundException { ArrayList < JaxInfo > fields = null ; // allow for lazy instantiation, because many structures won't have XmlType Class < ? > cls = clazz ; // Build up Method names ...
This is recursive if a member is a JAXB Object as well .
677
15
15,079
public Result < List < Data > > readByUserRole ( AuthzTrans trans , String user , String role ) { return psUserInRole . read ( trans , R_TEXT + " by User " + user + " and Role " + role , new Object [ ] { user , role } ) ; }
Direct Lookup of User Role Don t forget to check for Expiration
65
14
15,080
public static byte [ ] encryptMD5 ( byte [ ] input ) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest . getInstance ( "MD5" ) ; md . update ( input ) ; return md . digest ( ) ; }
Encrypt MD5 from Byte Array to Byte Array
54
10
15,081
public static boolean isEqual ( byte ba1 [ ] , byte ba2 [ ] ) { if ( ba1 . length != ba2 . length ) return false ; for ( int i = 0 ; i < ba1 . length ; ++ i ) { if ( ba1 [ i ] != ba2 [ i ] ) return false ; } return true ; }
Compare two byte arrays for equivalency
75
7
15,082
public static String readString ( DataInputStream is , byte [ ] _buff ) throws IOException { int l = is . readInt ( ) ; byte [ ] buff = _buff ; switch ( l ) { case - 1 : return null ; case 0 : return "" ; default : // Cover case where there is a large string, without always allocating a large buffer. if ( l > buff . le...
We use bytes here to set a Maximum
119
8
15,083
public static void writeStringSet ( DataOutputStream os , Collection < String > set ) throws IOException { if ( set == null ) { os . writeInt ( - 1 ) ; } else { os . writeInt ( set . size ( ) ) ; for ( String s : set ) { writeString ( os , s ) ; } } }
Write a set with proper sizing
72
6
15,084
public static void writeStringMap ( DataOutputStream os , Map < String , String > map ) throws IOException { if ( map == null ) { os . writeInt ( - 1 ) ; } else { Set < Entry < String , String > > es = map . entrySet ( ) ; os . writeInt ( es . size ( ) ) ; for ( Entry < String , String > e : es ) { writeString ( os , e...
Write a map
115
3
15,085
public final static StringBuilder buildLine ( Level level , StringBuilder sb , Object [ ] elements ) { sb . append ( level . name ( ) ) ; return buildLine ( sb , elements ) ; }
Add the Level to the Buildline for Logging types that don t specify or straight Streams etc . Then buildline
45
24
15,086
public void log ( Level level , Object ... elements ) { if ( willWrite . compareTo ( level ) <= 0 ) { StringBuilder sb = buildLine ( level , new StringBuilder ( ) , elements ) ; if ( context == null ) { System . out . println ( sb . toString ( ) ) ; } else { context . log ( sb . toString ( ) ) ; } } }
Standard mechanism for logging given being within a Servlet Context
86
11
15,087
public void log ( Exception e , Object ... elements ) { if ( willWrite . compareTo ( Level . ERROR ) <= 0 ) { StringBuilder sb = buildLine ( Level . ERROR , new StringBuilder ( ) , elements ) ; if ( context == null ) { sb . append ( e . toString ( ) ) ; System . out . println ( sb . toString ( ) ) ; } else { context . ...
Standard mechanism for logging an Exception given being within a Servlet Context etc
105
14
15,088
public String getProperty ( String string , String def ) { String rv = null ; if ( props != null ) rv = props . getProperty ( string , def ) ; if ( rv == null ) { rv = context . getInitParameter ( string ) ; } return rv == null ? def : rv ; }
Get the Property from Context
70
5
15,089
public void prime ( LogTarget lt , int prime ) throws APIException { for ( int i = 0 ; i < prime ; ++ i ) { Pooled < T > pt = new Pooled < T > ( creator . create ( ) , this , lt ) ; synchronized ( list ) { list . addFirst ( pt ) ; ++ count ; } } }
Preallocate a certain number of T Objects . Useful for services so that the first transactions don t get hit with all the Object creation costs
76
28
15,090
public void drain ( ) { synchronized ( list ) { for ( int i = 0 ; i < list . size ( ) ; ++ i ) { Pooled < T > pt = list . remove ( ) ; creator . destroy ( pt . content ) ; pt . logTarget . log ( "Pool drained " , creator . toString ( ) ) ; } count = spares = 0 ; } }
Destroy and remove all remaining objects . This is valuable for closing down all Allocated objects cleanly for exiting . It is also a good method for removing objects when for instance all Objects are invalid because of broken connections etc .
82
44
15,091
public boolean validate ( ) { boolean rv = true ; synchronized ( list ) { for ( Pooled < T > t : list ) { if ( ! creator . isValid ( t . content ) ) { rv = false ; t . toss ( ) ; list . remove ( t ) ; } } } return rv ; }
This function will validate whether the Objects are still in a usable state . If not they are tossed from the Pool . This is valuable to have when Remote Connections go down and there is a question on whether the Pooled Objects are still functional .
69
49
15,092
public T get ( Env env ) throws APIException { Thread t = Thread . currentThread ( ) ; T obj = objs . get ( t ) ; if ( obj == null || refreshed > obj . created ( ) ) { try { obj = cnst . newInstance ( new Object [ ] { env } ) ; } catch ( InvocationTargetException e ) { throw new APIException ( e . getTargetException ( ...
Get the T class from the current thread
144
8
15,093
public void remove ( Env env ) { T obj = objs . remove ( Thread . currentThread ( ) ) ; if ( obj != null ) obj . destroy ( env ) ; }
Remove the object from the Thread instances
39
7
15,094
public Result < List < Data > > readByUser ( AuthzTrans trans , final String user ) { DAOGetter getter = new DAOGetter ( trans , dao ( ) ) { public Result < List < Data > > call ( ) { // If the call is for THIS user, and it exists, get from TRANS, add to TRANS if not. if ( user != null && user . equals ( trans . user (...
Special Case . User Roles by User are very likely to be called many times in a Transaction to validate May User do ... Pull result and make accessible by the Trans which is always keyed by User .
238
41
15,095
public Rcli < CLIENT > clientAs ( String apiVersion , ServletRequest req ) throws CadiException { Rcli < CLIENT > cl = client ( apiVersion ) ; return cl . forUser ( transferSS ( ( ( HttpServletRequest ) req ) . getUserPrincipal ( ) ) ) ; }
Use this API when you have permission to have your call act as the end client s ID .
66
19
15,096
public static final AAFCon < ? > obtain ( Object servletRequest ) { if ( servletRequest instanceof CadiWrap ) { Lur lur = ( ( CadiWrap ) servletRequest ) . getLur ( ) ; if ( lur != null ) { if ( lur instanceof EpiLur ) { AbsAAFLur < ? > aal = ( AbsAAFLur < ? > ) ( ( EpiLur ) lur ) . subLur ( AbsAAFLur . class ) ; if ( ...
Return the backing AAFCon if there is a Lur Setup that is AAF .
165
17
15,097
public static String reverseDomain ( String user ) { StringBuilder sb = null ; String [ ] split = Split . split ( ' ' , user ) ; int at ; for ( int i = split . length - 1 ; i >= 0 ; -- i ) { if ( sb == null ) { sb = new StringBuilder ( ) ; } else { sb . append ( ' ' ) ; } if ( ( at = split [ i ] . indexOf ( ' ' ) ) > 0...
Take a Fully Qualified User and get a Namespace from it .
167
14
15,098
public static synchronized boolean denyIP ( String ip ) { boolean rv = false ; if ( deniedIP == null ) { deniedIP = new HashMap < String , Counter > ( ) ; deniedIP . put ( ip , new Counter ( ip ) ) ; // Noted duplicated for minimum time spent rv = true ; } else if ( deniedIP . get ( ip ) == null ) { deniedIP . put ( ip...
Return of True means IP has been added . Return of False means IP already added .
119
17
15,099
public static synchronized boolean removeDenyIP ( String ip ) { if ( deniedIP != null && deniedIP . remove ( ip ) != null ) { writeIP ( ) ; if ( deniedIP . isEmpty ( ) ) { deniedIP = null ; } return true ; } return false ; }
Return of True means IP has was removed . Return of False means IP wasn t being denied .
61
19