archiva-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Olivier Lamy <ol...@apache.org>
Subject Re: [2/3] archiva-redback-core git commit: Setting database schema names from JDO
Date Sat, 01 Oct 2016 00:31:01 GMT
On 1 October 2016 at 06:38, <martin_s@apache.org> wrote:

> Setting database schema names from JDO
>
>
> Project: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/repo
> Commit: http://git-wip-us.apache.org/repos/asf/archiva-redback-
> core/commit/f3bcedfd
> Tree: http://git-wip-us.apache.org/repos/asf/archiva-redback-
> core/tree/f3bcedfd
> Diff: http://git-wip-us.apache.org/repos/asf/archiva-redback-
> core/diff/f3bcedfd
>
> Branch: refs/heads/jpa
> Commit: f3bcedfdf824fc3d90dc35b51b7a863ebd421f49
> Parents: 9e09e8f
> Author: Martin Stockhammer <martin_s@apache.org>
> Authored: Fri Sep 30 22:37:22 2016 +0200
> Committer: Martin Stockhammer <martin_s@apache.org>
> Committed: Fri Sep 30 22:37:22 2016 +0200
>
> ----------------------------------------------------------------------
>  .../redback/users/jpa/JpaUserManager.java       | 35 +++++++++++++++++---
>  .../redback/users/jpa/model/JpaUser.java        | 23 ++++++++++++-
>  .../src/main/resources/spring-context.xml       | 31 +++++++++++++++++
>  .../redback/users/jpa/JpaUserManagerTest.java   |  1 -
>  4 files changed, 84 insertions(+), 6 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/archiva-redback-
> core/blob/f3bcedfd/redback-users/redback-users-providers/
> redback-users-jpa/src/main/java/org/apache/archiva/redback/users/jpa/
> JpaUserManager.java
> ----------------------------------------------------------------------
> diff --git a/redback-users/redback-users-providers/redback-users-jpa/
> src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java
> b/redback-users/redback-users-providers/redback-users-jpa/
> src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java
> index c4c83f6..448552d 100644
> --- a/redback-users/redback-users-providers/redback-users-jpa/
> src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java
> +++ b/redback-users/redback-users-providers/redback-users-jpa/
> src/main/java/org/apache/archiva/redback/users/jpa/JpaUserManager.java
> @@ -75,7 +75,6 @@ public class JpaUserManager extends AbstractUserManager {
>
>      @Override
>      public User createUser(String username, String fullName, String
> emailAddress) throws UserManagerException {
> -
>          JpaUser user = new JpaUser();
>          user.setUsername(username);
>          user.setFullName(fullName);
> @@ -270,6 +269,27 @@ public class JpaUserManager extends
> AbstractUserManager {
>
>      @Override
>      public void addUserUnchecked(User user) throws UserManagerException {
> +        log.info("addUserUnchecked "+user.getUsername());
> +        if ( !( user instanceof JpaUser ) )
> +        {
> +            throw new UserManagerException( "Unable to Add User. User
> object " + user.getClass().getName() +
> +                    " is not an instance of " + JpaUser.class.getName() );
> +        }
> +
> +        if ( org.codehaus.plexus.util.StringUtils.isEmpty(
> user.getUsername() ) )
>

Do not hesitate to use StringUtils from commons-lang! (this one is pure
legacy :-) )


> +        {
> +            throw new IllegalStateException(
> +                    Messages.getString( "user.manager.cannot.add.user.without.username"
> ) ); //$NON-NLS-1$
> +        }
> +
> +        em.getTransaction().begin();
> +        TypedQuery<JpaUser> q = em.createQuery("SELECT u FROM JpaUser u",
> JpaUser.class);
> +        for (JpaUser u : q.getResultList()) {
> +            log.info("USER FOUND: "+u.getUsername());
> +        }
> +        log.info("NEW USER "+user.getUsername());
> +        em.persist((JpaUser)user);
> +        em.getTransaction().commit();
>
>      }
>
> @@ -277,9 +297,16 @@ public class JpaUserManager extends
> AbstractUserManager {
>      public void eraseDatabase() {
>          EntityManager em = getEm();
>          em.getTransaction().begin();
> -        Query q = em.createQuery("DELETE FROM JpaUser u");
> -        q.executeUpdate();
> +        TypedQuery<JpaUser> q = em.createQuery("SELECT u FROM JpaUser u",
> JpaUser.class);
> +        for (JpaUser u : q.getResultList()) {
> +            u.getPreviousEncodedPasswords().clear();
> +        }
> +        em.flush();
> +        Query qd = em.createQuery("DELETE FROM JpaUser u");
> +        qd.executeUpdate();
>          em.getTransaction().commit();
> +        em.clear();
> +
>      }
>
>      @Override
> @@ -298,7 +325,7 @@ public class JpaUserManager extends
> AbstractUserManager {
>
>      @Override
>      public String getDescriptionKey() {
> -        return null;
> +        return "archiva.redback.usermanager.jpa";
>      }
>
>
>
> http://git-wip-us.apache.org/repos/asf/archiva-redback-
> core/blob/f3bcedfd/redback-users/redback-users-providers/
> redback-users-jpa/src/main/java/org/apache/archiva/
> redback/users/jpa/model/JpaUser.java
> ----------------------------------------------------------------------
> diff --git a/redback-users/redback-users-providers/redback-users-jpa/
> src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java
> b/redback-users/redback-users-providers/redback-users-jpa/
> src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java
> index 04f441e..cfdaa4e 100644
> --- a/redback-users/redback-users-providers/redback-users-jpa/
> src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java
> +++ b/redback-users/redback-users-providers/redback-users-jpa/
> src/main/java/org/apache/archiva/redback/users/jpa/model/JpaUser.java
> @@ -19,9 +19,13 @@ package org.apache.archiva.redback.users.jpa.model;
>   * under the License.
>   */
>
> +import javax.persistence.CollectionTable;
> +import javax.persistence.Column;
>  import javax.persistence.ElementCollection;
>  import javax.persistence.Entity;
>  import javax.persistence.Id;
> +import javax.persistence.JoinColumn;
> +import javax.persistence.OrderColumn;
>  import javax.persistence.Table;
>  import java.util.ArrayList;
>  import java.util.Date;
> @@ -35,21 +39,38 @@ import java.util.List;
>  public class JpaUser implements org.apache.archiva.redback.users.User {
>
>      @Id
> +    @Column(name="USERNAME")
>      private String username;
> -
> +    @Column(name="FULL_NAME")
>      private String fullName;
> +    @Column(name="EMAIL")
>      private String email;
> +    @Column(name="ENCODED_PASSWORD")
>      private String encodedPassword;
> +    @Column(name="LAST_PASSWORD_CHANGE")
>      private Date lastPasswordChange;
>      @ElementCollection
> +    @OrderColumn(name="INTEGER_IDX")
> +    @Column(name="STRING_ELE")
> +    @CollectionTable(name="JDOUSER_PREVIOUSENCODEDPASSWORDS",
> +            joinColumns = @JoinColumn(name = "USERNAME_OID",
> referencedColumnName = "USERNAME")
> +    )
>      private List<String> previousEncodedPasswords = new
> ArrayList<String>();
> +    @Column(name="PERMANENT")
>      private boolean permanent;
> +    @Column(name="LOCKED")
>      private boolean locked;
> +    @Column(name="PASSWORD_CHANGE_REQUIRED")
>      private boolean passwordChangeRequired;
> +    @Column(name="VALIDATED")
>      private boolean validated;
> +    @Column(name="COUNT_FAILED_LOGIN_ATTEMPTS")
>      private int countFailedLoginAttempts;
> +    @Column(name="ACCOUNT_CREATION_DATE")
>      private Date accountCreationDate;
> +    @Column(name="LAST_LOGIN_DATE")
>      private Date lastLoginDate;
> +    @Column(name="USER_PASSSWORD")
>      private String rawPassword;
>
>
>
> http://git-wip-us.apache.org/repos/asf/archiva-redback-
> core/blob/f3bcedfd/redback-users/redback-users-providers/
> redback-users-jpa/src/main/resources/spring-context.xml
> ----------------------------------------------------------------------
> diff --git a/redback-users/redback-users-providers/redback-users-jpa/
> src/main/resources/spring-context.xml b/redback-users/redback-users-
> providers/redback-users-jpa/src/main/resources/spring-context.xml
> new file mode 100644
> index 0000000..a56a218
> --- /dev/null
> +++ b/redback-users/redback-users-providers/redback-users-jpa/
> src/main/resources/spring-context.xml
> @@ -0,0 +1,31 @@
> +<?xml version="1.0"?>
> +
> +<!--
> +  ~ Licensed to the Apache Software Foundation (ASF) under one
> +  ~ or more contributor license agreements.  See the NOTICE file
> +  ~ distributed with this work for additional information
> +  ~ regarding copyright ownership.  The ASF licenses this file
> +  ~ to you under the Apache License, Version 2.0 (the
> +  ~ "License"); you may not use this file except in compliance
> +  ~ with the License.  You may obtain a copy of the License at
> +  ~
> +  ~   http://www.apache.org/licenses/LICENSE-2.0
> +  ~
> +  ~ Unless required by applicable law or agreed to in writing,
> +  ~ software distributed under the License is distributed on an
> +  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> +  ~ KIND, either express or implied.  See the License for the
> +  ~ specific language governing permissions and limitations
> +  ~ under the License.
> +  -->
> +<beans xmlns="http://www.springframework.org/schema/beans"
> +       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> +       xmlns:context="http://www.springframework.org/schema/context"
> +       xsi:schemaLocation="http://www.springframework.org/schema/beans
> +           http://www.springframework.org/schema/beans/spring-beans-
> 3.0.xsd
> +           http://www.springframework.org/schema/context
> +           http://www.springframework.org/schema/context/spring-
> context-3.0.xsd">
> +
> +  <context:component-scan base-package="org.apache.archiva.redback.users.jpa"
> />
> +
> +</beans>
> \ No newline at end of file
>
> http://git-wip-us.apache.org/repos/asf/archiva-redback-
> core/blob/f3bcedfd/redback-users/redback-users-providers/
> redback-users-jpa/src/test/java/org/apache/archiva/redback/users/jpa/
> JpaUserManagerTest.java
> ----------------------------------------------------------------------
> diff --git a/redback-users/redback-users-providers/redback-users-jpa/
> src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java
> b/redback-users/redback-users-providers/redback-users-jpa/
> src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java
> index 4556755..75cda6d 100644
> --- a/redback-users/redback-users-providers/redback-users-jpa/
> src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java
> +++ b/redback-users/redback-users-providers/redback-users-jpa/
> src/test/java/org/apache/archiva/redback/users/jpa/JpaUserManagerTest.java
> @@ -65,7 +65,6 @@ public class JpaUserManagerTest extends
> AbstractUserManagerTestCase {
>          is.close();
>          EntityManagerFactory emf = Persistence.
> createEntityManagerFactory("redback-jpa",props);
>
> -        log.info("test setup");
>          jpaUserManager.setEntityManager(emf.createEntityManager());
>          super.setUserManager(jpaUserManager);
>          assertNotNull(jpaUserManager);
>
>


-- 
Olivier Lamy
http://twitter.com/olamy | http://linkedin.com/in/olamy

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message