コード例 #1
0
  public int registerAddressOfUser(MySqlHelper helper, User user, int userId) {
    String query =
        "insert into address(UserId,AddressLine1, AddressLine2, City, State, ZipCode, Lattitude,Longitude) values(?, ?, ?, ?, ?, ?, ?, ?)";
    try {
      java.sql.PreparedStatement addressPreparedStatement =
          helper.conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);

      addressPreparedStatement.setInt(1, userId);
      addressPreparedStatement.setString(2, user.getAddress().getAddressLine1());
      addressPreparedStatement.setString(3, user.getAddress().getAddressLine2());
      addressPreparedStatement.setString(4, user.getAddress().getCity());
      addressPreparedStatement.setString(5, user.getAddress().getState());
      addressPreparedStatement.setString(6, user.getAddress().getZipCode());
      addressPreparedStatement.setString(7, user.getAddress().getLattitude());
      addressPreparedStatement.setString(8, user.getAddress().getLongitude());

      addressPreparedStatement.executeUpdate();
      ResultSet rs = addressPreparedStatement.getGeneratedKeys();
      if (rs.next()) {
        int last_inserted_id = rs.getInt(1);
        return last_inserted_id;
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return -1;
  }
コード例 #2
0
ファイル: UserDaoTest.java プロジェクト: kapabh/test1
  public void testUpdateUser() throws Exception {
    User user = dao.get(1L);

    Address address = user.getAddress();
    address.setAddress1("new address");
    user.setTimeZone("US/Central");

    dao.saveUser(user);

    user = dao.get(1L);
    assertEquals(address, user.getAddress());
    assertEquals("new address", user.getAddress().getAddress1());
    assertEquals("US/Central", user.getTimeZone());

    // verify that violation occurs when adding new user with same username
    user.setId(null);

    endTransaction();

    try {
      dao.saveUser(user);
      // flush();
      fail("saveUser didn't throw DataIntegrityViolationException");
    } catch (DataIntegrityViolationException e) {
      assertNotNull(e);
      log.debug("expected exception: " + e.getMessage());
    }
  }
コード例 #3
0
ファイル: Users.java プロジェクト: revenone73/openlab-java-01
  public ArrayList findByConditon(User u) {
    if (u.getId() != 0) {}

    if (u.getAddress() != null) {}

    return null;
  }
コード例 #4
0
 public boolean addDate(User user) {
   ContentValues values = new ContentValues();
   values.put(User.NAME, user.getName());
   values.put(User.MOBILE, user.getMobile());
   values.put(User.DANWEI, user.getDanwei());
   values.put(User.QQ, user.getQq());
   values.put(User.ADDRESS, user.getAddress());
   return db.save(TABLENAME, values);
 }
コード例 #5
0
 public boolean updateUser(User user) {
   ContentValues values = new ContentValues();
   values.put(User.NAME, user.getName());
   values.put(User.ADDRESS, user.getAddress());
   values.put(User.QQ, user.getQq());
   values.put(User.DANWEI, user.getDanwei());
   values.put(User.MOBILE, user.getMobile());
   return db.update(TABLENAME, values, "id_db=?", new String[] {user.getId_DB() + ""});
 }
コード例 #6
0
ファイル: UserTest.java プロジェクト: liangzhuo/Pursue
 @Test
 public void testListUser() {
   IUserOperation userOperation = session.getMapper(IUserOperation.class);
   List<User> users = userOperation.selectUsers("%");
   for (User user : users) {
     System.out.println(user.getUsername());
     System.out.println(user.getAddress());
   }
 }
コード例 #7
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   nameET = (EditText) findViewById(R.id.name);
   danweiET = (EditText) findViewById(R.id.danwei);
   mobileET = (EditText) findViewById(R.id.mobile);
   qqET = (EditText) findViewById(R.id.qq);
   addressET = (EditText) findViewById(R.id.address);
   Bundle localBundle = getIntent().getExtras();
   int id = localBundle.getInt("user_ID");
   ContactsTable ct = new ContactsTable(this);
   user = ct.getUserByID(id);
   nameET.setText(user.getName());
   danweiET.setText(user.getDanwei());
   mobileET.setText(user.getMobile());
   qqET.setText(user.getQq());
   addressET.setText(user.getAddress());
 }
コード例 #8
0
ファイル: Users.java プロジェクト: remibantos/jeeshop
  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  @PermitAll
  public User create(@NotNull User user) {

    if (user.getId() != null) {
      throw new WebApplicationException(Response.Status.BAD_REQUEST);
    }
    User userByLogin = userFinder.findByLogin(user.getLogin());

    if (userByLogin != null) {
      throw new WebApplicationException(Response.Status.CONFLICT);
    }

    final Address userAddress = user.getAddress();

    if (userAddress != null) {
      if (userAddress.getId() != null) {
        throw new WebApplicationException(Response.Status.BAD_REQUEST);
      }

      if (!countryChecker.isAvailable(userAddress.getCountryIso3Code())) {
        LOG.error("Country {} is not available", userAddress.getCountryIso3Code());
        throw new WebApplicationException(Response.Status.BAD_REQUEST);
      }
    }

    entityManager.persist(user);
    Role userRole = roleFinder.findByName(RoleName.user);
    user.setRoles(Sets.newHashSet(userRole));

    user.setPassword(hashSha256Base64(user.getPassword()));

    if (!sessionContext.isCallerInRole(ADMIN)) {
      user.setActivated(false);
      generateActionTokenAndSendMail(user, Mails.userRegistration);
    }

    return user;
  }
コード例 #9
0
  // Test: Get User of id 1
  // Test: Check if user 1 details are as expected.
  private void testGetUser1Details() {

    User user =
        client
            .target(REST_SERVICE_URL)
            .path("/{userid}")
            .resolveTemplate("userid", 1)
            .request(MediaType.APPLICATION_XML)
            .get(User.class);

    String result = FAIL;

    // Verify user data
    if (user.getName().equals("Mahesh")
        && user.getContactNumber().equals("+9198855117733")
        && user.getAddress().equals("Christchurch")) {
      result = PASS;
    }
    System.out.println(
        "Test case name: testGetUser and verify User Data is as expected, Result: " + result);
  }
コード例 #10
0
  @Test
  public void testLoadSingleObjectWithNoTypeAndOneContainment() throws JsonProcessingException {
    JsonNode data =
        mapper
            .createObjectNode()
            .put("userId", "1")
            .put("name", "Paul")
            .set("address", mapper.createObjectNode().put("addId", "a1").put("city", "Prague"));

    User result =
        mapper
            .reader()
            .withAttribute(RESOURCE_SET, resourceSet)
            .withAttribute(ROOT_ELEMENT, ModelPackage.Literals.USER)
            .treeToValue(data, User.class);

    assertNotNull(result);

    assertEquals("1", result.getUserId());
    assertEquals("Paul", result.getName());
    assertEquals("MALE", result.getSex().getLiteral());

    assertNotNull(result.getAddress());
  }
コード例 #11
0
ファイル: Users.java プロジェクト: revenone73/openlab-java-01
 public void updateUsrById(User u) {
   int id = u.getId();
   User u2 = findById(id);
   u2.setAddress(u.getAddress());
   u2.setCode(u.getCode());
 }