Thanks for raising this issue, Nicholas. Can you include the full stack trace for the error? The template policy may need to grant some additional privilege to the engine jar file. It is also possible that you have run into the following defect: https://issues.apache.org/jira/browse/DERBY-4354

Thanks,
-Rick

On 2/17/17, 9:42 AM, nicholas walton wrote:
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