001    /*
002     * Copyright (C) 2008 Adam Cornett This program is free software; you can
003     * redistribute it and/or modify it under the terms of the GNU General Public
004     * License as published by the Free Software Foundation; either version 3 of the
005     * License, or (at your option) any later version. This program is distributed
006     * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
007     * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
008     * See the GNU General Public License for more details. You should have received
009     * a copy of the GNU General Public License along with this program; if not, see
010     * <http://www.gnu.org/licenses>.
011     */
012    
013    package net.codescore.test;
014    
015    import java.util.Random;
016    
017    import org.apache.cayenne.CayenneRuntimeException;
018    import org.apache.cayenne.access.DataContext;
019    
020    import net.codescore.dbo.Problem;
021    import net.codescore.dbo.TestCase;
022    import net.codescore.managers.ProblemManager;
023    
024    public class GenSimonData {
025            private static DataContext dc;
026            private final static boolean dont_kill_the_system = false;
027    
028            /**
029             * @param args
030             */
031            public static void main(String[] args) {
032    
033                    System.out
034                            .println("Generating " + max + " rows of test data for simon");
035                    dc = DataContext.createDataContext();
036                    genData();
037                    System.out.println("Done");
038    
039            }
040    
041            private static final int max = 100000;
042            static final String data =
043                    "�����e���V�C���&�B�+s��B\\�:Sl[t�\\��}t��6�7�9�X���\"Ys��뭖&o��-�䌍���������M�";
044    
045            private static void genData() {
046                    if (dont_kill_the_system)
047                            return;
048                    Problem p = ProblemManager.getProblemByID(dc, 9999);
049                    Random r = new Random();
050                    System.out.println("Generating new cases");
051                    for (int i = 1; i <= max; i++) {
052                            TestCase tc = dc.newObject(TestCase.class);
053                            tc.setProblem(p);
054                            tc.setInput(data);
055                            tc.setOutput(data);
056                            tc.setActive(true);
057                            if (i % 25000 == 0)
058                                    dc.commitChanges();
059                    }
060                    try {
061                            dc.commitChanges();
062                    } catch (CayenneRuntimeException e) {
063                            e.printStackTrace();
064                            return;
065                    }
066            }
067    }