Package play.exceptions

Examples of play.exceptions.UnexpectedException


                      .get();
                  if(res!=null){
                    // sets the object to the owner field into the relation entity
                   
                    if(ownerField == null) {
                      throw new UnexpectedException("In related Model "+relClass.getName()+" owner field '"+owner+"' not found");
                    }
                    siena.Util.setField(res, ownerField, o);
                    res.save();
                  }
                   
                  else Validation.addError(name+"."+field.getName(), "validation.notFound", _id);
                }
               
              }
              // now remaining objects have to be unowned
              for(Object relObj:relObjs){
                siena.Util.setField(relObj, ownerField, null);
                SienaPlugin.pm().save(relObj);
              }

              // can't set arraylist to Query<T>
              // bw.set(field.getName(), o, l);
            }
          }
          // builds simple entity for simple association
          else {
            @SuppressWarnings("unchecked")
            Class<? extends siena.Model> relClass = (Class<? extends siena.Model>)Play.classloader.loadClass(relation);
            String idName = keyName(relClass);
            String[] ids = params.get(name + "." + field.getName() + "@"+idName);
            if(ids == null) {
              ids = params.get(name + "." + field.getName() + "."+idName);
            }
            if (ids != null && ids.length > 0 && !ids[0].equals("")) {
              params.remove(name + "." + field.getName() + "."+idName);
              params.remove(name + "." + field.getName() + "@"+idName);

              siena.Model res =
                siena.Model.all(relClass)
                  .filter(idName, Binder.directBind(ids[0], keyType(relClass)))
                  .get();
              if(res!=null)
                bw.set(field.getName(), o, res);
              else Validation.addError(name+"."+field.getName(), "validation.notFound", ids[0]);

            } else if(ids != null && ids.length > 0 && ids[0].equals("")) {
              bw.set(field.getName(), o , null);
              params.remove(name + "." + field.getName() + "."+idName);
              params.remove(name + "." + field.getName() + "@"+idName);
            }
          }                   
        }
        else if(isJson){
          String[] jsonStr = params.get(name + "." + field.getName());
          if (jsonStr != null && jsonStr.length > 0 && !jsonStr[0].equals("")) {
            try {
              //com.google.gson.JsonParser parser = new com.google.gson.JsonParser();
              //parser.parse(jsonStr[0]);
             
              Json json = Json.loads(jsonStr[0]);
              if(json!=null){
                bw.set(field.getName(), o, json);
                params.remove(name + "." + field.getName());
              }
              else Validation.addError(name+"."+field.getName(), "validation.notParsable");
            }catch(JsonParseException ex){
              ex.printStackTrace();
              Logger.error("json parserdelete exception:%s",
                  ex.getCause()!=null?ex.getCause().getMessage(): ex.getMessage());
              Validation.addError(
                  name+"."+field.getName(),
                  "validation.notParsable",
                  ex.getCause()!=null?ex.getCause().getMessage(): ex.getMessage());
            }catch(SienaException ex){
              ex.printStackTrace();
              Logger.error("json parserdelete exception:%s",
                  ex.getCause()!=null?ex.getCause().getMessage(): ex.getMessage());
              Validation.addError(
                  name+"."+field.getName(),
                  "validation.notParsable",
                  ex.getCause()!=null?ex.getCause().getMessage(): ex.getMessage());
            }
            catch(IllegalArgumentException ex){
              ex.printStackTrace();
              Logger.error("json parser exception:%s",
                  ex.getCause()!=null?ex.getCause().getMessage(): ex.getMessage());
              Validation.addError(
                  name+"."+field.getName(),
                  "validation.notParsable",
                  ex.getCause()!=null?ex.getCause().getMessage(): ex.getMessage());
            }
          }
        } 
      }
      // Then bind
      // all composites objects (simple entity, list and maps) are managed
      // by this function
      // v1.0.x code
      // bw.bind(name, o.getClass(), params, "", o);

            RootParamNode paramNode = RootParamNode.convert(params);
            // no http params to bind this object ? so we won't try to bind this object
            if(paramNode.getChild(name) == null) {
                return null;
            }
      // v1.1 compliant

            bw.bind(name, (Type)o.getClass(), params, "", o, o.getClass().getAnnotations());
     
      return (T) o;
    } catch (Exception e) {
      throw new UnexpectedException(e);
    }
  }
View Full Code Here


      if(db != null && db.toLowerCase().equals("sdb")){
        return "nosql:sdb";
      }
     
        if((db==null || db=="" ) && (dbUrl == null || dbUrl == "")){
          throw new UnexpectedException("SienaPlugin : not using GAE requires at least a db=xxx config");
        }
        if((db!=null && db.contains("postgresql"))
            || (dbUrl!=null && dbUrl.contains("postgresql"))){
          return "sql:postgresql";
        }
View Full Code Here

      Logger.info("Siena DB Type: %s", dbType);
      final String db = Play.configuration.getProperty("db");
            final String dbUrl = Play.configuration.getProperty("db.url");
            if((db==null || db=="" ) && (dbUrl == null || dbUrl == "")){
              throw new UnexpectedException("SienaPlugin : not using GAE requires at least a db config");
            }
            if(dbType.contains("postgresql")){
              persistenceManager = new PostgresqlPersistenceManager(new PlayConnectionManager(), null);
              ddlType = "postgresql";
              generator = new DdlGenerator("postgresql");
            }else if(dbType.contains("h2")){
              // the H2 dbMode in Play is "mysql"
              persistenceManager = new H2PersistenceManager(new PlayConnectionManager(), null, "mysql");
              // the DDL type is mysql because in play the DB is H2 in Mysql mode.
              // But the DDLGenerator is wired to h2
              // because longvarchar and CLOB is not managed the same way in H2/MYSQL and real MYSQL
              ddlType = "mysql";
              generator = new DdlGenerator("h2");
            }
            else if(dbType.contains("google")){
              persistenceManager = new GoogleSqlPersistenceManager(new PlayConnectionManager(), null);
              generator = new DdlGenerator("mysql");
            }
            else {
              persistenceManager = new JdbcPersistenceManager(new PlayConnectionManager(), null);
              generator = new DdlGenerator("mysql");
            }
      Logger.debug("Siena DDL Type: %s", ddlType);
     
      // Alter tables before installing
            for(Class<?> c : classes) {
              // adds classes to the DDL generator
              generator.addTable(c);
            }
            // get the Database model
      Database database = generator.getDatabase();
 
      Platform platform = PlatformFactory.createNewPlatformInstance(ddlType);
      platform.setDataSource(DB.datasource);
      // siena.ddl can have create/update/ddl
      // if siena.ddl is defined, uses it
      // if not:
      // in dev mode, will be update by default
      // in prod mode, will be none by default
      String ddl = "none";
      if(Play.mode.isDev()){
        ddl = Play.configuration.getProperty("siena.ddl", "update");
        Logger.debug("Siena DDL dev mode: %s", ddl);
      }else if(Play.mode.isProd()){
        ddl = Play.configuration.getProperty("siena.ddl", "none");
        Logger.debug("Siena DDL prod mode: %s", ddl);       
      }

      if("create".equals(ddl)){
          if(Logger.isDebugEnabled()) {
              Logger.debug("Siena DDL Generator SQL: %s", platform.getCreateModelSql(database, false, false));
          }
        // creates tables and do not drop tables and do not continues on error
        try {
          platform.createModel(connection, database, false, false);
        }catch(DatabaseOperationException ex){
          Logger.warn("Siena DDL createTables generated exception:%s", ex.getCause()!=null?ex.getCause():ex.getMessage());
        }
      }else if("update".equals(ddl)){
        Database currentDatabase = platform.readModelFromDatabase(connection, ddlType);
       
        if(!disableJPA){
          // Remove from the current schema those tables that are not known by Siena,
            // since they're likely to be JPA classes.
            // Iterate in reverse order since removeTable() changes the list size.
            for (int i = currentDatabase.getTableCount() - 1; i >= 0; i--) {
                Table table = currentDatabase.getTable(i);
                if(database.findTable(table.getName(), false) == null){
                    Logger.debug("Keeping existing table %s", table.getName());
                    currentDatabase.removeTable(i);
                }
            }
        }
       
        if(Logger.isDebugEnabled()){
            Logger.debug("Siena DDL Generator SQL: %s", platform.getAlterModelSql(currentDatabase, database));
        }

                // alters tables and continues on error
        platform.alterModel(currentDatabase, database, true);
      }
     
      // activate lifecycle or not
      if(useLifecycle()){
        Logger.debug("Siena activating lifecycle management");
        persistenceManager = new PersistenceManagerLifeCycleWrapper(persistenceManager);
      }

      // is it required ?
      // connection.close();
      // for googlesql, forces Google driver
      //if(dbType.contains("google")){
      //  Properties p = new Properties();
      //  p.setProperty("driver", "com.google.appengine.api.rdbms.AppEngineDriver");
      //  p.setProperty("url", Play.configuration.getProperty("db.url"));
      //  p.setProperty("user", Play.configuration.getProperty("db.user"));
      //  p.setProperty("password", Play.configuration.getProperty("db.pass"));

      //  persistenceManager.init(p);
      //}else {
        persistenceManager.init(null);
      //}

            if(!disableJPA){
                JPAPlugin.closeTx(false);
            }
                         
        } else if(dbType.equals("nosql:gae")) {
      Logger.debug("Siena DB Type: GAE");
            persistenceManager = new GaePersistenceManager();
     
            // activate lifecycle or not
      if(useLifecycle()){
        Logger.debug("Siena activating lifecycle management");
        persistenceManager = new PersistenceManagerLifeCycleWrapper(persistenceManager);
      }

      persistenceManager.init(null);
        }
        else if(dbType.equals("nosql:sdb")) {
      Logger.debug("Siena DB Type: SDB");
            persistenceManager = new SdbPersistenceManager();

            String awsAccessKeyId = Play.configuration.getProperty("siena.aws.accesskeyid");           
            String awsSecretAccessKey = Play.configuration.getProperty("siena.aws.secretaccesskey");
            String prefix = Play.configuration.getProperty("siena.aws.prefix", "siena_devel_");
            String consistentread = Play.configuration.getProperty("siena.aws.consistentread", "true");

            if(awsAccessKeyId == null || awsSecretAccessKey == null){
              throw new UnexpectedException("siena.aws.accesskeyid & siena.aws.secretaccesskey required in conf");
            }
           
            Properties p = new Properties();
            p.setProperty("implementation", "siena.sdb.SdbPersistenceManager");
            p.setProperty("awsAccessKeyId", awsAccessKeyId);
View Full Code Here

                        if(o == null) {
                            return SienaModelUtils.create(clazz, name, params, annotations);
                        }
                      return SienaModelUtils.edit(o, name, params, annotations);
                  } catch (Exception e) {
                      throw new UnexpectedException(e);
                  }
          }
            }
            return SienaModelUtils.create(clazz, name, params, annotations);
        }
View Full Code Here

     */
    public static void deleteDirectory(String path) {
        try {
            FileUtils.deleteDirectory(Play.getFile(path));
        } catch (IOException ex) {
            throw new UnexpectedException(ex);
        }
    }
View Full Code Here

            case JS:
                return jsSession();
            case CSS:
                return cssSession();
        }
        throw new UnexpectedException("unknown resource type: " + rt.name());
    }
View Full Code Here

    //private static YUICompressor cssC_ = new YUICompressor(ResourceType.CSS);
    @Override
    public boolean serveStatic(VirtualFile file, Request request, Response response) {
        if (null == jsM_) {
            if (Play.mode == Mode.DEV) Play.start();
            else throw new UnexpectedException("Minimizer not initialized");
        }
        String fn = file.getName();
        if (fn.endsWith(".coffee") || (fn.endsWith(".js") && jsM_.isMinimizeEnabled() && !file.relativePath().startsWith(cacheUrlPath_()))) {
            return processStatic_(file, request, response, ResourceType.JS);
        }
View Full Code Here

                            //info_("loading duplicate property for %s: %s", k, v);
                            p.setProperty(k, v);
                        }
                    }
                } catch (Exception e) {
                    throw new UnexpectedException("error loading conf/greenscript.conf");
                }
            }
        }
        this.configFiles_ = this.currentConfigFiles();
        //info_("greenscript.conf loaded: %s", p);
View Full Code Here

      if (e instanceof JapidRuntimeException) {
        throw (JapidRuntimeException) e;
      }
     
     
      throw new UnexpectedException(e);
    }
  }
View Full Code Here

  @Override
  public void onApplicationStop() {
    try {

    } catch (Exception e) {
      throw new UnexpectedException(e);
    }
  }
View Full Code Here

TOP

Related Classes of play.exceptions.UnexpectedException

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.