Code to generate cls classes,(means creating Database tables with columns using simple Java Project),using GreenDAO in Android..



->  For doing this U first create a Java Project(not Android Proj)..
->  Wrote below code on it ..After completion just press Ctrl+F11 to run that code...
->  After that u must be Refresh the Project to Display all generated classes..
->  Next all generated classes will be Copied and Used in Ur ParkingHero Project..
->  Dont forget to import required Jar files of "freemarker.jar" , "greenDAO-generator.jar" files into Ur Project..
->  Here No need of Creating XML files..

->  I implemented all this stuff while doing ,Modifying the Existing ParkingHero Project into Three Tier Architecture..

ExampleDaoGenerator.java:-

/*
 * Copyright (C) 2011 Markus Junginger, greenrobot (http://greenrobot.de)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.greenrobot.daogenerator.gentest;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;

/**
 * Generates entities and DAOs for the example project DaoExample.
 *
 * Run it as a Java application (not Android).
 *
 * @author Markus
 */
public class ExampleDaoGenerator {

    public static void main(String[] args) throws Exception {
        Schema schema = new Schema(3, "de.greenrobot.daoexample");      
       
     
        /**
         * Here in this below  code we Establish a ForignKey realtionShip between
         * ->  Ticket and Evidence Table...
         * ->  Vehicle and VehicleImage Table(For Vehicle Images will be added to particular vehicle..)
         * ->   Vehicle and Tickets Table(for display all Vehicles related to the given Ticket..)         *
         */
       
        //Vehicle table...
        Entity vehicle = schema.addEntity("clsVehicle");
        vehicle.setTableName("tblVehicles");
        vehicle.addIdProperty().index(); ////like vehicle Id
        vehicle.addIntProperty("UserID");
        vehicle.addStringProperty("RegisteredOwner");
        vehicle.addStringProperty("Make");
        vehicle.addStringProperty("Model");
        vehicle.addStringProperty("Color");
        vehicle.addStringProperty("BodyType");
        vehicle.addStringProperty("PlateType");
        vehicle.addStringProperty("PlateNumber");
        vehicle.addStringProperty("State");
        vehicle.addStringProperty("VINNumber").index();
        vehicle.addIntProperty("YearOfRegistration").index();
        vehicle.addIntProperty("ManufacturingYear").index();
        vehicle.addDateProperty("ExpiryDate");
        vehicle.addBooleanProperty("IsDeleted").index();
        vehicle.addBooleanProperty("IsAutoFightOn").index();
        vehicle.addBooleanProperty("IsAutoPayOn");
        vehicle.addDateProperty("DateAddedTimeStamp").index();
        vehicle.addDateProperty("LastUpdatedTimeStamp").index();
       
       
        //Ticket Table..
        Entity Ticket = schema.addEntity("clsTicket");
        Ticket.setTableName("tblTickets");
        Ticket.addIdProperty().index();
        Ticket.addLongProperty("TicketID").index();   
    
      //forign key ...
        Property TicketVehicleID = Ticket.addLongProperty("VehicleID").notNull().getProperty();
        ToMany  vehicleToTicket= vehicle.addToMany(Ticket, TicketVehicleID);
        vehicleToTicket.setName("vehicleTickets");
           Ticket.addStringProperty("TicketNumber").index();
        Ticket.addDateProperty("DateOfOffence");
        Ticket.addStringProperty("TimeOfOffence");
        Ticket.addStringProperty("PlaceOfOffence");
        Ticket.addLongProperty("ViolationCode");
        Ticket.addStringProperty("ViolationDescription");
        Ticket.addStringProperty("NycStatus");
        Ticket.addStringProperty("Status");
        Ticket.addBooleanProperty("IsAutoScanned");
        Ticket.addBooleanProperty("IsDeleted");
        Ticket.addBooleanProperty("AreWeFightingThisTicket");
        Ticket.addFloatProperty("NycFineAmount");
        Ticket.addFloatProperty("NycPenalty");
        Ticket.addFloatProperty("NycPaid");
        Ticket.addFloatProperty("NycReduction");
        Ticket.addFloatProperty("NycInterest");
        Ticket.addFloatProperty("PhFee");
        Ticket.addFloatProperty("PhPaid");
        Ticket.addFloatProperty("PhConveyance");
        Ticket.addFloatProperty("PhRefund");
        Ticket.addDateProperty("DateAddedTimeStamp").index();
        Ticket.addDateProperty("LastUpdatedTimeStamp").index();
        Ticket.addBooleanProperty("AreWePayingThisTicket");
        Ticket.addIntProperty("StatusId");
       
       
        //Address table...
        Entity address = schema.addEntity("clsAddress");
        address.setTableName("tblAddressBook");
        address.addIntProperty("AddressID").index();
        address.addIntProperty("UserID");
        address.addStringProperty("Name");
        address.addStringProperty("Address1");
        address.addStringProperty("Address2");
        address.addStringProperty("City");
        address.addStringProperty("State");
        address.addStringProperty("Zip");
        address.addStringProperty("Phone1");
        address.addStringProperty("Phone2");
        address.addBooleanProperty("IsCurrentAddress").index();
        address.addBooleanProperty("IsBusiness");
        address.addBooleanProperty("IsDefaultBillingAddress");
        address.addBooleanProperty("IsDeleted").index();
        address.addDateProperty("DateAddedTimeStamp").index();
        address.addDateProperty("LastUpdatedTimeStamp").index();
       
        //Creditcard table............
        Entity creditCard = schema.addEntity("clsCreditCard");
        creditCard.setTableName("tblCreditCards");
        creditCard.addIntProperty("CreditCardID").index();
        creditCard.addIntProperty("UserID");
        creditCard.addIntProperty("AddressID").index();
        creditCard.addStringProperty("CardNumber");
        creditCard.addIntProperty("VerificationCode");
        creditCard.addStringProperty("CardHolderName");
        creditCard.addStringProperty("CardType");
        creditCard.addIntProperty("ExpirationMonth");
        creditCard.addIntProperty("ExpirationYear");
        creditCard.addBooleanProperty("IsDefaultCard").index();
        creditCard.addBooleanProperty("IsDeleted").index();
        creditCard.addDateProperty("DateAddedTimeStamp").index();
        creditCard.addDateProperty("LastUpdatedTimeStamp").index();
       
       
        //Evidence table.....
        Entity evidence = schema.addEntity("clsEvidence");
        evidence.setTableName("tblEvidence");
        evidence.addIdProperty().index();
        evidence.addIntProperty("EvidenceID").index();
        evidence.addIntProperty("TicketID");
       
        //Setting Forign key relation ...
        Property TicketSLNO = evidence.addLongProperty("TicketSLNO").notNull().getProperty();
        ToMany ticketsToEvidence = Ticket.addToMany(evidence, TicketSLNO);
        ticketsToEvidence.setName("Ticketevidences");
       
        evidence.addIntProperty("UserID");
        evidence.addStringProperty("SiteUrl");
        evidence.addStringProperty("Note");
        evidence.addBooleanProperty("IsReviewerNotes");      
        evidence.addBooleanProperty("IsDeleted");
        evidence.addDateProperty("DateAddedTimeStamp").index();
        evidence.addStringProperty("LocalUrl").index();
        evidence.addStringProperty("LocalThumbleImageUrl").index();
        evidence.addBooleanProperty("IsImgDownloadPending").index();
        evidence.addBooleanProperty("IsImgUploadPending").index();
       
       
       
        //Vehicle Image table........
         Entity vehicleImage = schema.addEntity("clsVehicleImage");
         vehicleImage.setTableName("tblVehicleImage");
         vehicleImage.addIntProperty("VehicleImageID").index();
       
       
       
        //Setting Forign forign key ...
         Property VehicleID = vehicleImage.addLongProperty("VehicleID").notNull().getProperty();
         ToMany  vehicleToVehiclImage= vehicle.addToMany(vehicleImage, VehicleID);
         vehicleToVehiclImage.setName("vehicleImages");
       
         vehicleImage.addIntProperty("UserID");
         vehicleImage.addStringProperty("Note");
         vehicleImage.addStringProperty("ImageURL");
         vehicleImage.addBooleanProperty("IsDeleted").index();
         vehicleImage.addDateProperty("DateAddedTimeStamp").index();
         vehicleImage.addStringProperty("LocalURL").index();
         vehicleImage.addBooleanProperty("IsImgDownloadPending").index();
       
       
         //User table....
         Entity user = schema.addEntity("clsUser");
         user.setTableName("tblUsers");
         user.addIntProperty("UserID").index();
         user.addStringProperty("FirstName");
         user.addStringProperty("LastName");
         user.addStringProperty("EmailAddress");
         user.addStringProperty("Password");
         user.addDateProperty("DOB");
         user.addBooleanProperty("IsActive");          
         user.addBooleanProperty("IsEmailVerified");
         user.addStringProperty("SignUpTimeStamp");
         user.addDateProperty("LastUpdatedTimeStamp").index();
         user.addBooleanProperty("RememberMe");
       
       
         ///The End

        new DaoGenerator().generateAll(schema, "../DaoExampleGenerator/src-gen");
    }

}


Comments

Popular posts from this blog

Custom Dialog with no title and full screen in Android

Best working code to set Date limits on Date Picker Dialog,in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard