001: /*
002: * TestPerClassSequenceFactory.java
003: *
004: * Created on October 6, 2006, 2:25 PM
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: /*
011: * Licensed to the Apache Software Foundation (ASF) under one
012: * or more contributor license agreements. See the NOTICE file
013: * distributed with this work for additional information
014: * regarding copyright ownership. The ASF licenses this file
015: * to you under the Apache License, Version 2.0 (the
016: * "License"); you may not use this file except in compliance
017: * with the License. You may obtain a copy of the License at
018: *
019: * http://www.apache.org/licenses/LICENSE-2.0
020: *
021: * Unless required by applicable law or agreed to in writing,
022: * software distributed under the License is distributed on an
023: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
024: * KIND, either express or implied. See the License for the
025: * specific language governing permissions and limitations
026: * under the License.
027: */
028: package org.apache.openjpa.persistence.jdbc.schema;
029:
030: import java.util.*;
031: import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
032: import org.apache.openjpa.jdbc.meta.ClassMapping;
033: import org.apache.openjpa.jdbc.schema.Sequence;
034: import org.apache.openjpa.kernel.Seq;
035: import org.apache.openjpa.kernel.StoreContext;
036: import org.apache.openjpa.meta.ClassMetaData;
037:
038: import org.apache.openjpa.persistence.jdbc.common.apps.*;
039:
040: import java.lang.annotation.Annotation;
041: import junit.framework.*;
042: import javax.persistence.EntityManager;
043: import javax.persistence.EntityManagerFactory;
044: import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
045: import org.apache.openjpa.persistence.OpenJPAEntityManager;
046:
047: public class TestPerClassSequenceFactory extends
048: org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest {
049:
050: /** Creates a new instance of TestPerClassSequenceFactory */
051: public TestPerClassSequenceFactory() {
052: }
053:
054: public TestPerClassSequenceFactory(String test) {
055: super (test);
056: }
057:
058: public void testPerClassSequenceFactory() throws Exception {
059: Map props = new HashMap();
060: props.put("openjpa.Sequence", "table");
061:
062: OpenJPAEntityManagerFactory factory = (OpenJPAEntityManagerFactory) getEmf(props);
063:
064: JDBCConfiguration conf = (JDBCConfiguration) factory
065: .getConfiguration();
066: ClassMapping mapping1 = conf.getMappingRepositoryInstance()
067: .getMapping(RuntimeTest1.class, null, true);
068: ClassMapping mapping2 = conf.getMappingRepositoryInstance()
069: .getMapping(PerClassTestObject.class, null, true);
070: ClassMapping mapping3 = conf.getMappingRepositoryInstance()
071: .getMapping(PerClassTestObject2.class, null, true);
072:
073: OpenJPAEntityManager pm = (OpenJPAEntityManager) currentEntityManager();
074: //FIXME jthomas
075: /*
076: Sequence s1 = pm.getIdentitySequence(mapping1.getDescribedType());
077: Sequence s2 = pm.getIdentitySequence(mapping2.getDescribedType());
078: Sequence s3 = pm.getFieldSequence(mapping3.getDescribedType(), "age");
079: assertTrue(((SequenceImpl) s1).getDelegate()
080: instanceof TableJDBCSeq);
081: assertTrue(((SequenceImpl) s2).getDelegate().toString(),
082: ((SequenceImpl) s2).getDelegate()
083: instanceof DummySequenceFactory);
084: assertTrue(((SequenceImpl) s2).getDelegate().toString(),
085: ((SequenceImpl) s3).getDelegate()
086: instanceof DummySequenceFactory);
087: */
088: }
089:
090: public static class DummySequenceFactory implements Seq {
091:
092: private long _val = 1;
093:
094: public void setType(int type) {
095: }
096:
097: public Object next(StoreContext ctx, ClassMetaData meta) {
098: _val++;
099: return current(ctx, meta);
100: }
101:
102: public Object current(StoreContext ctx, ClassMetaData meta) {
103: return new Long(_val);
104: }
105:
106: public void allocate(int num, StoreContext ctx,
107: ClassMetaData meta) {
108: }
109:
110: public void close() {
111: }
112: }
113:
114: }
|