use of com.codename1.rad.models.Property.Description in project CodenameOne by codenameone.
the class SQLMap method select.
/**
* Fetches the components from the database matching the given cmp description, the fields that aren't
* null within the cmp will match the where clause
* @param cmp the component to match
* @param orderBy the column to order by, can be null to ignore order
* @param ascending true to indicate ascending order
* @param maxElements the maximum number of elements returned can be 0 or lower to ignore
* @param page the page within the query to match the max elements value
* @return the result of the query
*/
public java.util.List<PropertyBusinessObject> select(PropertyBusinessObject cmp, Property orderBy, boolean ascending, int maxElements, int page) throws IOException, InstantiationException {
String tableName = getTableName(cmp);
StringBuilder createStatement = new StringBuilder("SELECT * FROM ");
createStatement.append(tableName);
ArrayList<Object> params = new ArrayList<Object>();
createStatement.append(" WHERE ");
boolean found = false;
for (PropertyBase p : cmp.getPropertyIndex()) {
if (p instanceof Property) {
if (((Property) p).get() != null) {
if (found) {
createStatement.append(" AND ");
}
found = true;
params.add(((Property) p).get());
createStatement.append(getColumnName(p));
createStatement.append(" = ?");
}
}
}
// all properties are null undo the where append
if (!found) {
createStatement = new StringBuilder("SELECT * FROM ");
createStatement.append(tableName);
}
if (orderBy != null) {
createStatement.append(" ORDER BY ");
createStatement.append(getColumnName(orderBy));
if (!ascending) {
createStatement.append(" DESC");
}
}
if (maxElements > 0) {
createStatement.append(" LIMIT ");
createStatement.append(maxElements);
if (page > 0) {
createStatement.append(" OFFSET ");
createStatement.append(page * maxElements);
}
}
Cursor c = null;
try {
ArrayList<PropertyBusinessObject> response = new ArrayList<PropertyBusinessObject>();
c = executeQuery(createStatement.toString(), params.toArray());
while (c.next()) {
PropertyBusinessObject pb = (PropertyBusinessObject) cmp.getClass().newInstance();
for (PropertyBase p : pb.getPropertyIndex()) {
Row currentRow = c.getRow();
SqlType t = getSqlType(p);
if (t == SqlType.SQL_EXCLUDE) {
continue;
}
Object value = t.getValue(currentRow, c.getColumnIndex(getColumnName(p)), p);
if (p instanceof Property) {
((Property) p).set(value);
}
}
response.add(pb);
}
c.close();
return response;
} catch (Throwable t) {
Log.e(t);
if (c != null) {
c.close();
}
if (t instanceof IOException) {
throw ((IOException) t);
} else {
throw new IOException(t.toString());
}
}
}
use of com.codename1.rad.models.Property.Description in project CodenameOne by codenameone.
the class SQLMap method selectImpl.
/**
* Fetches the components from the database matching the given cmp description, the fields that aren't
* null within the cmp will match the where clause
* @param not indicates if the query should be a "not" query
* @param cmp the component to match
* @param orderBy the column to order by, can be null to ignore order
* @param ascending true to indicate ascending order
* @param maxElements the maximum number of elements returned can be 0 or lower to ignore
* @param page the page within the query to match the max elements value
* @return the result of the query
*/
private java.util.List<PropertyBusinessObject> selectImpl(boolean not, PropertyBusinessObject cmp, Property orderBy, boolean ascending, int maxElements, int page) throws IOException, InstantiationException {
String tableName = getTableName(cmp);
StringBuilder createStatement = new StringBuilder("SELECT * FROM ");
createStatement.append(tableName);
ArrayList<Object> params = new ArrayList<Object>();
createStatement.append(" WHERE ");
boolean found = false;
for (PropertyBase p : cmp.getPropertyIndex()) {
if (p instanceof Property) {
if (((Property) p).get() != null) {
if (found) {
createStatement.append(" AND ");
}
found = true;
params.add(((Property) p).get());
createStatement.append(getColumnName(p));
if (not) {
createStatement.append(" <> ?");
} else {
createStatement.append(" = ?");
}
}
}
}
// all properties are null undo the where append
if (!found) {
createStatement = new StringBuilder("SELECT * FROM ");
createStatement.append(tableName);
}
if (orderBy != null) {
createStatement.append(" ORDER BY ");
createStatement.append(getColumnName(orderBy));
if (!ascending) {
createStatement.append(" DESC");
}
}
if (maxElements > 0) {
createStatement.append(" LIMIT ");
createStatement.append(maxElements);
if (page > 0) {
createStatement.append(" OFFSET ");
createStatement.append(page * maxElements);
}
}
Cursor c = null;
try {
ArrayList<PropertyBusinessObject> response = new ArrayList<PropertyBusinessObject>();
c = executeQuery(createStatement.toString(), params.toArray());
while (c.next()) {
PropertyBusinessObject pb = (PropertyBusinessObject) cmp.getClass().newInstance();
for (PropertyBase p : pb.getPropertyIndex()) {
Row currentRow = c.getRow();
SqlType t = getSqlType(p);
if (t == SqlType.SQL_EXCLUDE) {
continue;
}
Object value = t.getValue(currentRow, c.getColumnIndex(getColumnName(p)), p);
if (p instanceof Property) {
((Property) p).set(value);
}
}
response.add(pb);
}
c.close();
return response;
} catch (Throwable t) {
Log.e(t);
if (c != null) {
c.close();
}
if (t instanceof IOException) {
throw ((IOException) t);
} else {
throw new IOException(t.toString());
}
}
}
use of com.codename1.rad.models.Property.Description in project CodenameOne by codenameone.
the class SQLMap method selectImpl.
/**
* Fetches the components from the database matching the given cmp description, the fields that aren't
* null within the cmp will match the where clause
* @param where the where statement
* @param propertyClass the class of the property business object
* @param params the parameters to use in the where statement
* @param orderBy the column to order by, can be null to ignore order
* @param ascending true to indicate ascending order
* @param maxElements the maximum number of elements returned can be 0 or lower to ignore
* @param page the page within the query to match the max elements value
* @return the result of the query
*/
private java.util.List<PropertyBusinessObject> selectImpl(PropertyBusinessObject cmp, String where, Class propertyClass, Object[] params, Property orderBy, boolean ascending, int maxElements, int page) throws IOException, InstantiationException {
String tableName = getTableName(cmp);
StringBuilder createStatement = new StringBuilder("SELECT * FROM ");
createStatement.append(tableName);
if (where != null && where.length() > 0) {
if (!where.toUpperCase().startsWith(" WHERE ")) {
createStatement.append(" WHERE ");
}
createStatement.append(where);
}
if (orderBy != null) {
createStatement.append(" ORDER BY ");
createStatement.append(getColumnName(orderBy));
if (!ascending) {
createStatement.append(" DESC");
}
}
if (maxElements > 0) {
createStatement.append(" LIMIT ");
createStatement.append(maxElements);
if (page > 0) {
createStatement.append(" OFFSET ");
createStatement.append(page * maxElements);
}
}
Cursor c = null;
try {
ArrayList<PropertyBusinessObject> response = new ArrayList<PropertyBusinessObject>();
c = executeQuery(createStatement.toString(), params);
while (c.next()) {
PropertyBusinessObject pb = (PropertyBusinessObject) propertyClass.newInstance();
for (PropertyBase p : pb.getPropertyIndex()) {
Row currentRow = c.getRow();
SqlType t = getSqlType(p);
if (t == SqlType.SQL_EXCLUDE) {
continue;
}
Object value = t.getValue(currentRow, c.getColumnIndex(getColumnName(p)), p);
if (p instanceof Property) {
((Property) p).set(value);
}
}
response.add(pb);
}
c.close();
return response;
} catch (Throwable t) {
Log.e(t);
if (c != null) {
c.close();
}
if (t instanceof IOException) {
throw ((IOException) t);
} else {
throw new IOException(t.toString());
}
}
}
use of com.codename1.rad.models.Property.Description in project CodenameOne by codenameone.
the class GenerateArchetypeFromTemplateMojo method generateBaseArchetype.
private File generateBaseArchetype(String string, File templateFile) throws TemplateParseException, IOException {
Dependency out = new Dependency();
String archetype = extractSectionFrom(string, "archetype");
Properties props = new Properties();
props.load(new StringReader(archetype));
String[] requiredProperties = new String[] { "artifactId", "groupId", "version" };
for (String key : requiredProperties) {
if (!props.containsKey(key)) {
throw new TemplateParseException("archetype property " + key + " required and missing. Make sure it is defined in the [archetype] section of the template");
}
}
File dest = new File(outputDir, props.getProperty("artifactId"));
if (dest.exists()) {
if (overwrite) {
FileUtils.deleteDirectory(dest);
} else {
throw new IOException("Project already exists at " + dest + ". Delete this project before regenerating");
}
}
String base = props.getProperty("extends", null);
if (base == null) {
throw new TemplateParseException("[archetype] section requires the 'extends' property to specify the path to the archetype project that this extends");
}
baseArchetypeDir = new File(base);
if (!baseArchetypeDir.isAbsolute()) {
baseArchetypeDir = new File(templateFile.getParentFile(), base);
}
if (!baseArchetypeDir.exists()) {
throw new IOException("Cannot find archetype project that this template extends. Looking for it in " + baseArchetypeDir);
}
if (!new File(baseArchetypeDir, "pom.xml").exists()) {
throw new IOException("Base archetype directory " + baseArchetypeDir + " is not a maven project.");
}
FileUtils.copyDirectory(baseArchetypeDir, dest);
File pomFile = new File(dest, "pom.xml");
String groupId = null;
String artifactId = null;
String version = null;
if (props.containsKey("id")) {
String id = props.getProperty("id");
String[] parts = id.split(":");
if (parts.length != 3) {
throw new TemplateParseException("Failed ot parse id property in [archetype] section. It should be in the format groupId:artifactId:version");
}
groupId = parts[0];
artifactId = parts[1];
version = parts[2];
}
groupId = props.getProperty("groupId", groupId);
artifactId = props.getProperty("artifactId", artifactId);
version = props.getProperty("version", version);
if (groupId == null || artifactId == null || version == null) {
throw new TemplateParseException("The [archetype] section is required, and must have at least groupId, artifactId, and version defined. You may also define these using the id property in the format groupId:artifactId:version");
}
String parentTag = "";
String parentGroupId = null;
String parentArtifactId = null;
String parentVersion = null;
if (props.containsKey("parent")) {
String parent = props.getProperty("parent");
String[] parts = parent.split(":");
if (parts.length != 3) {
throw new TemplateParseException("Failed to parse parent property in [archetype] section. It should be in the format groupId:artifactId:version");
}
parentGroupId = parts[0];
parentArtifactId = parts[1];
parentVersion = parts[2];
}
parentGroupId = props.getProperty("parentGroupId", parentGroupId);
parentArtifactId = props.getProperty("parentArtifactId", parentArtifactId);
parentVersion = props.getProperty("parentVersion", parentVersion);
if (parentGroupId != null && parentVersion != null && parentArtifactId != null) {
parentTag = " <parent>\n" + " <groupId>" + parentGroupId + "</groupId>\n" + " <artifactId>" + parentArtifactId + "</artifactId>\n" + " <version>" + parentVersion + "</version>\n" + " </parent>\n";
}
String pomContents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + " <modelVersion>4.0.0</modelVersion>\n" + parentTag + " <groupId>" + groupId + "</groupId>\n" + " <artifactId>" + artifactId + "</artifactId>\n" + " <version>" + version + "</version>\n" + " <packaging>maven-archetype</packaging>\n" + "\n" + " <name>" + artifactId + "</name>\n" + "\n" + "\n" + " <build>\n" + " <extensions>\n" + " <extension>\n" + " <groupId>org.apache.maven.archetype</groupId>\n" + " <artifactId>archetype-packaging</artifactId>\n" + " <version>3.2.0</version>\n" + " </extension>\n" + " </extensions>\n" + "\n" + " <pluginManagement>\n" + " <plugins>\n" + " <plugin>\n" + " <artifactId>maven-archetype-plugin</artifactId>\n" + " <version>3.2.0</version>\n" + " </plugin>\n" + " </plugins>\n" + " </pluginManagement>\n" + " </build>\n" + "\n" + " <description>Artifact generated using the cn1:generate-archetype goal</description>\n" + "\n" + " <url>https://www.codenameone.com</url>\n" + "\n" + " <licenses>\n" + " <license>\n" + " <name>GPL v2 With Classpath Exception</name>\n" + " <url>https://openjdk.java.net/legal/gplv2+ce.html</url>\n" + " <distribution>repo</distribution>\n" + " <comments>A business-friendly OSS license</comments>\n" + " </license>\n" + " </licenses>\n" + "</project>\n";
FileUtils.writeStringToFile(pomFile, pomContents, "UTF-8");
return dest;
}
use of com.codename1.rad.models.Property.Description in project CodenameOne by codenameone.
the class SafeAreasSample method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World", new BorderLayout());
Tabs tabs = new Tabs();
Container tab1Contents = new Container();
tab1Contents.setLayout(BoxLayout.y());
tab1Contents.setScrollableY(true);
Button openDialog = new Button("Open Dialog");
openDialog.addActionListener(evt -> {
Dialog.show("Test Dialog", "Test", "OK", null);
});
tab1Contents.add(openDialog);
tab1Contents.setSafeArea(true);
String[] names = new String[] { "John", "Mary", "Joseph", "Solomon", "Jan", "Judy", "Patricia", "Ron", "Harry" };
String[] positions = new String[] { "Wizard", "Judge", "Doctor" };
int len = names.length;
for (int i = 0; i < len; i++) {
MultiButton btn = new MultiButton(names[i]);
btn.setTextLine2(positions[i % positions.length]);
tab1Contents.add(btn);
}
Container tab2Contents = new Container();
tab2Contents.setLayout(BoxLayout.y());
tab2Contents.setScrollableY(true);
for (int i = 0; i < len; i++) {
MultiButton btn = new MultiButton(names[i]);
btn.setTextLine2(positions[i % positions.length]);
tab2Contents.add(btn);
}
String description = "This Demo shows the use of safeArea to ensure that a container's children are not covered by the notch on iPhone X. You should run this demo using the iPhone X skin or iPhone X device to see the difference.\n\n" + "The Safe tab uses setSafeArea(true) to ensure that the children are not affected by the notch. The unsafe tab is not. \n\n" + "You'll need to use landscape mode to see the difference because the notch will be on the left or right in that case.";
SpanLabel spanLabel = new SpanLabel(description);
spanLabel.setSafeArea(true);
tabs.addTab("Description", spanLabel);
tabs.addTab("Safe Tab", tab1Contents);
tabs.addTab("Unsafe Tab", tab2Contents);
hi.add(BorderLayout.CENTER, tabs);
hi.show();
}
Aggregations