]> git.mxchange.org Git - jshop-core.git/commitdiff
Removed logger, the EJB container didn't accept this.
authorRoland Haeder <roland@mxchange.org>
Thu, 17 Sep 2015 10:45:33 +0000 (12:45 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 17 Sep 2015 10:45:33 +0000 (12:45 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/org/mxchange/jshopcore/model/customer/CustomerUtils.java

index e712d771953cb3555ba7d4eb5ed2bd3c2f33e765..72e024e35c294d975162ff48664e0a4bab2f378a 100644 (file)
@@ -20,9 +20,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.text.MessageFormat;
 import org.mxchange.jcore.BaseFrameworkSystem;
-import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
 
 /**
  * An utilities class for customers
@@ -41,42 +39,42 @@ public class CustomerUtils extends BaseFrameworkSystem {
         * Generates an unique customer number by checking is existence
         *
         * @param connection Connection instance
-        * @param logger Logger instance
         * @return Generated customer number (not used before)
         * @throws java.sql.SQLException If any SQL error occured
         */
-       public static String generateCustomerNumber (final Connection connection, final LoggerBeanLocal logger) throws SQLException {
-               // logger cannot be null
-               if (null == logger) {
-                       // Abort here
-                       throw new NullPointerException("logger is null");
-               }
-
+       public static String generateCustomerNumber (final Connection connection) throws SQLException {
                // Trace message
-               logger.logTrace(MessageFormat.format("generateCustomerNumber: connection={0},logger={1} - CALLED!", connection, logger));
-
+               // TODO: utils.getLogger().logTrace(MessageFormat.format("generateCustomerNumber: connection={0} - CALLED!", connection));
                // connection cannot be null
                if (null == connection) {
                        // Abort here
-                       throw new NullPointerException("connection is null");
+                       throw new NullPointerException("connection is null"); //NOI18N
                }
 
                // Prepare statement
-               PreparedStatement statement = connection.prepareStatement("SELECT `id` FROM `customer` WHERE `customer_number` = ? LIMIT 1");
+               PreparedStatement statement = connection.prepareStatement("SELECT `id` FROM `customer` WHERE `customer_number` = ? LIMIT 1"); //NOI18N
 
                // Generate number
-               String customerNumber = Long.toString(Math.round(Math.random() * 100000)) + "-" +  Long.toString(Math.round(Math.random() * 1000));
+               String customerNumber = null;
 
                // Default is found
                boolean isFound = true;
+               long part1 = 0;
+               long part2 = 0;
 
                // Is the number used?
                while (isFound) {
-                       // Debug message
-                       logger.logDebug(MessageFormat.format("generateCustomerNumber: customerNumber={0}", customerNumber));
+                       // Both number parts
+                       part1 = Math.round(Math.random() * 100000);
+                       part2 = Math.round(Math.random() * 1000);
+
+                       // Generate new number
+                       customerNumber = String.format("%s-%s", part1, part2); //NOI18N
 
+                       // Debug message
+                       // TODO: utils.getLogger().logDebug(MessageFormat.format("generateCustomerNumber: customerNumber={0}", customerNumber));
                        // Insert customer number
-                       statement.setString(0, customerNumber);
+                       statement.setString(1, customerNumber);
 
                        // Find it
                        statement.execute();
@@ -84,23 +82,12 @@ public class CustomerUtils extends BaseFrameworkSystem {
                        // Get result
                        ResultSet result = statement.getResultSet();
 
-                       // Rewind it
-                       result.beforeFirst();
-
-                       // Found a record?
-                       if (result.isLast()) {
-                               // Not found
-                               isFound = false;
-                               break;
-                       }
-
-                       // Generate new number
-                       customerNumber = Long.toString(Math.round(Math.random() * 100000)) + "-" +  Long.toString(Math.round(Math.random() * 1000));
+                       // Try to get next result
+                       isFound = result.next();
                }
 
                // Trace message
-               logger.logTrace(MessageFormat.format("generateCustomerNumber: customerNumber={0} - EXIT!", customerNumber));
-
+               // TODO: utils.getLogger().logTrace(MessageFormat.format("generateCustomerNumber: customerNumber={0} - EXIT!", customerNumber));
                // Found one
                return customerNumber;
        }