com.googlecode.paradox.data.TableData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of paradoxdriver Show documentation
Show all versions of paradoxdriver Show documentation
A Paradox Java Driver (using JDBC 4)
The newest version!
/*
* Copyright (c) 2009 Leonardo Alves da Costa
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details. You should have received a copy of the GNU General Public License along with this
* program. If not, see .
*/
package com.googlecode.paradox.data;
import com.googlecode.paradox.ConnectionInfo;
import com.googlecode.paradox.data.filefilters.TableFilter;
import com.googlecode.paradox.exceptions.DataError;
import com.googlecode.paradox.exceptions.ParadoxDataException;
import com.googlecode.paradox.metadata.Field;
import com.googlecode.paradox.metadata.Table;
import com.googlecode.paradox.metadata.paradox.ParadoxTable;
import com.googlecode.paradox.metadata.schema.DirectorySchema;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.sql.SQLException;
import java.util.*;
/**
* Utility class for loading table files.
*
* @since 1.0
*/
public final class TableData extends AbstractParadoxData {
/**
* Utility class.
*/
private TableData() {
super();
}
/**
* Gets all tables within a pattern.
*
* @param schema the schema directory.
* @param pattern the pattern.
* @param connectionInfo the connection information.
* @return the tables filtered.
*/
public static List listTables(final DirectorySchema schema, final String pattern, final ConnectionInfo connectionInfo) {
final List tables = new ArrayList<>();
final File[] fileList = schema.getSchemaFile().listFiles(new TableFilter(connectionInfo.getLocale(), pattern));
if (fileList != null) {
Arrays.sort(fileList);
for (final File file : fileList) {
Table cachedTable = schema.getFromCache(file);
if (cachedTable != null) {
tables.add(cachedTable);
} else {
try {
final ParadoxTable table = loadHeader(file, connectionInfo);
Arrays.stream(table.getFields()).forEach(field -> field.setTable(table));
table.loadIndexes();
table.loadValidations();
tables.add(table);
// Update the cache.
schema.addCache(table, file.lastModified());
} catch (final SQLException e) {
connectionInfo.addWarning(e);
}
}
}
}
return tables;
}
/**
* Load the table data from file.
*
* @param table the table to read.
* @param fields the fields to read.
* @return the row values.
* @throws SQLException in case of failures.
*/
public static List