public void testGetQueryWithSqlScriptSpecified() {
   DBTreeListClass dbtlc = new DBTreeListClass();
   assertEquals("", dbtlc.getSql());
   String sql = "select doc.name, doc.title, doc.creator from XWikiDocument as doc";
   dbtlc.setSql(sql);
   assertEquals(sql, dbtlc.getQuery(getContext()));
 }
 public void testGetQueryWithValueSpecified() {
   DBTreeListClass dbtlc = new DBTreeListClass();
   dbtlc.setValueField("doc.name");
   assertEquals(
       "select distinct doc.name, doc.name, doc.parent from XWikiDocument as doc",
       dbtlc.getQuery(getContext()));
 }
 public void testGetQueryWithClassSpecified() {
   DBTreeListClass dbtlc = new DBTreeListClass();
   dbtlc.setClassname("XWiki.XWikiUsers");
   assertEquals(
       "select distinct doc.fullName, doc.fullName, doc.parent"
           + " from XWikiDocument as doc, BaseObject as obj"
           + " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'",
       dbtlc.getQuery(getContext()));
 }
 public void testGetQueryWithIdValueAndParentSpecified() {
   DBTreeListClass dbtlc = new DBTreeListClass();
   dbtlc.setIdField("doc.name");
   dbtlc.setValueField("doc.title");
   dbtlc.setParentField("doc.space");
   assertEquals(
       "select distinct doc.name, doc.title, doc.space" + " from XWikiDocument as doc",
       dbtlc.getQuery(getContext()));
   dbtlc.setValueField("obj.name");
   assertEquals(
       "select distinct doc.name, obj.name, doc.space"
           + " from XWikiDocument as doc, BaseObject as obj where doc.fullName=obj.name",
       dbtlc.getQuery(getContext()));
   dbtlc.setIdField("obj.className");
   dbtlc.setParentField("obj.id");
   assertEquals(
       "select distinct obj.className, obj.name, obj.id" + " from BaseObject as obj",
       dbtlc.getQuery(getContext()));
 }
 public void testGetQueryWithIdSpecified() {
   DBTreeListClass dbtlc = new DBTreeListClass();
   dbtlc.setIdField("doc.name");
   assertEquals(
       "select distinct doc.name, doc.name, doc.parent from XWikiDocument as doc",
       dbtlc.getQuery(getContext()));
   dbtlc.setIdField("obj.className");
   assertEquals(
       "select distinct obj.className, obj.className, doc.parent"
           + " from XWikiDocument as doc, BaseObject as obj"
           + " where doc.fullName=obj.name",
       dbtlc.getQuery(getContext()));
   dbtlc.setIdField("property");
   assertEquals(
       "select distinct doc.property, doc.property, doc.parent" + " from XWikiDocument as doc",
       dbtlc.getQuery(getContext()));
 }
 public void testGetQueryWithIdAndClassnameSpecified() {
   DBTreeListClass dbtlc = new DBTreeListClass();
   dbtlc.setClassname("XWiki.XWikiUsers");
   dbtlc.setIdField("doc.name");
   assertEquals(
       "select distinct doc.name, doc.name, doc.parent"
           + " from XWikiDocument as doc, BaseObject as obj"
           + " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'",
       dbtlc.getQuery(getContext()));
   dbtlc.setIdField("obj.className");
   assertEquals(
       "select distinct obj.className, obj.className, doc.parent"
           + " from XWikiDocument as doc, BaseObject as obj"
           + " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'",
       dbtlc.getQuery(getContext()));
   dbtlc.setIdField("property");
   assertEquals(
       "select distinct idprop.value, idprop.value, doc.parent"
           + " from XWikiDocument as doc, BaseObject as obj, StringProperty as idprop"
           + " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'"
           + " and obj.id=idprop.id.id and idprop.id.name='property'",
       dbtlc.getQuery(getContext()));
 }
Esempio n. 7
0
  /** @since 1.8M1 */
  public boolean addDBTreeListField(
      String fieldName,
      String fieldPrettyName,
      int size,
      boolean multiSelect,
      boolean relationalStorage,
      String sql) {
    if (get(fieldName) == null) {
      DBTreeListClass list_class = new DBTreeListClass();
      list_class.setName(fieldName);
      list_class.setPrettyName(fieldPrettyName);
      list_class.setSize(size);
      list_class.setMultiSelect(multiSelect);
      list_class.setRelationalStorage(relationalStorage);
      list_class.setSql(sql);
      list_class.setObject(this);
      put(fieldName, list_class);

      return true;
    }

    return false;
  }
 public void testGetQueryWhenNoSQLSCriptSpecified() {
   DBTreeListClass dbtlc = new DBTreeListClass();
   assertEquals(
       "select doc.name from XWikiDocument doc where 1 = 0", dbtlc.getQuery(getContext()));
 }
 public void testGetQueryWithIdValueParentAndClassSpecified() {
   DBTreeListClass dbtlc = new DBTreeListClass();
   dbtlc.setClassname("XWiki.XWikiUsers");
   dbtlc.setIdField("doc.name");
   dbtlc.setValueField("doc.name");
   dbtlc.setParentField("doc.name");
   assertEquals(
       "select distinct doc.name, doc.name, doc.name"
           + " from XWikiDocument as doc, BaseObject as obj"
           + " where doc.fullName=obj.name and obj.className='XWiki.XWikiUsers'",
       dbtlc.getQuery(getContext()));
   dbtlc.setIdField("prop1");
   dbtlc.setValueField("prop1");
   dbtlc.setParentField("prop1");
   assertEquals(
       "select distinct idprop.value, idprop.value, idprop.value"
           + " from BaseObject as obj, StringProperty as idprop"
           + " where obj.className='XWiki.XWikiUsers'"
           + " and obj.id=idprop.id.id and idprop.id.name='prop1'",
       dbtlc.getQuery(getContext()));
   dbtlc.setValueField("prop2");
   assertEquals(
       "select distinct idprop.value, valueprop.value, idprop.value"
           + " from BaseObject as obj, StringProperty as idprop, StringProperty as valueprop"
           + " where obj.className='XWiki.XWikiUsers'"
           + " and obj.id=idprop.id.id and idprop.id.name='prop1'"
           + " and obj.id=valueprop.id.id and valueprop.id.name='prop2'",
       dbtlc.getQuery(getContext()));
   dbtlc.setParentField("prop2");
   assertEquals(
       "select distinct idprop.value, valueprop.value, valueprop.value"
           + " from BaseObject as obj, StringProperty as idprop, StringProperty as valueprop"
           + " where obj.className='XWiki.XWikiUsers'"
           + " and obj.id=idprop.id.id and idprop.id.name='prop1'"
           + " and obj.id=valueprop.id.id and valueprop.id.name='prop2'",
       dbtlc.getQuery(getContext()));
   dbtlc.setParentField("prop3");
   assertEquals(
       "select distinct idprop.value, valueprop.value, parentprop.value"
           + " from BaseObject as obj, StringProperty as idprop,"
           + " StringProperty as valueprop, StringProperty as parentprop"
           + " where obj.className='XWiki.XWikiUsers'"
           + " and obj.id=idprop.id.id and idprop.id.name='prop1'"
           + " and obj.id=valueprop.id.id and valueprop.id.name='prop2'"
           + " and obj.id=parentprop.id.id and parentprop.id.name='prop3'",
       dbtlc.getQuery(getContext()));
 }