You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by ka...@apache.org on 2013/07/19 11:33:22 UTC
[39/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/TimeComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/TimeComparator.java b/core/src/main/java/org/apache/metamodel/util/TimeComparator.java
new file mode 100644
index 0000000..5601deb
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/TimeComparator.java
@@ -0,0 +1,207 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.eobjects.metamodel.util;
+
+import java.text.DateFormat;
+import java.text.DateFormatSymbols;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.Locale;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Compares dates of various formats. Since this class has unchecked generic
+ * conversion it can compare java.util.Date, java.sql.Date, java.sql.Time,
+ * java.util.Calendar, Date-formatted strings etc.
+ */
+public final class TimeComparator implements Comparator<Object> {
+
+ private static final Logger logger = LoggerFactory.getLogger(TimeComparator.class);
+
+ private static final String[] prototypePatterns = { "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd HH:mm:ss",
+ "yyyy-MM-dd HH:mm", "HH:mm:ss.SSS", "yyyy-MM-dd", "dd-MM-yyyy", "yy-MM-dd", "MM-dd-yyyy", "HH:mm:ss",
+ "HH:mm" };
+
+ private static final Comparator<Object> _instance = new TimeComparator();
+
+ public static Comparator<Object> getComparator() {
+ return _instance;
+ }
+
+ private TimeComparator() {
+ }
+
+ public static Comparable<Object> getComparable(final Object o) {
+ final Date dt1 = toDate(o);
+ return new Comparable<Object>() {
+
+ @Override
+ public boolean equals(Object obj) {
+ return _instance.equals(obj);
+ }
+
+ public int compareTo(Object o) {
+ return _instance.compare(dt1, o);
+ }
+
+ @Override
+ public String toString() {
+ return "TimeComparable[time=" + dt1 + "]";
+ }
+ };
+ }
+
+ public int compare(final Object o1, final Object o2) {
+ if (o1 == null && o2 == null) {
+ return 0;
+ }
+ if (o1 == null) {
+ return -1;
+ }
+ if (o2 == null) {
+ return 1;
+ }
+ try {
+ Date dt1 = toDate(o1);
+ Date dt2 = toDate(o2);
+ return dt1.compareTo(dt2);
+ } catch (Exception e) {
+ logger.error("Could not compare {} and {}", o1, o2);
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static Date toDate(final Object value) {
+ Date result = null;
+ if (value == null) {
+ result = null;
+ } else if (value instanceof Date) {
+ result = (Date) value;
+ } else if (value instanceof Calendar) {
+ result = ((Calendar) value).getTime();
+ } else if (value instanceof String) {
+ result = convertFromString((String) value);
+ } else if (value instanceof Number) {
+ result = convertFromNumber((Number) value);
+ }
+
+ if (result == null) {
+ logger.warn("Could not convert '{}' to date, returning null", value);
+ }
+
+ return result;
+ }
+
+ public static boolean isTimeBased(Object o) {
+ if (o instanceof Date || o instanceof Calendar) {
+ return true;
+ }
+ return false;
+ }
+
+ private static Date convertFromString(final String value) {
+ try {
+ long longValue = Long.parseLong(value);
+ return convertFromNumber(longValue);
+ } catch (NumberFormatException e) {
+ // do nothing, proceed to dateFormat parsing
+ }
+
+ // try with Date.toString() date format first
+ try {
+ DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(Locale.US);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", dateFormatSymbols);
+ return dateFormat.parse(value);
+ } catch (ParseException e) {
+ // do noting
+ }
+
+ for (String prototypePattern : prototypePatterns) {
+ if (prototypePattern.length() == value.length()) {
+ DateFormat dateFormat;
+ try {
+ dateFormat = DateUtils.createDateFormat(prototypePattern);
+ return dateFormat.parse(value);
+ } catch (Exception e) {
+ // proceed to next formatter
+ }
+
+ if (prototypePattern.indexOf('-') != -1) {
+ // try with '.' in stead of '-'
+ try {
+ dateFormat = DateUtils.createDateFormat(prototypePattern.replaceAll("\\-", "\\."));
+ return dateFormat.parse(value);
+ } catch (Exception e) {
+ // proceed to next formatter
+ }
+
+ // try with '/' in stead of '-'
+ try {
+ dateFormat = DateUtils.createDateFormat(prototypePattern.replaceAll("\\-", "\\/"));
+ return dateFormat.parse(value);
+ } catch (Exception e) {
+ // proceed to next formatter
+ }
+ }
+ }
+
+ }
+
+ return null;
+ }
+
+ private static Date convertFromNumber(Number value) {
+ Number numberValue = (Number) value;
+ long longValue = numberValue.longValue();
+
+ String stringValue = Long.toString(longValue);
+ // test if the number is actually a format of the type yyyyMMdd
+ if (stringValue.length() == 8 && (stringValue.startsWith("1") || stringValue.startsWith("2"))) {
+ try {
+ return DateUtils.createDateFormat("yyyyMMdd").parse(stringValue);
+ } catch (Exception e) {
+ // do nothing, proceed to next method of conversion
+ }
+ }
+
+ // test if the number is actually a format of the type yyMMdd
+ if (stringValue.length() == 6) {
+ try {
+ return DateUtils.createDateFormat("yyMMdd").parse(stringValue);
+ } catch (Exception e) {
+ // do nothing, proceed to next method of conversion
+ }
+ }
+
+ if (longValue > 5000000) {
+ // this number is most probably amount of milliseconds since
+ // 1970
+ return new Date(longValue);
+ } else {
+ // this number is most probably the amount of days since
+ // 1970
+ return new Date(longValue * 1000 * 60 * 60 * 24);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/ToStringComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/ToStringComparator.java b/core/src/main/java/org/apache/metamodel/util/ToStringComparator.java
new file mode 100644
index 0000000..cfca4c5
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/ToStringComparator.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.eobjects.metamodel.util;
+
+import java.util.Comparator;
+
+/**
+ * Uses the toString method for comparison of objects
+ */
+public final class ToStringComparator implements Comparator<Object> {
+
+ private static Comparator<Object> _instance = new ToStringComparator();
+
+ public static Comparator<Object> getComparator() {
+ return _instance;
+ }
+
+ private ToStringComparator() {
+ }
+
+ public static Comparable<Object> getComparable(final Object o) {
+ final String s = o.toString();
+ return new Comparable<Object>() {
+
+ @Override
+ public boolean equals(Object obj) {
+ return _instance.equals(obj);
+ }
+
+ public int compareTo(Object o2) {
+ return _instance.compare(s, o2);
+ }
+
+ @Override
+ public String toString() {
+ return "ToStringComparable[string=" + s + "]";
+ }
+ };
+ }
+
+ public int compare(Object o1, Object o2) {
+ if (o1 == null && o2 == null) {
+ return -1;
+ }
+ if (o1 == null) {
+ return -1;
+ }
+ if (o2 == null) {
+ return 1;
+ }
+ return o1.toString().compareTo(o2.toString());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/TruePredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/TruePredicate.java b/core/src/main/java/org/apache/metamodel/util/TruePredicate.java
new file mode 100644
index 0000000..5def8d3
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/TruePredicate.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.eobjects.metamodel.util;
+
+import java.io.Serializable;
+
+/**
+ * A predicate that is always true
+ *
+ * @param <E>
+ */
+public final class TruePredicate<E> implements Predicate<E>, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Boolean eval(E arg) {
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return Boolean.TRUE.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj != null && obj.getClass() == TruePredicate.class;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java b/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java
new file mode 100644
index 0000000..c95f381
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/UnicodeWriter.java
@@ -0,0 +1,236 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.eobjects.metamodel.util;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+
+/**
+ * Writes Unicode text to an output stream. If the specified encoding is a
+ * Unicode, then the text is preceeded by the proper Unicode BOM. If it is any
+ * other encoding, this class behaves just like <code>OutputStreamWriter</code>.
+ * This class is here because Java's <code>OutputStreamWriter</code> apparently
+ * doesn't believe in writing BOMs.
+ * <p>
+ *
+ * For optimum performance, it is recommended that you wrap all instances of
+ * <code>UnicodeWriter</code> with a <code>java.io.BufferedWriter</code>.
+ *
+ * This file is a redistribution of Rubert Futrell from FifeSoft UnicodeWriter
+ * (also LGPL licensed).
+ *
+ * <pre>
+ * UnicodeWriter.java - Writes Unicode output with the proper BOM.
+ * Copyright (C) 2004 Robert Futrell
+ * robert_futrell at users.sourceforge.net
+ * http://fifesoft.com/rsyntaxtextarea
+ * </pre>
+ *
+ * @author Robert Futrell
+ * @version 0.7
+ */
+public class UnicodeWriter extends Writer {
+
+ public static final byte[] UTF8_BOM = new byte[] { (byte) 0xEF,
+ (byte) 0xBB, (byte) 0xBF };
+
+ public static final byte[] UTF16LE_BOM = new byte[] { (byte) 0xFF,
+ (byte) 0xFE };
+
+ public static final byte[] UTF16BE_BOM = new byte[] { (byte) 0xFE,
+ (byte) 0xFF };
+
+ public static final byte[] UTF32LE_BOM = new byte[] { (byte) 0xFF,
+ (byte) 0xFE, (byte) 0x00, (byte) 0x00 };
+
+ public static final byte[] UTF32BE_BOM = new byte[] { (byte) 0x00,
+ (byte) 0x00, (byte) 0xFE, (byte) 0xFF };
+
+ /**
+ * The writer actually doing the writing.
+ */
+ private final OutputStreamWriter writer;
+
+ /**
+ * This is a utility constructor since the vast majority of the time, this
+ * class will be used to write Unicode files.
+ *
+ * @param fileName
+ * The file to which to write the Unicode output.
+ * @param encoding
+ * The encoding to use.
+ * @throws UnsupportedEncodingException
+ * If the specified encoding is not supported.
+ * @throws IOException
+ * If an IO exception occurs.
+ */
+ public UnicodeWriter(String fileName, String encoding)
+ throws UnsupportedEncodingException, IOException {
+ this(new FileOutputStream(fileName), encoding);
+ }
+
+ /**
+ * This is a utility constructor since the vast majority of the time, this
+ * class will be used to write Unicode files.
+ *
+ * @param file
+ * The file to which to write the Unicode output.
+ * @param encoding
+ * The encoding to use.
+ * @throws UnsupportedEncodingException
+ * If the specified encoding is not supported.
+ * @throws IOException
+ * If an IO exception occurs.
+ */
+ public UnicodeWriter(File file, String encoding)
+ throws UnsupportedEncodingException, IOException {
+ this(new FileOutputStream(file), encoding);
+ }
+
+ /**
+ * Creates a new writer.
+ *
+ * @param outputStream
+ * The output stream to write.
+ * @param encoding
+ * The encoding to use.
+ * @throws UnsupportedEncodingException
+ * If the specified encoding is not supported.
+ * @throws IOException
+ * If an IO exception occurs.
+ */
+ public UnicodeWriter(OutputStream outputStream, String encoding)
+ throws UnsupportedEncodingException, IOException {
+ writer = createWriter(outputStream, encoding);
+ }
+
+ /**
+ * Closes this writer.
+ *
+ * @throws IOException
+ * If an IO exception occurs.
+ */
+ @Override
+ public void close() throws IOException {
+ writer.close();
+ }
+
+ /**
+ * Flushes the stream.
+ *
+ * @throws IOException
+ * If an IO exception occurs.
+ */
+ @Override
+ public void flush() throws IOException {
+ writer.flush();
+ }
+
+ /**
+ * Initializes the internal output stream and writes the BOM if the
+ * specified encoding is a Unicode encoding.
+ *
+ * @param outputStream
+ * The output stream we are writing.
+ * @param encoding
+ * The encoding in which to write.
+ * @throws UnsupportedEncodingException
+ * If the specified encoding isn't supported.
+ * @throws IOException
+ * If an I/O error occurs while writing a BOM.
+ */
+ private OutputStreamWriter createWriter(OutputStream outputStream,
+ String encoding) throws UnsupportedEncodingException, IOException {
+ OutputStreamWriter writer = new OutputStreamWriter(outputStream,
+ encoding);
+
+ // Write the proper BOM if they specified a Unicode encoding.
+ // NOTE: Creating an OutputStreamWriter with encoding "UTF-16"
+ // DOES write out the BOM; "UTF-16LE", "UTF-16BE", "UTF-32", "UTF-32LE"
+ // and "UTF-32BE" don't.
+ if ("UTF-8".equalsIgnoreCase(encoding)) {
+ outputStream.write(UTF8_BOM, 0, UTF8_BOM.length);
+ } else if ("UTF-16LE".equalsIgnoreCase(encoding)) {
+ outputStream.write(UTF16LE_BOM, 0, UTF16LE_BOM.length);
+ } else if (/* "UTF-16".equalsIgnoreCase(encoding) || */
+ "UTF-16BE".equalsIgnoreCase(encoding)) {
+ outputStream.write(UTF16BE_BOM, 0, UTF16BE_BOM.length);
+ } else if ("UTF-32LE".equalsIgnoreCase(encoding)) {
+ outputStream.write(UTF32LE_BOM, 0, UTF32LE_BOM.length);
+ } else if ("UTF-32".equalsIgnoreCase(encoding)
+ || "UTF-32BE".equalsIgnoreCase(encoding)) {
+ outputStream.write(UTF32BE_BOM, 0, UTF32BE_BOM.length);
+ }
+
+ return writer;
+ }
+
+ /**
+ * Writes a portion of an array of characters.
+ *
+ * @param cbuf
+ * The buffer of characters.
+ * @param off
+ * The offset from which to start writing characters.
+ * @param len
+ * The number of characters to write.
+ * @throws IOException
+ * If an I/O error occurs.
+ */
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ writer.write(cbuf, off, len);
+ }
+
+ /**
+ * Writes a single character.
+ *
+ * @param c
+ * An integer specifying the character to write.
+ * @throws IOException
+ * If an IO error occurs.
+ */
+ @Override
+ public void write(int c) throws IOException {
+ writer.write(c);
+ }
+
+ /**
+ * Writes a portion of a string.
+ *
+ * @param str
+ * The string from which to write.
+ * @param off
+ * The offset from which to start writing characters.
+ * @param len
+ * The number of characters to write.
+ * @throws IOException
+ * If an IO error occurs.
+ */
+ @Override
+ public void write(String str, int off, int len) throws IOException {
+ writer.write(str, off, len);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/UrlResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/UrlResource.java b/core/src/main/java/org/apache/metamodel/util/UrlResource.java
new file mode 100644
index 0000000..b195b95
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/UrlResource.java
@@ -0,0 +1,150 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.eobjects.metamodel.util;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+/**
+ * Resource based on URL or URI.
+ */
+public class UrlResource implements Resource, Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final URI _uri;
+
+ public UrlResource(URL url) {
+ try {
+ _uri = url.toURI();
+ } catch (URISyntaxException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public UrlResource(URI uri) {
+ _uri = uri;
+ }
+
+ public UrlResource(String urlString) {
+ try {
+ _uri = new URI(urlString);
+ } catch (URISyntaxException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "UrlResource[" + _uri + "]";
+ }
+
+ /**
+ * Gets the URI associated with this resource.
+ *
+ * @return
+ */
+ public URI getUri() {
+ return _uri;
+ }
+
+ @Override
+ public String getName() {
+ final String name = _uri.toString();
+ final int lastSlash = name.lastIndexOf('/');
+ final int lastBackSlash = name.lastIndexOf('\\');
+ final int lastIndex = Math.max(lastSlash, lastBackSlash);
+ if (lastIndex != -1) {
+ final String lastPart = name.substring(lastIndex + 1);
+ if (!"".equals(lastPart)) {
+ return lastPart;
+ }
+ }
+ return name;
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ @Override
+ public void write(Action<OutputStream> writeCallback) throws ResourceException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void append(Action<OutputStream> appendCallback) throws ResourceException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void read(Action<InputStream> readCallback) throws ResourceException {
+ final InputStream in = read();
+ try {
+ readCallback.run(in);
+ } catch (Exception e) {
+ throw new ResourceException(this, "Error occurred in read callback", e);
+ } finally {
+ FileHelper.safeClose(in);
+ }
+ }
+
+ @Override
+ public <E> E read(Func<InputStream, E> readCallback) throws ResourceException {
+ final InputStream in = read();
+ try {
+ E result = readCallback.eval(in);
+ return result;
+ } catch (Exception e) {
+ throw new ResourceException(this, "Error occurred in read callback", e);
+ } finally {
+ FileHelper.safeClose(in);
+ }
+ }
+
+ @Override
+ public boolean isExists() {
+ return true;
+ }
+
+ @Override
+ public long getSize() {
+ return -1;
+ }
+
+ @Override
+ public long getLastModified() {
+ return -1;
+ }
+
+ @Override
+ public InputStream read() throws ResourceException {
+ try {
+ return _uri.toURL().openStream();
+ } catch (Exception e) {
+ throw new ResourceException(this, "Failed to open InputStream", e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/Weekday.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/Weekday.java b/core/src/main/java/org/apache/metamodel/util/Weekday.java
new file mode 100644
index 0000000..d9ab224
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/Weekday.java
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.eobjects.metamodel.util;
+
+import java.util.Calendar;
+
+/**
+ * Provides a handy and type-safe enum around the weekdays otherwise defined as
+ * int constants in java.util.Calendar.
+ *
+ * @author Kasper Sørensen
+ */
+public enum Weekday implements HasName {
+
+ MONDAY(Calendar.MONDAY),
+
+ TUESDAY(Calendar.TUESDAY),
+
+ WEDNESDAY(Calendar.WEDNESDAY),
+
+ THURSDAY(Calendar.THURSDAY),
+
+ FRIDAY(Calendar.FRIDAY),
+
+ SATURDAY(Calendar.SATURDAY),
+
+ SUNDAY(Calendar.SUNDAY);
+
+ private int calendarConstant;
+
+ private Weekday(int calendarConstant) {
+ this.calendarConstant = calendarConstant;
+ }
+
+ public int getCalendarConstant() {
+ return calendarConstant;
+ }
+
+ public static Weekday getByCalendarConstant(int calendarConstant) {
+ for (Weekday weekday : values()) {
+ if (weekday.getCalendarConstant() == calendarConstant) {
+ return weekday;
+ }
+ }
+ return null;
+ }
+
+ public Weekday next() {
+ if (this == SUNDAY) {
+ return MONDAY;
+ }
+ return values()[ordinal() + 1];
+ }
+
+ public Weekday previous() {
+ if (this == MONDAY) {
+ return SUNDAY;
+ }
+ return values()[ordinal() - 1];
+ }
+
+ @Override
+ public String getName() {
+ final String capitalized = toString();
+ return capitalized.charAt(0) + capitalized.substring(1).toLowerCase();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java b/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java
new file mode 100644
index 0000000..36f388a
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/WildcardPattern.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.eobjects.metamodel.util;
+
+import java.io.Serializable;
+import java.util.StringTokenizer;
+
+import org.eobjects.metamodel.query.FilterItem;
+
+/**
+ * Represents a pattern with a wildcard character. These are typically used in
+ * FilterItems with the LIKE operator.
+ *
+ * @see FilterItem
+ */
+public final class WildcardPattern implements Serializable {
+
+ private static final long serialVersionUID = 857462137797209624L;
+ private String _pattern;
+ private char _wildcard;
+ private boolean _endsWithDelim;
+
+ public WildcardPattern(String pattern, char wildcard) {
+ _pattern = pattern;
+ _wildcard = wildcard;
+ _endsWithDelim = (_pattern.charAt(pattern.length() - 1) == _wildcard);
+ }
+
+ public boolean matches(String value) {
+ if (value == null) {
+ return false;
+ }
+ StringTokenizer st = new StringTokenizer(_pattern,
+ Character.toString(_wildcard));
+ int charIndex = 0;
+ while (st.hasMoreTokens()) {
+ String token = st.nextToken();
+ charIndex = value.indexOf(token, charIndex);
+ if (charIndex == -1) {
+ return false;
+ }
+ charIndex = charIndex + token.length();
+ }
+ if (!_endsWithDelim) {
+ // Unless the last char of the pattern is a wildcard, we need to
+ // have reached the end of the string
+ if (charIndex != value.length()) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/apache/metamodel/util/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/metamodel/util/package-info.java b/core/src/main/java/org/apache/metamodel/util/package-info.java
new file mode 100644
index 0000000..0423170
--- /dev/null
+++ b/core/src/main/java/org/apache/metamodel/util/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+/**
+ * Utilities and convenient classes
+ */
+package org.eobjects.metamodel.util;
+
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/AbstractDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/AbstractDataContext.java b/core/src/main/java/org/eobjects/metamodel/AbstractDataContext.java
deleted file mode 100644
index 3300e17..0000000
--- a/core/src/main/java/org/eobjects/metamodel/AbstractDataContext.java
+++ /dev/null
@@ -1,463 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.eobjects.metamodel;
-
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.DefaultCompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.builder.InitFromBuilder;
-import org.eobjects.metamodel.query.builder.InitFromBuilderImpl;
-import org.eobjects.metamodel.query.parser.QueryParser;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Abstract implementation of the DataContext interface. Provides convenient
- * implementations of all trivial and datastore-independent methods.
- *
- * @author Kasper Sørensen
- */
-public abstract class AbstractDataContext implements DataContext {
-
- private static final String NULL_SCHEMA_NAME_TOKEN = "<metamodel.schema.name.null>";
- private final ConcurrentMap<String, Schema> _schemaCache = new ConcurrentHashMap<String, Schema>();
- private final Comparator<? super String> _schemaNameComparator = SchemaNameComparator.getInstance();
- private String[] _schemaNameCache;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final DataContext refreshSchemas() {
- _schemaCache.clear();
- _schemaNameCache = null;
- return this;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final Schema[] getSchemas() throws MetaModelException {
- String[] schemaNames = getSchemaNames();
- Schema[] schemas = new Schema[schemaNames.length];
- for (int i = 0; i < schemaNames.length; i++) {
- final String name = schemaNames[i];
- final Schema schema = _schemaCache.get(getSchemaCacheKey(name));
- if (schema == null) {
- final Schema newSchema = getSchemaByName(name);
- if (newSchema == null) {
- throw new MetaModelException("Declared schema does not exist: " + name);
- }
- final Schema existingSchema = _schemaCache.putIfAbsent(getSchemaCacheKey(name), newSchema);
- if (existingSchema == null) {
- schemas[i] = newSchema;
- } else {
- schemas[i] = existingSchema;
- }
- } else {
- schemas[i] = schema;
- }
- }
- return schemas;
- }
-
- private String getSchemaCacheKey(String name) {
- if (name == null) {
- return NULL_SCHEMA_NAME_TOKEN;
- }
- return name;
- }
-
- /**
- * m {@inheritDoc}
- */
- @Override
- public final String[] getSchemaNames() throws MetaModelException {
- if (_schemaNameCache == null) {
- _schemaNameCache = getSchemaNamesInternal();
- }
- String[] schemaNames = Arrays.copyOf(_schemaNameCache, _schemaNameCache.length);
- Arrays.sort(schemaNames, _schemaNameComparator);
- return schemaNames;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final Schema getDefaultSchema() throws MetaModelException {
- Schema result = null;
- String defaultSchemaName = getDefaultSchemaName();
- if (defaultSchemaName != null) {
- result = getSchemaByName(defaultSchemaName);
- }
- if (result == null) {
- Schema[] schemas = getSchemas();
- if (schemas.length == 1) {
- result = schemas[0];
- } else {
- int highestTableCount = -1;
- for (int i = 0; i < schemas.length; i++) {
- final Schema schema = schemas[i];
- String name = schema.getName();
- if (schema != null) {
- name = name.toLowerCase();
- boolean isInformationSchema = name.startsWith("information") && name.endsWith("schema");
- if (!isInformationSchema && schema.getTableCount() > highestTableCount) {
- highestTableCount = schema.getTableCount();
- result = schema;
- }
- }
- }
- }
- }
- return result;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final InitFromBuilder query() {
- return new InitFromBuilderImpl(this);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Query parseQuery(final String queryString) throws MetaModelException {
- final QueryParser parser = new QueryParser(this, queryString);
- final Query query = parser.parse();
- return query;
- }
-
- @Override
- public CompiledQuery compileQuery(final Query query) throws MetaModelException {
- return new DefaultCompiledQuery(query);
- }
-
- @Override
- public DataSet executeQuery(CompiledQuery compiledQuery, Object... values) {
- assert compiledQuery instanceof DefaultCompiledQuery;
-
- final DefaultCompiledQuery defaultCompiledQuery = (DefaultCompiledQuery) compiledQuery;
- final Query query = defaultCompiledQuery.cloneWithParameterValues(values);
-
- return executeQuery(query);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final DataSet executeQuery(final String queryString) throws MetaModelException {
- final Query query = parseQuery(queryString);
- final DataSet dataSet = executeQuery(query);
- return dataSet;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final Schema getSchemaByName(String name) throws MetaModelException {
- Schema schema = _schemaCache.get(getSchemaCacheKey(name));
- if (schema == null) {
- if (name == null) {
- schema = getSchemaByNameInternal(null);
- } else {
- String[] schemaNames = getSchemaNames();
- for (String schemaName : schemaNames) {
- if (name.equalsIgnoreCase(schemaName)) {
- schema = getSchemaByNameInternal(name);
- break;
- }
- }
- if (schema == null) {
- for (String schemaName : schemaNames) {
- if (name.equalsIgnoreCase(schemaName)) {
- // try again with "schemaName" as param instead of
- // "name".
- schema = getSchemaByNameInternal(schemaName);
- break;
- }
- }
- }
- }
- if (schema != null) {
- Schema existingSchema = _schemaCache.putIfAbsent(getSchemaCacheKey(schema.getName()), schema);
- if (existingSchema != null) {
- // race conditions may cause two schemas to be created.
- // We'll favor the existing schema if possible, since schema
- // may contain lazy-loading logic and so on.
- return existingSchema;
- }
- }
- }
- return schema;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final Column getColumnByQualifiedLabel(final String columnName) {
- if (columnName == null) {
- return null;
- }
- Schema schema = null;
- final String[] schemaNames = getSchemaNames();
- for (final String schemaName : schemaNames) {
- if (schemaName == null) {
- // search without schema name (some databases have only a single
- // schema with no name)
- schema = getSchemaByName(null);
- if (schema != null) {
- Column column = getColumn(schema, columnName);
- if (column != null) {
- return column;
- }
- }
- } else {
- // Search case-sensitive
- Column col = searchColumn(schemaName, columnName, columnName);
- if (col != null) {
- return col;
- }
- }
- }
-
- final String columnNameInLowerCase = columnName.toLowerCase();
- for (final String schemaName : schemaNames) {
- if (schemaName != null) {
- // search case-insensitive
- String schameNameInLowerCase = schemaName.toLowerCase();
- Column col = searchColumn(schameNameInLowerCase, columnName, columnNameInLowerCase);
- if (col != null) {
- return col;
- }
- }
- }
-
- schema = getDefaultSchema();
- if (schema != null) {
- Column column = getColumn(schema, columnName);
- if (column != null) {
- return column;
- }
- }
-
- return null;
- }
-
- /**
- * Searches for a particular column within a schema
- *
- * @param schemaNameSearch
- * the schema name to use for search
- * @param columnNameOriginal
- * the original column name
- * @param columnNameSearch
- * the column name as it should be searched for (either the same
- * as original, or lower case in case of case-insensitive search)
- * @return
- */
- private Column searchColumn(String schemaNameSearch, String columnNameOriginal, String columnNameSearch) {
- if (columnNameSearch.startsWith(schemaNameSearch)) {
- Schema schema = getSchemaByName(schemaNameSearch);
- if (schema != null) {
- String tableAndColumnPath = columnNameOriginal.substring(schemaNameSearch.length());
-
- if (tableAndColumnPath.charAt(0) == '.') {
- tableAndColumnPath = tableAndColumnPath.substring(1);
-
- Column column = getColumn(schema, tableAndColumnPath);
- if (column != null) {
- return column;
- }
- }
- }
- }
- return null;
- }
-
- private final Column getColumn(final Schema schema, final String tableAndColumnPath) {
- Table table = null;
- String columnPath = tableAndColumnPath;
- final String[] tableNames = schema.getTableNames();
- for (final String tableName : tableNames) {
- if (tableName != null) {
- // search case-sensitive
- if (isStartingToken(tableName, tableAndColumnPath)) {
- table = schema.getTableByName(tableName);
- columnPath = tableAndColumnPath.substring(tableName.length());
-
- if (columnPath.charAt(0) == '.') {
- columnPath = columnPath.substring(1);
- break;
- }
- }
- }
- }
-
- if (table == null) {
- final String tableAndColumnPathInLowerCase = tableAndColumnPath.toLowerCase();
- for (final String tableName : tableNames) {
- if (tableName != null) {
- String tableNameInLowerCase = tableName.toLowerCase();
- // search case-insensitive
- if (isStartingToken(tableNameInLowerCase, tableAndColumnPathInLowerCase)) {
- table = schema.getTableByName(tableName);
- columnPath = tableAndColumnPath.substring(tableName.length());
-
- if (columnPath.charAt(0) == '.') {
- columnPath = columnPath.substring(1);
- break;
- }
- }
- }
- }
- }
-
- if (table == null && tableNames.length == 1) {
- table = schema.getTables()[0];
- }
-
- if (table != null) {
- Column column = table.getColumnByName(columnPath);
- if (column != null) {
- return column;
- }
- }
-
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final Table getTableByQualifiedLabel(final String tableName) {
- if (tableName == null) {
- return null;
- }
- Schema schema = null;
- String[] schemaNames = getSchemaNames();
- for (String schemaName : schemaNames) {
- if (schemaName == null) {
- // there's an unnamed schema present.
- schema = getSchemaByName(null);
- if (schema != null) {
- Table table = schema.getTableByName(tableName);
- return table;
- }
- } else {
- // case-sensitive search
- if (isStartingToken(schemaName, tableName)) {
- schema = getSchemaByName(schemaName);
- }
- }
- }
-
- if (schema == null) {
- final String tableNameInLowerCase = tableName.toLowerCase();
- for (final String schemaName : schemaNames) {
- if (schemaName != null) {
- // case-insensitive search
- final String schemaNameInLowerCase = schemaName.toLowerCase();
- if (isStartingToken(schemaNameInLowerCase, tableNameInLowerCase)) {
- schema = getSchemaByName(schemaName);
- }
- }
- }
- }
-
- if (schema == null) {
- schema = getDefaultSchema();
- }
-
- String tablePart = tableName.toLowerCase();
- String schemaName = schema.getName();
- if (schemaName != null && isStartingToken(schemaName.toLowerCase(), tablePart)) {
- tablePart = tablePart.substring(schemaName.length());
- if (tablePart.startsWith(".")) {
- tablePart = tablePart.substring(1);
- }
- }
-
- return schema.getTableByName(tablePart);
- }
-
- private boolean isStartingToken(String partName, String fullName) {
- if (fullName.startsWith(partName)) {
- final int length = partName.length();
- if (length == 0) {
- return false;
- }
- if (fullName.length() > length) {
- final char nextChar = fullName.charAt(length);
- if (isQualifiedPathDelim(nextChar)) {
- return true;
- }
- }
- }
- return false;
- }
-
- protected boolean isQualifiedPathDelim(char c) {
- return c == '.' || c == '"';
- }
-
- /**
- * Gets schema names from the non-abstract implementation. These schema
- * names will be cached except if the {@link #refreshSchemas()} method is
- * called.
- *
- * @return an array of schema names.
- */
- protected abstract String[] getSchemaNamesInternal();
-
- /**
- * Gets the name of the default schema.
- *
- * @return the default schema name.
- */
- protected abstract String getDefaultSchemaName();
-
- /**
- * Gets a specific schema from the non-abstract implementation. This schema
- * object will be cached except if the {@link #refreshSchemas()} method is
- * called.
- *
- * @param name
- * the name of the schema to get
- * @return a schema object representing the named schema, or null if no such
- * schema exists.
- */
- protected abstract Schema getSchemaByNameInternal(String name);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/AbstractUpdateCallback.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/AbstractUpdateCallback.java b/core/src/main/java/org/eobjects/metamodel/AbstractUpdateCallback.java
deleted file mode 100644
index 726af15..0000000
--- a/core/src/main/java/org/eobjects/metamodel/AbstractUpdateCallback.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.eobjects.metamodel;
-
-import java.util.Arrays;
-
-import org.eobjects.metamodel.create.TableCreationBuilder;
-import org.eobjects.metamodel.delete.RowDeletionBuilder;
-import org.eobjects.metamodel.drop.TableDropBuilder;
-import org.eobjects.metamodel.insert.RowInsertionBuilder;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-
-/**
- * Abstract implementation of the {@link UpdateCallback} interface. Implements
- * only the data store agnostic methods.
- *
- * @author Kasper Sørensen
- */
-public abstract class AbstractUpdateCallback implements UpdateCallback {
-
- private final DataContext _dataContext;
-
- public AbstractUpdateCallback(DataContext dataContext) {
- _dataContext = dataContext;
- }
-
- @Override
- public TableCreationBuilder createTable(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException {
- Schema schema = getSchema(schemaName);
- return createTable(schema, tableName);
- }
-
- @Override
- public TableDropBuilder dropTable(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException {
- Table table = getTable(schemaName, tableName);
- return dropTable(table);
- }
-
- @Override
- public TableDropBuilder dropTable(Schema schema, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException {
- Table table = schema.getTableByName(tableName);
- if (table == null) {
- throw new IllegalArgumentException("Nu such table '" + tableName + "' found in schema: " + schema
- + ". Available tables are: " + Arrays.toString(schema.getTableNames()));
- }
- return dropTable(table);
- }
-
- @Override
- public final RowInsertionBuilder insertInto(String tableName) throws IllegalArgumentException,
- IllegalStateException {
- return insertInto(getTable(tableName));
- }
-
- @Override
- public RowInsertionBuilder insertInto(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException {
- return insertInto(getTable(schemaName, tableName));
- }
-
- private Table getTable(String schemaName, String tableName) {
- final Schema schema = getSchema(schemaName);
- final Table table = schema.getTableByName(tableName);
- if (table == null) {
- throw new IllegalArgumentException("Nu such table '" + tableName + "' found in schema: " + schema
- + ". Available tables are: " + Arrays.toString(schema.getTableNames()));
- }
- return table;
- }
-
- private Schema getSchema(String schemaName) {
- final Schema schema = _dataContext.getSchemaByName(schemaName);
- if (schema == null) {
- throw new IllegalArgumentException("No such schema: " + schemaName);
- }
- return schema;
- }
-
- @Override
- public final RowDeletionBuilder deleteFrom(String tableName) {
- return deleteFrom(getTable(tableName));
- }
-
- @Override
- public RowDeletionBuilder deleteFrom(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException {
- final Table table = getTable(schemaName, tableName);
- return deleteFrom(table);
- }
-
- @Override
- public final TableDropBuilder dropTable(String tableName) {
- return dropTable(getTable(tableName));
- }
-
- @Override
- public final RowUpdationBuilder update(String tableName) {
- return update(getTable(tableName));
- }
-
- private Table getTable(String tableName) {
- Table table = getDataContext().getTableByQualifiedLabel(tableName);
- if (table == null) {
- throw new IllegalArgumentException("No such table: " + tableName);
- }
- return table;
- }
-
- @Override
- public DataContext getDataContext() {
- return _dataContext;
- }
-
- @Override
- public boolean isCreateTableSupported() {
- // since 2.0 all updateable datacontext have create table support
- return true;
- }
-
- @Override
- public boolean isInsertSupported() {
- // since 2.0 all updateable datacontext have create table support
- return true;
- }
-
- @Override
- public boolean isUpdateSupported() {
- return isInsertSupported() && isDeleteSupported();
- }
-
- @Override
- public RowUpdationBuilder update(String schemaName, String tableName) throws IllegalArgumentException,
- IllegalStateException, UnsupportedOperationException {
- final Table table = getTable(schemaName, tableName);
- return update(table);
- }
-
- @Override
- public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException,
- UnsupportedOperationException {
- return new DeleteAndInsertBuilder(this, table);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/BatchUpdateScript.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/BatchUpdateScript.java b/core/src/main/java/org/eobjects/metamodel/BatchUpdateScript.java
deleted file mode 100644
index 4d83ba3..0000000
--- a/core/src/main/java/org/eobjects/metamodel/BatchUpdateScript.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.eobjects.metamodel;
-
-/**
- * Indicator sub-interface of {@link UpdateScript}. Implementing your updates
- * using this interface indicates to the underlying
- * {@link UpdateableDataContext} that the update script represents a large batch
- * update and that appropriate optimizations may be taken into use if available.
- */
-public interface BatchUpdateScript extends UpdateScript {
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/CompositeDataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/CompositeDataContext.java b/core/src/main/java/org/eobjects/metamodel/CompositeDataContext.java
deleted file mode 100644
index 82d6c01..0000000
--- a/core/src/main/java/org/eobjects/metamodel/CompositeDataContext.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.eobjects.metamodel;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.FromItem;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.CompositeSchema;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Func;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * DataContext for composite datacontexts. Composite DataContexts wrap several
- * other datacontexts and makes cross-datastore querying possible.
- *
- * @author Kasper Sørensen
- */
-public class CompositeDataContext extends AbstractDataContext {
-
- private final static Logger logger = LoggerFactory.getLogger(CompositeDataContext.class);
- private Map<String, CompositeSchema> _compositeSchemas = new HashMap<String, CompositeSchema>();
- private DataContext[] _delegates;
-
- public CompositeDataContext(DataContext... delegates) {
- if (delegates == null) {
- throw new IllegalArgumentException("delegates cannot be null");
- }
- _delegates = delegates;
- }
-
- public CompositeDataContext(Collection<DataContext> delegates) {
- if (delegates == null) {
- throw new IllegalArgumentException("delegates cannot be null");
- }
- _delegates = delegates.toArray(new DataContext[delegates.size()]);
- }
-
- @Override
- public DataSet executeQuery(Query query) throws MetaModelException {
- // a set of all datacontexts involved
- Set<DataContext> dataContexts = new HashSet<DataContext>();
-
- // find all datacontexts involved, by investigating FROM items
- List<FromItem> items = query.getFromClause().getItems();
- for (FromItem item : items) {
- List<FromItem> tableFromItems = MetaModelHelper.getTableFromItems(item);
- for (FromItem fromItem : tableFromItems) {
- Table table = fromItem.getTable();
-
- DataContext dc = getDataContext(table);
- if (dc == null) {
- throw new MetaModelException("Could not resolve child-datacontext for table: " + table);
- }
- dataContexts.add(dc);
- }
- }
-
- if (dataContexts.isEmpty()) {
- throw new MetaModelException("No suiting delegate DataContext to execute query: " + query);
- } else if (dataContexts.size() == 1) {
- Iterator<DataContext> it = dataContexts.iterator();
- assert it.hasNext();
- DataContext dc = it.next();
- return dc.executeQuery(query);
- } else {
- // we create a datacontext which can materialize tables from
- // separate datacontexts.
- final Func<Table, DataContext> dataContextRetrievalFunction = new Func<Table, DataContext>() {
- @Override
- public DataContext eval(Table table) {
- return getDataContext(table);
- }
- };
- return new CompositeQueryDelegate(dataContextRetrievalFunction).executeQuery(query);
- }
- }
-
- private DataContext getDataContext(Table table) {
- DataContext result = null;
- if (table != null) {
- Schema schema = table.getSchema();
-
- if (schema != null) {
- for (DataContext dc : _delegates) {
- Schema dcSchema = dc.getSchemaByName(schema.getName());
- if (dcSchema != null) {
-
- // first round = try with schema identity match
- if (dcSchema == schema) {
- logger.debug("DataContext for '{}' resolved (using identity) to: '{}'", table, dcSchema);
- result = dc;
- break;
- }
- }
- }
-
- if (result == null) {
- for (DataContext dc : _delegates) {
- Schema dcSchema = dc.getSchemaByName(schema.getName());
- if (dcSchema != null) {
- // second round = try with schema equals method
- if (dcSchema.equals(schema)) {
- logger.debug("DataContext for '{}' resolved (using equals) to: '{}'", table, dcSchema);
- result = dc;
- break;
- }
- }
- }
- }
- }
- }
-
- if (result == null) {
- logger.warn("Couldn't resolve DataContext for {}", table);
- }
- return result;
- }
-
- @Override
- public String getDefaultSchemaName() throws MetaModelException {
- for (DataContext dc : _delegates) {
- Schema schema = dc.getDefaultSchema();
- if (schema != null) {
- return schema.getName();
- }
- }
- return null;
- }
-
- @Override
- public Schema getSchemaByNameInternal(String name) throws MetaModelException {
- CompositeSchema compositeSchema = _compositeSchemas.get(name);
- if (compositeSchema != null) {
- return compositeSchema;
- }
- List<Schema> matchingSchemas = new ArrayList<Schema>();
- for (DataContext dc : _delegates) {
- Schema schema = dc.getSchemaByName(name);
- if (schema != null) {
- matchingSchemas.add(schema);
- }
- }
- if (matchingSchemas.size() == 1) {
- return matchingSchemas.iterator().next();
- }
- if (matchingSchemas.size() > 1) {
- if (logger.isInfoEnabled()) {
- logger.info("Name-clash detected for Schema '{}'. Creating CompositeSchema.");
- }
- compositeSchema = new CompositeSchema(name, matchingSchemas);
- _compositeSchemas.put(name, compositeSchema);
- return compositeSchema;
- }
- return null;
- }
-
- @Override
- public String[] getSchemaNamesInternal() throws MetaModelException {
- Set<String> set = new HashSet<String>();
- for (DataContext dc : _delegates) {
- String[] schemaNames = dc.getSchemaNames();
- for (String name : schemaNames) {
- if (!MetaModelHelper.isInformationSchema(name)) {
- // we skip information schemas, since they're anyways going
- // to be incomplete and misleading.
- set.add(name);
- }
- }
- }
- String[] result = set.toArray(new String[set.size()]);
- Arrays.sort(result);
- return result;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/CompositeQueryDelegate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/CompositeQueryDelegate.java b/core/src/main/java/org/eobjects/metamodel/CompositeQueryDelegate.java
deleted file mode 100644
index a2d5a7f..0000000
--- a/core/src/main/java/org/eobjects/metamodel/CompositeQueryDelegate.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.eobjects.metamodel;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.util.Func;
-
-final class CompositeQueryDelegate extends QueryPostprocessDelegate {
-
- private final Func<Table, DataContext> _dataContextRetrievalFunction;
-
- public CompositeQueryDelegate(
- Func<Table, DataContext> dataContextRetrievalFunction) {
- _dataContextRetrievalFunction = dataContextRetrievalFunction;
- }
-
- @Override
- protected DataSet materializeMainSchemaTable(Table table, Column[] columns,
- int maxRows) {
- // find the appropriate datacontext to execute a simple
- // table materialization query
- DataContext dc = _dataContextRetrievalFunction.eval(table);
- Query q = new Query().select(columns).from(table);
- if (maxRows >= 0) {
- q.setMaxRows(maxRows);
- }
- return dc.executeQuery(q);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/DataContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/DataContext.java b/core/src/main/java/org/eobjects/metamodel/DataContext.java
deleted file mode 100644
index b536d7d..0000000
--- a/core/src/main/java/org/eobjects/metamodel/DataContext.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.eobjects.metamodel;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.query.CompiledQuery;
-import org.eobjects.metamodel.query.Query;
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.query.builder.InitFromBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Schema;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * A DataContext represents the central entry point for interactions with
- * datastores. The DataContext contains of the structure of data (in the form of
- * schemas) and interactions (in the form of queries) with data.
- *
- * @author Kasper Sørensen
- */
-public interface DataContext {
-
- /**
- * Enforces a refresh of the schemas. If not refreshed, cached schema
- * objects may be used.
- *
- * @return this DataContext
- */
- public DataContext refreshSchemas();
-
- /**
- * Gets all schemas within this DataContext.
- *
- * @return the schemas in this data context. Schemas are cached for reuse in
- * many situations so if you want to update the schemas, use the
- * refreshSchemas() method.
- * @throws MetaModelException
- * if an error occurs retrieving the schema model
- */
- public Schema[] getSchemas() throws MetaModelException;
-
- /**
- * Gets the names of all schemas within this DataContext.
- *
- * @return an array of valid schema names
- * @throws MetaModelException
- * if an error occurs retrieving the schema model
- */
- public String[] getSchemaNames() throws MetaModelException;
-
- /**
- * Gets the default schema of this DataContext.
- *
- * @return the schema that you are most probable to be interested in. The
- * default schema is determined by finding the schema with most
- * available of tables. In a lot of situations there will only be a
- * single available schema and in that case this will of course be
- * the schema returned.
- * @throws MetaModelException
- * if an error occurs retrieving the schema model
- */
- public Schema getDefaultSchema() throws MetaModelException;
-
- /**
- * Gets a schema by a specified name.
- *
- * @param name
- * the name of the desired schema
- * @return the Schema with the specified name or null if no such schema
- * exists
- * @throws MetaModelException
- * if an error occurs retrieving the schema model
- */
- public Schema getSchemaByName(String name) throws MetaModelException;
-
- /**
- * Starts building a query using the query builder API. This way of building
- * queries is the preferred approach since it provides a more type-safe
- * approach to building API's as well as allows the DataContext
- * implementation to be aware of the query building process.
- *
- * @return a query builder component at the initial position in building a
- * query.
- */
- public InitFromBuilder query();
-
- /**
- * Parses a string-based SQL query and produces a corresponding
- * {@link Query} object.
- *
- * @param queryString
- * the SQL query to parse
- * @return a {@link Query} object corresponding to the SQL query.
- * @throws MetaModelException
- * in case the parsing was unsuccesful.
- */
- public Query parseQuery(String queryString) throws MetaModelException;
-
- /**
- * Executes a query against the DataContext.
- *
- * @param query
- * the query object to execute
- * @return the {@link DataSet} produced from executing the query
- * @throws MetaModelException
- * if the specified query does not make sense or cannot be
- * executed because of restraints on the type of datastore.
- */
- public DataSet executeQuery(Query query) throws MetaModelException;
-
- /**
- * Compiles a query, preparing it for reuse. Often times compiled queries
- * have a performance improvement when executed, but at the cost of a
- * preparation time penalty. Therefore it is adviced to use compiled queries
- * when the same query is to be fired multiple times.
- *
- * Compiled queries can contain {@link QueryParameter}s as operands in the
- * WHERE clause, making it possible to reuse the same query with different
- * parameter values.
- *
- * @see CompiledQuery
- * @see QueryParameter
- *
- * @param query
- * the query object to execute, possibly holding one or more
- * {@link QueryParameter}s.
- * @return the {@link CompiledQuery} after preparing the query
- *
- * @throws MetaModelException
- * if preparing the query is unsuccesful
- */
- public CompiledQuery compileQuery(Query query) throws MetaModelException;
-
- /**
- * Executes a compiled query with given values as parameters.
- *
- * @param compiledQuery
- * the compiledQuery object to execute
- * @param values
- * the values for parameters in the {@link CompiledQuery}.
- * @return the {@link DataSet} produced from executing the query.
- */
- public DataSet executeQuery(CompiledQuery compiledQuery, Object... values);
-
- /**
- * Parses and executes a string-based SQL query.
- *
- * This method is essentially equivalent to calling first
- * {@link #parseQuery(String)} and then {@link #executeQuery(Query)} with
- * the parsed query.
- *
- * @param query
- * the SQL query to parse
- * @return the {@link DataSet} produced from executing the query
- * @throws MetaModelException
- * if either parsing or executing the query produces an
- * exception
- */
- public DataSet executeQuery(String queryString) throws MetaModelException;
-
- /**
- * Finds a column in the DataContext based on a fully qualified column
- * label. The qualified label consists of the the schema, table and column
- * name, delimited by a dot (.).
- *
- * @param columnName
- * @return a column that matches the qualified label, or null if no such
- * column exists
- */
- public Column getColumnByQualifiedLabel(final String columnName);
-
- /**
- * Finds a table in the DataContext based on a fully qualified table label.
- * The qualified label consists of the the schema and table name, delimited
- * by a dot (.).
- *
- * @param tableName
- * @return a table that matches the qualified label, or null if no such
- * table exists
- */
- public Table getTableByQualifiedLabel(final String tableName);
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/DeleteAndInsertBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/DeleteAndInsertBuilder.java b/core/src/main/java/org/eobjects/metamodel/DeleteAndInsertBuilder.java
deleted file mode 100644
index 91f26fb..0000000
--- a/core/src/main/java/org/eobjects/metamodel/DeleteAndInsertBuilder.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.eobjects.metamodel;
-
-import java.util.List;
-import java.util.ListIterator;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.DefaultRow;
-import org.eobjects.metamodel.data.Row;
-import org.eobjects.metamodel.data.SimpleDataSetHeader;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-import org.eobjects.metamodel.update.AbstractRowUpdationBuilder;
-import org.eobjects.metamodel.update.RowUpdationBuilder;
-
-/**
- * Simple implementation of the {@link RowUpdationBuilder} interface, which
- * simply uses a combined delete+insert strategy for performing updates. Note
- * that this implementation is not desirable performance-wise in many cases, but
- * does provide a functional equivalent to a "real" update.
- */
-public class DeleteAndInsertBuilder extends AbstractRowUpdationBuilder {
-
- private final AbstractUpdateCallback _updateCallback;
-
- public DeleteAndInsertBuilder(AbstractUpdateCallback updateCallback, Table table) {
- super(table);
- assert updateCallback.isInsertSupported();
- assert updateCallback.isDeleteSupported();
- _updateCallback = updateCallback;
- }
-
- @Override
- public void execute() throws MetaModelException {
- // retain rows in memory
- List<Row> rows = getRowsToUpdate();
-
- // delete rows
- _updateCallback.deleteFrom(getTable()).where(getWhereItems()).execute();
-
- // modify rows
- rows = updateRows(rows);
-
- // insert rows
- for (Row row : rows) {
- _updateCallback.insertInto(getTable()).like(row).execute();
- }
- }
-
- private List<Row> updateRows(List<Row> rows) {
- for (ListIterator<Row> it = rows.listIterator(); it.hasNext();) {
- final Row original = (Row) it.next();
- final Row updated = update(original);
- it.set(updated);
- }
- return rows;
- }
-
- /**
- * Produces an updated row out of the original
- *
- * @param original
- * @return
- */
- private Row update(final Row original) {
- SelectItem[] items = original.getSelectItems();
- Object[] values = new Object[items.length];
- for (int i = 0; i < items.length; i++) {
- final Object value;
- Column column = items[i].getColumn();
- if (isSet(column)) {
- // use update statement's value
- value = getValues()[i];
- } else {
- // use original value
- value = original.getValue(i);
- }
- values[i] = value;
- }
- return new DefaultRow(new SimpleDataSetHeader(items), values);
- }
-
- protected List<Row> getRowsToUpdate() {
- final DataContext dc = _updateCallback.getDataContext();
- final Table table = getTable();
- final List<FilterItem> whereItems = getWhereItems();
- final DataSet dataSet = dc.query().from(table).select(table.getColumns()).where(whereItems).execute();
- final List<Row> rows = dataSet.toRows();
- return rows;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/InconsistentRowFormatException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/InconsistentRowFormatException.java b/core/src/main/java/org/eobjects/metamodel/InconsistentRowFormatException.java
deleted file mode 100644
index fd67478..0000000
--- a/core/src/main/java/org/eobjects/metamodel/InconsistentRowFormatException.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.eobjects.metamodel;
-
-import org.eobjects.metamodel.data.DataSet;
-import org.eobjects.metamodel.data.Row;
-
-/**
- * Abstract exception type that represents exceptions that occur when reading a
- * data format which contain formatting errors or inconsistencies in on or more
- * rows.
- *
- * Typically {@link InconsistentRowFormatException}s are thrown when calling
- * {@link DataSet#next()}.
- *
- * All {@link InconsistentRowFormatException}s are optional, meaning that you
- * can turn them on and off. When turned off the result of
- * {@link #getProposedRow()} will be used transparently instead of throwing the
- * exception.
- *
- * @author Kasper Sørensen
- */
-public abstract class InconsistentRowFormatException extends MetaModelException {
-
- private static final long serialVersionUID = 1L;
-
- private final Row _proposedRow;
- private final int _rowNumber;
-
- public InconsistentRowFormatException(Row proposedRow, int rowNumber) {
- super();
- _proposedRow = proposedRow;
- _rowNumber = rowNumber;
- }
-
- public InconsistentRowFormatException(Row proposedRow, int rowNumber,
- Exception cause) {
- super(cause);
- _proposedRow = proposedRow;
- _rowNumber = rowNumber;
- }
-
- /**
- * Gets the row as MetaModel would gracefully interpret it.
- *
- * @return a row object which represents the {@link Row} as MetaModel would
- * gracefully interpret it.
- */
- public Row getProposedRow() {
- return _proposedRow;
- }
-
- /**
- * Gets the row number (1-based).
- *
- * @return the index of the row.
- */
- public int getRowNumber() {
- return _rowNumber;
- }
-
- @Override
- public String getMessage() {
- return "Inconsistent row format of row no. " + getRowNumber() + ".";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/MetaModelException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/MetaModelException.java b/core/src/main/java/org/eobjects/metamodel/MetaModelException.java
deleted file mode 100644
index 787b8c5..0000000
--- a/core/src/main/java/org/eobjects/metamodel/MetaModelException.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-package org.eobjects.metamodel;
-
-/**
- * Unchecked exception used to signal errors occuring in MetaModel.
- *
- * All MetaModelExceptions represent errors discovered withing the MetaModel
- * framework. Typically these will occur if you have put together a query that
- * is not meaningful or if there is a structural problem in a schema.
- */
-public class MetaModelException extends RuntimeException {
-
- private static final long serialVersionUID = 5455738384633428319L;
-
- public MetaModelException(String message, Exception cause) {
- super(message, cause);
- }
-
- public MetaModelException(String message) {
- super(message);
- }
-
- public MetaModelException(Exception cause) {
- super(cause);
- }
-
- public MetaModelException() {
- super();
- }
-}
\ No newline at end of file