All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.sql.table.DatabaseCol Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.sql.table;


import java.util.HashSet;
import java.util.Set;

import com.hfg.exception.ProgrammingException;
import com.hfg.util.CompareUtil;
import com.hfg.util.StringUtil;


//------------------------------------------------------------------------------
/**
 Database column object.
 
@author J. Alex Taylor, hairyfatguy.com
*/ //------------------------------------------------------------------------------ // com.hfg XML/HTML Coding Library // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library 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 // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //------------------------------------------------------------------------------ public class DatabaseCol implements Cloneable, Comparable { private DatabaseTable mTable; private String mName; private int mType; private boolean mIsId; private boolean mNotRetrievedByDefault; private DatabaseSequence mSequence; private Set mTags; // For comparison performance private String mQualifiedNameForCompareTo; private Integer mCachedHashCode; //########################################################################### // CONSTRUCTORS //########################################################################### //--------------------------------------------------------------------------- public DatabaseCol(DatabaseTable inTable, String inName, int inType) { mTable = inTable; mName = inName; mType = inType; mTable.addCol(this); } //########################################################################### // PUBLIC METHODS //########################################################################### //--------------------------------------------------------------------------- public DatabaseCol clone() { DatabaseCol clone; try { clone = (DatabaseCol) super.clone(); } catch (CloneNotSupportedException e) { throw new ProgrammingException(e); } return clone; } //--------------------------------------------------------------------------- private String getQualifiedNameForCompareTo() { if (null == mQualifiedNameForCompareTo) { mQualifiedNameForCompareTo = getTable().getQualifiedName() + "." + name(); } return mQualifiedNameForCompareTo; } //--------------------------------------------------------------------------- @Override public int compareTo(DatabaseCol inObj2) { return (inObj2 != null ? getQualifiedNameForCompareTo().compareTo(inObj2.getQualifiedNameForCompareTo()) : -1); } //--------------------------------------------------------------------------- @Override public boolean equals(Object inObj2) { return (inObj2 != null && inObj2 instanceof DatabaseCol && 0 == compareTo((DatabaseCol) inObj2)); } //--------------------------------------------------------------------------- @Override public int hashCode() { if (null == mCachedHashCode) { mCachedHashCode = getQualifiedNameForCompareTo().hashCode(); } return mCachedHashCode; } //--------------------------------------------------------------------------- public String name() { return mName; } //--------------------------------------------------------------------------- public String qname(String inPrefix) { return (StringUtil.isSet(inPrefix) ? inPrefix + "." : "") + mName; } //--------------------------------------------------------------------------- public String getQualifiedName() { String prefix = null; if (getTable() != null) { if (StringUtil.isSet(getTable().getAlias())) { prefix = getTable().getAlias(); } else { prefix = getTable().name(); } } return (prefix != null ? prefix + "." : "") + name(); } //--------------------------------------------------------------------------- @Override public String toString() { return getQualifiedName(); } //--------------------------------------------------------------------------- public DatabaseTable getTable() { return mTable; } //--------------------------------------------------------------------------- public DatabaseCol setTable(DatabaseTable inValue) { mTable = inValue; mQualifiedNameForCompareTo = null; return this; } //--------------------------------------------------------------------------- public int getType() { return mType; } //--------------------------------------------------------------------------- public DatabaseCol setIsId(boolean inValue) { mIsId = inValue; return this; } //--------------------------------------------------------------------------- public boolean isId() { return mIsId; } //--------------------------------------------------------------------------- public DatabaseCol setRetrievedByDefault(boolean inValue) { mNotRetrievedByDefault = ! inValue; return this; } //--------------------------------------------------------------------------- public boolean getRetrievedByDefault() { return ! mNotRetrievedByDefault; } //--------------------------------------------------------------------------- public DatabaseCol setSequence(DatabaseSequence inValue) { mSequence = inValue; return this; } //--------------------------------------------------------------------------- public DatabaseSequence getSequence() { return mSequence; } //--------------------------------------------------------------------------- public DatabaseCol tag(String inValue) { if (null == mTags) { mTags = new HashSet<>(3); } mTags.add(inValue); return this; } //--------------------------------------------------------------------------- public boolean tagged(String inValue) { return (mTags != null && mTags.contains(inValue)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy