public ForeignKey(Table table, String name, Column[] columns, UniqueKey key, boolean cascade) { super(table, name, columns); if (key == null) { throw new IllegalArgumentException("Unique key cannot be null."); } m_key = key; m_cascade = cascade; Column[] fk = getColumns(); Column[] uk = m_key.getColumns(); if (fk.length != uk.length) { throw new IllegalArgumentException( "Foreign columns don't match unique key: fk = " + getSQL() + " uk = " + key.getSQL()); } for (int i = 0; i < fk.length; i++) { if (fk[i].getType() == Integer.MIN_VALUE) { fk[i].setType(uk[i].getType()); fk[i].setSize(uk[i].getSize()); } else { if (fk[i].getType() != uk[i].getType() && fk[i].getSize() != uk[i].getSize()) { throw new IllegalArgumentException("Foreign columns don't match unique key."); } } } m_key.addForeignKey(this); }
public void setClean(UniqueKey<Key>... types) { synchronized (dirty) { for (UniqueKey<Key> t : types) { dirty.remove(t.getKey()); } } }
/** * Specify that a list of cache objects are 'dirty' and need to be saved to db * * @param types */ public void setDirty(UniqueKey<Key>... types) { synchronized (dirty) { for (UniqueKey<Key> t : types) { if (map.containsKey(t.getKey())) dirty.add(t.getKey()); } } }
String getColumnSQL() { StringBuffer result = new StringBuffer(); result.append(" "); if (getName() != null) { result.append("constraint " + getName() + "\n "); } result.append("references "); result.append(m_key.getTable().getName()); result.append(m_key.getColumnList()); if (m_cascade) { result.append(" on delete cascade"); } return result.toString(); }
@SuppressWarnings("unchecked") /** * get a key. if varArgs is not null these values will be passed to the serializer in the case * that the cache object does not exist * * @param key cache key * @param varArgs arguments that will be passed to serializer when a key is not found * @return */ public Value get(Key key, Object... varArgs) { if (DEBUG) System.out.println(" - getting key = " + key + " contains=" + map.containsKey(key)); CacheElement o = map.get(key); // UniqueKey<Key> t = map.get(key); if (o == null) { MutableBoolean isdirty = new MutableBoolean(false); UniqueKey<Key> t = serializer.load(key, isdirty, varArgs); if (DEBUG) System.out.println(" - loaded element = " + t + " "); if (t == null) return null; o = new CacheElement(t); key = t.getKey(); synchronized (map) { map.put(key, o); } if (DEBUG) System.out.println( " - adding key = " + key + " contains=" + map.containsKey(key) + " dirty=" + dirty); if (isdirty.booleanValue()) { // / If its dirty, add to our dirty set synchronized (dirty) { dirty.add(key); } } } o.setUsed(); if (autoFlush && autoFlushTime != null) { flushOld(autoFlushTime); } return (Value) o.v; }
/** * remove a cache object using the type given * * @param type * @return */ public Value remove(UniqueKey<Key> type) { return remove(type.getKey()); }
/** * get a cache object using the key from the given param. * * @param type * @param varArgs * @return */ public Value get(UniqueKey<Key> type, Object... varArgs) { return get(type.getKey(), varArgs); }
/** * get a cache object using the key from the given param * * @param type * @return */ public Value get(UniqueKey<Key> type) { return get(type.getKey()); }