use of com.manydesigns.portofino.model.database.Table in project Portofino by ManyDesigns.
the class SessionFactoryBuilder method mapOneToMany.
protected void mapOneToMany(ForeignKey foreignKey) throws NotFoundException, CannotCompileException {
CtClass cc = getMappedClass(foreignKey.getToTable());
ClassFile ccFile = cc.getClassFile();
ConstPool constPool = ccFile.getConstPool();
Table fromTable = foreignKey.getFromTable();
CtField field = new CtField(classPool.get(List.class.getName()), foreignKey.getActualManyPropertyName(), cc);
String referencedClassName = getMappedClassName(fromTable);
field.setGenericSignature("Ljava/util/List<L" + referencedClassName.replace('.', '/') + ";>;");
cc.addField(field);
AnnotationsAttribute fieldAnnotations = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
Annotation annotation;
annotation = new Annotation(OneToMany.class.getName(), constPool);
annotation.addMemberValue("targetEntity", new ClassMemberValue(referencedClassName, constPool));
annotation.addMemberValue("mappedBy", new StringMemberValue(foreignKey.getActualOnePropertyName(), constPool));
// TODO cascade?
finalizeRelationshipProperty(cc, field, annotation, fieldAnnotations);
}
use of com.manydesigns.portofino.model.database.Table in project Portofino by ManyDesigns.
the class SessionFactoryBuilder method deriveMappedClassName.
@NotNull
public static String deriveMappedClassName(Table table, EntityMode entityMode) {
String packageName = table.getSchema().getQualifiedName().toLowerCase();
String className = table.getActualEntityName();
if (entityMode == EntityMode.POJO) {
className = toJavaLikeName(className);
} else {
className = className.replaceAll("-|\\h", "");
}
if (Character.isDigit(className.charAt(0))) {
className = "_" + className;
}
String fullName = packageName + "." + className;
if (entityMode == EntityMode.POJO) {
fullName = ensureValidJavaName(fullName);
}
for (Table other : table.getSchema().getDatabase().getAllTables()) {
if (other != table && other.getActualJavaClass() != null && other.getActualJavaClass().getName().equals(fullName)) {
fullName += "_1";
}
}
return fullName;
}
use of com.manydesigns.portofino.model.database.Table in project Portofino by ManyDesigns.
the class CrudActionTest method setupJPetStore.
protected void setupJPetStore() throws Exception {
Session session = persistence.getSession("jpetstore");
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("sql/jpetstore-postgres-schema.sql"));
RunScript.execute(connection, reader);
reader = new InputStreamReader(getClass().getResourceAsStream("sql/jpetstore-postgres-dataload.sql"));
RunScript.execute(connection, reader);
}
});
session.getTransaction().commit();
persistence.syncDataModel("jpetstore");
// Table ordersTable = DatabaseLogic.findTableByName(persistence.getModel(), "jpetstore", "PUBLIC", "ORDERS");
// ordersTable.getPrimaryKey().getPrimaryKeyColumns().get(0).setGenerator(new TableGenerator());
Table supplierTable = DatabaseLogic.findTableByName(persistence.getModel(), "jpetstore", "PUBLIC", "SUPPLIER");
supplierTable.getPrimaryKey().getPrimaryKeyColumns().get(0).setGenerator(new IncrementGenerator());
// Table testTable = DatabaseLogic.findTableByName(persistence.getModel(), "jpetstore", "PUBLIC", "TEST");
// testTable.getPrimaryKey().getPrimaryKeyColumns().get(0).setGenerator(new SequenceGenerator());
}
use of com.manydesigns.portofino.model.database.Table in project Portofino by ManyDesigns.
the class UsersAction method createApplication.
@Path("/check-wizard")
@POST
public boolean createApplication(WizardInfo wizard) throws Exception {
Table userTable = UpstairsAction.getTable(persistence.getModel(), wizard.usersTable);
if (userTable == null) {
return true;
}
Column userPasswordColumn = UpstairsAction.getColumn(userTable, wizard.userPasswordProperty);
if (userPasswordColumn == null) {
return true;
}
if (userPasswordColumn.getActualJavaType() != String.class) {
RequestMessages.addErrorMessage("The type of the password column, " + userPasswordColumn.getColumnName() + ", is not string: " + userPasswordColumn.getActualJavaType().getSimpleName());
return false;
}
if (userPasswordColumn.getLength() < 32) {
// TODO: would make sense to conditionalize this on the encryption algorithm + encoding combination
RequestMessages.addErrorMessage("The length of the password column, " + userPasswordColumn.getColumnName() + ", is less than 32: " + userPasswordColumn.getLength());
return false;
}
return true;
}
Aggregations