/*
* Copyright 2002 (C) TJDO.
* All rights reserved.
*
* This software is distributed under the terms of the TJDO License version 1.0.
* See the terms of the TJDO License in the documentation provided with this software.
*
* $Id: Key.java,v 1.4 2003/04/16 03:26:58 jackknifebarber Exp $
*/
package com.triactive.jdo.store;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.jdo.JDOFatalInternalException;
abstract class Key
{
protected BaseTable table;
protected ArrayList columns = new ArrayList();
protected Key(BaseTable table)
{
this.table = table;
}
protected void assertSameTable(Column col)
{
if (!table.equals(col.getTable()))
throw new JDOFatalInternalException("Cannot add " + col + " as key column for " + table);
}
public BaseTable getTable()
{
return table;
}
public List getColumns()
{
return Collections.unmodifiableList(columns);
}
public String getColumnList()
{
return getColumnList(columns);
}
public boolean startsWith(Key k)
{
int kSize = k.columns.size();
return kSize <= columns.size() && k.columns.equals(columns.subList(0, kSize));
}
protected static void setMinSize(List list, int size)
{
while (list.size() < size)
list.add(null);
}
public static String getColumnList(Collection cols)
{
StringBuffer s = new StringBuffer("(");
Iterator i = cols.iterator();
while (i.hasNext())
{
Column col = (Column)i.next();
if (col == null)
s.append('?');
else
s.append(col.getName());
if (i.hasNext())
s.append(',');
}
s.append(')');
return s.toString();
}
}
|