Skip to content

Commit

Permalink
MONDRIAN: Oops, forgot a few files.
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 4443]
  • Loading branch information
julianhyde committed Nov 21, 2005
1 parent d88f133 commit 4739658
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/mondrian/rolap/cache/SmartCache.java
@@ -0,0 +1,25 @@
/*
//This software is subject to the terms of the Common Public License
//Agreement, available at the following URL:
//http://www.opensource.org/licenses/cpl.html.
//Copyright (C) 2004-2005 TONBELLER AG
//All Rights Reserved.
//You must accept the terms of that agreement to use this software.
*/
package mondrian.rolap.cache;

public interface SmartCache {

/**
* places a key/value pair into the queue
* @return the previous value of <code>key</code> or null
*/
Object put(Object key, Object value);

Object get(Object key);

void clear();

int size();

}
98 changes: 98 additions & 0 deletions src/main/mondrian/rolap/cache/SoftSmartCache.java
@@ -0,0 +1,98 @@
/*
//This software is subject to the terms of the Common Public License
//Agreement, available at the following URL:
//http://www.opensource.org/licenses/cpl.html.
//Copyright (C) 2004-2005 TONBELLER AG
//All Rights Reserved.
//You must accept the terms of that agreement to use this software.
*/
package mondrian.rolap.cache;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Map;

/**
* a map with soft references that is cleaned up in regular intervals.
* <p>
* There is no contains(key) method because it makes no sense - after
* contains() returns true, the garbage collector may remove
* the value that was contained. Instead the code should call get() and
* keep a reference to the value to prevent garbage collection.
*
* @author av
* @since Nov 3, 2005
*/
public class SoftSmartCache implements SmartCache {

Map cache = new HashMap();
ReferenceQueue queue = new ReferenceQueue();

/**
* an entry in the cache that contains the key for
* the cache map to remove the entry when its value
* has been garbage collected
*
* @author rk
* @since Nov 7, 2005
*/
class CacheReference extends SoftReference {
Object key;

public CacheReference(Object key, Object value) {
super(value, queue);
this.key = key;
}

public String toString() {
return String.valueOf(get());
}
}

/* (non-Javadoc)
* @see mondrian.rolap.cache.SmartCache#put(java.lang.Object, java.lang.Object)
*/
public synchronized Object put(Object key, Object value) {
// remove garbage collected entries from cache
CacheReference ref;
while ((ref = (CacheReference) queue.poll()) != null) {
cache.remove(ref.key);
}

// put new entry into cache
ref = new CacheReference(key, value);
ref = (CacheReference) cache.put(key, ref);
if (ref != null)
return ref.get();
return null;
}

/* (non-Javadoc)
* @see mondrian.rolap.cache.SmartCache#get(java.lang.Object)
*/
public synchronized Object get(Object key) {
SoftReference ref = (SoftReference) cache.get(key);
if (ref == null)
return null;
Object value = ref.get();
if (value == null)
cache.remove(key);
return value;
}

/* (non-Javadoc)
* @see mondrian.rolap.cache.SmartCache#clear()
*/
public void clear() {
cache.clear();
}

/* (non-Javadoc)
* @see mondrian.rolap.cache.SmartCache#size()
*/
public int size() {
return cache.size();
}

}
52 changes: 52 additions & 0 deletions src/main/mondrian/rolap/sql/MemberChildrenConstraint.java
@@ -0,0 +1,52 @@
/*
//This software is subject to the terms of the Common Public License
//Agreement, available at the following URL:
//http://www.opensource.org/licenses/cpl.html.
//Copyright (C) 2004-2005 TONBELLER AG
//All Rights Reserved.
//You must accept the terms of that agreement to use this software.
*/
package mondrian.rolap.sql;

import java.util.List;

import mondrian.rolap.RolapLevel;
import mondrian.rolap.RolapMember;

/**
* restricts the SQL result of a MembersChildren query in SqlMemberSource.
* @see mondrian.rolap.SqlMemberSource
*
* @author av
* @since Nov 2, 2005
*/
public interface MemberChildrenConstraint extends SqlConstraint {

/**
* modifies a Member.Children sqlQuery so that only the children
* of <code>parent</code> will be returned in the resultset
* @param sqlQuery the query to modify
* @param parent the parent member that restricts the returned children
*/
public void addMemberConstraint(SqlQuery sqlQuery, RolapMember parent);

/**
* modifies a Member.Children sqlQuery so that (all or some) children
* of <em>all</em> parent members contained in <code>parents</code> will
* be returned in the resultset.
* @param sqlQuery the query to modify
* @param parents list of parent members that restrict the returned children.
* all parents will belong to the same level and there at least two in the list.
*/
public void addMemberConstraint(SqlQuery sqlQuery, List parents);

/**
* will be called once for the level that contains the
* children of a Member.Children query. If the condition requires so,
* it may join the levels table to the fact table.
* @param sqlQuery the query to modify
* @param level the level that contains the children
*/
public void addLevelConstraint(SqlQuery query, RolapLevel level);

}
29 changes: 29 additions & 0 deletions src/main/mondrian/rolap/sql/SqlConstraint.java
@@ -0,0 +1,29 @@
/*
//This software is subject to the terms of the Common Public License
//Agreement, available at the following URL:
//http://www.opensource.org/licenses/cpl.html.
//Copyright (C) 2004-2005 TONBELLER AG
//All Rights Reserved.
//You must accept the terms of that agreement to use this software.
*/
package mondrian.rolap.sql;

/**
* restricts the members that are fetched by SqlMemberSource.
* <p>
* @see mondrian.rolap.SqlMemberSource
*
* @author av
* @since Nov 2, 2005
*/
public interface SqlConstraint {

/**
* Returns a key that becomes part of the key for caching the
* result of the SQL query. So SqlConstraint instances that
* produce the same SQL resultset must return equal keys
* in terms of equal() and hashCode().
* @return valid key or null to prevent the result from being cached
*/
Object getCacheKey();
}
27 changes: 27 additions & 0 deletions src/main/mondrian/rolap/sql/SqlQueryChecker.java
@@ -0,0 +1,27 @@
/*
// $Id$
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// (C) Copyright 2002-2005 Kana Software, Inc. and others.
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
// jhyde, Mar 21, 2002
*/
package mondrian.rolap.sql;

/**
* Runs a SQL query.
*
* <p>Useful for testing purposes.
*
* @author jhyde
* @since 30 August, 2001
* @version $Id$
*/
public interface SqlQueryChecker {
void onGenerate(SqlQuery q);
}

// End SqlQueryChecker.java

0 comments on commit 4739658

Please sign in to comment.