本文整理了Java中com.psddev.dari.db.Query.getOptions
方法的一些代码示例,展示了Query.getOptions
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getOptions
方法的具体详情如下:
包路径:com.psddev.dari.db.Query
类名称:Query
方法名:getOptions
[英]Returns the map of custom options that are passed to the underlying database.
[中]返回传递到基础数据库的自定义选项的映射。
代码示例来源:origin: perfectsense/dari
/** Adds a custom option with the given {@code key} and {@code value}. */
public Query<E> option(String key, Object value) {
getOptions().put(key, value);
return this;
}
代码示例来源:origin: perfectsense/dari
@Override
public boolean equals(Object other) {
if (!(other instanceof FunnelCacheProducer)) {
return false;
}
FunnelCacheProducer otherProducer = (FunnelCacheProducer) other;
return (otherProducer.sqlQuery + otherProducer.query.getOptions().get(RETURN_ORIGINAL_DATA_QUERY_OPTION))
.equals(sqlQuery + query.getOptions().get(RETURN_ORIGINAL_DATA_QUERY_OPTION));
}
代码示例来源:origin: perfectsense/dari
@Override
public Connection openQueryConnection(Query<?> query) {
if (query != null) {
Connection connection = (Connection) query.getOptions().get(CONNECTION_QUERY_OPTION);
if (connection != null) {
return connection;
}
}
return super.openQueryConnection(query);
}
代码示例来源:origin: perfectsense/dari
private Join createJoin(String queryKey) {
String alias = "i" + joins.size();
Join join = new Join(alias, queryKey);
joins.add(join);
if (queryKey.equals(query.getOptions().get(SqlDatabase.MYSQL_INDEX_HINT_QUERY_OPTION))) {
mysqlIndexHint = join;
}
return join;
}
代码示例来源:origin: perfectsense/dari
/**
* Returns {@code true} if the caching should be disabled when
* running the query.
*
* @deprecated Use {@link Query#isCache} instead.
*/
@Deprecated
public boolean isDisabled() {
Boolean old = ObjectUtils.to(Boolean.class, getOriginalObject().getOptions().get(IS_DISABLED_QUERY_OPTION));
return old != null ? old : disabled;
}
代码示例来源:origin: perfectsense/dari
protected void closeResources(Query<?> query, Connection connection, Statement statement, ResultSet result) {
if (result != null) {
try {
result.close();
} catch (SQLException error) {
// Not likely and probably harmless.
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException error) {
// Not likely and probably harmless.
}
}
Object queryConnection;
if (connection != null
&& (query == null
|| (queryConnection = query.getOptions().get(CONNECTION_QUERY_OPTION)) == null
|| !connection.equals(queryConnection))) {
try {
if (!connection.isClosed()) {
connection.close();
}
} catch (SQLException ex) {
// Not likely and probably harmless.
}
}
}
代码示例来源:origin: perfectsense/dari
void closeResources(Query<?> query, Connection connection, Statement statement, ResultSet result) {
if (result != null) {
try {
result.close();
} catch (SQLException error) {
// Not likely and probably harmless.
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException error) {
// Not likely and probably harmless.
}
}
Object queryConnection;
if (connection != null
&& (query == null
|| (queryConnection = query.getOptions().get(CONNECTION_QUERY_OPTION)) == null
|| !connection.equals(queryConnection))) {
try {
if (!connection.isClosed()) {
connection.close();
}
} catch (SQLException ex) {
// Not likely and probably harmless.
}
}
}
代码示例来源:origin: perfectsense/dari
@Override
public Connection openQueryConnection(Query<?> query) {
if (query != null) {
Connection connection = (Connection) query.getOptions().get(CONNECTION_QUERY_OPTION);
if (connection != null) {
return connection;
}
Boolean useRead = ObjectUtils.to(Boolean.class, query.getOptions().get(USE_READ_DATA_SOURCE_QUERY_OPTION));
if (useRead == null) {
useRead = Boolean.TRUE;
}
if (!useRead) {
return openConnection();
}
}
return super.openQueryConnection(query);
}
代码示例来源:origin: perfectsense/dari
private boolean checkFunnelCache(Query<?> query) {
return query.isCache()
&& !query.isReferenceOnly()
&& isEnableFunnelCache()
&& !Boolean.TRUE.equals(query.getOptions().get(Database.DISABLE_FUNNEL_CACHE_QUERY_OPTION))
&& funnelCache != null;
}
代码示例来源:origin: perfectsense/dari
private boolean checkReplicationCache(Query<?> query) {
return query.isCache()
&& !query.isMaster()
&& isEnableReplicationCache()
&& !Boolean.TRUE.equals(query.getOptions().get(DISABLE_REPLICATION_CACHE_QUERY_OPTION))
&& mysqlBinaryLogReader != null
&& mysqlBinaryLogReader.isConnected();
}
代码示例来源:origin: perfectsense/dari
private void startQueryEvent(String event, Query<?> query) {
StackTraceElement caller = null;
Profiler.Static.pauseThreadEvent();
try {
StackTraceElement[] elements = new Throwable().getStackTrace();
for (int i = 2, length = elements.length; i < length; ++ i) {
StackTraceElement element = elements[i];
String className = element.getClassName();
Class<?> c = ObjectUtils.getClassByName(className);
if (c == null
|| !(Database.class.isAssignableFrom(c)
|| Query.class.isAssignableFrom(c))) {
caller = element;
break;
}
}
} finally {
Profiler.Static.resumeThreadEvent();
}
Object resolving = query.getOptions().get(State.REFERENCE_RESOLVING_QUERY_OPTION);
if (resolving != null) {
Profiler.Static.startThreadEvent(event + " (Reference Resolving)", resolving, query.getOptions().get(State.REFERENCE_FIELD_QUERY_OPTION), caller);
} else {
Profiler.Static.startThreadEvent(event, caller, query);
}
}
代码示例来源:origin: perfectsense/brightspot-cms
private void addLegacyDatabaseSupport(Query query) {
boolean usesLegacyDatabase = false;
Database database = query.getDatabase();
while (database instanceof ForwardingDatabase) {
database = ((ForwardingDatabase) database).getDelegate();
}
if (database instanceof SqlDatabase) {
usesLegacyDatabase = true;
} else if (database instanceof AggregateDatabase) {
usesLegacyDatabase = ((AggregateDatabase) database).getDelegatesByClass(SqlDatabase.class).size() > 0;
}
if (usesLegacyDatabase) {
query.getOptions().put(SqlDatabase.USE_JDBC_FETCH_SIZE_QUERY_OPTION, false);
query.setSorters(null); // SqlDatabase#ByIdIterator does not support sorters
}
}
代码示例来源:origin: perfectsense/dari
@Override
public <T> Iterable<T> readIterable(Query<T> query, int fetchSize) {
Boolean useJdbc = ObjectUtils.to(Boolean.class, query.getOptions().get(USE_JDBC_FETCH_SIZE_QUERY_OPTION));
if (useJdbc == null) {
useJdbc = Boolean.TRUE;
}
if (useJdbc) {
return selectIterableWithOptions(buildSelectStatement(query), fetchSize, query);
} else {
return new ByIdIterable<T>(query, fetchSize);
}
}
代码示例来源:origin: perfectsense/dari
@Override
public <T> Iterable<T> readIterable(Query<T> query, int fetchSize) {
if (query.getSorters().isEmpty()) {
if (!ObjectUtils.to(boolean.class, query.getOptions().get(DISABLE_BY_ID_ITERATOR_OPTION))) {
return ByIdIterator.iterable(query, fetchSize);
}
}
return selectIterable(buildSelectStatement(query), fetchSize, query);
}
代码示例来源:origin: perfectsense/dari
<T> T createSavedObjectFromReplicationCache(UUID id, byte[] data, Map<String, Object> dataJson, Query<T> query) {
UUID typeId = ObjectUtils.to(UUID.class, dataJson.get(StateSerializer.TYPE_KEY));
T object = createSavedObject(typeId, id, query);
State state = State.getInstance(object);
@SuppressWarnings("unchecked")
Map<String, Object> dataJsonClone = (Map<String, Object>) cloneJson(dataJson);
state.setValues(dataJsonClone);
if (query != null && ObjectUtils.to(boolean.class, query.getOptions().get(RETURN_ORIGINAL_DATA_QUERY_OPTION))) {
state.getExtras().put(ORIGINAL_DATA_EXTRA, data);
}
return swapObjectType(query, object);
}
代码示例来源:origin: perfectsense/dari
/**
* Builds an SQL statement that can be used to list all rows
* matching the given {@code query}.
*/
public String buildSelectStatement(Query<?> query) {
try {
Query<?> strippedQuery = query.clone();
// Remove any possibility that multiple CachingDatabases will be cached in the sqlQueryCache.
strippedQuery.setDatabase(this);
strippedQuery.getOptions().remove(State.REFERENCE_RESOLVING_QUERY_OPTION);
return addComment(sqlQueryCache.getUnchecked(strippedQuery), query);
} catch (UncheckedExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else {
throw new DatabaseException(this, cause);
}
}
}
代码示例来源:origin: perfectsense/dari
protected <T> T createSavedObjectFromReplicationCache(byte[] typeId, UUID id, byte[] data, Map<String, Object> dataJson, Query<T> query) {
T object = createSavedObject(typeId, id, query);
State objectState = State.getInstance(object);
objectState.setValues(cloneDataJson(dataJson));
Boolean returnOriginal = query != null ? ObjectUtils.to(Boolean.class, query.getOptions().get(RETURN_ORIGINAL_DATA_QUERY_OPTION)) : null;
if (returnOriginal == null) {
returnOriginal = Boolean.FALSE;
}
if (returnOriginal) {
objectState.getExtras().put(ORIGINAL_DATA_EXTRA, data);
}
return swapObjectType(query, object);
}
代码示例来源:origin: perfectsense/dari
/**
* Creates a previously saved object using the given {@code result},
* and sets common state options based on the given {@code query}.
*
* @param result Nonnull.
* @param query Nullable.
* @return Nonnull.
* @see #createSavedObject(Object, Object, Query)
*/
protected <T> T createSavedObjectUsingResultSet(ResultSet result, Query<T> query) throws SQLException {
T object = createSavedObject(result.getObject(2), result.getObject(1), query);
State objectState = State.getInstance(object);
if (!objectState.isReferenceOnly()) {
byte[] data = result.getBytes(3);
if (data != null) {
objectState.setValues(StateSerializer.deserialize(data));
objectState.getExtras().put(DATA_LENGTH_EXTRA, data.length);
if (query != null
&& ObjectUtils.to(boolean.class, query.getOptions().get(RETURN_ORIGINAL_DATA_QUERY_OPTION))) {
objectState.getExtras().put(ORIGINAL_DATA_EXTRA, data);
}
}
}
return swapObjectType(query, object);
}
代码示例来源:origin: perfectsense/dari
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
} else if (other instanceof Query) {
Query<?> otherQuery = (Query<?>) other;
return ObjectUtils.equals(group, otherQuery.group)
&& ObjectUtils.equals(objectClass, otherQuery.objectClass)
&& ObjectUtils.equals(predicate, otherQuery.predicate)
&& ObjectUtils.equals(getSorters(), otherQuery.getSorters())
&& ObjectUtils.equals(getDatabase(), otherQuery.getDatabase())
&& ObjectUtils.equals(getFields(), otherQuery.getFields())
&& ObjectUtils.equals(getOptions(), otherQuery.getOptions())
&& isResolveToReferenceOnly == otherQuery.isResolveToReferenceOnly
&& ObjectUtils.equals(timeout, otherQuery.timeout);
} else {
return false;
}
}
代码示例来源:origin: perfectsense/dari
@Override
public int hashCode() {
return ObjectUtils.hashCode(
getGroup(),
getObjectClass(),
getPredicate(),
getSorters(),
getDatabase(),
getFields(),
getOptions(),
isResolveToReferenceOnly(),
getTimeout());
}
内容来源于网络,如有侵权,请联系作者删除!