Eli Mesika has uploaded a new change for review.

Change subject: Hosts from another data center displayed when...
......................................................................

Hosts from another data center displayed when...

Hosts from another data center displayed when clicked on Hosts in tree view for 
cluster names with a single difference

The way the ESCAPE character is used was changed between 8.4 and 9.x
The '_' character is considered as regexp '?' character in the case
ilike is used as the condition operator, therefore, we are forced to
sign it as a normal character that is part of the string
However, it seems that PG 8.4 forces us to use double ESCAPE character
for that while it will not find any matching with one ESCAPE character
and PG 9.1 is exactly the opposite , one ESCAPE character works while
double ESCAPE characters will bring no data.
I am trying to prevent as much as I can referencing the PG version in
the code(i.e running a select version(); query and according to the
result determine if to replace '_' with '\_' or with '\\_'

The patch adds a new configuration variable PgMajorRelease that is
computed when the 0000_config.sql script is running.
The value of this variable is used to determine how to skip the special
character '_' if found in the value string.

Change-Id: I808fe02553b5554b76f08b43a30fb0ffd7d99973
Signed-off-by: Eli Mesika <[email protected]>
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=874660
---
M backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
M 
backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/SyntaxChecker.java
3 files changed, 49 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/41/11541/1

diff --git a/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql 
b/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
index 147212d..391c52a 100644
--- a/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
+++ b/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
@@ -737,3 +737,20 @@
 SELECT  __temp_update_ldap_provier_types();
 DROP FUNCTION __temp_update_ldap_provier_types();
 
+
+create or replace function __temp_set_pg_major_release()
+RETURNS void
+AS $procedure$
+DECLARE
+    v_pg_major_release char(1);
+BEGIN
+    -- the folowing evaluates currently to 8 on PG 8.x and to 9 on PG 9.x
+    v_pg_major_release:=substring ((string_to_array(version(),' '))[2],1,1);
+    perform 
fn_db_add_config_value('PgMajorRelease',v_pg_major_release,'general');
+    -- ensure that if PG was upgraded we will get the right value
+    perform 
fn_db_update_config_value('PgMajorRelease',v_pg_major_release,'general');
+END; $procedure$
+LANGUAGE plpgsql;
+SELECT  __temp_set_pg_major_release();
+DROP FUNCTION __temp_set_pg_major_release();
+
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
index 43d51b0..ce30ff3 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
@@ -1357,6 +1357,10 @@
     @DefaultValueAttribute("95")
     LogMaxSwapUsedThresholdInPercentage(415),
 
+    @TypeConverterAttribute(Integer.class)
+    @DefaultValueAttribute("9")
+    PgMajorRelease(416),
+
     Invalid(65535);
 
     private int intValue;
diff --git 
a/backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/SyntaxChecker.java
 
b/backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/SyntaxChecker.java
index 9d0a98a..445d19d 100644
--- 
a/backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/SyntaxChecker.java
+++ 
b/backend/manager/modules/searchbackend/src/main/java/org/ovirt/engine/core/searchbackend/SyntaxChecker.java
@@ -1092,7 +1092,19 @@
         final String tableName = mSearchObjectAC.getRelatedTableName(objName);
         // Since '_' is treated in Postgres as '?' when using like, (i.e. 
match any single character)
         // we have to escape this character in the value to make it treated as 
a regular character.
-        customizedValue = customizedValue.replace("_", "\\_");
+        // Due to changes between PG8.x and PG9.x on ESCAPE representation in 
a string, we should
+        // figure out what PG Release is running in order to escape the 
special character(_) correctly
+        // This is done in a IF block and not with Method Factory pattern 
since this is the only change
+        // right now, if we encounter other changes, this will be refactored 
to use the Method Factory pattern.
+        String replaceWith = "_";
+        if (Config.<Integer> GetValue(ConfigValues.PgMajorRelease) == 
PgMajorRelease.PG8.getValue()) {
+            replaceWith = "\\\\_";
+        }
+        else if (Config.<Integer> GetValue(ConfigValues.PgMajorRelease) == 
PgMajorRelease.PG9.getValue()) {
+            replaceWith = "\\_";
+        }
+
+        customizedValue = customizedValue.replace("_", replaceWith);
         switch (conditionType) {
         case FreeText:
         case FreeTextSpecificObj:
@@ -1113,4 +1125,19 @@
     }
 
     private static Log log = LogFactory.getLog(SyntaxChecker.class);
+
+    private static enum PgMajorRelease {
+        PG8(8),
+        PG9(9);
+
+        private int value;
+
+        private PgMajorRelease(int value) {
+            this.value = value;
+        }
+
+        public int getValue() {
+            return value;
+        }
+    }
 }


--
To view, visit http://gerrit.ovirt.org/11541
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I808fe02553b5554b76f08b43a30fb0ffd7d99973
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Eli Mesika <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to