Exemplo n.º 1
0
  /**
   * This method returns all languages for a certain repository.
   *
   * @param repositoryId
   * @return
   * @throws SystemException
   * @throws Exception
   */
  public List getLanguageVOList(Integer repositoryId, Database db)
      throws SystemException, Exception {
    String key = "" + repositoryId + "_allLanguages";
    logger.info("key:" + key);
    List list = (List) CacheController.getCachedObject("languageCache", key);
    if (list != null) {
      logger.info("There was an cached list:" + list);
    } else {
      list = new ArrayList();

      OQLQuery oql =
          db.getOQLQuery(
              "SELECT l FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl l WHERE l.repositoryLanguages.repository = $1 ORDER BY l.repositoryLanguages.sortOrder, l.languageId");
      oql.bind(repositoryId);

      QueryResults results = oql.execute(Database.ReadOnly);
      while (results.hasMore()) {
        Language language = (Language) results.next();
        list.add(language.getValueObject());
      }

      results.close();
      oql.close();

      if (list.size() > 0) CacheController.cacheObject("languageCache", key, list);
    }

    return list;
  }
Exemplo n.º 2
0
  /**
   * Returns the Language with the given languageCode fetched within a given transaction.
   *
   * @param code
   * @param db
   * @return
   * @throws SystemException
   * @throws Bug
   */
  public Language getLanguageWithCode(String code, Database db) throws SystemException, Bug {
    Language language = null;

    try {
      OQLQuery oql =
          db.getOQLQuery(
              "SELECT f FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl f WHERE f.languageCode = $1");
      oql.bind(code);

      QueryResults results = oql.execute();
      this.logger.info("Fetching entity in read/write mode" + code);

      if (results.hasMore()) {
        language = (Language) results.next();
      }

      results.close();
      oql.close();
    } catch (Exception e) {
      throw new SystemException(
          "An error occurred when we tried to fetch a named language. Reason:" + e.getMessage(), e);
    }

    return language;
  }
Exemplo n.º 3
0
  /** Get the SystemUser with the userName */
  public SystemUser getSystemUserWithName(String userName, Database db)
      throws SystemException, Bug {
    SystemUser systemUser = null;
    OQLQuery oql;
    try {
      oql =
          db.getOQLQuery(
              "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SystemUserImpl u WHERE u.userName = $1");
      oql.bind(userName);

      QueryResults results = oql.execute();
      this.logger.info("Fetching entity in read/write mode" + userName);

      if (results.hasMore()) {
        systemUser = (SystemUser) results.next();
        logger.info("found one:" + systemUser.getFirstName());
      }

      results.close();
      oql.close();
    } catch (Exception e) {
      throw new SystemException(
          "An error occurred when we tried to fetch " + userName + " Reason:" + e.getMessage(), e);
    }

    return systemUser;
  }
Exemplo n.º 4
0
  public List getFilteredSystemUserList(String searchString, Database db)
      throws SystemException, Bug, Exception {
    List filteredList = new ArrayList();

    OQLQuery oql =
        db.getOQLQuery(
            "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SystemUserImpl u ORDER BY u.userName");

    QueryResults results = oql.execute(Database.ReadOnly);

    while (results.hasMore()) {
      SystemUser extranetUser = (SystemUser) results.next();
      boolean include = false;
      if (searchString == null || searchString.equals("")) {
        include = true;
      } else {
        if (extranetUser.getFirstName().toLowerCase().indexOf(searchString.toLowerCase()) > -1)
          include = true;
        else if (extranetUser.getLastName().toLowerCase().indexOf(searchString.toLowerCase()) > -1)
          include = true;
        else if (extranetUser.getUserName().toLowerCase().indexOf(searchString.toLowerCase()) > -1)
          include = true;
        else if (extranetUser.getEmail().toLowerCase().indexOf(searchString.toLowerCase()) > -1)
          include = true;
      }

      if (include) filteredList.add(extranetUser);
    }

    results.close();
    oql.close();

    return filteredList;
  }
Exemplo n.º 5
0
  /** Get the SystemUser with the userName */
  public SystemUserVO getReadOnlySystemUserVOWithName(String userName, Database db)
      throws SystemException, Bug {
    SystemUserVO systemUserVO = null;

    try {
      OQLQuery oql =
          db.getOQLQuery(
              "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SmallSystemUserImpl u WHERE u.userName = $1");
      oql.bind(userName);

      QueryResults results = oql.execute(Database.ReadOnly);

      if (results.hasMore()) {
        SystemUser systemUser = (SystemUser) results.next();
        systemUserVO = systemUser.getValueObject();
      }

      results.close();
      oql.close();
    } catch (Exception e) {
      throw new SystemException(
          "An error occurred when we tried to fetch " + userName + " Reason:" + e.getMessage(), e);
    }

    return systemUserVO;
  }
Exemplo n.º 6
0
  public void runTest() throws PersistenceException, SQLException {
    OQLQuery oql;
    TestObject object;
    QueryResults enumeration;

    _db.begin();

    // Determine if test object exists, if not create it.
    // If it exists, set the name to some predefined value
    // that this test will later override.
    oql = _db.getOQLQuery("SELECT object FROM jdo.TestObject object WHERE id = $1");
    oql.bind(50);
    enumeration = oql.execute();
    if (enumeration.hasMore()) {
      object = (TestObject) enumeration.next();
      stream.println("Retrieved object: " + object);
      object.setValue1(TestObject.DefaultValue1);
      object.setValue2(TestObject.DefaultValue2);
    } else {
      object = new TestObject();
      object.setId(50);
      stream.println("Creating new object: " + object);
      _db.create(object);
    }
    oql.close();
    _db.commit();

    try {
      stream.println("CALL SQL query");
      _db.begin();
      oql =
          _db.getOQLQuery(
              "CALL SQL SELECT ID,VALUE1,VALUE2 FROM TEST_TABLE WHERE (ID = $1) AS jdo.TestObject");
      oql.bind(50);
      enumeration = oql.execute();
      if (enumeration.hasMore()) {
        object = (TestObject) enumeration.next();
        stream.println("Retrieved object: " + object);
      } else {
        fail("test object not found");
      }
      oql.close();
      _db.commit();
    } catch (Exception e) {
      fail("Exception thrown " + e);
    }
  }
Exemplo n.º 7
0
 public void test(final Database db) throws Exception {
   db.begin();
   String s = "SELECT e FROM " + Employee.class.getName() + " e " + "WHERE e.holiday > $1";
   OQLQuery qry = db.getOQLQuery(s);
   qry.bind(50.0);
   QueryResults rst = qry.execute();
   while (rst.hasMore()) {
     Employee emp = (Employee) rst.next();
     emp.setHoliday(50.0f);
   }
   rst.close();
   qry.close();
   db.commit();
 }
Exemplo n.º 8
0
  public void testQuery() throws Exception {
    Database database;

    // create some products
    database = _category.getDatabase();
    database.begin();

    database.create(new Product(1, "LCD", KindEnum.MONITOR));
    database.create(new Product(2, "Laser", KindEnum.PRINTER));
    database.create(new Product(3, "Desktop", KindEnum.COMPUTER));
    database.create(new Product(4, "Notebook", KindEnum.COMPUTER));

    database.commit();
    database.close();

    // query and delete all product
    database = _category.getDatabase();
    database.begin();

    Product pq;
    OQLQuery query =
        database.getOQLQuery(
            "select p from " + jdo.tc167.Product.class.getName() + " p order by p.id");
    QueryResults results = query.execute();

    pq = (Product) results.next();
    assertEquals(pq, new Product(1, "LCD", KindEnum.MONITOR));
    database.remove(pq);

    pq = (Product) results.next();
    assertEquals(pq, new Product(2, "Laser", KindEnum.PRINTER));
    database.remove(pq);

    pq = (Product) results.next();
    assertEquals(pq, new Product(3, "Desktop", KindEnum.COMPUTER));
    database.remove(pq);

    pq = (Product) results.next();
    assertEquals(pq, new Product(4, "Notebook", KindEnum.COMPUTER));
    database.remove(pq);

    assertFalse(results.hasMore());
    results.close();
    query.close();

    database.commit();
    database.close();
  }
Exemplo n.º 9
0
  /** This method returns the master language within an transaction. */
  public Language getMasterLanguage(Database db, Integer repositoryId)
      throws SystemException, Exception {
    Language language = null;

    OQLQuery oql =
        db.getOQLQuery(
            "SELECT l FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl l WHERE l.repositoryLanguages.repository.repositoryId = $1 ORDER BY l.repositoryLanguages.sortOrder, l.languageId");
    oql.bind(repositoryId);

    QueryResults results = oql.execute(Database.ReadOnly);

    if (results.hasMore()) {
      language = (Language) results.next();
    }

    results.close();
    oql.close();

    return language;
  }
Exemplo n.º 10
0
  public List<SystemUserVO> getSystemUserVOListWithPassword(String password, Database db)
      throws SystemException, Bug, Exception {
    List<SystemUserVO> filteredVOList = new ArrayList<SystemUserVO>();

    OQLQuery oql =
        db.getOQLQuery(
            "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SystemUserImpl u WHERE u.password = $1 ORDER BY u.userName");
    oql.bind(password);

    QueryResults results = oql.execute(Database.ReadOnly);

    while (results.hasMore()) {
      SystemUser extranetUser = (SystemUser) results.next();
      filteredVOList.add(extranetUser.getValueObject());
    }

    results.close();
    oql.close();

    return filteredVOList;
  }
Exemplo n.º 11
0
  public SystemUserVO getSystemUserVO(Database db, String userName, String password)
      throws SystemException, Exception {
    SystemUserVO systemUserVO = null;

    OQLQuery oql =
        db.getOQLQuery(
            "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SmallSystemUserImpl u WHERE u.userName = $1 AND u.password = $2");
    oql.bind(userName);
    oql.bind(password);

    QueryResults results = oql.execute(Database.ReadOnly);

    if (results.hasMore()) {
      SystemUser systemUser = (SystemUser) results.next();
      systemUserVO = systemUser.getValueObject();
    }

    results.close();
    oql.close();

    return systemUserVO;
  }
Exemplo n.º 12
0
  public void setUp() throws PersistenceException {
    _jdo = _category.getJDO();
    _jdo.setCallbackInterceptor(_i);
    _jdo.setInstanceFactory(_i);

    _db = _category.getDatabase();

    OQLQuery oql;
    QueryResults qres;

    LOG.debug("Delete everything");
    _db.begin();
    oql =
        _db.getOQLQuery("SELECT p FROM " + TimeStampableObject.class.getName() + " p WHERE id=$1");
    oql.bind(TimeStampableObject.DEFAULT_ID);
    qres = oql.execute();
    while (qres.hasMore()) {
      _db.remove(qres.next());
    }
    oql.close();
    _db.commit();
  }
Exemplo n.º 13
0
  public SystemUser getSystemUser(Database db, String userName, String password)
      throws SystemException, Exception {
    SystemUser systemUser = null;

    OQLQuery oql =
        db.getOQLQuery(
            "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SystemUserImpl u WHERE u.userName = $1 AND u.password = $2");
    oql.bind(userName);
    oql.bind(password);

    QueryResults results = oql.execute();
    this.logger.info("Fetching entity in read/write mode" + userName);

    if (results.hasMore()) {
      systemUser = (SystemUser) results.next();
      logger.info("found one:" + systemUser.getFirstName());
    }

    results.close();
    oql.close();

    return systemUser;
  }
Exemplo n.º 14
0
  public void tearDown() throws PersistenceException {
    if (_db.isActive()) {
      _db.rollback();
    }

    OQLQuery oql;
    QueryResults qres;

    LOG.debug("Delete everything");
    _db.begin();
    oql =
        _db.getOQLQuery("SELECT p FROM " + TimeStampableObject.class.getName() + " p WHERE id=$1");
    oql.bind(TimeStampableObject.DEFAULT_ID);
    qres = oql.execute();
    while (qres.hasMore()) {
      _db.remove(qres.next());
    }
    oql.close();
    _db.commit();

    _db.close();

    _jdo.setCallbackInterceptor(null);
  }
Exemplo n.º 15
0
  /** Get if the SystemUser with the userName exists */
  public boolean systemUserExists(String userName, Database db) throws SystemException, Bug {
    boolean systemUserExists = false;

    try {
      OQLQuery oql =
          db.getOQLQuery(
              "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SmallSystemUserImpl u WHERE u.userName = $1");
      oql.bind(userName);

      QueryResults results = oql.execute(Database.ReadOnly);

      if (results.hasMore()) {
        systemUserExists = true;
      }

      results.close();
      oql.close();
    } catch (Exception e) {
      throw new SystemException(
          "An error occurred when we tried to fetch " + userName + " Reason:" + e.getMessage(), e);
    }

    return systemUserExists;
  }
  /** Gets and precaches all propertycategory-objects. */
  public void preCacheAllPropertiesCategoryVOList() throws SystemException, Exception {
    Database db = CastorDatabaseService.getDatabase();

    beginTransaction(db);

    try {
      Timer t = new Timer();
      Map<Integer, CategoryVO> categoriesMap = new HashMap<Integer, CategoryVO>();
      OQLQuery oql1 =
          db.getOQLQuery(
              "SELECT c FROM org.infoglue.cms.entities.management.impl.simple.CategoryImpl c ORDER BY c.categoryId");

      QueryResults results1 = oql1.execute(Database.ReadOnly);
      while (results1.hasMore()) {
        Category category = (Category) results1.next();
        categoriesMap.put(category.getId(), category.getValueObject());
      }

      results1.close();
      oql1.close();
      logger.warn("Categories took: " + t.getElapsedTime());
      // getCastorCategory().setLevel(Level.DEBUG);
      // getCastorJDOCategory().setLevel(Level.DEBUG);

      OQLQuery oql =
          db.getOQLQuery(
              "SELECT c FROM org.infoglue.cms.entities.management.impl.simple.SmallPropertiesCategoryImpl c ORDER BY c.propertiesCategoryId");

      QueryResults results = oql.execute(Database.ReadOnly);
      while (results.hasMore()) {
        PropertiesCategory propertiesCategory = (PropertiesCategory) results.next();

        String key =
            "categoryVOList_"
                + propertiesCategory.getAttributeName()
                + "_"
                + propertiesCategory.getEntityName()
                + "_"
                + propertiesCategory.getEntityId();
        List<CategoryVO> categoryVOList =
            (List<CategoryVO>) CacheController.getCachedObject("propertiesCategoryCache", key);
        if (categoryVOList == null) {
          categoryVOList = new ArrayList<CategoryVO>();
          CacheController.cacheObject("propertiesCategoryCache", key, categoryVOList);
        }

        if (propertiesCategory.getValueObject().getCategoryId() != null) {
          CategoryVO categoryVO =
              categoriesMap.get(propertiesCategory.getValueObject().getCategoryId());
          if (categoryVO != null) categoryVOList.add(categoryVO);
          else
            logger.info(
                "An inconsistency found. The propertyCategory "
                    + propertiesCategory.getId()
                    + " pointed to a missing categoryID: "
                    + propertiesCategory.getValueObject().getCategoryId());
          /*
          			try
          			{
          				CategoryVO categoryVO = CategoryController.getController().findById(propertiesCategory.getValueObject().getCategoryId(), db).getValueObject();
          				categoryVOList.add(categoryVO);
          			}
          			catch (Exception e)
          			{
          				logger.error("An inconsistency found. The propertyCategory " + propertiesCategory.getId() + " pointed to a missing category:" + e.getMessage());
          }
          */
        }

        /*
        if(propertiesCategory.getCategory() != null)
        {
        	categoryVOList.add(propertiesCategory.getCategory().getValueObject());
        	//System.out.println("Category was ok for: " + key);
        }
        //else
        	//System.out.println("Category was null for: " + key);
        */
      }

      // getCastorCategory().setLevel(Level.WARN);
      // getCastorJDOCategory().setLevel(Level.WARN);

      results.close();
      oql.close();

      CacheController.cacheObject("propertiesCategoryCache", "allValuesCached", true);

      logger.warn("PropCategories took: " + t.getElapsedTime());

      commitTransaction(db);
    } catch (Exception e) {
      logger.error("An error occurred when we tried to fetch the list of PropertiesCategory:" + e);
      rollbackTransaction(db);
      throw new SystemException(e.getMessage());
    }
  }
Exemplo n.º 17
0
  public List getFilteredSystemUserList(
      String firstName,
      String lastName,
      String userName,
      String email,
      String[] roleNames,
      Database db)
      throws SystemException, Bug, Exception {
    List filteredList = new ArrayList();

    OQLQuery oql =
        db.getOQLQuery(
            "SELECT u FROM org.infoglue.cms.entities.management.impl.simple.SystemUserImpl u ORDER BY u.userName");

    QueryResults results = oql.execute(Database.ReadOnly);

    while (results.hasMore()) {
      SystemUser extranetUser = (SystemUser) results.next();
      boolean include = true;

      if (firstName != null
          && !firstName.equals("")
          && extranetUser.getFirstName().toLowerCase().indexOf(firstName.toLowerCase()) == -1)
        include = false;

      if (lastName != null
          && !lastName.equals("")
          && extranetUser.getLastName().toLowerCase().indexOf(lastName.toLowerCase()) == -1)
        include = false;

      if (userName != null
          && !userName.equals("")
          && extranetUser.getUserName().toLowerCase().indexOf(userName.toLowerCase()) == -1)
        include = false;

      if (email != null
          && !email.equals("")
          && extranetUser.getEmail().toLowerCase().indexOf(email.toLowerCase()) == -1)
        include = false;

      boolean hasRoles = true;
      if (roleNames != null && roleNames.length > 0) {
        for (int i = 0; i < roleNames.length; i++) {
          String roleName = roleNames[i];
          if (roleName != null && !roleName.equals("")) {
            Collection roles = extranetUser.getRoles();
            Iterator rolesIterator = roles.iterator();
            boolean hasRole = false;
            while (rolesIterator.hasNext()) {
              Role role = (Role) rolesIterator.next();
              if (role.getRoleName().equalsIgnoreCase(roleName)) {
                hasRole = true;
                break;
              }
            }

            if (!hasRole) {
              hasRoles = false;
              break;
            }
          }
        }
      }

      if (include && hasRoles) filteredList.add(extranetUser);
    }

    results.close();
    oql.close();

    return filteredList;
  }