OPENJPA-1442:

setting svn:eol-style native

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@909530 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2010-02-12 17:52:38 +00:00
parent e603bdc5c8
commit 5f8ad3e811
9 changed files with 561 additions and 561 deletions

View File

@ -1,56 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class EBigDecimalID {
@Id
@Column(precision=20,scale=5)
private BigDecimal id;
private String name;
public EBigDecimalID() {}
public EBigDecimalID(BigDecimal id) {
this.id = id;
this.name = "BigDecimalID "+id;
}
public BigDecimal getId() {
return id;
}
public void setId(BigDecimal id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class EBigDecimalID {
@Id
@Column(precision=20,scale=5)
private BigDecimal id;
private String name;
public EBigDecimalID() {}
public EBigDecimalID(BigDecimal id) {
this.id = id;
this.name = "BigDecimalID "+id;
}
public BigDecimal getId() {
return id;
}
public void setId(BigDecimal id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,55 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import java.math.BigInteger;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class EBigIntegerID {
@Id
private BigInteger id;
private String name;
public EBigIntegerID() {}
public EBigIntegerID(BigInteger id) {
this.id = id;
this.name = "BigIntegerID "+id;
}
public BigInteger getId() {
return id;
}
public void setId(BigInteger id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import java.math.BigInteger;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class EBigIntegerID {
@Id
private BigInteger id;
private String name;
public EBigIntegerID() {}
public EBigIntegerID(BigInteger id) {
this.id = id;
this.name = "BigIntegerID "+id;
}
public BigInteger getId() {
return id;
}
public void setId(BigInteger id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,55 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class EDBigDecimalID {
@Id
@OneToOne
private EBigDecimalID rid;
private String name;
public EDBigDecimalID() {}
public EDBigDecimalID(EBigDecimalID rid) {
this.rid = rid;
this.name = "Rel BigDecimalID "+rid.getId();
}
public EBigDecimalID getRid() {
return rid;
}
public void setRid(EBigDecimalID rid) {
this.rid = rid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class EDBigDecimalID {
@Id
@OneToOne
private EBigDecimalID rid;
private String name;
public EDBigDecimalID() {}
public EDBigDecimalID(EBigDecimalID rid) {
this.rid = rid;
this.name = "Rel BigDecimalID "+rid.getId();
}
public EBigDecimalID getRid() {
return rid;
}
public void setRid(EBigDecimalID rid) {
this.rid = rid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,55 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class EDBigIntegerID {
@Id
@OneToOne
private EBigIntegerID rid;
private String name;
public EDBigIntegerID() {}
public EDBigIntegerID(EBigIntegerID rid) {
this.rid = rid;
this.name = "Rel BigIntegerID "+rid.getId();
}
public EBigIntegerID getRid() {
return rid;
}
public void setRid(EBigIntegerID rid) {
this.rid = rid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class EDBigIntegerID {
@Id
@OneToOne
private EBigIntegerID rid;
private String name;
public EDBigIntegerID() {}
public EDBigIntegerID(EBigIntegerID rid) {
this.rid = rid;
this.name = "Rel BigIntegerID "+rid.getId();
}
public EBigIntegerID getRid() {
return rid;
}
public void setRid(EBigIntegerID rid) {
this.rid = rid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,55 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class EDDateID {
@Id
@OneToOne
private EDateID rid;
private String name;
public EDDateID() {}
public EDDateID(EDateID rid) {
this.rid = rid;
this.name = "Rel DateID "+rid.getId();
}
public EDateID getRid() {
return rid;
}
public void setRid(EDateID rid) {
this.rid = rid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class EDDateID {
@Id
@OneToOne
private EDateID rid;
private String name;
public EDDateID() {}
public EDDateID(EDateID rid) {
this.rid = rid;
this.name = "Rel DateID "+rid.getId();
}
public EDateID getRid() {
return rid;
}
public void setRid(EDateID rid) {
this.rid = rid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,55 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class EDSQLDateID {
@Id
@OneToOne
private ESQLDateID rid;
private String name;
public EDSQLDateID() {}
public EDSQLDateID(ESQLDateID rid) {
this.rid = rid;
this.name = "Rel SQLDateID "+rid.getId();
}
public ESQLDateID getRid() {
return rid;
}
public void setRid(ESQLDateID rid) {
this.rid = rid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class EDSQLDateID {
@Id
@OneToOne
private ESQLDateID rid;
private String name;
public EDSQLDateID() {}
public EDSQLDateID(ESQLDateID rid) {
this.rid = rid;
this.name = "Rel SQLDateID "+rid.getId();
}
public ESQLDateID getRid() {
return rid;
}
public void setRid(ESQLDateID rid) {
this.rid = rid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,54 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class EDateID {
@Id
private Date id;
private String name;
public EDateID() {}
public EDateID(Date id) {
this.id = id;
this.name = "DateID "+id;
}
public Date getId() {
return id;
}
public void setId(Date id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class EDateID {
@Id
private Date id;
private String name;
public EDateID() {}
public EDateID(Date id) {
this.id = id;
this.name = "DateID "+id;
}
public Date getId() {
return id;
}
public void setId(Date id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,53 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import java.sql.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class ESQLDateID {
@Id
private Date id;
private String name;
public ESQLDateID() {}
public ESQLDateID(Date id) {
this.id = id;
this.name = "SQLDateID "+id;
}
public Date getId() {
return id;
}
public void setId(Date id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import java.sql.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class ESQLDateID {
@Id
private Date id;
private String name;
public ESQLDateID() {}
public ESQLDateID(Date id) {
this.id = id;
this.name = "SQLDateID "+id;
}
public Date getId() {
return id;
}
public void setId(Date id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,123 +1,123 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
public class TestDerivedIdentity extends SQLListenerTestCase {
public void setUp() {
setUp(EBigDecimalID.class, EDBigDecimalID.class,
EBigIntegerID.class, EDBigIntegerID.class,
EDateID.class, EDDateID.class,
ESQLDateID.class, EDSQLDateID.class,
CLEAR_TABLES);
populate();
}
public void populate() {
EntityManager em = emf.createEntityManager();
for (int i = 0; i < 2; i++) {
long time = (long) (System.currentTimeMillis() / 1000)+i*1317;
BigDecimal did = new BigDecimal(time);
EBigDecimalID e1 = new EBigDecimalID(did);
EDBigDecimalID e2 = new EDBigDecimalID(e1);
em.persist(e1);
em.persist(e2);
int time2 = (int) (System.currentTimeMillis() / 1000)+i*7131;
BigInteger iid = new BigInteger(Integer.toString(time2));
EBigIntegerID e3 = new EBigIntegerID(iid);
EDBigIntegerID e4 = new EDBigIntegerID(e3);
em.persist(e3);
em.persist(e4);
Date id = new Date(time);
EDateID e5 = new EDateID(id);
EDDateID e6 = new EDDateID(e5);
em.persist(e5);
em.persist(e6);
if (i == 0) {
java.sql.Date sid = new java.sql.Date(time);
ESQLDateID e7 = new ESQLDateID(sid);
EDSQLDateID e8 = new EDSQLDateID(e7);
em.persist(e7);
em.persist(e8);
}
}
em.getTransaction().begin();
em.getTransaction().commit();
em.close();
}
public void testDerivedIdentity() {
EntityManager em = emf.createEntityManager();
Query query = null;
String str[] = {
"select e from EDDateID e",
"select e from EDBigDecimalID e",
"select e from EDBigIntegerID e",
"select e from EDSQLDateID e",
"select e from EDDateID e join fetch e.rid",
"select e from EDBigDecimalID e join fetch e.rid",
"select e from EDBigIntegerID e join fetch e.rid",
"select e from EDSQLDateID e join fetch e.rid",
};
for (int i = 0; i < str.length; i++) {
query = em.createQuery(str[i]);
List rs = query.getResultList();
assertTrue(rs.size() > 0);
for (int j = 0; j < rs.size(); j++) {
Object e = rs.get(j);
String name = null;
Object oid = null;
if (e instanceof EDDateID) {
name = ((EDDateID)e).getName();
oid = ((EDDateID)e).getRid().getId();
} else if (e instanceof EDBigDecimalID) {
name = ((EDBigDecimalID)e).getName();
oid = ((EDBigDecimalID)e).getRid().getId();
} else if (e instanceof EDBigIntegerID) {
name = ((EDBigIntegerID)e).getName();
oid = ((EDBigIntegerID)e).getRid().getId();
} else if (e instanceof EDSQLDateID) {
name = ((EDSQLDateID)e).getName();
oid = ((EDSQLDateID)e).getRid().getId();
}
//System.out.println(name);
//System.out.println(oid.toString());
assertTrue(name.startsWith("Rel"));
}
}
em.close();
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.openjpa.persistence.derivedid;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
public class TestDerivedIdentity extends SQLListenerTestCase {
public void setUp() {
setUp(EBigDecimalID.class, EDBigDecimalID.class,
EBigIntegerID.class, EDBigIntegerID.class,
EDateID.class, EDDateID.class,
ESQLDateID.class, EDSQLDateID.class,
CLEAR_TABLES);
populate();
}
public void populate() {
EntityManager em = emf.createEntityManager();
for (int i = 0; i < 2; i++) {
long time = (long) (System.currentTimeMillis() / 1000)+i*1317;
BigDecimal did = new BigDecimal(time);
EBigDecimalID e1 = new EBigDecimalID(did);
EDBigDecimalID e2 = new EDBigDecimalID(e1);
em.persist(e1);
em.persist(e2);
int time2 = (int) (System.currentTimeMillis() / 1000)+i*7131;
BigInteger iid = new BigInteger(Integer.toString(time2));
EBigIntegerID e3 = new EBigIntegerID(iid);
EDBigIntegerID e4 = new EDBigIntegerID(e3);
em.persist(e3);
em.persist(e4);
Date id = new Date(time);
EDateID e5 = new EDateID(id);
EDDateID e6 = new EDDateID(e5);
em.persist(e5);
em.persist(e6);
if (i == 0) {
java.sql.Date sid = new java.sql.Date(time);
ESQLDateID e7 = new ESQLDateID(sid);
EDSQLDateID e8 = new EDSQLDateID(e7);
em.persist(e7);
em.persist(e8);
}
}
em.getTransaction().begin();
em.getTransaction().commit();
em.close();
}
public void testDerivedIdentity() {
EntityManager em = emf.createEntityManager();
Query query = null;
String str[] = {
"select e from EDDateID e",
"select e from EDBigDecimalID e",
"select e from EDBigIntegerID e",
"select e from EDSQLDateID e",
"select e from EDDateID e join fetch e.rid",
"select e from EDBigDecimalID e join fetch e.rid",
"select e from EDBigIntegerID e join fetch e.rid",
"select e from EDSQLDateID e join fetch e.rid",
};
for (int i = 0; i < str.length; i++) {
query = em.createQuery(str[i]);
List rs = query.getResultList();
assertTrue(rs.size() > 0);
for (int j = 0; j < rs.size(); j++) {
Object e = rs.get(j);
String name = null;
Object oid = null;
if (e instanceof EDDateID) {
name = ((EDDateID)e).getName();
oid = ((EDDateID)e).getRid().getId();
} else if (e instanceof EDBigDecimalID) {
name = ((EDBigDecimalID)e).getName();
oid = ((EDBigDecimalID)e).getRid().getId();
} else if (e instanceof EDBigIntegerID) {
name = ((EDBigIntegerID)e).getName();
oid = ((EDBigIntegerID)e).getRid().getId();
} else if (e instanceof EDSQLDateID) {
name = ((EDSQLDateID)e).getName();
oid = ((EDSQLDateID)e).getRid().getId();
}
//System.out.println(name);
//System.out.println(oid.toString());
assertTrue(name.startsWith("Rel"));
}
}
em.close();
}
}