Set only space for tabs.

This commit is contained in:
Christian P. MOMON 2020-09-13 02:10:28 +02:00
parent a33a9215df
commit 9d05c7024f
8 changed files with 1048 additions and 1048 deletions

View file

@ -34,37 +34,37 @@ import fr.devinsy.statoolinfos.cli.StatoolInfosCLI;
*/ */
public final class StatoolInfosLauncher public final class StatoolInfosLauncher
{ {
private static Logger logger = LoggerFactory.getLogger(StatoolInfosLauncher.class); private static Logger logger = LoggerFactory.getLogger(StatoolInfosLauncher.class);
/** /**
* Instantiates a new statool infos launcher. * Instantiates a new statool infos launcher.
*/ */
private StatoolInfosLauncher() private StatoolInfosLauncher()
{ {
} }
/** /**
* The main method. * The main method.
* *
* @param args * @param args
* the arguments * the arguments
*/ */
public static void main(final String[] args) public static void main(final String[] args)
{ {
// Configure log. // Configure log.
File loggerConfig = new File("log4j.peroperties"); File loggerConfig = new File("log4j.peroperties");
if (loggerConfig.exists()) if (loggerConfig.exists())
{ {
PropertyConfigurator.configure(loggerConfig.getAbsolutePath()); PropertyConfigurator.configure(loggerConfig.getAbsolutePath());
logger.info("Dedicated log configuration done."); logger.info("Dedicated log configuration done.");
logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile()); logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile());
} }
else else
{ {
BasicConfigurator.configure(new ConsoleAppender(new EnhancedPatternLayout("%m%n"))); BasicConfigurator.configure(new ConsoleAppender(new EnhancedPatternLayout("%m%n")));
} }
// Run. // Run.
StatoolInfosCLI.run(args); StatoolInfosCLI.run(args);
} }
} }

View file

@ -25,48 +25,48 @@ import fr.devinsy.statoolinfos.core.StatoolInfosException;
*/ */
public class StatoolInfosCLIException extends StatoolInfosException public class StatoolInfosCLIException extends StatoolInfosException
{ {
private static final long serialVersionUID = 2986878456227891377L; private static final long serialVersionUID = 2986878456227891377L;
/** /**
* Instantiates a new statool infos CLI exception. * Instantiates a new statool infos CLI exception.
*/ */
public StatoolInfosCLIException() public StatoolInfosCLIException()
{ {
super(); super();
} }
/** /**
* Instantiates a new statool infos CLI exception. * Instantiates a new statool infos CLI exception.
* *
* @param message * @param message
* the message * the message
*/ */
public StatoolInfosCLIException(final String message) public StatoolInfosCLIException(final String message)
{ {
super(message); super(message);
} }
/** /**
* Instantiates a new statool infos CLI exception. * Instantiates a new statool infos CLI exception.
* *
* @param message * @param message
* the message * the message
* @param cause * @param cause
* the cause * the cause
*/ */
public StatoolInfosCLIException(final String message, final Throwable cause) public StatoolInfosCLIException(final String message, final Throwable cause)
{ {
super(message, cause); super(message, cause);
} }
/** /**
* Instantiates a new statool infos CLI exception. * Instantiates a new statool infos CLI exception.
* *
* @param cause * @param cause
* the cause * the cause
*/ */
public StatoolInfosCLIException(final Throwable cause) public StatoolInfosCLIException(final Throwable cause)
{ {
super(cause); super(cause);
} }
} }

View file

@ -26,115 +26,115 @@ import fr.devinsy.strings.StringSet;
*/ */
interface PathProperties interface PathProperties
{ {
/** /**
* Gets the. * Gets the.
* *
* @param path * @param path
* the path * the path
* @return the string * @return the string
*/ */
String get(final String path); String get(final String path);
/** /**
* Gets the by prefix. * Gets the by prefix.
* *
* @param prefix * @param prefix
* the prefix * the prefix
* @return the by prefix * @return the by prefix
*/ */
public PathProperties getByPrefix(String prefix); public PathProperties getByPrefix(String prefix);
/** /**
* Gets the keys. * Gets the keys.
* *
* @return the keys * @return the keys
*/ */
StringList getPaths(); StringList getPaths();
/** /**
* Gets the prefixes. * Gets the prefixes.
* *
* @return the prefixes * @return the prefixes
*/ */
StringSet getPrefixes(); StringSet getPrefixes();
/** /**
* Gets the prefix list. * Gets the prefix list.
* *
* @return the prefix list * @return the prefix list
*/ */
StringList getPrefixList(); StringList getPrefixList();
/** /**
* Gets the property. * Gets the property.
* *
* @param path * @param path
* the path * the path
* @return the property * @return the property
*/ */
PathProperty getProperty(final String path); PathProperty getProperty(final String path);
/** /**
* Put. * Put.
* *
* @param key * @param key
* the key * the key
* @param value * @param value
* the value * the value
*/ */
void put(final String key, final String value); void put(final String key, final String value);
/** /**
* Delete path. * Delete path.
* *
* @param path * @param path
* the path * the path
*/ */
void removePath(final String path); void removePath(final String path);
/** /**
* Removes the prefix. * Removes the prefix.
* *
* @param prefix * @param prefix
* the prefix * the prefix
*/ */
void removeSection(final String prefix); void removeSection(final String prefix);
/** /**
* Size. * Size.
* *
* @return the int * @return the int
*/ */
int size(); int size();
/** /**
* To string list. * To string list.
* *
* @return the string list * @return the string list
*/ */
StringList toStringList(); StringList toStringList();
/** /**
* To string list formatted. * To string list formatted.
* *
* @return the string list * @return the string list
*/ */
StringList toStringListFormatted(); StringList toStringListFormatted();
/** /**
* Gets the prefix. * Gets the prefix.
* *
* @param source * @param source
* the source * the source
* @return the prefix * @return the prefix
*/ */
static String getPrefix(final String source) static String getPrefix(final String source)
{ {
String result; String result;
result = source.substring(source.indexOf(".")); result = source.substring(source.indexOf("."));
// //
return result; return result;
} }
} }

View file

@ -25,57 +25,57 @@ import org.apache.commons.lang3.StringUtils;
*/ */
public class PathProperty public class PathProperty
{ {
private String path; private String path;
private String value; private String value;
/** /**
* Instantiates a new path property. * Instantiates a new path property.
* *
* @param path * @param path
* the key * the key
* @param value * @param value
* the value * the value
*/ */
public PathProperty(final String path, final String value) public PathProperty(final String path, final String value)
{ {
if (StringUtils.isAllBlank(path)) if (StringUtils.isAllBlank(path))
{ {
throw new IllegalArgumentException("Path is blank."); throw new IllegalArgumentException("Path is blank.");
} }
else else
{ {
this.path = path; this.path = path;
this.value = value; this.value = value;
} }
} }
public String getLeaf() public String getLeaf()
{ {
String result; String result;
result = this.path.substring(this.path.lastIndexOf('.') + 1); result = this.path.substring(this.path.lastIndexOf('.') + 1);
// //
return result; return result;
} }
public String getPath() public String getPath()
{ {
return this.path; return this.path;
} }
public String getValue() public String getValue()
{ {
return this.value; return this.value;
} }
public void setPath(final String path) public void setPath(final String path)
{ {
this.path = path; this.path = path;
} }
public void setValue(final String value) public void setValue(final String value)
{ {
this.value = value; this.value = value;
} }
} }

View file

@ -33,436 +33,436 @@ import fr.devinsy.strings.StringSet;
*/ */
public class PathPropertyList extends ArrayList<PathProperty> implements PathProperties public class PathPropertyList extends ArrayList<PathProperty> implements PathProperties
{ {
private static final long serialVersionUID = -8491243013973609457L; private static final long serialVersionUID = -8491243013973609457L;
private static final Logger logger = LoggerFactory.getLogger(PathPropertyList.class); private static final Logger logger = LoggerFactory.getLogger(PathPropertyList.class);
/** /**
* Instantiates a new path property list. * Instantiates a new path property list.
*/ */
public PathPropertyList() public PathPropertyList()
{ {
super(); super();
} }
/** /**
* Instantiates a new path property list. * Instantiates a new path property list.
* *
* @param initialCapacity * @param initialCapacity
* the initial capacity * the initial capacity
*/ */
public PathPropertyList(final int initialCapacity) public PathPropertyList(final int initialCapacity)
{ {
super(initialCapacity); super(initialCapacity);
} }
/** /**
* Instantiates a new path property list. * Instantiates a new path property list.
* *
* @param source * @param source
* the source * the source
*/ */
public PathPropertyList(final PathPropertyList source) public PathPropertyList(final PathPropertyList source)
{ {
super(); super();
if (source != null) if (source != null)
{ {
this.ensureCapacity(source.size()); this.ensureCapacity(source.size());
for (PathProperty property : source) for (PathProperty property : source)
{ {
this.add(property); this.add(property);
} }
} }
} }
/** /**
* Gets the. * Gets the.
* *
* @param path * @param path
* the path. * the path.
* @return the string * @return the string
*/ */
@Override @Override
public String get(final String path) public String get(final String path)
{ {
String result; String result;
PathProperty property = getProperty(path); PathProperty property = getProperty(path);
if (property == null) if (property == null)
{ {
result = null; result = null;
} }
else else
{ {
result = property.getValue(); result = property.getValue();
} }
// //
return result; return result;
} }
/** /**
* Gets the by prefix. * Gets the by prefix.
* *
* @param prefix * @param prefix
* the prefix * the prefix
* @return the by prefix * @return the by prefix
*/ */
@Override @Override
public PathPropertyList getByPrefix(final String prefix) public PathPropertyList getByPrefix(final String prefix)
{ {
PathPropertyList result; PathPropertyList result;
result = new PathPropertyList(); result = new PathPropertyList();
if (StringUtils.isNotBlank(prefix)) if (StringUtils.isNotBlank(prefix))
{ {
String pattern; String pattern;
if (prefix.endsWith(".")) if (prefix.endsWith("."))
{ {
pattern = prefix; pattern = prefix;
} }
else else
{ {
pattern = prefix + "."; pattern = prefix + ".";
} }
boolean ended = false; boolean ended = false;
Iterator<PathProperty> iterator = iterator(); Iterator<PathProperty> iterator = iterator();
while (!ended) while (!ended)
{ {
if (iterator.hasNext()) if (iterator.hasNext())
{ {
PathProperty current = iterator.next(); PathProperty current = iterator.next();
if (StringUtils.startsWith(current.getPath(), pattern)) if (StringUtils.startsWith(current.getPath(), pattern))
{ {
result.add(current); result.add(current);
} }
} }
else else
{ {
ended = true; ended = true;
} }
} }
} }
// //
return result; return result;
} }
/** /**
* Gets the index property. * Gets the index property.
* *
* @param path * @param path
* the path * the path
* @return the index property * @return the index property
*/ */
public int getIndexProperty(final String path) public int getIndexProperty(final String path)
{ {
int result; int result;
boolean ended = false; boolean ended = false;
int index = 0; int index = 0;
result = -1; result = -1;
while (!ended) while (!ended)
{ {
if (index < size()) if (index < size())
{ {
PathProperty current = this.get(index); PathProperty current = this.get(index);
if (StringUtils.equals(current.getPath(), path)) if (StringUtils.equals(current.getPath(), path))
{ {
ended = true; ended = true;
result = index; result = index;
} }
else else
{ {
index += 1; index += 1;
} }
} }
else else
{ {
ended = true; ended = true;
result = -1; result = -1;
} }
} }
// //
return result; return result;
} }
/** /**
* Gets the keys. * Gets the keys.
* *
* @return the keys * @return the keys
*/ */
@Override @Override
public StringList getPaths() public StringList getPaths()
{ {
StringList result; StringList result;
result = new StringList(); result = new StringList();
for (PathProperty property : this) for (PathProperty property : this)
{ {
result.add(property.getPath()); result.add(property.getPath());
} }
// //
return result; return result;
} }
/** /**
* Gets the prefixes. * Gets the prefixes.
* *
* @return the prefixes * @return the prefixes
*/ */
@Override @Override
public StringSet getPrefixes() public StringSet getPrefixes()
{ {
StringSet result; StringSet result;
result = new StringSet(); result = new StringSet();
for (PathProperty property : this) for (PathProperty property : this)
{ {
result.add(getPrefix(property.getPath())); result.add(getPrefix(property.getPath()));
} }
// //
return result; return result;
} }
/** /**
* Gets the prefix list. * Gets the prefix list.
* *
* @return the prefix list * @return the prefix list
*/ */
@Override @Override
public StringList getPrefixList() public StringList getPrefixList()
{ {
StringList result; StringList result;
result = new StringList(); result = new StringList();
for (PathProperty property : this) for (PathProperty property : this)
{ {
String prefix = getPrefix(property.getPath()); String prefix = getPrefix(property.getPath());
if (!result.contains(prefix)) if (!result.contains(prefix))
{ {
result.add(prefix); result.add(prefix);
} }
} }
// //
return result; return result;
} }
/** /**
* Gets the property. * Gets the property.
* *
* @param path * @param path
* the path * the path
* @return the property * @return the property
*/ */
@Override @Override
public PathProperty getProperty(final String path) public PathProperty getProperty(final String path)
{ {
PathProperty result; PathProperty result;
boolean ended = false; boolean ended = false;
Iterator<PathProperty> iterator = this.iterator(); Iterator<PathProperty> iterator = this.iterator();
result = null; result = null;
while (!ended) while (!ended)
{ {
if (iterator.hasNext()) if (iterator.hasNext())
{ {
PathProperty current = iterator.next(); PathProperty current = iterator.next();
if (StringUtils.equals(current.getPath(), path)) if (StringUtils.equals(current.getPath(), path))
{ {
ended = true; ended = true;
result = current; result = current;
} }
} }
else else
{ {
ended = true; ended = true;
result = null; result = null;
} }
} }
// //
return result; return result;
} }
/** /**
* Put. * Put.
* *
* @param path * @param path
* the path * the path
* @param value * @param value
* the value * the value
*/ */
@Override @Override
public void put(final String path, final String value) public void put(final String path, final String value)
{ {
if (StringUtils.isNotBlank(path)) if (StringUtils.isNotBlank(path))
{ {
PathProperty property = getProperty(path); PathProperty property = getProperty(path);
if (property == null) if (property == null)
{ {
add(new PathProperty(path, value)); add(new PathProperty(path, value));
} }
else else
{ {
property.setValue(property.getValue()); property.setValue(property.getValue());
} }
} }
} }
/** /**
* Delete path. * Delete path.
* *
* @param path * @param path
* the path * the path
*/ */
@Override @Override
public void removePath(final String path) public void removePath(final String path)
{ {
String result; String result;
boolean ended = false; boolean ended = false;
Iterator<PathProperty> iterator = this.iterator(); Iterator<PathProperty> iterator = this.iterator();
result = null; result = null;
while (!ended) while (!ended)
{ {
if (iterator.hasNext()) if (iterator.hasNext())
{ {
PathProperty current = iterator.next(); PathProperty current = iterator.next();
if (StringUtils.equals(current.getPath(), path)) if (StringUtils.equals(current.getPath(), path))
{ {
ended = true; ended = true;
iterator.remove(); iterator.remove();
} }
} }
else else
{ {
ended = true; ended = true;
result = null; result = null;
} }
} }
} }
/** /**
* Removes the section. * Removes the section.
* *
* @param prefix * @param prefix
* the prefix * the prefix
*/ */
@Override @Override
public void removeSection(final String prefix) public void removeSection(final String prefix)
{ {
if (StringUtils.isNotBlank(prefix)) if (StringUtils.isNotBlank(prefix))
{ {
String pattern; String pattern;
if (prefix.endsWith(".")) if (prefix.endsWith("."))
{ {
pattern = prefix; pattern = prefix;
} }
else else
{ {
pattern = prefix + "."; pattern = prefix + ".";
} }
boolean ended = false; boolean ended = false;
Iterator<PathProperty> iterator = iterator(); Iterator<PathProperty> iterator = iterator();
while (!ended) while (!ended)
{ {
if (iterator.hasNext()) if (iterator.hasNext())
{ {
PathProperty current = iterator.next(); PathProperty current = iterator.next();
if (StringUtils.startsWith(current.getPath(), pattern)) if (StringUtils.startsWith(current.getPath(), pattern))
{ {
iterator.remove(); iterator.remove();
} }
} }
else else
{ {
ended = true; ended = true;
} }
} }
} }
} }
/** /**
* To string list. * To string list.
* *
* @return the string list * @return the string list
*/ */
@Override @Override
public StringList toStringList() public StringList toStringList()
{ {
StringList result; StringList result;
result = new StringList(); result = new StringList();
for (String path : getPaths()) for (String path : getPaths())
{ {
String value = get(path); String value = get(path);
result.add(path + "=" + value); result.add(path + "=" + value);
} }
// //
return result; return result;
} }
/** /**
* To string list formatted. * To string list formatted.
* *
* @return the string list * @return the string list
*/ */
@Override @Override
public StringList toStringListFormatted() public StringList toStringListFormatted()
{ {
StringList result; StringList result;
result = new StringList(); result = new StringList();
StringList prefixes = getPrefixList(); StringList prefixes = getPrefixList();
// sort prefixes. // sort prefixes.
for (String prefix : prefixes) for (String prefix : prefixes)
{ {
result.add("# [" + StringUtils.capitalize(prefix) + "]"); result.add("# [" + StringUtils.capitalize(prefix) + "]");
PathPropertyList section = getByPrefix(prefix); PathPropertyList section = getByPrefix(prefix);
result.addAll(section.toStringList()); result.addAll(section.toStringList());
result.add(""); result.add("");
} }
// //
return result; return result;
} }
/** /**
* Gets the prefix. * Gets the prefix.
* *
* @param source * @param source
* the source * the source
* @return the prefix * @return the prefix
*/ */
private static String getPrefix(final String source) private static String getPrefix(final String source)
{ {
String result; String result;
result = source.substring(0, source.indexOf(".")); result = source.substring(0, source.indexOf("."));
// //
return result; return result;
} }
} }

View file

@ -31,247 +31,247 @@ import fr.devinsy.strings.StringSet;
*/ */
public class PathPropertySet public class PathPropertySet
{ {
private static final Logger logger = LoggerFactory.getLogger(PathPropertySet.class); private static final Logger logger = LoggerFactory.getLogger(PathPropertySet.class);
private Hashtable<String, String> data; private Hashtable<String, String> data;
/** /**
* Instantiates a new path properties. * Instantiates a new path properties.
* *
* @throws StatoolInfosException * @throws StatoolInfosException
* the statool infos exception * the statool infos exception
*/ */
public PathPropertySet() public PathPropertySet()
{ {
this.data = new Hashtable<String, String>(); this.data = new Hashtable<String, String>();
} }
/** /**
* Instantiates a new path properties. * Instantiates a new path properties.
* *
* @param initialCapacity * @param initialCapacity
* the initial capacity * the initial capacity
* @throws StatoolInfosException * @throws StatoolInfosException
* the statool infos exception * the statool infos exception
*/ */
public PathPropertySet(final int initialCapacity) public PathPropertySet(final int initialCapacity)
{ {
this.data = new Hashtable<String, String>(initialCapacity); this.data = new Hashtable<String, String>(initialCapacity);
} }
/** /**
* Instantiates a new path properties. * Instantiates a new path properties.
* *
* @param source * @param source
* the source * the source
*/ */
public PathPropertySet(final PathPropertySet source) public PathPropertySet(final PathPropertySet source)
{ {
this.data = new Hashtable<String, String>(source.size()); this.data = new Hashtable<String, String>(source.size());
for (String path : source.getPaths()) for (String path : source.getPaths())
{ {
this.data.put(path, source.get(path)); this.data.put(path, source.get(path));
} }
} }
/** /**
* Adds the. * Adds the.
* *
* @param key * @param key
* the key * the key
* @param value * @param value
* the value * the value
*/ */
public void add(final String key, final String value) public void add(final String key, final String value)
{ {
this.data.put(key, value); this.data.put(key, value);
} }
/** /**
* Gets the. * Gets the.
* *
* @param path * @param path
* the path * the path
* @return the string * @return the string
*/ */
public String get(final String path) public String get(final String path)
{ {
String result; String result;
result = this.data.get(path); result = this.data.get(path);
// //
return result; return result;
} }
/** /**
* Gets the keys. * Gets the keys.
* *
* @return the keys * @return the keys
*/ */
public StringList getPaths() public StringList getPaths()
{ {
StringList result; StringList result;
result = new StringList(); result = new StringList();
for (Object key : this.data.keySet()) for (Object key : this.data.keySet())
{ {
result.add((String) key); result.add((String) key);
} }
// //
return result; return result;
} }
/** /**
* Gets the prefixes. * Gets the prefixes.
* *
* @return the prefixes * @return the prefixes
*/ */
public StringSet getPrefixes() public StringSet getPrefixes()
{ {
StringSet result; StringSet result;
result = new StringSet(); result = new StringSet();
for (Object key : this.data.keySet()) for (Object key : this.data.keySet())
{ {
result.add(getPrefix((String) key)); result.add(getPrefix((String) key));
} }
// //
return result; return result;
} }
/** /**
* Gets the prefix list. * Gets the prefix list.
* *
* @return the prefix list * @return the prefix list
*/ */
public StringList getPrefixList() public StringList getPrefixList()
{ {
StringList result; StringList result;
result = new StringList(); result = new StringList();
for (Object key : this.data.keySet()) for (Object key : this.data.keySet())
{ {
result.add(getPrefix((String) key)); result.add(getPrefix((String) key));
} }
// //
return result; return result;
} }
/** /**
* Put. * Put.
* *
* @param key * @param key
* the key * the key
* @param value * @param value
* the value * the value
*/ */
public void put(final String key, final String value) public void put(final String key, final String value)
{ {
this.data.put(key, value); this.data.put(key, value);
} }
/** /**
* Delete path. * Delete path.
* *
* @param path * @param path
* the path * the path
*/ */
public String removePath(final String path) public String removePath(final String path)
{ {
String result; String result;
result = this.data.remove(path); result = this.data.remove(path);
// //
return result; return result;
} }
/** /**
* Size. * Size.
* *
* @return the int * @return the int
*/ */
public int size() public int size()
{ {
int result; int result;
result = this.data.size(); result = this.data.size();
// //
return result; return result;
} }
/** /**
* To string list. * To string list.
* *
* @return the string list * @return the string list
*/ */
public StringList toStringList() public StringList toStringList()
{ {
StringList result; StringList result;
result = new StringList(); result = new StringList();
for (String path : getPaths()) for (String path : getPaths())
{ {
String value = get(path); String value = get(path);
result.add(path + "=" + value); result.add(path + "=" + value);
} }
// //
return result; return result;
} }
/** /**
* To string list formatted. * To string list formatted.
* *
* @return the string list * @return the string list
*/ */
public StringList toStringListFormatted() public StringList toStringListFormatted()
{ {
StringList result; StringList result;
result = new StringList(); result = new StringList();
StringList lines = toStringList(); StringList lines = toStringList();
StringList prefixes = getPrefixList(); StringList prefixes = getPrefixList();
// sort prefixes. // sort prefixes.
for (String prefix : prefixes) for (String prefix : prefixes)
{ {
result.add("# [" + prefix + "]"); result.add("# [" + prefix + "]");
StringList sectionLines = lines.filter("^" + prefix + "\\..*"); StringList sectionLines = lines.filter("^" + prefix + "\\..*");
result.addAll(sectionLines); result.addAll(sectionLines);
result.add(""); result.add("");
} }
// //
return result; return result;
} }
/** /**
* Gets the prefix. * Gets the prefix.
* *
* @param source * @param source
* the source * the source
* @return the prefix * @return the prefix
*/ */
private static String getPrefix(final String source) private static String getPrefix(final String source)
{ {
String result; String result;
result = source.substring(source.indexOf(".")); result = source.substring(source.indexOf("."));
// //
return result; return result;
} }
} }

View file

@ -25,48 +25,48 @@ package fr.devinsy.statoolinfos.core;
*/ */
public class StatoolInfosException extends Exception public class StatoolInfosException extends Exception
{ {
private static final long serialVersionUID = 8323299610751708972L; private static final long serialVersionUID = 8323299610751708972L;
/** /**
* Instantiates a new Juga exception. * Instantiates a new Juga exception.
*/ */
public StatoolInfosException() public StatoolInfosException()
{ {
super(); super();
} }
/** /**
* Instantiates a new Juga exception. * Instantiates a new Juga exception.
* *
* @param message * @param message
* the message * the message
*/ */
public StatoolInfosException(final String message) public StatoolInfosException(final String message)
{ {
super(message); super(message);
} }
/** /**
* Instantiates a new Juga exception. * Instantiates a new Juga exception.
* *
* @param message * @param message
* the message * the message
* @param cause * @param cause
* the cause * the cause
*/ */
public StatoolInfosException(final String message, final Throwable cause) public StatoolInfosException(final String message, final Throwable cause)
{ {
super(message, cause); super(message, cause);
} }
/** /**
* Instantiates a new Juga exception. * Instantiates a new Juga exception.
* *
* @param cause * @param cause
* the cause * the cause
*/ */
public StatoolInfosException(final Throwable cause) public StatoolInfosException(final Throwable cause)
{ {
super(cause); super(cause);
} }
} }

View file

@ -37,236 +37,236 @@ import fr.devinsy.statoolinfos.core.StatoolInfosException;
*/ */
public final class SQLUtils public final class SQLUtils
{ {
private static Logger logger = LoggerFactory.getLogger(SQLUtils.class); private static Logger logger = LoggerFactory.getLogger(SQLUtils.class);
/** /**
* Instantiates a new SQL utils. * Instantiates a new SQL utils.
*/ */
private SQLUtils() private SQLUtils()
{ {
} }
/** /**
* Close quietly. * Close quietly.
* *
* @param connection * @param connection
* the connection * the connection
*/ */
public static void closeQuietly(final Connection connection) public static void closeQuietly(final Connection connection)
{ {
if (connection != null) if (connection != null)
{ {
try try
{ {
connection.close(); connection.close();
} }
catch (SQLException exception) catch (SQLException exception)
{ {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
} }
/** /**
* Close quietly. * Close quietly.
* *
* @param connection * @param connection
* the connection * the connection
* @param statement * @param statement
* the statement * the statement
* @param resultSet * @param resultSet
* the result set * the result set
*/ */
public static void closeQuietly(final Connection connection, final Statement statement, final ResultSet resultSet) public static void closeQuietly(final Connection connection, final Statement statement, final ResultSet resultSet)
{ {
// //
if (connection != null) if (connection != null)
{ {
try try
{ {
connection.close(); connection.close();
} }
catch (SQLException exception) catch (SQLException exception)
{ {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
// //
if (statement != null) if (statement != null)
{ {
try try
{ {
statement.close(); statement.close();
} }
catch (SQLException exception) catch (SQLException exception)
{ {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
// //
if (resultSet != null) if (resultSet != null)
{ {
try try
{ {
resultSet.close(); resultSet.close();
} }
catch (SQLException exception) catch (SQLException exception)
{ {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
} }
/** /**
* Close quietly. * Close quietly.
* *
* @param statement * @param statement
* the statement * the statement
* @param resultSet * @param resultSet
* the result set * the result set
*/ */
public static void closeQuietly(final Statement statement, final ResultSet resultSet) public static void closeQuietly(final Statement statement, final ResultSet resultSet)
{ {
// //
if (statement != null) if (statement != null)
{ {
try try
{ {
statement.close(); statement.close();
} }
catch (SQLException exception) catch (SQLException exception)
{ {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
// //
if (resultSet != null) if (resultSet != null)
{ {
try try
{ {
resultSet.close(); resultSet.close();
} }
catch (SQLException exception) catch (SQLException exception)
{ {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
} }
/** /**
* Gets the connexion. * Gets the connexion.
* *
* @param serverUrl * @param serverUrl
* the server url * the server url
* @param databaseName * @param databaseName
* the database name * the database name
* @param login * @param login
* the login * the login
* @param password * @param password
* the password * the password
* @return the connexion * @return the connexion
* @throws StatoolInfosException * @throws StatoolInfosException
* the agir statool exception * the agir statool exception
*/ */
public static Connection getConnexion(final String serverUrl, final String databaseName, final String login, final String password) throws StatoolInfosException public static Connection getConnexion(final String serverUrl, final String databaseName, final String login, final String password) throws StatoolInfosException
{ {
Connection result; Connection result;
try try
{ {
if (StringUtils.isBlank(serverUrl)) if (StringUtils.isBlank(serverUrl))
{ {
throw new IllegalArgumentException("Undefined server URL."); throw new IllegalArgumentException("Undefined server URL.");
} }
else if (StringUtils.isBlank(databaseName)) else if (StringUtils.isBlank(databaseName))
{ {
throw new IllegalArgumentException("Undefined database name."); throw new IllegalArgumentException("Undefined database name.");
} }
else if (StringUtils.isBlank(login)) else if (StringUtils.isBlank(login))
{ {
throw new IllegalArgumentException("Undefined database login."); throw new IllegalArgumentException("Undefined database login.");
} }
else else
{ {
Class.forName("com.mysql.jdbc.Driver").newInstance(); Class.forName("com.mysql.jdbc.Driver").newInstance();
result = DriverManager.getConnection(serverUrl + databaseName + "?useUnicode=true&amp;amp;characterEncoding=utf8", login, password); result = DriverManager.getConnection(serverUrl + databaseName + "?useUnicode=true&amp;amp;characterEncoding=utf8", login, password);
} }
} }
catch (SQLException exception) catch (SQLException exception)
{ {
throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception); throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception);
} }
catch (InstantiationException exception) catch (InstantiationException exception)
{ {
throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception); throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception);
} }
catch (IllegalAccessException exception) catch (IllegalAccessException exception)
{ {
throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception); throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception);
} }
catch (ClassNotFoundException exception) catch (ClassNotFoundException exception)
{ {
throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception); throw new StatoolInfosException("Database connection failed: " + exception.getMessage(), exception);
} }
// //
return result; return result;
} }
/** /**
* Gets the nullable long. * Gets the nullable long.
* *
* @param resultSet * @param resultSet
* the result set * the result set
* @param index * @param index
* the index * the index
* @return the nullable long * @return the nullable long
* @throws SQLException * @throws SQLException
* the SQL exception * the SQL exception
*/ */
public static Long getNullableLong(final ResultSet resultSet, final int index) throws SQLException public static Long getNullableLong(final ResultSet resultSet, final int index) throws SQLException
{ {
Long result; Long result;
if (resultSet.getObject(index) == null) if (resultSet.getObject(index) == null)
{ {
result = null; result = null;
} }
else else
{ {
result = resultSet.getLong(index); result = resultSet.getLong(index);
} }
// //
return result; return result;
} }
/** /**
* To date time. * To date time.
* *
* @param source * @param source
* the source * the source
* @return the local date time * @return the local date time
*/ */
public static LocalDateTime toLocalDateTime(final java.sql.Timestamp source) public static LocalDateTime toLocalDateTime(final java.sql.Timestamp source)
{ {
LocalDateTime result; LocalDateTime result;
if (source == null) if (source == null)
{ {
result = null; result = null;
} }
else else
{ {
long seconds = source.getTime() / 1000; long seconds = source.getTime() / 1000;
long nanos = (source.getTime() - seconds * 1000) * 1000000; long nanos = (source.getTime() - seconds * 1000) * 1000000;
result = LocalDateTime.ofEpochSecond(seconds, (int) nanos, ZoneOffset.UTC); result = LocalDateTime.ofEpochSecond(seconds, (int) nanos, ZoneOffset.UTC);
} }
// //
return result; return result;
} }
} }