From: Roland Haeder Date: Thu, 17 Sep 2015 10:45:33 +0000 (+0200) Subject: Removed logger, the EJB container didn't accept this. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a415a2681bfae51ec417c1d3dd67629439c9632e;p=jcustomer-core.git Removed logger, the EJB container didn't accept this. Signed-off-by:Roland Häder --- diff --git a/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java b/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java index e712d77..72e024e 100644 --- a/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java +++ b/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java @@ -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; }