Android Open Source - DKO Code Generator






From Project

Back to project page DKO.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project DKO listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.kered.dko.ant;
//from  w  ww.ja v  a2  s. c o  m
import java.io.File;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

public class CodeGenerator extends Task {
  
  CodeGeneratorBase base = new CodeGeneratorBase();

  /**
   * Path to the jar file that should be generated.
   * @param s
   */
  public void setJarfile(final String s) {
    base.setJarfile(s);
  }

  /**
   * Optional path to the jar file that should be generated containing only source code.
   * @param s
   */
  public void setSrcJarfile(final String s) {
    base.setSrcJarfile(s);
  }
  
  /**
   * Optional set of space-separated prefixes to strip from table names.
   * @param s
   */
  public void setStripPrefixes(final String s) {
    base.setStripPrefixes(s);
  }
  
  /**
   * The output directory for the generated java classes.
   * @param s
   */
  public void setJavaOutputDir(final String s) {
    base.setJavaOutputDir(s);
  }

  /**
   * Whether to enable debugging in the generated code.
   * @param s
   */
  public void setDebug(final String s) {
    base.setDebug(s);
  }

  /**
   * The base path of the generated classes.  For instance, with a base path of "org.kered.myapp",
   * a schema called "mydb" and a table "my_table", the generated class would be {@code org.kered.myapp.mydb.MyTable}.
   * @param s
   */
  public void setPackage(final String s) {
    base.setPackage(s);
  }
  
  public void setAllConstType(final String s) {
    base.setAllConstType(s);
  }

  public void setAllConstFactory(final String s) {
    base.setAllConstFactory(s);
  }

  /**
   * The classpath to use when compiling the genned code
   * @param s
   */
  public void setClasspath(final String s) {
    base.setClasspath(s);
  }

  /**
   * Defines the default datasource for for all generated classes.  This should look like a Java assignment
   * operation that calls some code of yours that returns a datasource.  For instance: {@code myDb = MyDataSourceFactory.getDataSource();} <br>
   * @param s
   */
  public void setDataSource(final String s) {
    base.setDataSource(s);
  }

  /**
   * The path to the JSON file (generated with {@link org.kered.dko.ant.SchemaExtractorBase}) containing your database schema.
   * @param s
   */
  public void setSchemas(final String s) {
    base.setSchemas(s);
  }

  /**
   * By default generated DKO {@code toString()} methods call {@code toStringSimple()}
   * (which display columns in the primary key plus any fields named like "*name*").
   * If instead you'd like it to default to calling {@code toStringDetailed()} (which
   * returns all fetched fields), set this to true.
   * @param s
   */
  public void setUseDetailedToString(final String s) {
    base.setUseDetailedToString(s);
  }

//  public void setGson(final String s) {
//    this.genGson  = Util.truthy(s);
//  }
//
  /**
   * By default, DKOs use the schema name as the package name.  If you want to specify
   * your own package name, do so here.  Format is comma separated with "as"... like so:
   * "schema1 as pkg1, schema2 as pkg2, schema3 as pkg3"
   * @param s
   */
  public void setAliases(final String s) {
    base.setSchemaAliases(s);
  }

  /**
   * Path to the optional enums JSON file (which would be generated by {@link org.kered.dko.ant.SchemaExtractorBase}).
   * @param s
   */
  public void setEnums(final String s) {
    base.setEnums(s);
  }

  /**
   * Path to an optional user-written JSON that controls what default types should map to what
   * custom java types and how to convert those types.  For instance, SQL timestamp columns by default
   * map to {@code java.sql.Timestamp} classes.  If instead you'd prefer {@code java.util.Date}s:
   *
   * <pre>{
   *     "class_mappings": {
   *         "java.sql.Timestamp": "java.util.Date",
   *     },
   *     "functions": {
   *       "java.sql.Timestamp java.util.Date" :
   *           "new java.util.Date((%s).getTime()",
   *       "java.util.Date java.sql.Timestamp" :
   *           "new java.sql.Timestamp((%s).getTime()",
   *     }
   * }</pre>
   *
   * Note the "functions" section where you can provide code that converts from one to another.
   * <p>
   * If you don't want all types to be mapped the same way for all classes, you can specify Java
   * regex statements (matched against the schema/table/column names) to specify certain classes.
   * For example, this will do the same as the previous example, but only for fields with names ending in "_date":
   *
   * <pre>{
   *     "schema_mappings": {
   *         ".*_date": "java.util.Date",
   *     },
   *     "functions": {
   *       "java.sql.Timestamp java.util.Date" :
   *           "new java.util.Date((%s).getTime()",
   *       "java.util.Date java.sql.Timestamp" :
   *           "new java.sql.Timestamp((%s).getTime()",
   *     }
   * }</pre>
   *
   * @param s
   */
  public void setTypeMappings(final String s) {
    base.setTypeMappings(s);
  }

  /**
   * Sets the path to your javac binary.
   * @param s
   */
  public void setJavac(final String s) {
    base.setJavac(s);
  }

  /**
   * Sets the Javac target Java version for the compiled code.
   * @param s
   */
  public void setJavacTarget(final String s) {
    base.setJavacTarget(s);
  }

  /**
   * Sets the Javac source parameter.
   * @param s
   */
  public void setJavacSource(final String s) {
    base.setJavacSource(s);
  }

  /**
   * Usually DKOs use the automatically generated FK relationships extracted from the database.  But sometimes
   * those foreign keys aren't actually there.  (usually for performance reasons)  Specifying this file lets
   * you add FK relationships to the generated code regardless.  The format is JSON like the following:
   *
   * <pre>{
   *     "fk_1":{
   *         "reffing": ["my_schema","product"],
   *         "reffed": ["my_schema","manufacturer"],
   *         "columns": {"manufacturer_id": "id"}
   *     },
   * }</pre>
   *
   * This will create a FK relationship from {@code product.manufacturer_id} to {@code manufacturer.id}.
   * Compound keys are simply additional entries in the "columns" map.
   *
   * @param s
   */
  public void setFakeFKs(final String s) {
    base.setFakeFks(s);
  }

  /**
   * DKOs support a variety of callbacks pre and post database operations.  Specify this parameter for
   * where the generated DKOs should look.  For instance, a schema/table {@code myapp.product} could
   * generate a class {@code org.kered.myapp.Product}.  Which if given a callback package of
   * "org.kered.myapp.callbacks" would look for callback methods in {@code org.kered.myapp.callbacks.ProductCB}.
   *
   * @param s
   */
  public void setCallbackPackage(final String s) {
    base.setCallbackPackage(s);
  }

  @Override
  public void execute() {
    try {
      base.execute();
    } catch (RuntimeException e) {
      throw new BuildException(e);
    }
  }

}




Java Source Code List

.HelloWorld.java
org.kered.contactlensfinder.DB.java
org.kered.contactlensfinder.MainActivity.java
org.kered.contactlensfinder.ViewManufacturersActivity.java
org.kered.contactlensfinder.ViewProductsActivity.java
org.kered.contactlensfinder.ViewPropertiesActivity.java
org.kered.dko.AbstractQuery.java
org.kered.dko.Bulk.java
org.kered.dko.CSV.java
org.kered.dko.ClosableIterator.java
org.kered.dko.Condition.java
org.kered.dko.Constants.java
org.kered.dko.Context.java
org.kered.dko.DBQuery.java
org.kered.dko.DBRowIterator.java
org.kered.dko.Diff.java
org.kered.dko.DualIterator.java
org.kered.dko.Expression.java
org.kered.dko.Field.java
org.kered.dko.FilteringQuery.java
org.kered.dko.Function.java
org.kered.dko.InMemoryQuery.java
org.kered.dko.Join.java
org.kered.dko.LazyCacheIterable.java
org.kered.dko.LocalJoin.java
org.kered.dko.M.java
org.kered.dko.Main.java
org.kered.dko.MatryoshkaQuery.java
org.kered.dko.PeekableClosableIterator.java
org.kered.dko.PeekableIterator.java
org.kered.dko.QueryAddField.java
org.kered.dko.QueryFactory.java
org.kered.dko.QuerySnapshot.java
org.kered.dko.Query.java
org.kered.dko.SQLFunction.java
org.kered.dko.SelectAsMapIterable.java
org.kered.dko.SelectFromOAI.java
org.kered.dko.SelectSingleColumn.java
org.kered.dko.SoftJoinUtil.java
org.kered.dko.SoftJoin.java
org.kered.dko.SqlContext.java
org.kered.dko.Statistics.java
org.kered.dko.SubQueryField.java
org.kered.dko.TableInfo.java
org.kered.dko.TableWrapper.java
org.kered.dko.Table.java
org.kered.dko.TemporaryTableFactory.java
org.kered.dko.TmpTableBuilder.java
org.kered.dko.Tuple.java
org.kered.dko.UsageMonitor.java
org.kered.dko.UsageStats.java
org.kered.dko.Util.java
org.kered.dko.ant.ClassGenerator.java
org.kered.dko.ant.CodeGeneratorBase.java
org.kered.dko.ant.CodeGenerator.java
org.kered.dko.ant.DataSourceGenerator.java
org.kered.dko.ant.GsonGenerator.java
org.kered.dko.ant.JoinGenerator.java
org.kered.dko.ant.Main.java
org.kered.dko.ant.SchemaExtractorBase.java
org.kered.dko.ant.SchemaExtractor.java
org.kered.dko.ant.Util.java
org.kered.dko.datasource.CheapConnectionPoolingDataSource.java
org.kered.dko.datasource.ConnectionCountingDataSource.java
org.kered.dko.datasource.JDBCDriverDataSource.java
org.kered.dko.datasource.MatryoshkaDataSource.java
org.kered.dko.datasource.MirroredDataSource.java
org.kered.dko.datasource.ReflectedDataSource.java
org.kered.dko.datasource.SingleConnectionDataSource.java
org.kered.dko.datasource.SingleThreadedDataSource.java
org.kered.dko.datasource.UnClosableConnection.java
org.kered.dko.datasource.Util.java
org.kered.dko.json.CDL.java
org.kered.dko.json.CookieList.java
org.kered.dko.json.Cookie.java
org.kered.dko.json.HTTPTokener.java
org.kered.dko.json.HTTP.java
org.kered.dko.json.JSONArray.java
org.kered.dko.json.JSONException.java
org.kered.dko.json.JSONML.java
org.kered.dko.json.JSONObject.java
org.kered.dko.json.JSONString.java
org.kered.dko.json.JSONStringer.java
org.kered.dko.json.JSONTokener.java
org.kered.dko.json.JSONWriter.java
org.kered.dko.json.Pickle.java
org.kered.dko.json.XMLTokener.java
org.kered.dko.json.XML.java
org.kered.dko.junk.DerbyLoadTestSchema.java
org.kered.dko.junk.OracleCreateTestUser.java
org.kered.dko.junk.OracleLoadTestSchema.java
org.kered.dko.persistence.Util.java
org.kered.dko.util.DumpDatabase.java
sakila.Example0.java
sakila.Example1.java
sakila.Example2.java
sakila.Util.java