2014年9月27日 星期六

hibernate GETconstraintName/自動產生class


http://docs.jboss.org/tools/OLD/2.0.0.GA/hibernatetools/en/html_single/index.html
http://hibernate.org/tools/
http://tools.jboss.org/features/hibernate.html




e.getErrorCode() :1452
e.getConstraintName() :null
e.getMessage() :could not execute statement
e.getCause().getMessage(() :Cannot add or update a child row: a foreign key constraint fails (`ewallet`.`transaction`, CONSTRAINT `transaction_ibfk_2` FOREIGN KEY (`storeId`) REFERENCES `store` (`storeId`) ON DELETE CASCADE ON UPDATE CASCADE)



package com.transaction;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.hibernate.exception.ConstraintViolationException;

import com.HibernateUtil;
import com.Jdbcmysql;
import com.QueryTool;
import com.Tool;
import com.WebConfig;
import com.google.gson.Gson;
import com.hibernatebean.Store;
import com.hibernatebean.Transaction;
import com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException;
import com.object.ForgotPwObject;
import com.object.RegisterTransactionObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class RegisterTransaction extends ActionSupport {

    /**
     *
     */
    private static final long serialVersionUID = -3094866975438328785L;
    private HashMap<String, Object> registerTransactionReturnMes;

    public HashMap<String, Object> getRegisterTransactionReturnMes() {
        return registerTransactionReturnMes;
    }

    public void setRegisterTransactionReturnMes(HashMap<String, Object> registerTransactionReturnMes) {
        this.registerTransactionReturnMes = registerTransactionReturnMes;
    }

    int effectLines = 0;
    Jdbcmysql jdbcmysql;
    String preparedStatementSql;
    private HibernateUtil hibernateUtil;

    public String execute() {
        registerTransactionReturnMes = new HashMap<String, Object>();

        // test();

        ActionContext context = ActionContext.getContext();
        HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);

        /*
         * String encodeData = request.getParameter("encodeData"); Tool tool =
         * new Tool(); Gson gson = new Gson(); RegisterTransactionObject
         * registerTransactionObject = new RegisterTransactionObject();
         * registerTransactionObject =
         * gson.fromJson(tool.decryptionToString(encodeData),
         * RegisterTransactionObject.class);
         */

        String storeId = request.getParameter("storeId");
        String price = request.getParameter("price");

        // jdbcmysql = new Jdbcmysql("ewallet", WebConfig.DatabaseIp);

        try {
            hibernateUtil = new HibernateUtil();
            Transaction transaction = new Transaction();
            Store store = new Store();
            store.setStoreId(Integer.parseInt(storeId));
            transaction.setStore(store);
            transaction.setPrice(Integer.parseInt(price));
            hibernateUtil.sessionBeginTransaction();
            int transactionId = (Integer) hibernateUtil.getSession().save(transaction);
            hibernateUtil.commitTransactionAndClose();
            registerTransactionReturnMes.put("issus", "1");
            registerTransactionReturnMes.put("msg", "註冊交易成功");
            registerTransactionReturnMes.put("transactionId", transactionId);

           
        } catch (ConstraintViolationException e) {
            System.out.println("e.getErrorCode() :" + e.getErrorCode());
            System.out.println("e.getConstraintName() :" + e.getConstraintName());
            System.out.println("e.getMessage() :" + e.getMessage());
            System.out.println("e.getCause().getMessage(() :" + e.getCause().getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            hibernateUtil.close();

           
            return SUCCESS;

        }
        hibernateUtil.close();
        return SUCCESS;
    }

}

2014年9月24日 星期三

service mysqld restart 查看被占用的port


http://stackoverflow.com/questions/5310945/deployment-errorstarting-of-tomcat-failed-the-server-port-8080-is-already-in-u

查看被占用的port
netstat -tulpn | grep 'your_port_number'
kill -9 248 

service mysqld restart

[mysql安裝位置]
/var/lib/mysql
 
 
 
SHOW  PROCESSLIST 
 
 
 

2014年9月23日 星期二

zbar in android studio


 https://github.com/dm77/ZBarScanner/tree/master/ZBarScannerLibrary
https://github.com/ZBar/ZBar/tree/master/android
https://groups.google.com/forum/#!msg/adt-dev/nQobKd2Gl_8/ctDp9viWaxoJ
http://stackoverflow.com/questions/17340240/jni-folder-in-android-studio/22488155#22488155
http://stackoverflow.com/questions/16952388/android-studio-zbar

Did anyone of you noticed that this process include the .so files twice into the final apk? I recently switched to Android Studio and started using Gradle to build my Android project and I've got a weird behavior. Basically, I have a lib in app/src/main/jniLibs, divided in two folders: armeabi and armeabi-7va. The problem is that since I use Gradle, the APK file is twice more heavier. The reason is that Gradle copy the *.so files twice in the APK at two different locations: - lib/ - main/jniLibs/ When I used to build using Eclipse, everything was fine, *.so files were copied only one time. Does anyone know if there is a way to avoid this behavior? Is this a bug in Gradle or am I doing something wrong?

2014年9月22日 星期一

otto+androidannotations

package com.ewallet.citygo.fragment.home;

import android.os.Bundle;

import android.support.v4.app.Fragment;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.Button;

import android.widget.EditText;



import com.ewallet.citygo.R;

import com.ewallet.citygo.otto.OttoBus;

import com.ewallet.citygo.otto.UpdateTitleEvent;

import com.ewallet.citygo.utils.Utils;

import com.squareup.otto.Subscribe;



import org.androidannotations.annotations.Bean;

import org.androidannotations.annotations.Click;

import org.androidannotations.annotations.EFragment;

import org.androidannotations.annotations.ViewById;



@EFragment(R.layout.forgotpw)

public class ForgotPw extends Fragment {





    @ViewById

    EditText etCode;

    @ViewById

    EditText  etpw1;

    @ViewById

    EditText  etpw2;

    @ViewById

    Button butCancle;

    @ViewById

    Button butSure;



    @Bean

    OttoBus bus;







    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        //v = inflater.inflate(R.layout.forgotpw, container, false);

        bus.post(new UpdateTitleEvent("Clicks"));

       // Utils.alert(getActivity(), "post");

        return null;

    }



    @Click  // When R.id.butSure button is clicked

    void butSure() {

        try{

            if(etpw1.getText().length()>1){



            }

            //Utils.alert(getActivity(), "按了按鈕");

           // etpw1.setText("ffe");

        }catch (Exception e){

            e.printStackTrace();

            Utils.alert(getActivity(), "請不要留空!");

        }





    }

    @Click

    void butCancle() {

        onUpdateTitle(new UpdateTitleEvent("title"));

    }



    @Subscribe

    public void onUpdateTitle(UpdateTitleEvent event) {

        etCode.setText(event.title);

        Utils.alert(getActivity(), "Subscribe!"+event.title);

    }



}



</pre>

2014年9月18日 星期四

FIDDLER

Host: 106.187.38.21:8080
Content-Length: 12
Content-Type: application/x-www-form-urlencoded

2014年9月16日 星期二

Google Analytics_TrackedFragment

https://developers.google.com/analytics/devguides/collection/android/v4/events
 把要用的extends TrackedFragment
package com.ewallet.sdk;

使用方法:trackedFragmentSetupEvent(v,"button5");

要顯示的 code
import com.ewallet.citygo.CGApplication;

import com.google.analytics.tracking.android.EasyTracker;

import com.google.analytics.tracking.android.Fields;

import com.google.analytics.tracking.android.MapBuilder;

import com.google.android.gms.analytics.HitBuilders;

import com.google.android.gms.analytics.HitBuilders.EventBuilder;

import com.google.android.gms.analytics.Tracker;



import android.os.Bundle;

import android.support.v4.app.Fragment;

import android.view.View;

import android.widget.Button;



public class TrackedFragment extends Fragment {

    private Tracker tracker;

    private String activityId;

    private String fragmentId;



    @Override

    public void onCreate(final Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);



        this.tracker = CGApplication.getInstance().getTracker(CGApplication.TrackerName.APP_TRACKER);

        this.fragmentId = getClass().getSimpleName();

        this.activityId = getActivity().getClass().getSimpleName();

    }



    



    @Override

    public void onResume() {

        super.onResume();



        //this.tracker.set(Fields.SCREEN_NAME, getClass().getSimpleName());

        this.tracker.send( MapBuilder.createAppView().set("page:", activityId+":"+fragmentId).build() );

    }

    



    public void trackedFragmentSetupEvent(View v, String labelId) {

        EventBuilder h=new HitBuilders.EventBuilder();

        h.setCategory(activityId);

        h.setAction(fragmentId);

        h.setLabel(labelId);

        this.tracker.send(h.build());



    }

}

2014年9月15日 星期一

volley只允許一次 並且不重試


        postRequest.setRetryPolicy(new DefaultRetryPolicy(20 * 1000, 1, 1.0f));//只允許一次 並且不重試

analytics-api

http://java.dzone.com/articles/working-google-analytics-api

2014年9月11日 星期四

避免不小心離開APPonBackPressed() {

@Override
    public void onBackPressed() {
        //避免不小心離開APP
        if(Utils.getMemberId()>0){
           
            if(getSupportFragmentManager().getBackStackEntryCount()<1){
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
                alertBuilder.setIcon(R.drawable.mobile);
                alertBuilder.setTitle("訊息:");
                alertBuilder.setMessage("你要離開嗎?");
                // final EditText et1 = new EditText(MainPageActivity.this);
                // et1.setInputType(InputType.TYPE_CLASS_NUMBER);
                // alertBuilder.setView(et1);
                alertBuilder.setPositiveButton("確認", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        finish();
                    }
                });

                alertBuilder.setNegativeButton("取消", null);
                alertBuilder.show();
            }else{
                super.onBackPressed();
            }
        }else{
            AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
            alertBuilder.setIcon(R.drawable.mobile);
            alertBuilder.setTitle("訊息:");
            alertBuilder.setMessage("你要離開嗎?");
            // final EditText et1 = new EditText(MainPageActivity.this);
            // et1.setInputType(InputType.TYPE_CLASS_NUMBER);
            // alertBuilder.setView(et1);
            alertBuilder.setPositiveButton("確認", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    finish();
                }
            });

            alertBuilder.setNegativeButton("取消", null);
            alertBuilder.show();
        }
       
        // getSupportFragmentManager().popBackStack();
    }


2014年9月10日 星期三

To DROP a UNIQUE Constraint

http://www.w3schools.com/sql/sql_unique.asp

2014年9月4日 星期四

readPhone

package com.ewallet.citygo.tool;

import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.util.Log;

public class HomeTool {
    private static HomeTool homeTool = null;
    public static HomeTool getInstance(){  //新增一個public method getInstance()判斷有沒有new過
         if(homeTool == null){
             homeTool = new HomeTool();
           
         }
         return homeTool;
       
    }
   
    public void readPhone(Context context){
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

        //取得 IMEI 碼↓
        String IMEI = telephonyManager.getDeviceId();
        Log.d("IMEI:",IMEI);

        //取得 IMSI 碼↓
        String IMSI=telephonyManager.getSubscriberId();
        Log.d("IMSI:",IMSI);
        //取的 SIM 卡序號↓
        String SIM=telephonyManager.getSimSerialNumber();
        Log.d("SIM:",SIM);
        //取得 PhoneType↓ (NONE、GSM、CDMA、SIP)
        int PhoneType=telephonyManager.getPhoneType();
        Log.d("PhoneType:",""+PhoneType);
        //取得目前網路類型↓ (UNKNOWN、GPRS、EDGE、HSDPA、CDMA、......)
        int UNKNOWN =telephonyManager.getNetworkType();
        Log.d("UNKNOWN:",""+UNKNOWN);
        //取得國家代碼↓ (TW)
        String TW=telephonyManager.getNetworkCountryIso();
        Log.d("TW:",""+TW);

        //取得電信商名稱↓ (中華電信)
        String Operator =telephonyManager.getNetworkOperatorName();
        Log.d("Operator",""+Operator);
        // 主機版名稱
        String board = Build.BOARD;
       
        // 品牌名稱
        String brand = Build.BRAND;
       
        // CPU + ABI
        String cpu = Build.CPU_ABI;
       
        // 設備名稱
        String device = Build.DEVICE;
       
        // 版本號碼
        String display = Build.DISPLAY;
       
        // 設備識別碼
        String fingerprint = Build.FINGERPRINT;
       
        // HOST
        String host = Build.HOST;
       
        // 版本號碼
        String id = Build.ID;
       
        // 製造商
        String manufacturer = Build.MANUFACTURER;
       
        // 模組號碼
        String model = Build.MODEL;
       
        // 產品名稱
        String product = Build.PRODUCT;
       
        // 設備描述
        String tags = Build.TAGS;
       
        // 設備類別; user or eng
        String type = Build.TYPE;
       
        // USER
        String user = Build.USER;
    }
   
}

2014年9月1日 星期一

redirectAction

 http://honda418.iteye.com/blog/460724

<action name="updateTransaction" class="com.Transaction.UpdateTransaction">
             <result name="success" type="redirectAction" >
             <param name="actionName">auth</param>
              <param name="transactionIdpass">${transactionIdpass}</param>
              </result>
        </action>
      
       <action name="auth"  class="com.Transaction.Auth">
            <result type="json">
                <param name="noCache">true</param>
                <param name="excludeNullProperties">true</param>
                <param name="root">authRetMsg</param>
            </result>
      </action>