![JAR search and dependency download from the Maven repository](/logo.png)
com.viaoa.ds.jdbc.db.Table Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of oa-core Show documentation
Show all versions of oa-core Show documentation
Object Automation library
/* Copyright 1999 Vince Via [email protected]
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.
*/
package com.viaoa.ds.jdbc.db;
import java.lang.reflect.*;
import java.util.*;
import com.viaoa.util.ClassModifier;
import com.viaoa.util.OAArray;
/**
Used for mapping database Tables with OAObjects.
*/
public class Table {
public String name;
public Class clazz;
private Link[] links = new Link[0];
private Column[] columns = new Column[0];
private Index[] indexes = new Index[0];
public boolean bLink; // is this a link table
public Class[] subclasses; // set by Database when all tables are loaded
Constructor constructor;
// runtime use only
public transient Class[] selectClasses;
public transient Column[] selectColumnArray;
public transient String selectColumns;
public transient String selectPKColumns;
public transient DataAccessObject dataAccessObject;
public Table() {
}
public Table(String name, Class clazz) {
this.name = name;
this.clazz = clazz;
}
public Table(String name, boolean isLinkTable) {
this.name = name;
this.bLink = isLinkTable;
}
public void setIndexes(Index[] indexes) {
this.indexes = indexes;
}
public void addIndex(Index index) {
int x = indexes.length;
Index[] ixs = new Index[x+1];
System.arraycopy(indexes, 0, ixs, 0, x);
ixs[x] = index;
indexes = ixs;
}
public Index[] getIndexes() {
return indexes;
}
public Link getLink(Class clazz) {
for (int i=0; links != null && i 0) {
Class c = ClassModifier.getClassWrapper(cs[0]);
column.clazz = c;
}
}
}
}
protected void updateLinks(boolean bUpdateToLinks) {
// 1: flag all columns that are a Fkey
for (int i=0; links!=null && i al = new ArrayList(15);
for (int i=0; columns != null && i < columns.length; i++) {
Column column = columns[i];
if (column.propertyName == null || column.propertyName.length() == 0) {
// get all columns that are foreign keys or primary keys
if (!column.primaryKey && !column.foreignKey) continue;
}
al.add(column);
}
Column[] cols = new Column[al.size()];
al.toArray(cols);
return cols;
}
/** columns that are needed to retrieve primary key.
*/
public Column[] getPrimaryKeyColumns() {
ArrayList al = new ArrayList(3);
for (int i=0; columns != null && i < columns.length; i++) {
Column column = columns[i];
if (column.primaryKey) al.add(column);
}
Column[] cols = new Column[al.size()];
al.toArray(cols);
return cols;
}
// get the matching link columns in the "to" table
public Column[] getLinkToColumns(Link link, Table toTable) {
if (link == null || toTable == null) return null;
String revProp = link.reversePropertyName;
Link[] links = toTable.getLinks();
Column[] hold = null;
for (int i=0; links!=null && i < links.length; i++) {
if (links[i].toTable == this) {
hold = links[i].fkeys;
if (revProp != null && links[i].propertyName.equalsIgnoreCase(revProp)) break;
}
}
return hold;
}
public Link getReverseLink(Link link) {
String revProp = link.reversePropertyName;
Link[] links = link.toTable.getLinks();
Column[] hold = null;
for (int i=0; links!=null && i < links.length; i++) {
if (links[i].toTable == this) {
if (revProp != null && links[i].propertyName.equalsIgnoreCase(revProp)) return links[i];
}
}
return null;
}
public void setDataAccessObject(DataAccessObject dao) {
dataAccessObject = dao;
}
public DataAccessObject getDataAccessObject() {
return dataAccessObject;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy