mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
no effective change - format only
This commit is contained in:
@@ -4,19 +4,19 @@ package com.avaje.ebeaninternal.server.text.csv;
|
||||
// rbygrave: Made some Java Generics tweaks to remove warnings
|
||||
|
||||
/**
|
||||
Copyright 2005 Bytecode Pty Ltd.
|
||||
|
||||
Licensed 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.
|
||||
* Copyright 2005 Bytecode Pty Ltd.
|
||||
* <p>
|
||||
* Licensed 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
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -27,223 +27,222 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Glen Smith's CSV reader released under Apache License version 2.
|
||||
*
|
||||
*
|
||||
* @author Glen Smith
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class CsvUtilReader {
|
||||
|
||||
private final BufferedReader br;
|
||||
private final BufferedReader br;
|
||||
|
||||
private boolean hasNext = true;
|
||||
private boolean hasNext = true;
|
||||
|
||||
private final char separator;
|
||||
private final char separator;
|
||||
|
||||
private final char quotechar;
|
||||
|
||||
private final int skipLines;
|
||||
private final char quotechar;
|
||||
|
||||
private boolean linesSkiped;
|
||||
private final int skipLines;
|
||||
|
||||
/** The default separator to use if none is supplied to the constructor. */
|
||||
public static final char DEFAULT_SEPARATOR = ',';
|
||||
private boolean linesSkiped;
|
||||
|
||||
/**
|
||||
* The default quote character to use if none is supplied to the
|
||||
* constructor.
|
||||
*/
|
||||
public static final char DEFAULT_QUOTE_CHARACTER = '"';
|
||||
|
||||
/**
|
||||
* The default line to start reading.
|
||||
*/
|
||||
public static final int DEFAULT_SKIP_LINES = 0;
|
||||
/** The default separator to use if none is supplied to the constructor. */
|
||||
public static final char DEFAULT_SEPARATOR = ',';
|
||||
|
||||
/**
|
||||
* Constructs CSVReader using a comma for the separator.
|
||||
*
|
||||
* @param reader
|
||||
* the reader to an underlying CSV source.
|
||||
*/
|
||||
public CsvUtilReader(Reader reader) {
|
||||
this(reader, DEFAULT_SEPARATOR);
|
||||
/**
|
||||
* The default quote character to use if none is supplied to the
|
||||
* constructor.
|
||||
*/
|
||||
public static final char DEFAULT_QUOTE_CHARACTER = '"';
|
||||
|
||||
/**
|
||||
* The default line to start reading.
|
||||
*/
|
||||
public static final int DEFAULT_SKIP_LINES = 0;
|
||||
|
||||
/**
|
||||
* Constructs CSVReader using a comma for the separator.
|
||||
*
|
||||
* @param reader
|
||||
* the reader to an underlying CSV source.
|
||||
*/
|
||||
public CsvUtilReader(Reader reader) {
|
||||
this(reader, DEFAULT_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs CSVReader with supplied separator.
|
||||
*
|
||||
* @param reader
|
||||
* the reader to an underlying CSV source.
|
||||
* @param separator
|
||||
* the delimiter to use for separating entries.
|
||||
*/
|
||||
public CsvUtilReader(Reader reader, char separator) {
|
||||
this(reader, separator, DEFAULT_QUOTE_CHARACTER);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs CSVReader with supplied separator and quote char.
|
||||
*
|
||||
* @param reader
|
||||
* the reader to an underlying CSV source.
|
||||
* @param separator
|
||||
* the delimiter to use for separating entries
|
||||
* @param quotechar
|
||||
* the character to use for quoted elements
|
||||
*/
|
||||
public CsvUtilReader(Reader reader, char separator, char quotechar) {
|
||||
this(reader, separator, quotechar, DEFAULT_SKIP_LINES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs CSVReader with supplied separator and quote char.
|
||||
*
|
||||
* @param reader
|
||||
* the reader to an underlying CSV source.
|
||||
* @param separator
|
||||
* the delimiter to use for separating entries
|
||||
* @param quotechar
|
||||
* the character to use for quoted elements
|
||||
* @param line
|
||||
* the line number to skip for start reading
|
||||
*/
|
||||
public CsvUtilReader(Reader reader, char separator, char quotechar, int line) {
|
||||
this.br = new BufferedReader(reader);
|
||||
this.separator = separator;
|
||||
this.quotechar = quotechar;
|
||||
this.skipLines = line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the entire file into a List with each element being a String[] of
|
||||
* tokens.
|
||||
*
|
||||
* @return a List of String[], with each String[] representing a line of the
|
||||
* file.
|
||||
*
|
||||
* @throws IOException
|
||||
* if bad things happen during the read
|
||||
*/
|
||||
public List<String[]> readAll() throws IOException {
|
||||
|
||||
List<String[]> allElements = new ArrayList<>();
|
||||
while (hasNext) {
|
||||
String[] nextLineAsTokens = readNext();
|
||||
if (nextLineAsTokens != null)
|
||||
allElements.add(nextLineAsTokens);
|
||||
}
|
||||
return allElements;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next line from the buffer and converts to a string array.
|
||||
*
|
||||
* @return a string array with each comma-separated element as a separate
|
||||
* entry.
|
||||
*
|
||||
* @throws IOException
|
||||
* if bad things happen during the read
|
||||
*/
|
||||
public String[] readNext() throws IOException {
|
||||
|
||||
String nextLine = getNextLine();
|
||||
return hasNext ? parseLine(nextLine) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next line from the file.
|
||||
*
|
||||
* @return the next line from the file without trailing newline
|
||||
* @throws IOException
|
||||
* if bad things happen during the read
|
||||
*/
|
||||
private String getNextLine() throws IOException {
|
||||
if (!this.linesSkiped) {
|
||||
for (int i = 0; i < skipLines; i++) {
|
||||
br.readLine();
|
||||
}
|
||||
this.linesSkiped = true;
|
||||
}
|
||||
String nextLine = br.readLine();
|
||||
if (nextLine == null) {
|
||||
hasNext = false;
|
||||
}
|
||||
return hasNext ? nextLine : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an incoming String and returns an array of elements.
|
||||
*
|
||||
* @param nextLine
|
||||
* the string to parse
|
||||
* @return the comma-tokenized list of elements, or null if nextLine is null
|
||||
* @throws IOException if bad things happen during the read
|
||||
*/
|
||||
private String[] parseLine(String nextLine) throws IOException {
|
||||
|
||||
if (nextLine == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs CSVReader with supplied separator.
|
||||
*
|
||||
* @param reader
|
||||
* the reader to an underlying CSV source.
|
||||
* @param separator
|
||||
* the delimiter to use for separating entries.
|
||||
*/
|
||||
public CsvUtilReader(Reader reader, char separator) {
|
||||
this(reader, separator, DEFAULT_QUOTE_CHARACTER);
|
||||
}
|
||||
|
||||
|
||||
List<String> tokensOnThisLine = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructs CSVReader with supplied separator and quote char.
|
||||
*
|
||||
* @param reader
|
||||
* the reader to an underlying CSV source.
|
||||
* @param separator
|
||||
* the delimiter to use for separating entries
|
||||
* @param quotechar
|
||||
* the character to use for quoted elements
|
||||
*/
|
||||
public CsvUtilReader(Reader reader, char separator, char quotechar) {
|
||||
this(reader, separator, quotechar, DEFAULT_SKIP_LINES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs CSVReader with supplied separator and quote char.
|
||||
*
|
||||
* @param reader
|
||||
* the reader to an underlying CSV source.
|
||||
* @param separator
|
||||
* the delimiter to use for separating entries
|
||||
* @param quotechar
|
||||
* the character to use for quoted elements
|
||||
* @param line
|
||||
* the line number to skip for start reading
|
||||
*/
|
||||
public CsvUtilReader(Reader reader, char separator, char quotechar, int line) {
|
||||
this.br = new BufferedReader(reader);
|
||||
this.separator = separator;
|
||||
this.quotechar = quotechar;
|
||||
this.skipLines = line;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean inQuotes = false;
|
||||
do {
|
||||
if (inQuotes) {
|
||||
// continuing a quoted section, reappend newline
|
||||
sb.append("\n");
|
||||
nextLine = getNextLine();
|
||||
if (nextLine == null)
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < nextLine.length(); i++) {
|
||||
|
||||
/**
|
||||
* Reads the entire file into a List with each element being a String[] of
|
||||
* tokens.
|
||||
*
|
||||
* @return a List of String[], with each String[] representing a line of the
|
||||
* file.
|
||||
*
|
||||
* @throws IOException
|
||||
* if bad things happen during the read
|
||||
*/
|
||||
public List<String[]> readAll() throws IOException {
|
||||
|
||||
List<String[]> allElements = new ArrayList<>();
|
||||
while (hasNext) {
|
||||
String[] nextLineAsTokens = readNext();
|
||||
if (nextLineAsTokens != null)
|
||||
allElements.add(nextLineAsTokens);
|
||||
}
|
||||
return allElements;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next line from the buffer and converts to a string array.
|
||||
*
|
||||
* @return a string array with each comma-separated element as a separate
|
||||
* entry.
|
||||
*
|
||||
* @throws IOException
|
||||
* if bad things happen during the read
|
||||
*/
|
||||
public String[] readNext() throws IOException {
|
||||
|
||||
String nextLine = getNextLine();
|
||||
return hasNext ? parseLine(nextLine) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next line from the file.
|
||||
*
|
||||
* @return the next line from the file without trailing newline
|
||||
* @throws IOException
|
||||
* if bad things happen during the read
|
||||
*/
|
||||
private String getNextLine() throws IOException {
|
||||
if (!this.linesSkiped) {
|
||||
for (int i = 0; i < skipLines; i++) {
|
||||
br.readLine();
|
||||
char c = nextLine.charAt(i);
|
||||
if (c == quotechar) {
|
||||
// this gets complex... the quote may end a quoted block, or escape another quote.
|
||||
// do a 1-char lookahead:
|
||||
if (inQuotes // we are in quotes, therefore there can be escaped quotes in here.
|
||||
&& nextLine.length() > (i + 1) // there is indeed another character to check.
|
||||
&& nextLine.charAt(i + 1) == quotechar) { // ..and that char. is a quote also.
|
||||
// we have two quote chars in a row == one quote char, so consume them both and
|
||||
// put one on the token. we do *not* exit the quoted text.
|
||||
sb.append(nextLine.charAt(i + 1));
|
||||
i++;
|
||||
} else {
|
||||
inQuotes = !inQuotes;
|
||||
// the tricky case of an embedded quote in the middle: a,bc"d"ef,g
|
||||
if (i > 2 //not on the begining of the line
|
||||
&& nextLine.charAt(i - 1) != this.separator //not at the begining of an escape sequence
|
||||
&& nextLine.length() > (i + 1) &&
|
||||
nextLine.charAt(i + 1) != this.separator //not at the end of an escape sequence
|
||||
) {
|
||||
sb.append(c);
|
||||
}
|
||||
this.linesSkiped = true;
|
||||
}
|
||||
} else if (c == separator && !inQuotes) {
|
||||
tokensOnThisLine.add(sb.toString().trim());
|
||||
sb = new StringBuilder(); // start work on next token
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
String nextLine = br.readLine();
|
||||
if (nextLine == null) {
|
||||
hasNext = false;
|
||||
}
|
||||
return hasNext ? nextLine : null;
|
||||
}
|
||||
}
|
||||
} while (inQuotes);
|
||||
tokensOnThisLine.add(sb.toString().trim());
|
||||
return tokensOnThisLine.toArray(new String[tokensOnThisLine.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an incoming String and returns an array of elements.
|
||||
*
|
||||
* @param nextLine
|
||||
* the string to parse
|
||||
* @return the comma-tokenized list of elements, or null if nextLine is null
|
||||
* @throws IOException if bad things happen during the read
|
||||
*/
|
||||
private String[] parseLine(String nextLine) throws IOException {
|
||||
/**
|
||||
* Closes the underlying reader.
|
||||
*
|
||||
* @throws IOException if the close fails
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
br.close();
|
||||
}
|
||||
|
||||
if (nextLine == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> tokensOnThisLine = new ArrayList<>();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean inQuotes = false;
|
||||
do {
|
||||
if (inQuotes) {
|
||||
// continuing a quoted section, reappend newline
|
||||
sb.append("\n");
|
||||
nextLine = getNextLine();
|
||||
if (nextLine == null)
|
||||
break;
|
||||
}
|
||||
for (int i = 0; i < nextLine.length(); i++) {
|
||||
|
||||
char c = nextLine.charAt(i);
|
||||
if (c == quotechar) {
|
||||
// this gets complex... the quote may end a quoted block, or escape another quote.
|
||||
// do a 1-char lookahead:
|
||||
if( inQuotes // we are in quotes, therefore there can be escaped quotes in here.
|
||||
&& nextLine.length() > (i+1) // there is indeed another character to check.
|
||||
&& nextLine.charAt(i+1) == quotechar ){ // ..and that char. is a quote also.
|
||||
// we have two quote chars in a row == one quote char, so consume them both and
|
||||
// put one on the token. we do *not* exit the quoted text.
|
||||
sb.append(nextLine.charAt(i+1));
|
||||
i++;
|
||||
}else{
|
||||
inQuotes = !inQuotes;
|
||||
// the tricky case of an embedded quote in the middle: a,bc"d"ef,g
|
||||
if(i>2 //not on the begining of the line
|
||||
&& nextLine.charAt(i-1) != this.separator //not at the begining of an escape sequence
|
||||
&& nextLine.length()>(i+1) &&
|
||||
nextLine.charAt(i+1) != this.separator //not at the end of an escape sequence
|
||||
){
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
} else if (c == separator && !inQuotes) {
|
||||
tokensOnThisLine.add(sb.toString().trim());
|
||||
sb = new StringBuilder(); // start work on next token
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
} while (inQuotes);
|
||||
tokensOnThisLine.add(sb.toString().trim());
|
||||
return tokensOnThisLine.toArray(new String[tokensOnThisLine.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the underlying reader.
|
||||
*
|
||||
* @throws IOException if the close fails
|
||||
*/
|
||||
public void close() throws IOException{
|
||||
br.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
package com.avaje.ebeaninternal.server.text.csv;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.sql.Types;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.plugin.ExpressionPath;
|
||||
@@ -24,200 +13,211 @@ import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.sql.Types;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Implementation of the CsvReader
|
||||
*/
|
||||
public class TCsvReader<T> implements CsvReader<T> {
|
||||
|
||||
private static final TimeStringParser TIME_PARSER = new TimeStringParser();
|
||||
private static final TimeStringParser TIME_PARSER = new TimeStringParser();
|
||||
|
||||
private final EbeanServer server;
|
||||
private final EbeanServer server;
|
||||
|
||||
private final BeanDescriptor<T> descriptor;
|
||||
private final BeanDescriptor<T> descriptor;
|
||||
|
||||
private final List<CsvColumn> columnList = new ArrayList<>();
|
||||
private final List<CsvColumn> columnList = new ArrayList<>();
|
||||
|
||||
private final CsvColumn ignoreColumn = new CsvColumn();
|
||||
private final CsvColumn ignoreColumn = new CsvColumn();
|
||||
|
||||
private boolean hasHeader;
|
||||
private boolean hasHeader;
|
||||
|
||||
private int logInfoFrequency = 1000;
|
||||
private int logInfoFrequency = 1000;
|
||||
|
||||
private String defaultTimeFormat = "HH:mm:ss";
|
||||
private String defaultDateFormat = "yyyy-MM-dd";
|
||||
private String defaultTimestampFormat = "yyyy-MM-dd hh:mm:ss.fffffffff";
|
||||
private Locale defaultLocale = Locale.getDefault();
|
||||
private String defaultTimeFormat = "HH:mm:ss";
|
||||
private String defaultDateFormat = "yyyy-MM-dd";
|
||||
private String defaultTimestampFormat = "yyyy-MM-dd hh:mm:ss.fffffffff";
|
||||
private Locale defaultLocale = Locale.getDefault();
|
||||
|
||||
/**
|
||||
* The batch size used for JDBC statement batching.
|
||||
*/
|
||||
protected int persistBatchSize = 30;
|
||||
/**
|
||||
* The batch size used for JDBC statement batching.
|
||||
*/
|
||||
protected int persistBatchSize = 30;
|
||||
|
||||
private boolean addPropertiesFromHeader;
|
||||
private boolean addPropertiesFromHeader;
|
||||
|
||||
public TCsvReader(EbeanServer server, BeanDescriptor<T> descriptor) {
|
||||
this.server = server;
|
||||
this.descriptor = descriptor;
|
||||
}
|
||||
public TCsvReader(EbeanServer server, BeanDescriptor<T> descriptor) {
|
||||
this.server = server;
|
||||
this.descriptor = descriptor;
|
||||
}
|
||||
|
||||
public void setDefaultLocale(Locale defaultLocale) {
|
||||
this.defaultLocale = defaultLocale;
|
||||
}
|
||||
public void setDefaultLocale(Locale defaultLocale) {
|
||||
this.defaultLocale = defaultLocale;
|
||||
}
|
||||
|
||||
public void setDefaultTimeFormat(String defaultTimeFormat) {
|
||||
this.defaultTimeFormat = defaultTimeFormat;
|
||||
}
|
||||
public void setDefaultTimeFormat(String defaultTimeFormat) {
|
||||
this.defaultTimeFormat = defaultTimeFormat;
|
||||
}
|
||||
|
||||
public void setDefaultDateFormat(String defaultDateFormat) {
|
||||
this.defaultDateFormat = defaultDateFormat;
|
||||
}
|
||||
public void setDefaultDateFormat(String defaultDateFormat) {
|
||||
this.defaultDateFormat = defaultDateFormat;
|
||||
}
|
||||
|
||||
public void setDefaultTimestampFormat(String defaultTimestampFormat) {
|
||||
this.defaultTimestampFormat = defaultTimestampFormat;
|
||||
}
|
||||
public void setDefaultTimestampFormat(String defaultTimestampFormat) {
|
||||
this.defaultTimestampFormat = defaultTimestampFormat;
|
||||
}
|
||||
|
||||
public void setPersistBatchSize(int persistBatchSize) {
|
||||
this.persistBatchSize = persistBatchSize;
|
||||
}
|
||||
public void setPersistBatchSize(int persistBatchSize) {
|
||||
this.persistBatchSize = persistBatchSize;
|
||||
}
|
||||
|
||||
public void setIgnoreHeader() {
|
||||
setHasHeader(true, false);
|
||||
}
|
||||
public void setIgnoreHeader() {
|
||||
setHasHeader(true, false);
|
||||
}
|
||||
|
||||
public void setAddPropertiesFromHeader() {
|
||||
setHasHeader(true, true);
|
||||
}
|
||||
public void setAddPropertiesFromHeader() {
|
||||
setHasHeader(true, true);
|
||||
}
|
||||
|
||||
public void setHasHeader(boolean hasHeader, boolean addPropertiesFromHeader) {
|
||||
this.hasHeader = hasHeader;
|
||||
this.addPropertiesFromHeader = addPropertiesFromHeader;
|
||||
}
|
||||
public void setHasHeader(boolean hasHeader, boolean addPropertiesFromHeader) {
|
||||
this.hasHeader = hasHeader;
|
||||
this.addPropertiesFromHeader = addPropertiesFromHeader;
|
||||
}
|
||||
|
||||
public void setLogInfoFrequency(int logInfoFrequency) {
|
||||
this.logInfoFrequency = logInfoFrequency;
|
||||
}
|
||||
public void setLogInfoFrequency(int logInfoFrequency) {
|
||||
this.logInfoFrequency = logInfoFrequency;
|
||||
}
|
||||
|
||||
public void addIgnore() {
|
||||
columnList.add(ignoreColumn);
|
||||
}
|
||||
public void addIgnore() {
|
||||
columnList.add(ignoreColumn);
|
||||
}
|
||||
|
||||
public void addProperty(String propertyName) {
|
||||
addProperty(propertyName, null);
|
||||
}
|
||||
public void addProperty(String propertyName) {
|
||||
addProperty(propertyName, null);
|
||||
}
|
||||
|
||||
public void addDateTime(String propertyName, String dateTimeFormat) {
|
||||
addDateTime(propertyName, dateTimeFormat, Locale.getDefault());
|
||||
}
|
||||
public void addDateTime(String propertyName, String dateTimeFormat) {
|
||||
addDateTime(propertyName, dateTimeFormat, Locale.getDefault());
|
||||
}
|
||||
|
||||
public void addDateTime(String propertyName, String dateTimeFormat, Locale locale) {
|
||||
public void addDateTime(String propertyName, String dateTimeFormat, Locale locale) {
|
||||
|
||||
ExpressionPath elProp = descriptor.getExpressionPath(propertyName);
|
||||
if (!elProp.isDateTimeCapable()) {
|
||||
throw new TextException("Property " + propertyName + " is not DateTime capable");
|
||||
}
|
||||
if (dateTimeFormat == null) {
|
||||
dateTimeFormat = getDefaultDateTimeFormat(elProp.getJdbcType());
|
||||
}
|
||||
ExpressionPath elProp = descriptor.getExpressionPath(propertyName);
|
||||
if (!elProp.isDateTimeCapable()) {
|
||||
throw new TextException("Property " + propertyName + " is not DateTime capable");
|
||||
}
|
||||
if (dateTimeFormat == null) {
|
||||
dateTimeFormat = getDefaultDateTimeFormat(elProp.getJdbcType());
|
||||
}
|
||||
|
||||
if (locale == null) {
|
||||
locale = defaultLocale;
|
||||
}
|
||||
if (locale == null) {
|
||||
locale = defaultLocale;
|
||||
}
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(dateTimeFormat, locale);
|
||||
DateTimeParser parser = new DateTimeParser(sdf, dateTimeFormat, elProp);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(dateTimeFormat, locale);
|
||||
DateTimeParser parser = new DateTimeParser(sdf, dateTimeFormat, elProp);
|
||||
|
||||
CsvColumn column = new CsvColumn(elProp, parser);
|
||||
columnList.add(column);
|
||||
}
|
||||
CsvColumn column = new CsvColumn(elProp, parser);
|
||||
columnList.add(column);
|
||||
}
|
||||
|
||||
private String getDefaultDateTimeFormat(int jdbcType) {
|
||||
switch (jdbcType) {
|
||||
case Types.TIME:
|
||||
return defaultTimeFormat;
|
||||
case Types.DATE:
|
||||
return defaultDateFormat;
|
||||
case Types.TIMESTAMP:
|
||||
return defaultTimestampFormat;
|
||||
private String getDefaultDateTimeFormat(int jdbcType) {
|
||||
switch (jdbcType) {
|
||||
case Types.TIME:
|
||||
return defaultTimeFormat;
|
||||
case Types.DATE:
|
||||
return defaultDateFormat;
|
||||
case Types.TIMESTAMP:
|
||||
return defaultTimestampFormat;
|
||||
|
||||
default:
|
||||
throw new RuntimeException("Expected java.sql.Types TIME,DATE or TIMESTAMP but got [" + jdbcType + "]");
|
||||
}
|
||||
}
|
||||
default:
|
||||
throw new RuntimeException("Expected java.sql.Types TIME,DATE or TIMESTAMP but got [" + jdbcType + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public void addProperty(String propertyName, StringParser parser) {
|
||||
public void addProperty(String propertyName, StringParser parser) {
|
||||
|
||||
ExpressionPath elProp = descriptor.getExpressionPath(propertyName);
|
||||
if (parser == null) {
|
||||
parser = elProp.getStringParser();
|
||||
}
|
||||
CsvColumn column = new CsvColumn(elProp, parser);
|
||||
columnList.add(column);
|
||||
}
|
||||
ExpressionPath elProp = descriptor.getExpressionPath(propertyName);
|
||||
if (parser == null) {
|
||||
parser = elProp.getStringParser();
|
||||
}
|
||||
CsvColumn column = new CsvColumn(elProp, parser);
|
||||
columnList.add(column);
|
||||
}
|
||||
|
||||
public void process(Reader reader) throws Exception {
|
||||
DefaultCsvCallback<T> callback = new DefaultCsvCallback<>(persistBatchSize, logInfoFrequency);
|
||||
process(reader, callback);
|
||||
}
|
||||
public void process(Reader reader) throws Exception {
|
||||
DefaultCsvCallback<T> callback = new DefaultCsvCallback<>(persistBatchSize, logInfoFrequency);
|
||||
process(reader, callback);
|
||||
}
|
||||
|
||||
public void process(Reader reader, CsvCallback<T> callback) throws Exception {
|
||||
public void process(Reader reader, CsvCallback<T> callback) throws Exception {
|
||||
|
||||
if (reader == null) {
|
||||
throw new NullPointerException("reader is null?");
|
||||
}
|
||||
if (callback == null) {
|
||||
throw new NullPointerException("callback is null?");
|
||||
}
|
||||
if (reader == null) {
|
||||
throw new NullPointerException("reader is null?");
|
||||
}
|
||||
if (callback == null) {
|
||||
throw new NullPointerException("callback is null?");
|
||||
}
|
||||
|
||||
CsvUtilReader utilReader = new CsvUtilReader(reader);
|
||||
CsvUtilReader utilReader = new CsvUtilReader(reader);
|
||||
|
||||
callback.begin(server);
|
||||
callback.begin(server);
|
||||
|
||||
int row = 0;
|
||||
int row = 0;
|
||||
|
||||
if (hasHeader) {
|
||||
String[] line = utilReader.readNext();
|
||||
if (addPropertiesFromHeader) {
|
||||
addPropertiesFromHeader(line);
|
||||
}
|
||||
callback.readHeader(line);
|
||||
}
|
||||
if (hasHeader) {
|
||||
String[] line = utilReader.readNext();
|
||||
if (addPropertiesFromHeader) {
|
||||
addPropertiesFromHeader(line);
|
||||
}
|
||||
callback.readHeader(line);
|
||||
}
|
||||
|
||||
try {
|
||||
do {
|
||||
++row;
|
||||
String[] line = utilReader.readNext();
|
||||
if (line == null) {
|
||||
--row;
|
||||
break;
|
||||
}
|
||||
try {
|
||||
do {
|
||||
++row;
|
||||
String[] line = utilReader.readNext();
|
||||
if (line == null) {
|
||||
--row;
|
||||
break;
|
||||
}
|
||||
|
||||
if (callback.processLine(row, line)) {
|
||||
// the line content is expected to be ok for processing
|
||||
if (line.length != columnList.size()) {
|
||||
// we have not got the expected number of columns
|
||||
String msg = "Error at line " + row + ". Expected [" + columnList.size() + "] columns "
|
||||
+ "but instead we have [" + line.length + "]. Line[" + Arrays.toString(line) + "]";
|
||||
throw new TextException(msg);
|
||||
}
|
||||
if (callback.processLine(row, line)) {
|
||||
// the line content is expected to be ok for processing
|
||||
if (line.length != columnList.size()) {
|
||||
// we have not got the expected number of columns
|
||||
String msg = "Error at line " + row + ". Expected [" + columnList.size() + "] columns "
|
||||
+ "but instead we have [" + line.length + "]. Line[" + Arrays.toString(line) + "]";
|
||||
throw new TextException(msg);
|
||||
}
|
||||
|
||||
T bean = buildBeanFromLineContent(row, line);
|
||||
T bean = buildBeanFromLineContent(row, line);
|
||||
|
||||
callback.processBean(row, line, bean);
|
||||
callback.processBean(row, line, bean);
|
||||
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
} while (true);
|
||||
|
||||
callback.end(row);
|
||||
callback.end(row);
|
||||
|
||||
} catch (Exception e) {
|
||||
// notify that an error occurred so that any
|
||||
// transaction can be rolled back if required
|
||||
callback.endWithError(row, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// notify that an error occurred so that any
|
||||
// transaction can be rolled back if required
|
||||
callback.endWithError(row, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void addPropertiesFromHeader(String[] line) {
|
||||
private void addPropertiesFromHeader(String[] line) {
|
||||
for (String aLine : line) {
|
||||
ElPropertyValue elProp = descriptor.getElGetValue(aLine);
|
||||
if (elProp == null) {
|
||||
@@ -238,106 +238,106 @@ public class TCsvReader<T> implements CsvReader<T> {
|
||||
addProperty(aLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDateTimeType(int t) {
|
||||
private boolean isDateTimeType(int t) {
|
||||
return t == Types.TIMESTAMP || t == Types.DATE || t == Types.TIME;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T buildBeanFromLineContent(int row, String[] line) {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T buildBeanFromLineContent(int row, String[] line) {
|
||||
|
||||
try {
|
||||
EntityBean entityBean = descriptor.createEntityBean();
|
||||
T bean = (T) entityBean;
|
||||
try {
|
||||
EntityBean entityBean = descriptor.createEntityBean();
|
||||
T bean = (T) entityBean;
|
||||
|
||||
int columnPos = 0;
|
||||
for (; columnPos < line.length; columnPos++) {
|
||||
convertAndSetColumn(columnPos, line[columnPos], entityBean);
|
||||
}
|
||||
int columnPos = 0;
|
||||
for (; columnPos < line.length; columnPos++) {
|
||||
convertAndSetColumn(columnPos, line[columnPos], entityBean);
|
||||
}
|
||||
|
||||
return bean;
|
||||
return bean;
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
String msg = "Error at line: " + row + " line[" + Arrays.toString(line) + "]";
|
||||
throw new RuntimeException(msg, e);
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
String msg = "Error at line: " + row + " line[" + Arrays.toString(line) + "]";
|
||||
throw new RuntimeException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void convertAndSetColumn(int columnPos, String strValue, EntityBean bean) {
|
||||
protected void convertAndSetColumn(int columnPos, String strValue, EntityBean bean) {
|
||||
|
||||
strValue = strValue.trim();
|
||||
strValue = strValue.trim();
|
||||
|
||||
if (strValue.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (strValue.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CsvColumn c = columnList.get(columnPos);
|
||||
c.convertAndSet(strValue, bean);
|
||||
}
|
||||
CsvColumn c = columnList.get(columnPos);
|
||||
c.convertAndSet(strValue, bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a column in the csv content.
|
||||
*/
|
||||
public static class CsvColumn {
|
||||
/**
|
||||
* Processes a column in the csv content.
|
||||
*/
|
||||
public static class CsvColumn {
|
||||
|
||||
private final ExpressionPath path;
|
||||
private final StringParser parser;
|
||||
private final ExpressionPath path;
|
||||
private final StringParser parser;
|
||||
|
||||
/**
|
||||
* Constructor for the IGNORE column.
|
||||
*/
|
||||
private CsvColumn() {
|
||||
this.path = null;
|
||||
this.parser = null;
|
||||
}
|
||||
/**
|
||||
* Constructor for the IGNORE column.
|
||||
*/
|
||||
private CsvColumn() {
|
||||
this.path = null;
|
||||
this.parser = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct with a property and parser.
|
||||
*/
|
||||
public CsvColumn(ExpressionPath path, StringParser parser) {
|
||||
this.path = path;
|
||||
this.parser = parser;
|
||||
}
|
||||
/**
|
||||
* Construct with a property and parser.
|
||||
*/
|
||||
public CsvColumn(ExpressionPath path, StringParser parser) {
|
||||
this.path = path;
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the string to the appropriate value and set it to the bean.
|
||||
*/
|
||||
public void convertAndSet(String strValue, EntityBean bean) {
|
||||
/**
|
||||
* Convert the string to the appropriate value and set it to the bean.
|
||||
*/
|
||||
public void convertAndSet(String strValue, EntityBean bean) {
|
||||
|
||||
if (parser != null && path != null) {
|
||||
Object value = parser.parse(strValue);
|
||||
path.pathSet(bean, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (parser != null && path != null) {
|
||||
Object value = parser.parse(strValue);
|
||||
path.pathSet(bean, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A StringParser for converting custom date/time/datetime strings into
|
||||
* appropriate java types (Date, Calendar, SQL Date, Time, Timestamp, JODA
|
||||
* etc).
|
||||
*/
|
||||
private static class DateTimeParser implements StringParser {
|
||||
/**
|
||||
* A StringParser for converting custom date/time/datetime strings into
|
||||
* appropriate java types (Date, Calendar, SQL Date, Time, Timestamp, JODA
|
||||
* etc).
|
||||
*/
|
||||
private static class DateTimeParser implements StringParser {
|
||||
|
||||
private final DateFormat dateFormat;
|
||||
private final ExpressionPath path;
|
||||
private final String format;
|
||||
private final DateFormat dateFormat;
|
||||
private final ExpressionPath path;
|
||||
private final String format;
|
||||
|
||||
DateTimeParser(DateFormat dateFormat, String format, ExpressionPath path) {
|
||||
this.dateFormat = dateFormat;
|
||||
this.path = path;
|
||||
this.format = format;
|
||||
}
|
||||
DateTimeParser(DateFormat dateFormat, String format, ExpressionPath path) {
|
||||
this.dateFormat = dateFormat;
|
||||
this.path = path;
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public Object parse(String value) {
|
||||
try {
|
||||
Date dt = dateFormat.parse(value);
|
||||
return path.parseDateTime(dt.getTime());
|
||||
public Object parse(String value) {
|
||||
try {
|
||||
Date dt = dateFormat.parse(value);
|
||||
return path.parseDateTime(dt.getTime());
|
||||
|
||||
} catch (ParseException e) {
|
||||
throw new TextException("Error parsing [" + value + "] using format[" + format + "]", e);
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
throw new TextException("Error parsing [" + value + "] using format[" + format + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.io.IOException;
|
||||
/**
|
||||
* A 'context' for reading entity beans from JSON.
|
||||
* <p>
|
||||
* This is used such that a load context and persistence context can be used to span multiple marshalling requests.
|
||||
* This is used such that a load context and persistence context can be used to span multiple marshalling requests.
|
||||
* </p>
|
||||
*/
|
||||
public class DJsonBeanReader<T> implements JsonBeanReader<T> {
|
||||
|
||||
@@ -129,7 +129,7 @@ public class DJsonContext implements JsonContext {
|
||||
@Override
|
||||
public <T> DJsonBeanReader createBeanReader(BeanType<T> beanType, JsonParser parser, JsonReadOptions options) throws JsonIOException {
|
||||
|
||||
BeanDescriptor<T> desc = (BeanDescriptor<T>)beanType;
|
||||
BeanDescriptor<T> desc = (BeanDescriptor<T>) beanType;
|
||||
ReadJson readJson = new ReadJson(desc, parser, options, determineObjectMapper(options));
|
||||
return new DJsonBeanReader<>(desc, readJson);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class DJsonScalar {
|
||||
public void write(JsonGenerator gen, Object value) throws IOException {
|
||||
|
||||
if (value instanceof String) {
|
||||
gen.writeString((String)value);
|
||||
gen.writeString((String) value);
|
||||
|
||||
} else {
|
||||
ScalarType scalarType = typeManager.getScalarType(value.getClass());
|
||||
|
||||
@@ -116,7 +116,7 @@ public class ReadJson {
|
||||
*/
|
||||
public <T> void persistenceContextPut(Object beanId, T currentBean) {
|
||||
|
||||
persistenceContextPutIfAbsent(beanId, (EntityBean)currentBean, rootDesc);
|
||||
persistenceContextPutIfAbsent(beanId, (EntityBean) currentBean, rootDesc);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ public class ReadJson {
|
||||
|
||||
Object existing = beanDesc.contextPutIfAbsent(persistenceContext, id, bean);
|
||||
if (existing != null) {
|
||||
beanDesc.merge(bean, (EntityBean)existing);
|
||||
beanDesc.merge(bean, (EntityBean) existing);
|
||||
|
||||
} else {
|
||||
if (loadContext != null) {
|
||||
@@ -156,10 +156,10 @@ public class ReadJson {
|
||||
public ObjectMapper getObjectMapper() {
|
||||
if (objectMapper == null) {
|
||||
throw new IllegalStateException(
|
||||
"Jackson ObjectMapper required but has not set. The ObjectMapper can be set on"
|
||||
+" either the ServerConfig or on JsonReadOptions.");
|
||||
"Jackson ObjectMapper required but has not set. The ObjectMapper can be set on"
|
||||
+ " either the ServerConfig or on JsonReadOptions.");
|
||||
}
|
||||
return (ObjectMapper)objectMapper;
|
||||
return (ObjectMapper) objectMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,7 +214,7 @@ public class ReadJson {
|
||||
* Typically this is used to read Transient properties where the type is unknown to Ebean.
|
||||
*/
|
||||
public Object readValueUsingObjectMapper(Class<?> propertyType) throws IOException {
|
||||
return getObjectMapper().readValue(parser, propertyType);
|
||||
return getObjectMapper().readValue(parser, propertyType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,8 +17,8 @@ import java.sql.Connection;
|
||||
public class AutoCommitTransactionManager extends TransactionManager {
|
||||
|
||||
public AutoCommitTransactionManager(boolean localL2Caching, ServerConfig serverConfig, ClusterManager clusterManager, BackgroundExecutor backgroundExecutor,
|
||||
DocStoreUpdateProcessor indexUpdateProcessor, BeanDescriptorManager descMgr) {
|
||||
|
||||
DocStoreUpdateProcessor indexUpdateProcessor, BeanDescriptorManager descMgr) {
|
||||
|
||||
super(localL2Caching, serverConfig, clusterManager, backgroundExecutor, indexUpdateProcessor, descMgr);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.transaction;
|
||||
|
||||
import com.avaje.ebean.annotation.DocStoreMode;
|
||||
import com.avaje.ebeaninternal.server.cache.CacheChangeSet;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequest;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeanservice.docstore.api.DocStoreUpdates;
|
||||
import com.avaje.ebeanservice.docstore.api.support.DocStoreDeleteEvent;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
@@ -10,10 +13,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.avaje.ebean.annotation.DocStoreMode;
|
||||
import com.avaje.ebeanservice.docstore.api.support.DocStoreDeleteEvent;
|
||||
import com.avaje.ebeanservice.docstore.api.DocStoreUpdates;
|
||||
|
||||
/**
|
||||
* Beans deleted by Id used for updating L2 Cache.
|
||||
*/
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* This only works for Postgres and H2 (and doesn't work for Oracle).
|
||||
*
|
||||
* <p>
|
||||
* Uses explicit begin statement to start the transactions.
|
||||
*/
|
||||
public class ExplicitJdbcTransaction extends JdbcTransaction {
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import java.sql.Connection;
|
||||
public class ExplicitTransactionManager extends TransactionManager {
|
||||
|
||||
public ExplicitTransactionManager(boolean localL2Caching, ServerConfig serverConfig, ClusterManager clusterManager, BackgroundExecutor backgroundExecutor,
|
||||
DocStoreUpdateProcessor indexUpdateProcessor, BeanDescriptorManager descMgr) {
|
||||
DocStoreUpdateProcessor indexUpdateProcessor, BeanDescriptorManager descMgr) {
|
||||
|
||||
super(localL2Caching, serverConfig, clusterManager, backgroundExecutor, indexUpdateProcessor, descMgr);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ import com.avaje.ebeaninternal.server.core.PersistRequest;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
|
||||
import com.avaje.ebeaninternal.server.lib.util.Str;
|
||||
import com.avaje.ebeaninternal.server.persist.BatchControl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.persistence.RollbackException;
|
||||
import java.io.IOException;
|
||||
@@ -26,8 +29,6 @@ import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* JDBC Connection based transaction.
|
||||
|
||||
@@ -151,7 +151,7 @@ public class JtaTransactionManager implements ExternalTransactionManager {
|
||||
}
|
||||
|
||||
public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
|
||||
SecurityException, IllegalStateException, SystemException {
|
||||
SecurityException, IllegalStateException, SystemException {
|
||||
}
|
||||
|
||||
public int getStatus() throws SystemException {
|
||||
|
||||
@@ -6,10 +6,10 @@ import com.avaje.ebeaninternal.api.TransactionEvent;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable.TableIUD;
|
||||
import com.avaje.ebeaninternal.server.cache.CacheChangeSet;
|
||||
import com.avaje.ebeanservice.docstore.api.DocStoreUpdates;
|
||||
import com.avaje.ebeaninternal.server.cluster.ClusterManager;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
import com.avaje.ebeanservice.docstore.api.DocStoreUpdates;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
+2
-2
@@ -67,8 +67,8 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
|
||||
public boolean isEmpty() {
|
||||
return beanPersistList.isEmpty()
|
||||
&& (tableList == null || tableList.isEmpty())
|
||||
&& (deleteByIdMap == null || deleteByIdMap.isEmpty());
|
||||
&& (tableList == null || tableList.isEmpty())
|
||||
&& (deleteByIdMap == null || deleteByIdMap.isEmpty());
|
||||
}
|
||||
|
||||
public void addBeanPersistIds(BeanPersistIds beanPersist) {
|
||||
|
||||
@@ -140,7 +140,7 @@ public final class ConvertInetAddresses {
|
||||
// The argument was malformed, i.e. not an IP string literal.
|
||||
if (addr == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("'%s' is not an IP string literal.", ipString));
|
||||
String.format("'%s' is not an IP string literal.", ipString));
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -159,8 +159,7 @@ public final class ConvertInetAddresses {
|
||||
* {@link IPAddressUtil#textToNumericFormatV4} or
|
||||
* {@link IPAddressUtil#textToNumericFormatV6}.
|
||||
*/
|
||||
throw new IllegalArgumentException(
|
||||
String.format("'%s' is extremely broken.", ipString), e);
|
||||
throw new IllegalArgumentException(String.format("'%s' is extremely broken.", ipString), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,21 @@ import java.time.YearMonth;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Currency;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@@ -330,7 +344,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
for (Object value : EnumSet.allOf(enumClass).toArray()) {
|
||||
mappedClasses.add(value.getClass());
|
||||
}
|
||||
for (Class<?> cls: mappedClasses) {
|
||||
for (Class<?> cls : mappedClasses) {
|
||||
typeMap.put(cls, scalarType);
|
||||
}
|
||||
logAdd(scalarType);
|
||||
@@ -363,8 +377,8 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
if (found == null) {
|
||||
if (type.getName().equals("org.joda.time.LocalTime")) {
|
||||
throw new IllegalStateException(
|
||||
"ScalarType of Joda LocalTime not defined. You need to set ServerConfig.jodaLocalTimeMode to"
|
||||
+ " either 'normal' or 'utc'. UTC is the old mode using UTC timezone but local time zone is now preferred as 'normal' mode.");
|
||||
"ScalarType of Joda LocalTime not defined. You need to set ServerConfig.jodaLocalTimeMode to"
|
||||
+ " either 'normal' or 'utc'. UTC is the old mode using UTC timezone but local time zone is now preferred as 'normal' mode.");
|
||||
}
|
||||
found = checkInterfaceTypes(type);
|
||||
}
|
||||
@@ -882,8 +896,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
// determine the types from generic parameter types using reflection
|
||||
Class<?>[] propParamTypes = TypeReflectHelper.getParams(prop.getClass(), CompoundTypeProperty.class);
|
||||
if (propParamTypes.length != 2) {
|
||||
throw new RuntimeException("Expecting 2 generic paramter types but got " + Arrays.toString(propParamTypes) + " for "
|
||||
+ prop.getClass());
|
||||
throw new RuntimeException("Expecting 2 generic paramter types but got " + Arrays.toString(propParamTypes) + " for " + prop.getClass());
|
||||
}
|
||||
|
||||
return propParamTypes[1];
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ImmutableMetaFactory {
|
||||
}
|
||||
|
||||
String msg = "Was unable to use reflection to find a constructor and appropriate getters for" +
|
||||
"immutable type " + cls + ". The errors while looking for the getter methods follow:";
|
||||
"immutable type " + cls + ". The errors while looking for the getter methods follow:";
|
||||
logger.error(msg);
|
||||
|
||||
for (RuntimeException runtimeException : errors) {
|
||||
@@ -48,7 +48,7 @@ public class ImmutableMetaFactory {
|
||||
}
|
||||
|
||||
msg = "Unable to use reflection to build ImmutableMeta for " + cls
|
||||
+ ". Associated Errors trying to find a constructor and getter methods have been logged";
|
||||
+ ". Associated Errors trying to find a constructor and getter methods have been logged";
|
||||
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.avaje.ebean.config.CompoundType;
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
|
||||
@SuppressWarnings({"rawtypes"})
|
||||
public class ReflectionBasedCompoundType implements CompoundType {
|
||||
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@SuppressWarnings({"rawtypes"})
|
||||
public class ReflectionBasedCompoundTypeProperty implements CompoundTypeProperty {
|
||||
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
|
||||
@SuppressWarnings({"rawtypes"})
|
||||
public class ReflectionBasedScalarTypeConverter implements ScalarTypeConverter {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ReflectionBasedScalarTypeConverter implements ScalarTypeConverter {
|
||||
return reader.invoke(beanType, NO_ARGS);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error invoking read method " + reader.getName()
|
||||
+ " on " + beanType.getClass().getName();
|
||||
+ " on " + beanType.getClass().getName();
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarTypeWrapper;
|
||||
import com.avaje.ebeaninternal.server.type.TypeManager;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ReflectionBasedTypeBuilder {
|
||||
|
||||
private final TypeManager typeManager;
|
||||
@@ -68,7 +68,7 @@ public class ReflectionBasedTypeBuilder {
|
||||
return lowerFirstChar(name.substring(3));
|
||||
}
|
||||
String msg = "Expecting method " + name + " to start with is or get "
|
||||
+ " so as to follow bean specification?";
|
||||
+ " so as to follow bean specification?";
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.avaje.ebeaninternal.server.util;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.config.EncryptKey;
|
||||
import com.avaje.ebeaninternal.api.BindParams;
|
||||
import com.avaje.ebeaninternal.api.BindParams.OrderedList;
|
||||
import com.avaje.ebeaninternal.api.BindParams.Param;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Parses the BindParams if they are using named parameters.
|
||||
* <p>
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
|
||||
<TITLE>Server side Utility objects</TITLE>
|
||||
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
|
||||
<TITLE>Server side Utility objects</TITLE>
|
||||
</HEAD>
|
||||
<Body BGCOLOR="#ffffff">
|
||||
Server side Utility objects
|
||||
|
||||
|
||||
|
||||
</Body>
|
||||
</HTML>
|
||||
</HTML>
|
||||
|
||||
Reference in New Issue
Block a user