-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEIIDDES-2383 Enabled support for cache hint in t-forms for virtual
tables and procedures * Also added support for leading and trailing comments in all SQL statement types includeing SELECT/INSERT/UPDATE/DELETE and virtual procedures
- Loading branch information
Showing
15 changed files
with
950 additions
and
17 deletions.
There are no files selected for viewing
157 changes: 157 additions & 0 deletions
157
plugins/teiid/org.teiid.runtime.client/api/org/teiid/translator/CacheDirective.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* See the COPYRIGHT.txt file distributed with this work for information | ||
* regarding copyright ownership. Some portions may be licensed | ||
* to Red Hat, Inc. under one or more contributor license agreements. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301 USA. | ||
*/ | ||
|
||
package org.teiid.translator; | ||
|
||
import java.io.Serializable; | ||
|
||
import org.teiid.core.util.EquivalenceUtil; | ||
import org.teiid.core.util.HashCodeUtil; | ||
|
||
public class CacheDirective implements Serializable { | ||
|
||
public static enum Scope { | ||
NONE, | ||
SESSION, | ||
USER, | ||
VDB; | ||
} | ||
|
||
public enum Invalidation { | ||
/** | ||
* No invalidation - the default | ||
*/ | ||
NONE, | ||
/** | ||
* Invalidate after new results have been obtained | ||
*/ | ||
LAZY, | ||
/** | ||
* Invalidate immediately | ||
*/ | ||
IMMEDIATE | ||
} | ||
|
||
private static final long serialVersionUID = -4119606289701982511L; | ||
|
||
private Boolean prefersMemory; | ||
private Boolean updatable; | ||
private Boolean readAll; | ||
private Long ttl; | ||
private Scope scope; | ||
private Invalidation invalidation = Invalidation.NONE; | ||
|
||
public CacheDirective() { | ||
} | ||
|
||
public CacheDirective(Boolean prefersMemory, Long ttl) { | ||
this.prefersMemory = prefersMemory; | ||
this.ttl = ttl; | ||
} | ||
|
||
public Boolean getPrefersMemory() { | ||
return prefersMemory; | ||
} | ||
|
||
public void setPrefersMemory(Boolean prefersMemory) { | ||
this.prefersMemory = prefersMemory; | ||
} | ||
|
||
/** | ||
* Get the time to live in milliseconds | ||
* @return | ||
*/ | ||
public Long getTtl() { | ||
return ttl; | ||
} | ||
|
||
/** | ||
* Set the time to live in milliseconds | ||
* @param ttl | ||
*/ | ||
public void setTtl(Long ttl) { | ||
this.ttl = ttl; | ||
} | ||
|
||
/** | ||
* Get whether the result is updatable and therefore sensitive to data changes. | ||
* @return | ||
*/ | ||
public Boolean getUpdatable() { | ||
return updatable; | ||
} | ||
|
||
public void setUpdatable(Boolean updatable) { | ||
this.updatable = updatable; | ||
} | ||
|
||
public Scope getScope() { | ||
return this.scope; | ||
} | ||
|
||
public void setScope(Scope scope) { | ||
this.scope = scope; | ||
} | ||
|
||
/** | ||
* Whether the engine should read and cache the entire results. | ||
* @return | ||
*/ | ||
public Boolean getReadAll() { | ||
return readAll; | ||
} | ||
|
||
public void setReadAll(Boolean readAll) { | ||
this.readAll = readAll; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == this) { | ||
return true; | ||
} | ||
if (!(obj instanceof CacheDirective)) { | ||
return false; | ||
} | ||
CacheDirective other = (CacheDirective)obj; | ||
return EquivalenceUtil.areEqual(this.prefersMemory, other.prefersMemory) | ||
&& EquivalenceUtil.areEqual(this.readAll, other.readAll) | ||
&& EquivalenceUtil.areEqual(this.ttl, other.ttl) | ||
&& EquivalenceUtil.areEqual(this.updatable, other.updatable) | ||
&& EquivalenceUtil.areEqual(this.scope, other.scope) | ||
&& EquivalenceUtil.areEqual(this.invalidation, other.invalidation); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return HashCodeUtil.hashCode(1, scope, ttl, updatable); | ||
} | ||
|
||
public Invalidation getInvalidation() { | ||
return invalidation; | ||
} | ||
|
||
public void setInvalidation(Invalidation invalidation) { | ||
this.invalidation = invalidation; | ||
} | ||
|
||
} |
111 changes: 111 additions & 0 deletions
111
plugins/teiid/org.teiid.runtime.client/common-core/org/teiid/core/util/EquivalenceUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* See the COPYRIGHT.txt file distributed with this work for information | ||
* regarding copyright ownership. Some portions may be licensed | ||
* to Red Hat, Inc. under one or more contributor license agreements. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301 USA. | ||
*/ | ||
|
||
package org.teiid.core.util; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Utilities to test the equivalence (see method-specific definitions) of any | ||
* two object/array references. | ||
*/ | ||
public class EquivalenceUtil { | ||
|
||
/** | ||
* Cannot be instantiated | ||
*/ | ||
protected EquivalenceUtil() { | ||
} | ||
|
||
/** | ||
* Tests whether two object references refer to equal objects. The object | ||
* references can both be null, in which case they are also considered equal. | ||
* @param obj1 object reference | ||
* @param obj2 object reference | ||
* @return true if both references are null, OR if neither is null and both | ||
* objects are equal; false otherwise | ||
*/ | ||
public static boolean areEqual(Object obj1, Object obj2) { | ||
if (obj1 == obj2) { | ||
return true; | ||
} else if (obj1 == null || obj2 == null) { | ||
return false; | ||
} else { | ||
return obj1.equals(obj2); | ||
} | ||
} | ||
|
||
/** | ||
* Tests whether two arrays are equivalent. This method ignores the array | ||
* types, but checks the number of references in each array, and the | ||
* equivalence of those references (in ascending index order). | ||
* @param array1 an object array | ||
* @param array2 an object array | ||
*/ | ||
public static boolean areEquivalent(Object[] array1, Object[] array2) { | ||
return Arrays.equals(array1, array2); | ||
} | ||
|
||
/** | ||
* Tests whether two objects references are equivalent but not the same object. | ||
* If both references are the same, this method will return false; | ||
* @param obj1 object reference | ||
* @param obj2 object reference | ||
* @return true if the two references are unequal, and the objects they | ||
* refer to are equal | ||
*/ | ||
public static boolean areStrictlyEquivalent(Object obj1, Object obj2) { | ||
if (obj1 == obj2 || obj1 == null || obj2 == null) { | ||
return false; | ||
} | ||
return areEqual(obj1, obj2); | ||
} | ||
|
||
/** | ||
* Tests whether the array references are equivalent, but are not the same. | ||
* This method checks for the strict equivalence of each pair of objects | ||
* in the two arrays (i.e. corresponding objects cannot be the same but must | ||
* be equivalent) in ascending index order. This method also considers a | ||
* null array and a 0-length array equivalent, and ignores the array type. | ||
* @param array1 an object array | ||
* @param array2 an object array | ||
* @return true if the arrays are equivalent, but not the same. | ||
*/ | ||
public static boolean areStrictlyEquivalent(Object[] array1, Object[] array2) { | ||
if (array1 == array2) { | ||
return false; | ||
} else if (array1 == null) { | ||
return array2.length == 0; | ||
} else if (array2 == null) { | ||
return array1.length == 0; | ||
} else if (array1.length != array2.length) { | ||
return false; | ||
} else { | ||
for (int i = 0; i < array1.length; i++) { | ||
if (!areStrictlyEquivalent(array1[i], array2[i])) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.