Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…va-11.0.2".

This is necessary for Hadoop compatibility. Later versions of Guava can also be used.
  • Loading branch information
julianhyde committed Feb 19, 2014
1 parent 4530bc2 commit 24cd792
Show file tree
Hide file tree
Showing 5 changed files with 537 additions and 3 deletions.
7 changes: 7 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ DynamoBI Corporation, http://github.com/dynamobi/luciddb/.

Copyright (C) 2005-2011 DynamoBI Corporation.

===============================================================================
This software includes code from the Guava project,
released under the Apache License, Version 2.0,
and available from https://code.google.com/p/guava-libraries/.

Copyright (C) 2007 The Guava Authors

===============================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this software except in compliance with the License.
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/net/hydromatic/optiq/jdbc/OptiqSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.hydromatic.optiq.*;
import net.hydromatic.optiq.Table;
import net.hydromatic.optiq.impl.MaterializedViewTable;
import net.hydromatic.optiq.util.Compatible;
import net.hydromatic.optiq.util.CompositeMap;

import org.eigenbase.util.Util;
Expand Down Expand Up @@ -82,7 +83,7 @@ public Table apply(Collection<TableFunctionEntry> input) {
return entry.getTableFunction().apply(ImmutableList.of());
}
}),
Maps.asMap(
Compatible.INSTANCE.asMap(
schema.getTableNames(),
new Function<String, Table>() {
public Table apply(String input) {
Expand All @@ -100,7 +101,7 @@ public TableFunction apply(TableFunctionEntry input) {
this.compositeSubSchemaMap =
CompositeMap.of(
subSchemaMap,
Maps.<String, OptiqSchema>asMap(
Compatible.INSTANCE.<String, OptiqSchema>asMap(
schema.getSubSchemaNames(),
new Function<String, OptiqSchema>() {
public OptiqSchema apply(String input) {
Expand Down
66 changes: 66 additions & 0 deletions core/src/main/java/net/hydromatic/optiq/util/Compatible.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
// Licensed to Julian Hyde under one or more contributor license
// agreements. See the NOTICE file distributed with this work for
// additional information regarding copyright ownership.
//
// Julian Hyde licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
package net.hydromatic.optiq.util;

import com.google.common.base.Function;
import com.google.common.collect.*;

import java.lang.reflect.*;
import java.util.*;

/** Compatibility layer.
*
* <p>Allows to use advanced functionality if the latest JDK or Guava version
* is present.</p>
*/
public interface Compatible {
Compatible INSTANCE = new Factory().create();

/** Same as Guava {@code Maps.asMap(set, function)}. */
<K, V> Map<K, V> asMap(Set<K> set, Function<? super K, V> function);

/** Creates the implementation of Compatible suitable for the
* current environment. */
class Factory {
Compatible create() {
return (Compatible) Proxy.newProxyInstance(
Compatible.class.getClassLoader(),
new Class<?>[] {Compatible.class},
new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
if (method.getName().equals("asMap")) {
// Use the Guava implementation Maps.asMap if it is available
try {
final Method guavaMethod = Maps.class.getMethod(
method.getName(), method.getParameterTypes());
return guavaMethod.invoke(null, args);
} catch (NoSuchMethodException e) {
Set set = (Set) args[0];
Function function = (Function) args[1];
return CompatibleGuava11.asMap(set, function);
}
}
return null;
}
});
}
}
}

// End Compatible.java
Loading

0 comments on commit 24cd792

Please sign in to comment.