Package de.iritgo.aktera.persist

Examples of de.iritgo.aktera.persist.PersistentFactory


      return updateNeeded;
    }

    createVersionTableIfNotExists(req);

    PersistentFactory pf = (PersistentFactory) req.getService(PersistentFactory.ROLE, req.getDomain());

    List<Configuration> moduleConfigs = de.iritgo.aktera.base.module.ModuleInfo
            .moduleConfigsSortedByDependency(req);

    for (Configuration moduleConfig : moduleConfigs)
    {
      String moduleId = moduleConfig.getAttribute("id", "unkown");
      ModuleVersion newVersion = new ModuleVersion(moduleConfig.getChild("version").getValue());

      ModuleVersion currentVersion = new ModuleVersion();

      try
      {
        Persistent version = pf.create("aktera.Version");

        version.setField("type", "M");
        version.setField("name", moduleId);

        if (version.find())
View Full Code Here


    return false;
  }

  public static void createVersionTableIfNotExists(ModelRequest request) throws ModelException
  {
    PersistentFactory pf = (PersistentFactory) request.getService(PersistentFactory.ROLE, request.getDomain());

    Persistent version = null;

    try
    {
      version = pf.create("aktera.Version");
      version.setField("type", "M");
      version.setField("name", "dummy");
      version.find();
    }
    catch (Exception x)
View Full Code Here

  {
    Output outModuleList = response.createOutput("modules");

    response.add(outModuleList);

    PersistentFactory pf = (PersistentFactory) request.getService(PersistentFactory.ROLE, request.getDomain());

    DataSourceComponent dataSourceComponent = (DataSourceComponent) request.getService(DataSourceComponent.ROLE,
            "keel-dbpool");

    updatePreProcessing(request, dataSourceComponent);

    boolean needReboot = false;
    boolean newUserPreferences = false;

    List<Configuration> moduleConfigs = de.iritgo.aktera.base.module.ModuleInfo
            .moduleConfigsSortedByDependency(request);

    for (Configuration moduleConfig : moduleConfigs)
    {
      String moduleId = moduleConfig.getAttribute("id", "unkown");
      String moduleName = moduleConfig.getChild("name").getValue("unkown");
      ModuleVersion newVersion = new ModuleVersion(moduleConfig.getChild("version").getValue(null));

      Output outModule = response.createOutput("module_" + moduleConfig.getAttribute("id", "unknown"));

      outModuleList.add(outModule);
      outModule.setAttribute("name", moduleName);
      outModule.setAttribute("description", moduleConfig.getChild("description").getValue(""));
      outModule.setAttribute("newVersion", newVersion.toString());

      ModuleVersion currentVersion = new ModuleVersion();

      try
      {
        Persistent version = pf.create("aktera.Version");

        version.setField("type", "M");
        version.setField("name", moduleId);

        if (version.find())
        {
          currentVersion = new ModuleVersion(version.getFieldString("version"));
        }
        else
        {
          currentVersion = new ModuleVersion("0.0.0");
        }
      }
      catch (Exception x)
      {
        outModule.setAttribute("oldVersion", currentVersion.toString());
        outModule.setAttribute("error", "unableToRetrieveCurrentVersion");
        outModule.setAttribute("errorException", x.toString());

        response.addOutput("updateError", "Y");

        continue;
      }

      outModule.setAttribute("oldVersion", currentVersion.toString());

      String updateHandlerClassName = moduleConfig.getChild("update").getAttribute("class", null);

      if (updateHandlerClassName != null)
      {
        try
        {
          System.out.println("UpdateDatabase: Updating module '" + moduleId + "' with handler '"
                  + updateHandlerClassName + "'");

          Class klass = Class.forName(updateHandlerClassName);

          if (klass != null)
          {
            UpdateHandler updateHandler = (UpdateHandler) klass.newInstance();

            Connection con = null;

            try
            {
              con = dataSourceComponent.getConnection();
              updateHandler.setConnection(con);
              updateHandler.updateDatabase(request, logger, con, pf, (ModuleVersion) currentVersion
                      .clone(), newVersion);
            }
            finally
            {
              con.close();
            }

            needReboot = needReboot || updateHandler.needReboot();
            newUserPreferences = newUserPreferences || updateHandler.hasNewUserPreferences();
          }
          else
          {
            System.out.println("UpdateDatabase: Unable to find update handler for module '" + moduleId
                    + "'");
          }
        }
        catch (ClassNotFoundException x)
        {
          System.out
                  .println("UpdateDatabase: Unable call update handler for module '" + moduleId
                          + "': " + x);
        }
        catch (Exception x)
        {
          outModule.setAttribute("error", "errorDuringUpdate");
          outModule.setAttribute("errorException", x.toString());

          response.addOutput("updateError", "Y");

          continue;
        }
      }

      try
      {
        Persistent version = pf.create("aktera.Version");

        version.setField("type", "M");
        version.setField("name", moduleId);

        if (version.find())
        {
          version.setField("version", newVersion.toString());
          version.update();
        }
        else
        {
          version.setField("version", newVersion.toString());
          version.add();
        }
      }
      catch (Exception x)
      {
        outModule.setAttribute("error", "unableToUpdateVersion");
        outModule.setAttribute("errorException", x.toString());
        response.addOutput("updateError", "Y");
      }
    }

    if (newUserPreferences)
    {
      try
      {
        Persistent sample = pf.create("keel.user");

        for (Persistent user : sample.query())
        {
          KeelPreferencesManager.createDefaultValues(request, user.getFieldInt("uid"));
        }
      }
      catch (PersistenceException x)
      {
        response.addOutput("updateError", "Y");
        response.addOutput("databaseError", x.getMessage());

        StringWriter stw = new StringWriter();
        PrintWriter pw = new PrintWriter(stw);

        x.printStackTrace(pw);
        response.addOutput("databaseErrorStackTrace", stw.getBuffer().toString().replaceAll("\n", "<br>"));
      }
    }

    if (response.get("updateError") == null)
    {
      try
      {
        Model appInfo = (Model) request.getService(Model.ROLE, "aktera.app-info");

        Configuration[] appConfigs = appInfo.getConfiguration().getChildren("app");

        for (int i = 0; i < appConfigs.length; ++i)
        {
          Configuration appConfig = appConfigs[i];

          Persistent version = pf.create("aktera.Version");

          version.setField("type", "A");
          version.setField("name", appConfig.getAttribute("id", "unkown"));

          if (version.find())
View Full Code Here

   * for another user
   */
  protected String getActualUserName(ModelRequest request)
    throws PersistenceException, PermissionException, ModelException
  {
    PersistentFactory pf = (PersistentFactory) request.getService(PersistentFactory.ROLE, request.getDomain());

    String userName = UserTools.getCurrentUserName(request);

    if (request.getParameter("userId") != null)
    {
      int userId = NumberTools.toInt(request.getParameter("userId"), UserTools.getCurrentUserId(request));

      if (! UserTools.currentUserIsInGroup(request, "manager") && UserTools.getCurrentUserId(request) != userId)
      {
        throw new PermissionException("Permission denied to edit com device function keys of user " + userId);
      }

      try
      {
        Persistent user = pf.create("keel.user");

        user.setField("uid", userId);
        user.find();
        userName = user.getFieldString("name");
      }
View Full Code Here

        Configuration origSchema;

        try
        {
          PersistentFactory source = (PersistentFactory) getService(PersistentFactory.ROLE, sourceFactory);

          origSchema = source.getSchemaConfiguration(sourceSchema);
        }
        catch (ServiceException e1)
        {
          throw new ConfigurationException("Error getting top-level configuration from context", e1);
        }
View Full Code Here

  {
    try
    {
      Model self = (Model) req.getService(Model.ROLE, "aktera.preferences.manager");

      PersistentFactory persistentManager = (PersistentFactory) req.getService(PersistentFactory.ROLE, req
              .getDomain());

      Configuration[] configs = self.getConfiguration().getChildren("config");

      for (int i = 0; i < configs.length; ++i)
      {
        Configuration config = configs[i];

        Persistent configEntry = persistentManager.create("aktera.PreferencesConfig");

        configEntry.setField("userId", userId);
        configEntry.setField("category", config.getAttribute("category"));
        configEntry.setField("name", config.getAttribute("name"));
View Full Code Here

  {
    try
    {
      Model self = (Model) req.getService(Model.ROLE, "aktera.preferences.manager");

      PersistentFactory persistentManager = (PersistentFactory) req.getService(PersistentFactory.ROLE, req
              .getDomain());

      Configuration[] configs = self.getConfiguration().getChildren("config");

      for (int i = 0; i < configs.length; ++i)
      {
        Configuration config = configs[i];

        if (! config.getAttribute("category").equals(category) && ! config.getAttribute("name").equals(name))
        {
          continue;
        }

        Persistent configEntry = persistentManager.create("aktera.PreferencesConfig");

        configEntry.setField("userId", userId);
        configEntry.setField("category", config.getAttribute("category"));
        configEntry.setField("name", config.getAttribute("name"));
View Full Code Here

          log.debug("Unable to acces user environment from context!");
          throw new ModelException("Unable to acces user environment from context!");
        }
      }

      PersistentFactory persistentManager = (PersistentFactory) req.getService(PersistentFactory.ROLE, req
              .getDomain());

      Persistent keelUser = persistentManager.create("keel.user");

      keelUser.setField("uid", new Integer(uid));

      if (! keelUser.find())
      {
View Full Code Here

TOP

Related Classes of de.iritgo.aktera.persist.PersistentFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.