/** * A Factory used by the SQL class to turn a string sql query into an SQLString object. * This may just contain the sql given, or the given SQL may be overriden in the database and the object returned * will reflect that new SQL from the DB. * * @param sql The string to be used in a query * @return a SQLString object representing the given SQL */ @SuppressWarnings("GuardedByChecker") static FinalSQLString getUnregisteredQuery(String sql) { assert !isValidKey(sql) : "Unregistered Queries should not look like keys"; //$NON-NLS-1$ FinalSQLString cached = cachedUnregistered.get(canonicalizeStringAndRemoveWhitespaceEntirely(sql)); if (null != cached) { callbackOnUse.noteUse((SQLString) cached.delegate); return cached; } return new FinalSQLString(new SQLString(sql)); }
/** * Call this function to store a query to be used later with the given key. * @param key Unique identifier for this query * @param sql The query that will be stored */ public static RegisteredSQLString registerQuery(String key, String sql) { SQLString sqlString = new SQLString(key, sql, null); FinalSQLString newVal = new FinalSQLString(sqlString); FinalSQLString oldVal = registeredValues.put(key, newVal); assert null == oldVal || oldVal.delegate.equals(newVal.delegate) : "newVal: " + newVal + " oldVal: " + oldVal; //$NON-NLS-1$ //$NON-NLS-2$ return new RegisteredSQLString(sqlString); }
/** * Same as the overloaded registerQuery, but overrides the query for a specific DBType. * @param key Unique identifier representing this query * @param sql The query that will be stored * @param dbType Override the query for this DBType. * If this value is null, it is the same as <code>registerQuery(key, sql)</code> */ public static RegisteredSQLString registerQuery(String key, String sql, DBType dbType) { if (dbType == null) { return registerQuery(key, sql); } SQLString sqlString = new SQLString(key, sql, dbType); ConcurrentMap<DBType, FinalSQLString> newHash = new ConcurrentHashMap<DBType, FinalSQLString>(); ConcurrentMap<DBType, FinalSQLString> dbTypeHash = registeredValuesOverride.putIfAbsent(key, newHash); if (null == dbTypeHash) { dbTypeHash = newHash; } FinalSQLString newVal = new FinalSQLString(sqlString); FinalSQLString oldVal = dbTypeHash.put(dbType, newVal); assert null == oldVal || newVal.delegate.equals(oldVal.delegate) : "newVal: " + newVal + " oldVal: " + oldVal; //$NON-NLS-1$ //$NON-NLS-2$ return new RegisteredSQLString(sqlString); }
/** * A Factory used by the SQL class to turn a string sql query into an SQLString object. * This may just contain the sql given, or the given SQL may be overriden in the database and the object returned * will reflect that new SQL from the DB. * * @param sql The string to be used in a query * @return a SQLString object representing the given SQL */ @SuppressWarnings("GuardedByChecker") static FinalSQLString getUnregisteredQuery(String sql) { assert !isValidKey(sql) : "Unregistered Queries should not look like keys"; //$NON-NLS-1$ FinalSQLString cached = cachedUnregistered.get(canonicalizeStringAndRemoveWhitespaceEntirely(sql)); if (null != cached) { callbackOnUse.noteUse((SQLString) cached.delegate); return cached; } return new FinalSQLString(new SQLString(sql)); }
/** * Call this function to store a query to be used later with the given key. * @param key Unique identifier for this query * @param sql The query that will be stored */ public static RegisteredSQLString registerQuery(String key, String sql) { SQLString sqlString = new SQLString(key, sql, null); FinalSQLString newVal = new FinalSQLString(sqlString); FinalSQLString oldVal = registeredValues.put(key, newVal); assert null == oldVal || oldVal.delegate.equals(newVal.delegate) : "newVal: " + newVal + " oldVal: " + oldVal; //$NON-NLS-1$ //$NON-NLS-2$ return new RegisteredSQLString(sqlString); }
/** * Same as the overloaded registerQuery, but overrides the query for a specific DBType. * @param key Unique identifier representing this query * @param sql The query that will be stored * @param dbType Override the query for this DBType. * If this value is null, it is the same as <code>registerQuery(key, sql)</code> */ public static RegisteredSQLString registerQuery(String key, String sql, DBType dbType) { if (dbType == null) { return registerQuery(key, sql); } SQLString sqlString = new SQLString(key, sql, dbType); ConcurrentMap<DBType, FinalSQLString> newHash = new ConcurrentHashMap<DBType, FinalSQLString>(); ConcurrentMap<DBType, FinalSQLString> dbTypeHash = registeredValuesOverride.putIfAbsent(key, newHash); if (null == dbTypeHash) { dbTypeHash = newHash; } FinalSQLString newVal = new FinalSQLString(sqlString); FinalSQLString oldVal = dbTypeHash.put(dbType, newVal); assert null == oldVal || newVal.delegate.equals(oldVal.delegate) : "newVal: " + newVal + " oldVal: " + oldVal; //$NON-NLS-1$ //$NON-NLS-2$ return new RegisteredSQLString(sqlString); }