any updates? This is bogging me down. 2010/3/19, Gabriele Kahlout <[email protected]>: > Here is the code for wrapper methods that might be incorrect: > > public final static Connection connectToDerby(final File parentPath, > final boolean create) throws InstantiationException, > IllegalAccessException, ClassNotFoundException, SQLException { > // Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); > final Connection con = > DriverManager.getConnection("jdbc:derby:" + parentPath.getPath() + > File.separator + "db.sqlwrapper;create=" + create); > return con; > } > > public static boolean shutDownDerby() { > try { > Connection con = connectToDerby(); > con.close(); > con = > DriverManager.getConnection("jdbc:derby:db.sqlwrapper;shutdown=true"); > > } catch (SQLException e) { // with throw exception on > successful deletion. > return true; > } > return false; > } > > 2010/3/19, Gabriele Kahlout <[email protected]>: >> Here is the shortest test that shows the problem: >> >> import com.mysimpatico.sqlwrapper.*; >> import java.io.File; >> import java.sql.*; >> >> /* >> * To change this template, choose Tools | Templates >> * and open the template in the editor. >> */ >> /** >> * >> * @author simpatico >> */ >> public class DbDeletionTest { >> >> public static boolean deleteDir(File dir) { >> if (dir.isDirectory()) { >> String[] children = dir.list(); >> for (int i = 0; i < children.length; i++) { >> boolean success = deleteDir(new File(dir, children[i])); >> if (!success) { >> return false; >> } >> } // The directory is now empty so delete it return >> dir.delete(); } >> } >> return dir.delete(); >> } >> >> public static void test() throws Exception { >> final File dir = new File("test"); >> dir.mkdir(); >> final Connection con = SqlWrapper.connectToDerby(dir, true); >> final Statement st = con.createStatement(); >> SqlWrapper.setVendor(SqlWrapper.vendor.JAVADB); >> >> final String expTableName = "Expressions"; >> final String exp = "expression"; >> final ReferencedColumn expColumn = new ReferencedColumn(exp, >> SqlWrapper.VARCHAR, 100); >> final Table expTable = new Table(expTableName, expColumn, >> expColumn); >> st.executeUpdate(SqlWrapper.create(expTable)); >> con.close(); >> SqlWrapper.shutDownDerby(); >> deleteDir(dir); >> System.out.println("test executed."); >> >> } >> >> public static void main(String[] args) { >> try { >> test(); >> test(); >> } >> catch (Exception e) { >> e.printStackTrace(); >> } >> } >> } >> The libraries needed are: derby.jar, SqlWrapper.jar (just wraps around >> sql statements, u can replace it with sql strings). >> http://memorizeasy.googlecode.com/svn/tags/live/lib/derby.jar >> http://memorizeasy.googlecode.com/svn/tags/live/lib/sqlwrapper.jar >> >> The output is: >> test executed. >> Shutting down due to severe error. >> java.sql.SQLException: Table/View 'EXPRESSIONS' already exists in Schema >> 'APP'. >> at >> org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown >> Source) >> at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown >> Source) >> at >> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown >> Source) >> at >> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown >> Source) >> at >> org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown >> Source) >> at >> org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown >> Source) >> at >> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown >> Source) >> at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown >> Source) >> at >> org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unknown >> Source) >> at DbDeletionTest.test(DbDeletionTest.java:42) >> at DbDeletionTest.main(DbDeletionTest.java:53) >> Caused by: java.sql.SQLException: Table/View 'EXPRESSIONS' already >> exists in Schema 'APP'. >> at >> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown >> Source) >> at >> org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown >> Source) >> >> 2010/3/19, Gabriele Kahlout <[email protected]>: >>> 'rm -R myDbDirectory' in *nix' >>> How do you programmatically, from java do that (OS independent)? >>> What I do is I iterate over the db folder and delete all contents, as >>> returned by the java.io API. >>> >>> However, even doing that seems not sufficient. >>> I see that the test folder (the one that contains db.sqlwrapper) is >>> deleted after the first test, and created in the setup of the next. >>> However, I get: >>> >>> Caused by: ERROR X0Y32: Table/View 'EXPRESSIONS' already exists in >>> Schema >>> 'APP'. >>> >>> I think it has to do with the copy in memory not being updated with >>> the disk. That is because through the debugger, I've even manually >>> deleted the db, but to no avail. >>> Maybe this is more of a Java question now: >>> How do I make sure the memory is flushed/sync with the disk? Or that >>> derby, when creating a connection is not fooled by the cache in >>> memory? >>> >>> >>> 2010/3/19, Kristian Waagan <[email protected]>: >>>> On 19.03.10 10:11, Gabriele Kahlout wrote: >>>>> Also, I've copied from the code what I seem to need, and then end up >>>>> with when I use the db again in a 2nd method. >>>>> >>>>> Caused by: java.sql.SQLException: Database '/Volumes/STORE N >>>>> GO/ws/MemorizEasy/test/db.sqlwrapper' not found. >>>>> >>>>> Note that after destroying the schemas, I shut down the db, and delete >>>>> the test folder of the previous method. >>>>> >>>> >>>> Hi Gabriele, >>>> >>>> I don't know the requirements of your application, but note that in >>>> general you have three options: >>>> >>>> - clean the database and reuse it >>>> This is what we're doing in the Derby test framework (see the class >>>> that Bryan pointed to), because it would take much longer to actually >>>> delete and recreate the database files all the time. Here we use >>>> meta-data to detect all objects added to the database during the test, >>>> and then we drop them. >>>> >>>> - simply just delete the database on disk (i.e. 'rm -R myDbDirectory' >>>> in *nix) and create a new one for the next test (through JDBC, using >>>> 'jdbc:derby:...;create=true'). >>>> You should shut down the database before deleting the files on >>>> disk. >>>> >>>> - if you just need a database for a short period of time or similar, >>>> use an in-memory db. >>>> Remember to drop it [1] to free up the memory. >>>> >>>> It's hard to tell exactly what went wrong above, but are you sure the >>>> database is still on disk? >>>> Can you locate the directory? (you should see the directories >>>> db.sqlwrapper, db.sqlwrapper/seg0 and db.sqlwrapper/log) >>>> If not, why did it get deleted? >>>> >>>> >>>> -- >>>> Kristian >>>> >>>> [1] Note that proper support for this is added in 10.6, by using the >>>> "drop=true" attribute. In 10.5, the mechanism is different. >>>> >>>>> 2010/3/18, Gabriele Kahlout<[email protected]>: >>>>> >>>>>> I reached here: >>>>>> http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java?view=markup >>>>>> >>>>>> But then what do I do? The code relies on some other class, and it >>>>>> seems like I'd have to import the whole package to use it. Is that >>>>>> it? >>>>>> Besides that one cannot delete the APP schema (which is the one i >>>>>> use), while the code seems to want to do that. >>>>>> If not, is there how I can use this without concerning myself with >>>>>> the >>>>>> impl. details? >>>>>> >>>>>> 2010/3/18, Gabriele Kahlout<[email protected]>: >>>>>> >>>>>>> Can you provide a link to it? Also, is it in some library I could >>>>>>> use? >>>>>>> >>>>>>> 2010/3/18, Bryan Pendleton<[email protected]>: >>>>>>> >>>>>>>>> For testing, how can I make sure the tearDown completely deletes >>>>>>>>> the >>>>>>>>> db, and setUp creates a completely new copy, without using >>>>>>>>> in-memory >>>>>>>>> db? >>>>>>>>> >>>>>>>> We do this in the Derby regression test suite. >>>>>>>> >>>>>>>> Have a look at >>>>>>>> org.apache.derbyTesting.functionTests.junit.CleanDatabaseTestSetup.java >>>>>>>> >>>>>>>> thanks, >>>>>>>> >>>>>>>> bryan >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> -- >>>>>>> Regards, >>>>>>> K. Gabriele >>>>>>> >>>>>>> --- unchanged since 25/1/10 --- >>>>>>> P.S. Unless a notification (LON), please reply either with an answer >>>>>>> OR with " ACK" appended to this subject within 48 hours. Otherwise, >>>>>>> I >>>>>>> might resend. >>>>>>> In(LON, this) ∨ In(48h, TimeNow) ∨ ∃x. In(x, MyInbox) ∧ >>>>>>> IsAnswerTo(x, >>>>>>> this) ∨ (In(subject(this), subject(x)) ∧ In(ACK, subject(x)) ∧ >>>>>>> ¬IsAnswerTo(x,this)) ⇒ ¬IResend(this). >>>>>>> >>>>>>> Also note that correspondence may be received only from specified a >>>>>>> priori senders, or if the subject of this email ends with a code, >>>>>>> eg. >>>>>>> -LICHT01X, then also from senders whose reply contains it. >>>>>>> ∀x. In(x, MyInbox) ⇒ In(senderAddress(x), MySafeSenderList) ∨ (∃y. >>>>>>> In(y, subject(this) ) ∧ In(y,x) ∧ isCodeLike(y, -LICHT01X) ). >>>>>>> >>>>>>> >>>>>> >>>>>> -- >>>>>> Regards, >>>>>> K. Gabriele >>>>>> >>>>>> --- unchanged since 25/1/10 --- >>>>>> P.S. Unless a notification (LON), please reply either with an answer >>>>>> OR with " ACK" appended to this subject within 48 hours. Otherwise, I >>>>>> might resend. >>>>>> In(LON, this) ∨ In(48h, TimeNow) ∨ ∃x. In(x, MyInbox) ∧ IsAnswerTo(x, >>>>>> this) ∨ (In(subject(this), subject(x)) ∧ In(ACK, subject(x)) ∧ >>>>>> ¬IsAnswerTo(x,this)) ⇒ ¬IResend(this). >>>>>> >>>>>> Also note that correspondence may be received only from specified a >>>>>> priori senders, or if the subject of this email ends with a code, eg. >>>>>> -LICHT01X, then also from senders whose reply contains it. >>>>>> ∀x. In(x, MyInbox) ⇒ In(senderAddress(x), MySafeSenderList) ∨ (∃y. >>>>>> In(y, subject(this) ) ∧ In(y,x) ∧ isCodeLike(y, -LICHT01X) ). >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >>> -- >>> Regards, >>> K. Gabriele >>> >>> --- unchanged since 25/1/10 --- >>> P.S. Unless a notification (LON), please reply either with an answer >>> OR with " ACK" appended to this subject within 48 hours. Otherwise, I >>> might resend. >>> In(LON, this) ∨ In(48h, TimeNow) ∨ ∃x. In(x, MyInbox) ∧ IsAnswerTo(x, >>> this) ∨ (In(subject(this), subject(x)) ∧ In(ACK, subject(x)) ∧ >>> ¬IsAnswerTo(x,this)) ⇒ ¬IResend(this). >>> >>> Also note that correspondence may be received only from specified a >>> priori senders, or if the subject of this email ends with a code, eg. >>> -LICHT01X, then also from senders whose reply contains it. >>> ∀x. In(x, MyInbox) ⇒ In(senderAddress(x), MySafeSenderList) ∨ (∃y. >>> In(y, subject(this) ) ∧ In(y,x) ∧ isCodeLike(y, -LICHT01X) ). >>> >> >> >> -- >> Regards, >> K. Gabriele >> >> --- unchanged since 25/1/10 --- >> P.S. Unless a notification (LON), please reply either with an answer >> OR with " ACK" appended to this subject within 48 hours. Otherwise, I >> might resend. >> In(LON, this) ∨ In(48h, TimeNow) ∨ ∃x. In(x, MyInbox) ∧ IsAnswerTo(x, >> this) ∨ (In(subject(this), subject(x)) ∧ In(ACK, subject(x)) ∧ >> ¬IsAnswerTo(x,this)) ⇒ ¬IResend(this). >> >> Also note that correspondence may be received only from specified a >> priori senders, or if the subject of this email ends with a code, eg. >> -LICHT01X, then also from senders whose reply contains it. >> ∀x. In(x, MyInbox) ⇒ In(senderAddress(x), MySafeSenderList) ∨ (∃y. >> In(y, subject(this) ) ∧ In(y,x) ∧ isCodeLike(y, -LICHT01X) ). >> > > > -- > Regards, > K. Gabriele > > --- unchanged since 25/1/10 --- > P.S. Unless a notification (LON), please reply either with an answer > OR with " ACK" appended to this subject within 48 hours. Otherwise, I > might resend. > In(LON, this) ∨ In(48h, TimeNow) ∨ ∃x. In(x, MyInbox) ∧ IsAnswerTo(x, > this) ∨ (In(subject(this), subject(x)) ∧ In(ACK, subject(x)) ∧ > ¬IsAnswerTo(x,this)) ⇒ ¬IResend(this). > > Also note that correspondence may be received only from specified a > priori senders, or if the subject of this email ends with a code, eg. > -LICHT01X, then also from senders whose reply contains it. > ∀x. In(x, MyInbox) ⇒ In(senderAddress(x), MySafeSenderList) ∨ (∃y. > In(y, subject(this) ) ∧ In(y,x) ∧ isCodeLike(y, -LICHT01X) ). >
-- Regards, K. Gabriele --- unchanged since 25/1/10 --- P.S. Unless a notification (LON), please reply either with an answer OR with " ACK" appended to this subject within 48 hours. Otherwise, I might resend. In(LON, this) ∨ In(48h, TimeNow) ∨ ∃x. In(x, MyInbox) ∧ IsAnswerTo(x, this) ∨ (In(subject(this), subject(x)) ∧ In(ACK, subject(x)) ∧ ¬IsAnswerTo(x,this)) ⇒ ¬IResend(this). Also note that correspondence may be received only from specified a priori senders, or if the subject of this email ends with a code, eg. -LICHT01X, then also from senders whose reply contains it. ∀x. In(x, MyInbox) ⇒ In(senderAddress(x), MySafeSenderList) ∨ (∃y. In(y, subject(this) ) ∧ In(y,x) ∧ isCodeLike(y, -LICHT01X) ).
