Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAA-600: Started implementation of KAA-600.
- Loading branch information
Igor Khanenko
committed
Nov 10, 2015
1 parent
e3655cd
commit b98e402
Showing
12 changed files
with
369 additions
and
60 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
server/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/CTLSchemaDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.kaaproject.kaa.server.common.dao.impl; | ||
|
||
public interface CTLSchemaDao<T> extends SqlDao<T> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ao/src/main/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.kaaproject.kaa.server.common.dao.impl.sql; | ||
|
||
import org.hibernate.LockMode; | ||
import org.hibernate.LockOptions; | ||
import org.hibernate.Session; | ||
import org.kaaproject.kaa.server.common.dao.impl.CTLSchemaDao; | ||
import org.kaaproject.kaa.server.common.dao.model.sql.CTLSchema; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class HibernateCTLSchemaDao extends HibernateAbstractDao<CTLSchema> implements CTLSchemaDao<CTLSchema> { | ||
|
||
LockOptions lockOptions = new LockOptions(LockMode.PESSIMISTIC_WRITE); | ||
|
||
@Override | ||
public CTLSchema save(CTLSchema o) { | ||
Session session = getSession(); | ||
CTLSchema t = (CTLSchema) session.merge(o); | ||
session.flush(); | ||
return t; | ||
} | ||
|
||
@Override | ||
protected Class<CTLSchema> getEntityClass() { | ||
return CTLSchema.class; | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
...er/common/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package org.kaaproject.kaa.server.common.dao.model.sql; | ||
|
||
import org.kaaproject.kaa.common.dto.CTLSchemaDto; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.ForeignKey; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.JoinTable; | ||
import javax.persistence.ManyToMany; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
import javax.persistence.UniqueConstraint; | ||
import java.io.Serializable; | ||
import java.util.Set; | ||
|
||
@Entity | ||
@Table(name = "ctl", uniqueConstraints = | ||
@UniqueConstraint(columnNames = {"version", "fqn", "tenant_id"}, name = "ctl_unique_constraint")) | ||
public class CTLSchema extends GenericModel<CTLSchemaDto> implements Serializable { | ||
|
||
private Integer version; | ||
private String fqn; | ||
@ManyToOne(optional = true, fetch = FetchType.EAGER) | ||
@JoinColumn(nullable = true, name = "tenant_id", foreignKey = @ForeignKey(name = "fk_ctl_tenant_id")) | ||
private Tenant tenant; | ||
@Enumerated(EnumType.STRING) | ||
private CTLSchemaScope scope; | ||
@ManyToOne(optional = true, fetch = FetchType.EAGER) | ||
@JoinColumn(nullable = true, name = "app_id", foreignKey = @ForeignKey(name = "fk_ctl_app_id")) | ||
private Application application; | ||
private String body; | ||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) | ||
@JoinTable(name = "ctl_dependency", | ||
joinColumns = {@JoinColumn(name = "parent_id")}, foreignKey = @ForeignKey(name = "fk_ctl_pr_id"), | ||
inverseJoinColumns = {@JoinColumn(name = "child_id")}, inverseForeignKey = @ForeignKey(name = "fk_ctl_ch_id")) | ||
private Set<CTLSchema> dependencySet; | ||
|
||
public Integer getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(Integer version) { | ||
this.version = version; | ||
} | ||
|
||
public String getFqn() { | ||
return fqn; | ||
} | ||
|
||
public void setFqn(String fqn) { | ||
this.fqn = fqn; | ||
} | ||
|
||
public Tenant getTenant() { | ||
return tenant; | ||
} | ||
|
||
public void setTenant(Tenant tenant) { | ||
this.tenant = tenant; | ||
} | ||
|
||
public CTLSchemaScope getScope() { | ||
return scope; | ||
} | ||
|
||
public void setScope(CTLSchemaScope scope) { | ||
this.scope = scope; | ||
} | ||
|
||
public Application getApplication() { | ||
return application; | ||
} | ||
|
||
public void setApplication(Application application) { | ||
this.application = application; | ||
} | ||
|
||
public String getBody() { | ||
return body; | ||
} | ||
|
||
public void setBody(String body) { | ||
this.body = body; | ||
} | ||
|
||
public Set<CTLSchema> getDependencySet() { | ||
return dependencySet; | ||
} | ||
|
||
public void setDependencySet(Set<CTLSchema> dependencySet) { | ||
this.dependencySet = dependencySet; | ||
} | ||
|
||
@Override | ||
protected CTLSchemaDto createDto() { | ||
return new CTLSchemaDto(); | ||
} | ||
|
||
@Override | ||
public CTLSchemaDto toDto() { | ||
CTLSchemaDto ctlSchemaDto = createDto(); | ||
return ctlSchemaDto; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...mmon/dao/src/main/java/org/kaaproject/kaa/server/common/dao/model/sql/CTLSchemaScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.kaaproject.kaa.server.common.dao.model.sql; | ||
|
||
public enum CTLSchemaScope { | ||
SYSTEM, TENANT, APPLICATION, PLUGIN; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...rc/test/java/org/kaaproject/kaa/server/common/dao/impl/sql/HibernateCTLSchemaDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.kaaproject.kaa.server.common.dao.impl.sql; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.kaaproject.kaa.server.common.dao.model.sql.CTLSchema; | ||
import org.kaaproject.kaa.server.common.dao.model.sql.CTLSchemaScope; | ||
import org.kaaproject.kaa.server.common.dao.model.sql.Tenant; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.annotation.Rollback; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.UUID; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(locations = "/common-dao-test-context.xml") | ||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) | ||
@Transactional | ||
public class HibernateCTLSchemaDaoTest extends HibernateAbstractTest { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(HibernateCTLSchemaDaoTest.class); | ||
|
||
private ExecutorService executorService = Executors.newFixedThreadPool(10); | ||
private Tenant tenant; | ||
|
||
@Before | ||
@Rollback(false) | ||
public void go() { | ||
if (tenant == null) { | ||
tenant = generateTenant(); | ||
} | ||
} | ||
|
||
@After | ||
public void afterTest() throws InterruptedException { | ||
LOG.debug("If sdsfsddf"); | ||
} | ||
|
||
@Test | ||
@Rollback(false) | ||
public void saveCTLSchema() throws InterruptedException { | ||
ctlSchemaDao.save(generateCTLSchema(tenant)); | ||
ctlSchemaDao.save(generateCTLSchema(generateTenant())); | ||
} | ||
|
||
@Test | ||
@Rollback(false) | ||
public void multiThreadCTLSchemaSaveTest() throws InterruptedException { | ||
for (int i = 0; i < 100; i++) { | ||
executorService.submit(new Runnable() { | ||
@Override | ||
public void run() { | ||
ctlSchemaDao.save(generateCTLSchema(generateTenant())); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
private CTLSchema generateCTLSchema(Tenant tenant) { | ||
CTLSchema ctlSchema = new CTLSchema(); | ||
ctlSchema.setBody(UUID.randomUUID().toString()); | ||
ctlSchema.setVersion(1); | ||
ctlSchema.setTenant(tenant); | ||
ctlSchema.setFqn("org.kaaproject.kaa.ctl.TestSchema"); | ||
ctlSchema.setScope(CTLSchemaScope.SYSTEM); | ||
return ctlSchema; | ||
} | ||
} |
Oops, something went wrong.