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

com.spun.util.database.DatabaseObject Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package com.spun.util.database;

import java.sql.Statement;
import java.util.Collection;

public interface DatabaseObject
{
  public static DatabaseObject Null = new NullDatabaseObject();
  public boolean isNew();
  public void setNew(boolean b);
  public int getPkey();
  public boolean setPkey(int i);
  public Metadata getMetadata();
  public boolean save(Statement stmt);
  public boolean deleteFromDatabase(java.sql.Statement stmt);
  /**                     Inner Classes                                 **/
  public static class FilterNew implements com.spun.util.filters.Filter
  {
    public static FilterNew INSTANCE = new FilterNew();
    public boolean isExtracted(DatabaseObject object) throws IllegalArgumentException
    {
      if (!(object instanceof DatabaseObject))
      {
        throw new IllegalArgumentException(
            "Expected Object of Type DatabaseObject but got " + object.getClass().getName());
      }
      DatabaseObject o = (DatabaseObject) object;
      return o.isNew();
    }
  }
  public static class Utils
  {
    public static void saveAll(DatabaseObject[] objects, Statement stmt)
    {
      java.util.HashSet set = new java.util.HashSet();
      for (int i = 0; i < objects.length; i++)
      {
        DatabaseRelationshipPersistent object = (DatabaseRelationshipPersistent) objects[i];
        object.save(stmt, set, false);
      }
    }
    public static  T get(int pkey, T[] from)
    {
      if (from == null)
      { return null; }
      for (int i = 0; i < from.length; i++)
      {
        if (pkey == from[i].getPkey())
        { return from[i]; }
      }
      return null;
    }
    public static  T get(int pkey, Collection from)
    {
      for (T object : from)
      {
        if (pkey == object.getPkey())
        { return object; }
      }
      return null;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy