getAssociations() {
+ return Collections.unmodifiableList(associations);
+ }
+
+ /**
+ * Checks if this model has a named attribute that has the same name as argument.
+ *
+ * Throws IllegalArgumentException
in case it does not find it.
+ *
+ * @param attribute name of attribute or association target.
+ */
+ protected void checkAttribute(String attribute) {
+ if (!hasAttribute(attribute)) {
+ String sb = "Attribute: '" + attribute + "' is not defined in model: '" + getModelClass() + ". "
+ + "Available attributes: " + getAttributeNames();
+ throw new IllegalArgumentException(sb);
+ }
+ }
+
+ /**
+ * Provides column metadata map, keyed by attribute names.
+ * Table columns correspond to ActiveJDBC model attributes.
+ *
+ * @return Provides column metadata map, keyed by attribute names.
+ */
+ public Map getColumnMetadata() {
+ if (columnMetadata == null || columnMetadata.isEmpty())
+ throw new InitException("Failed to find table: " + getTableName());
+ return Collections.unmodifiableMap(columnMetadata);
+ }
+
+ void setColumnMetadata(Map columnMetadata) {
+ this.columnMetadata = columnMetadata;
+ }
+
+ /**
+ * Checks if there is association to the target model class.,
+ *
+ * @param targetModelClass class of a model that will be checked for association from current model.
+ * @return true if any association exists such that the current model is a source and targetModelClass is a target.
+ */
+ public boolean isAssociatedTo(Class extends Model> targetModelClass) {
+
+ if (targetModelClass == null) {
+ throw new NullPointerException();
+ }
+
+ for (Association association : associations) {
+ if (association.getTargetClass().equals(targetModelClass)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void removeAssociationForTarget(Class extends Model> modelClass) {
+ Association association = getAssociationForTarget(modelClass);
+ if (association != null) {
+ associations.remove(association);
+ }
+ }
+}