Package com.scooterframework.orm.activerecord

Examples of com.scooterframework.orm.activerecord.ActiveRecord


    /**
     * <tt>edit</tt> method prepares data for editing an existing <tt>owner</tt> record.
     */
    public String edit() {
      ActiveRecord owner = Owner.where("id=" + p("id")).getRecord();
        if (owner == null) {
            flash("notice", "There is no owner record with primary key as " + p("id"));
        }
        else {
            setViewData("owner", owner);
View Full Code Here


    /**
     * <tt>update</tt> method updates an existing <tt>owner</tt> record.
     */
    public String update() {
        ActiveRecord owner = null;
        try {
            owner = Owner.where("id=" + p("id")).getRecord();
            if (owner != null) {
                owner.setData(params());
                owner.update();
                flash("notice", "Owner was successfully updated.");

                return redirectTo(R.resourceRecordPath("owners", owner));
            }
            else {
View Full Code Here

    /**
     * user_tweets method
     */
    public String user_tweets() {
      String username = p("username");
      ActiveRecord user = Account.findFirst("username='" + username + "'");
        if (user != null) {
            setViewData("user_tweets", Tweet.findAll("account_id=" + user.getField("id")));
            setViewData("username", username);
            setViewData("user", user);
        }
        return null;
    }
View Full Code Here

    /**
     * <tt>create</tt> method creates a new <tt>account</tt> record.
     */
    public String create() {
        ActiveRecord newTweet = null;
        try {
            newTweet = Tweet.newRecord();
            newTweet.setData(params());

            //add login user'd account_id
            ActiveRecord loginUser = LoginHelper.loginUser();
          newTweet.setData("account_id", loginUser.getField("id"));

            newTweet.save();
            flash("notice", "Tweet was successfully created.");

            return redirectTo("/" + loginUser.getField("username"));
        }
        catch(Exception ex) {
            log.error("Error in create() caused by " + ex.getMessage());
            flash("error", "There was a problem creating the tweet record.");
        }
View Full Code Here

    noPrefix = isEmpty(classPrefix);
    noSuffix = isEmpty(classSuffix);
    packageName = classPrefix;
    controllerClassName = (noSuffix)?controllerNameCamel:(controllerNameCamel + classSuffix);
   
    ActiveRecord recordHome = generateActiveRecordHomeInstance(connectionName, model, table);
    if (recordHome.hasPrimaryKey()) {
      hasPrimaryKey = true;
    }
   
    if (!noPrefix) {
      packageLine = "package " + packageName + ";" + linebreak;
View Full Code Here

     */
    public static ActiveRecord associatedRecordOf(String key, String associatedModel, boolean refresh) {
        Object o = getObjectForKey(key);
        if (o == null) return null;
       
        ActiveRecord record = null;
        if (o instanceof ActiveRecord) {
            record = associatedRecordOf((ActiveRecord)o, associatedModel, refresh);
        }
        else {
            throw new IllegalArgumentException("Object represented by " + key +
View Full Code Here

     * @param connName   db connection name
     * @param model      model name of the ActiveRecord class
     * @return an ActiveRecord home instance of the model model
     */
    protected ActiveRecord generateActiveRecordHomeInstance(String connName, String model, String table) {
        ActiveRecord record = (ActiveRecord)modelHomes.get(model);
        if (record == null) {
          record = ActiveRecordUtil.generateActiveRecordInstance(ActiveRecordUtil.DEFAULT_RECORD_CLASS, connName, model, table);
          if (record != null) record.freeze();
          ActiveRecordUtil.setHomeInstance(record);
          modelHomes.put(model, record);
        }
        return record;
    }
View Full Code Here

       
        StringTokenizer st = new StringTokenizer(property, " .");
        int total = st.countTokens();
        Object tmp = null;
        int count = 0;
        ActiveRecord r = record;
        while(st.hasMoreTokens()) {
            String token = st.nextToken();
            count = count + 1;
            if (count == total) {
                tmp = r.getField(token);//The last token is a field name.
                break;
            }
            else {
                r = r.associated(token).getRecord();
            }
        }
       
        return tmp;
    }
View Full Code Here

        for (int i = 1; i < totalAssociations; i++) {
            String associationId = associations.get(i);
            List<ActiveRecord> tmp = new ArrayList<ActiveRecord>();
            int totalRecords = records.size();
            for (int j = 0; j < totalRecords; j++) {
              ActiveRecord r = records.get(j);
              if (r == null) continue;
                List<ActiveRecord> rds = r.allAssociated(associationId, refresh).getRecords();
                if (rds != null && rds.size() > 0) tmp.addAll(rds);
            }
            records = tmp;
        }
       
View Full Code Here

        if (associationName.indexOf('.') == -1) return record.associated(associationName, refresh).getRecord();
       
        StringTokenizer st = new StringTokenizer(associationName, ".");
        int total = st.countTokens();
        int count = 0;
        ActiveRecord r = record;
        while(st.hasMoreTokens()) {
            String token = st.nextToken();
            r = r.associated(token, refresh).getRecord();
           
            count = count + 1;
            if (count == total) {
                break;
            }
View Full Code Here

TOP

Related Classes of com.scooterframework.orm.activerecord.ActiveRecord

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.