Hi Nicholas,

I think that your issue is due to java policy ( either you need to change your 
Java policy file, or if you supply any do your derby context, update this one ).


Please check https://docs.oracle.com/cd/E19225-01/820-5594/ahtbo/index.html, 
and 

this 
http://docs.oracle.com/javase/7/docs/technotes/guides/security/permissions.html 

for more information.


In the end , I believe that you will need to append accessClassInPackage rights 
to the derby aggregator, org.apache.derby.agg.Aggregator;.



E.g. :

grant{ 
permission java.lang.RuntimePermission 
"accessClassInPackage.org.apache.derby.agg";
}



Regards,

George











Sent from Windows Mail





From: nicholas walton
Sent: ‎Friday‎, ‎February‎ ‎17‎, ‎2017 ‎7‎:‎42‎ ‎PM
To: derby-user@db.apache.org




Hi,



I need to extend Java’s aggregate functions to include Median, using the code 
below




import java.util.ArrayList;
import java.util.Collections;
import org.apache.derby.agg.Aggregator;

public class median<V extends Comparable<V>> 
      implements Aggregator<V,V,median<V>>
{
  private ArrayList<V> _values;

  public median() {}

  public void init() { _values = new ArrayList<V>(); }

  public void accumulate( V value ) { _values.add( value ); }

  public void merge( median<V> other )
  { 
      _values.addAll( other._values ); 
  }

  public V terminate()
  {
      Collections.sort( _values );

      int count = _values.size();

      if ( count == 0 ) { return null; }
      else { return _values.get( count/2 ); }
  }
}




To install I used




CALL 
SQLJ.INSTALL_JAR('/Users/nwalton/Documents/Databases/derbyStats/dist/derbyStats.jar',
 'NWALTON.median',0);
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY 
('derby.database.classpath','NWALTON.median’);



CREATE DERBY AGGREGATE "NWALTON"."MEDIAN" FOR DOUBLE RETURNS DOUBLE EXTERNAL 
NAME 'aggregates.median’ ;




At first this works fine in a trigger or in plain SQL but after a while I get 
the following error




Error code 30000, SQL state 38000: The exception 
'java.security.AccessControlException: access denied 
("java.lang.RuntimePermission" "accessClassInPackage.sun.reflect")' was thrown 
while evaluating an expression.
Error code 99999, SQL state XJ001: Java exception: 'access denied 
("java.lang.RuntimePermission" "accessClassInPackage.sun.reflect"): 
java.security.AccessControlException'.
Line 1, column 1




I’ve Googled to no avail for an answer! Can anyone suggest a solution. I’m 
running OS X Sierra Apache Derby Network Server - 10.6.2.1 - (999685) under 
Java version 1.8.0_31-b13.




Thanks in advance




Nick

Reply via email to