Re: DbUtils Best Practices

2007-09-13 Thread pouky
i'm seeing another point. Your QueryManager does not offer the guarantee to be a
singleton, you have to declare a private constructor.

Jérome.


Selon [EMAIL PROTECTED]:

 Selon [EMAIL PROTECTED]:

  Hi,
  I'm using a dao pattern, the call
 
  QueryManager.getInstance().getQueryRunner().query(...);
 
  is executed in my dao object.
 
  Servlet calls dao method.
 
 ok.

  What do you mean with it depends of your project size?
 Hi,
 If you have a small project it is not mandatory to spend a lot of time in the
 abstraction layers, but this is advised. If you implement this approach, life
 is
 wonderful. :)

 Jérome.

 
  Thanks a lot
 
  Diego
 
 
   Hi,
   It seems correct, why not, QueryRunner object is thread safe.
   Web layer which calls integration layer directly, it's a bad design but
   this
   depends of your project size.
  
   Jérome.
  
  
  
   Selon [EMAIL PROTECTED]:
  
   Hi, I'm developing a web application using DbUtils classes to execute
   queries and so on.
  
   I user QueryRunner class with a DataSource.
  
   I red this class is thread safe, so I implemented a Singleton to
   instance
   QueryRunner only once.
  
   This is my code:
  
   public class QueryManager {
  
private static QueryManager queryManager = null;
  
private static QueryRunner queryRunner = null;
  
static {
  try {
queryRunner = new QueryRunner(DataSourceSingleton.getInstance()
.getDataSource());
} catch (Exception e) {
}
}
  
public static QueryManager getInstance() {
   if (queryManager == null) {
queryManager = new QueryManager();
   }
   return queryManager;
}
  
public QueryRunner getQueryRunner() {
  return queryRunner;
}
  
   In my servlets I use:
  
   QueryManager.getInstance().getQueryRunner().query(...);
  
   Is this correct?
  
   Which is the best practice to use QueryRunner in a web context?
  
   Thanks a lot in advance
  
  
   -
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
  
  
  
  
  
   -
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
  
  
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 



 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: DbUtils Best Practices

2007-09-13 Thread pouky
add an action in the catch block and this will be perfect
;)
Jérome.



Selon [EMAIL PROTECTED]:

 I have changed my class:

 public class QueryManager {

  private static QueryManager queryManager = null;

  private QueryRunner queryRunner = null;

  private QueryManager() {
   try {
   queryRunner = new QueryRunner(DataSourceSingleton.getInstance()
   .getDataSource());
   } catch (Exception e) {
   }
  }

  public static QueryManager getInstance() {
if (queryManager == null) {
   queryManager = new QueryManager();
}
 return queryManager;
   }

  public QueryRunner getQueryRunner() {
return this.queryRunner;
  }

 Is what you meant?

 Thanks




  sorry, another point...
  queryRunner parameter must be a QueryManager member parameter, you have to
  remove static
 
  Selon [EMAIL PROTECTED]:
 
  i'm seeing another point. Your QueryManager does not offer the guarantee
  to
  be a
  singleton, you have to declare a private constructor.
 
  Jérome.
 
 
  Selon [EMAIL PROTECTED]:
 
   Selon [EMAIL PROTECTED]:
  
Hi,
I'm using a dao pattern, the call
   
QueryManager.getInstance().getQueryRunner().query(...);
   
is executed in my dao object.
   
Servlet calls dao method.
   
   ok.
  
What do you mean with it depends of your project size?
   Hi,
   If you have a small project it is not mandatory to spend a lot of time
  in
  the
   abstraction layers, but this is advised. If you implement this
  approach,
  life
   is
   wonderful. :)
  
   Jérome.
  
   
Thanks a lot
   
Diego
   
   
 Hi,
 It seems correct, why not, QueryRunner object is thread safe.
 Web layer which calls integration layer directly, it's a bad
  design but
 this
 depends of your project size.

 Jérome.



 Selon [EMAIL PROTECTED]:

 Hi, I'm developing a web application using DbUtils classes to
  execute
 queries and so on.

 I user QueryRunner class with a DataSource.

 I red this class is thread safe, so I implemented a Singleton to
 instance
 QueryRunner only once.

 This is my code:

 public class QueryManager {

  private static QueryManager queryManager = null;

  private static QueryRunner queryRunner = null;

  static {
try {
 queryRunner = new QueryRunner(DataSourceSingleton.getInstance()
 .getDataSource());
 } catch (Exception e) {
 }
  }

  public static QueryManager getInstance() {
 if (queryManager == null) {
 queryManager = new QueryManager();
 }
 return queryManager;
  }

  public QueryRunner getQueryRunner() {
return queryRunner;
  }

 In my servlets I use:

 QueryManager.getInstance().getQueryRunner().query(...);

 Is this correct?

 Which is the best practice to use QueryRunner in a web context?

 Thanks a lot in advance



 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]






 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


   
   
   
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
   
   
  
  
  
   -
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
  
  
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 



 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Commons email error with localhost server ?

2007-09-13 Thread Nicolas BOIRE

Hello,

I have an error when i tried to send a email with localhost server.
I have a postfix server mail on localhost and when i try to send a email 
in command line (telnet localhost 25 ), it's ok .


I use the commons-email-1.0.jar in tomcat 5.0

The stacktrace :
Caused by: javax.mail.MessagingException: 501 Syntax: HELO hostname

  at 
com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1308)

  at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:785)
  at 
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:327)

  at javax.mail.Service.connect(Service.java:236)
  at javax.mail.Service.connect(Service.java:137)
  at javax.mail.Service.connect(Service.java:86)
  at javax.mail.Transport.send0(Transport.java:150)
  at javax.mail.Transport.send(Transport.java:80)
  at org.apache.commons.mail.Email.sendMimeMessage(Email.java:863)
  ... 47 more


Thanks for your help .
Best regards,

Nicolas

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [lang] ClassCastException in Enum.compareTo with anonymous inner classes

2007-09-13 Thread Samuel Fleischle

Hi,
I updated from Commons Lang 2.1 to Commons Lang 2.3 and got some issues with 
the changed compareTo() method of Enum with anonymouse inner classes:

Here is my simplified Enum:


public class ItemStatus extends Enum
{
   // -- Static Fields
  public static final ItemStatus CANCEL = new ItemStatus(CANCEL, 
Cancel);

   public static final ItemStatus SHIPPED = new ItemStatus(SHIPPED, 
Shipped) {
public String getDisplayName() {
// do something special for this status
}
   };

  public static final ItemStatus MOVED = new ItemStatus(MOVED, Moved) {
public String getDisplayName() {
// do something special for this status
}
   };

   /** Contains each status. */
  private static Set statuses;

// -- Instance Fields
/** Name to display in user interfaces. */
private final String displayName;

   // --- Constructors

  protected ItemStatus(String name, String displayName) {
    super(name);
this.displayName = displayName;
    System.out.println(this.getClass().getName());
    buildStatusSet();
  }

  // --- Static Methods

  /**
   * Returns the item status enumeration object
 * for the given status name.
   *
   * @param itemStatus
   *    name of the item status
   * @return the enumeration object, or codenull/code if it does not
   * exist
   */
  public static ItemStatus valueOf(String itemStatus) {
    return (ItemStatus) getEnum(ItemStatus.class, itemStatus);
  }

  // --- Public Methods

  /**
   * [EMAIL PROTECTED]
   */
  // @Override
  public final Class getEnumClass() {
    return ItemStatus.class;
  }

  /**
   * Gets all defined ItemStatus.
   *
   * @return the enum object List
   * @see org.apache.commons.lang.enums.Enum#getEnumList(Class)
   */
  public static List getEnumList() {
    return getEnumList(ItemStatus.class);
  }

   public String getDisplayName() {
return displayName;
}

  // --- Private Methods

  /**
   * Adds the status name to a Set of status names.
   */
  private void buildStatusSet() {
    if (statuses == null) {
  statuses = new TreeSet();
    }
    statuses.add(this);
  }
}

And I got the ClassCastExcetion in the private buildStatusSet()-Method if I 
try to add the status to the TreeSet. The TreeSet calls the compareTo-Method of 
the Enum. In Commons Lang 2.2 this method was changed with an additional 
comparison of the classes.
In my constructor I added a System.out.println of the instantiated classes and 
got the following output for the classnames:

com.myapp.common.model.order.ItemStatus
com.myapp.common.model.order.ItemStatus$1
com.myapp.common.model.order.ItemStatus$2

The compareTo-Method now tries to compare ItemStatus$1 with ItemStatus$2 and 
says to me, that my ItemStatus-Enums are different classes.

I saw in JIRA there are some other issues in ValuedEnum.compareTo(). Is there a 
bug in the Enum.compareTo() implementation which got changed in Lang 2.2?

Thanks in advance for any help or comment on this issue.

Regards,
Sam


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [lang] ClassCastException in Enum.compareTo with anonymous inner classes

2007-09-13 Thread Jörg Schaible
Hi Samuel,

Samuel Fleischle wrote on Thursday, September 13, 2007 3:51 PM:

 Hi,
 I updated from Commons Lang 2.1 to Commons Lang 2.3 and got
 some issues with the changed compareTo() method of Enum with
 anonymouse inner classes: 
 
 Here is my simplified Enum:
 
 
 public class ItemStatus extends Enum
 {
// --
 Static Fields
   public static final ItemStatus CANCEL = new
 ItemStatus(CANCEL, Cancel);
 
public static final ItemStatus SHIPPED = new
 ItemStatus(SHIPPED, Shipped) {
   public String getDisplayName() {
   // do something special for this status
   }
};
 
   public static final ItemStatus MOVED = new
 ItemStatus(MOVED, Moved) {
   public String getDisplayName() {
   // do something special for this status
   }
};
 

[snip]

 }

[snip]
 
 com.myapp.common.model.order.ItemStatus
 com.myapp.common.model.order.ItemStatus$1
 com.myapp.common.model.order.ItemStatus$2
 
 The compareTo-Method now tries to compare ItemStatus$1 with
 ItemStatus$2 and says to me, that my ItemStatus-Enums are
 different classes.

Well, obviously those *are* different classes.

 I saw in JIRA there are some other issues in
 ValuedEnum.compareTo(). Is there a bug in the
 Enum.compareTo() implementation which got changed in Lang 2.2?

IIRC, this was more about using different class loaders loading the EnumValue 
class.
 
 Thanks in advance for any help or comment on this issue.

Why don't you factor out a (private) interface with this method? Write an 
addition ctor that takes such an implementation and use otherwise a default 
one. With this approach the enum class is always the same and the anonymous 
class is of a different type. Make the an additional field in the enum class 
keeping that implementation and declare it as transient for seamless 
serialization.

- Jörg

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]